65024U wrote:If your testing on a actual system, this wouldn't work. At least according to the Wiki, so a test on real hardware might be able to say more definitively.
I'm only using emulators but some day I would like to run my code on a real NES.
Bregalad wrote:I guess Final Fantasy would have a very low probability to crash when reseted on a FC.... If you hit the reset button at a time that the game is not in it's iddle loop, and that you are able to release the reset button a few cycles before a NMI triggers, the game will crash.
I would prefer my code to be deterministic but I guess I can live with that
blargg wrote:Let's say that NMI is enabled when your reset handler begins. This means that NMI could occur immediately after the first instruction, even if you disabled it there with something like LSR $2000. So writing 0 to $2001 just after reset is just making this less likely. Making bugs less likely seems like a bad idea, becuase it makes them harder to find during development. It seems that the hardware must disable NMI, or else there's no way to prevent this from occurring.
So should the write to $2000 be removed from the init code (replaced with a comment saying that "this can't happen") or should it be kept "just in case" (and maybe include it only in release builds)? Something like:
Code: Select all
reset:
sei
; Keep this write as close to reset as possible.
; It does absolutely nothing if the NMIs are disabled on reset
; (the sane scenario) but it reduces the chance of a crash
; if they're not.
.ifdef RELEASE
lsr $2000 ; Let's hope for the best. Btw, nice trick with the lsr.
.endif
ldx #$FF
txs
; ...
I'm just trying to write the best reset routine possible (and never touch this code again

) but none of the tutorials I've read addresses the fact that NMIs might be enabled after reset and/or writes to PPU registers might be ignored (I've read most of the wiki,
Nerdy Nights,
NES 101 and some code posted here on NesDev - if there is a tutorial that explains this I would appreciate if someone could post a link).
It might not seem that important/interesting (and it probably isn't

) but for me it's like an itch that just won't go away
