llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler
https://www.llvm-mos.org
Other
266 stars 53 forks source link

[Breaking] Rework MMC1 banking. #204

Closed mysterymath closed 11 months ago

mysterymath commented 11 months ago

This makes the interface for banking on MMC1 more consistent with the other mappers.

mysterymath commented 11 months ago

@asiekierka , @jroweboy

This incorporates some of what we talked about; what's maybe new is explicitly divvying up bits as either PRG state or CHR state. CHR state gets the set/split/defer treatment we talked about, while PRG sets are always immediate, and NMI leaves them alone. I've also honed in on reliability guarantees. For the most part, all sets need to be atomic and reliable with respect to IRQs/NMIs, except splits. Splits should be fine to drop if interrupted by a NMI (they're too late in that case). The still mustn't misfire and overwrite something else. If atomicity is cheap, it may still make sense to do it there too, but it doesn't seem strictly required.

If this looks good, I intend to continue refactoring in this fashion with MMC3, then on to the other mappers (working from greatest to least familiarity). I plan to merge all these pull requests together; little point in doing it halfway.

mysterymath commented 11 months ago

I've spent a bit thinking about whether set needs to be reliable in the case of NMI; I don't think it does. See the commit message for the details.

asiekierka commented 11 months ago

I think I agree. The only situation where unreliability could cause problem is if an NMI handler calls set while the non-NMI code is in the middle of calling set; but having both NMI and non-NMI code try to change the PPU state at the same time is bad programming practice.

mysterymath commented 11 months ago

I was gonna wait on this one, but I think this needs to go in sooner rather than later. MMC1 banking was a lot more subtly broken than I thought; this is as much a set of bug fixes as it is a naming change now.