Golden Rule

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Golden Rule

Post by neilbaldwin »

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.

:oops:
Drag
Posts: 1350
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Post by Drag »

I tend to have seperate variables for NMI and the main program for this reason. :P
Jaffe
Posts: 48
Joined: Sun May 14, 2006 10:26 am
Location: Norway

Post by Jaffe »

Been there done that....
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

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.
doppelganger
Posts: 183
Joined: Tue Apr 05, 2005 7:30 pm

Post by doppelganger »

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.
Be whatever the situation demands.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

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.
Post Reply