So I tried to take previous advice and separate my game logic from the NMI by having the NMI increase a counter and the main loop only processing logic once every 64 NMIs. Unfortunately, it isn't working as planned . It seems the game cycle runs more often than it should. Here's the main loop and NMI:
My guesses are the main loop still runs multiple times in between the NMIs that count to 0 and to 1. Another thing I believe is going on is the accumulator is probably getting changed in the middle of the main loop when an NMI is called, causing some trickery. In that case, does anyone have any suggestions on what is the appropriate use of each cpu register?
Code:
GameLoop:
LDA $01
CMP #$00
BNE DoNothing
JSR DoInput
DoNothing: JMP GameLoop
...
NMI:
LDX $01
INX
STX $01
CPX #$40
BNE CounterJump
LDX #$00
STX $01
CounterJump:
LDA #$00 ;Reload all the sprites
STA $2003
LDA #$02
STA $4014
RTI
LDA $01
CMP #$00
BNE DoNothing
JSR DoInput
DoNothing: JMP GameLoop
...
NMI:
LDX $01
INX
STX $01
CPX #$40
BNE CounterJump
LDX #$00
STX $01
CounterJump:
LDA #$00 ;Reload all the sprites
STA $2003
LDA #$02
STA $4014
RTI
My guesses are the main loop still runs multiple times in between the NMIs that count to 0 and to 1. Another thing I believe is going on is the accumulator is probably getting changed in the middle of the main loop when an NMI is called, causing some trickery. In that case, does anyone have any suggestions on what is the appropriate use of each cpu register?