Trying to swap entire nametable
Posted: Sat Aug 12, 2017 8:02 pm
Hi all
I'm able to initialize and render my first nametable just fine (start screen), but am having trouble trying to load a second nametable upon starting the game (play screen).
Here is what I'm doing:
1. During NMI I check for the start button press during my initial game state. If this happens I set a change state flag.
2. During my 'Forever' loop, outside of NMI, I check if the change flag is set, and if so, I update my game state then disable NMI:
3. I call a subroutine to repopulate my nametable. The code to populate is the same as my initial population code of the nametable, with the only difference being my pointer points to a new nametable dataset. (planning on making this subroutine reusable later by making what the pointer points to dynamic, for testing I'm just hardcoding it).
4. Upon return of this subroutine I re-enable NMI and sprites (not using sprites at the moment)
I can tell the logic is triggering, but my screen looks like the starting nametable just got mixed around. I see one tile from nametable 2, and I still see tiles from nametable 1.
I've been doing some reading on here and have learned something like this should not happen during NMI, and NMI should be off, so curious why this fails to work.
I'm able to initialize and render my first nametable just fine (start screen), but am having trouble trying to load a second nametable upon starting the game (play screen).
Here is what I'm doing:
1. During NMI I check for the start button press during my initial game state. If this happens I set a change state flag.
2. During my 'Forever' loop, outside of NMI, I check if the change flag is set, and if so, I update my game state then disable NMI:
Code: Select all
LDA #%00000000
STA $2000
Code: Select all
LoadPlayNametable:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
LDA #LOW(PlayNametable)
STA pointerLow
LDA #HIGH(PlayNametable)
STA pointerHigh
LDX #$00
LDY #$00
LoadPlayNametableLoop:
LDA [pointerLow], y
STA $2007
INY
CPY #$00
BNE LoadPlayNametableLoop
INC pointerHigh
INX
CPX #$04
BNE LoadPlayNametableLoop
RTS
Code: Select all
LDA #%10010000
STA $2000
I've been doing some reading on here and have learned something like this should not happen during NMI, and NMI should be off, so curious why this fails to work.