This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Golden Rule

Golden Rule
by on (#53790)
Don't modify temporary variables in your NMI.

Just don't.

Failure to observe this rule can lead to many, many wasted hours trying to track down a really, really tricky bug.


by on (#53791)
I tend to have seperate variables for NMI and the main program for this reason. :P

by on (#53792)
Been there done that....

by on (#53797)
I have separate variables for the NMI and IRQ most of the time too. In the NMI I only change variables that are otherwise controlled by the main thread when the game frame was flagged as complete, meaning that the main thread is doing nothing but waiting for the NMI, and it expects the variables to be changed.

by on (#53802)
Very good, but I'd like to propose an addendum: if you absolutely must use the temp variables in an NMI, push them to the stack first, remembering to pull them in reverse order afterwards.

by on (#53807)
I absolutely agree with this golden rule! I have temp variables separate for my main and NMI loops. I don't usually do anything with IRQs, so I don't have temp variables for that. My math routines are all designed to work with Main's temp vars, so if I have to use those in the NMI routine (which I shouldn't, because all calculations should really be done in Main), I just load the temp vars and push them to the stack.