Originally posted by: sempressimo
Thanks Mega Mario Man, now I have room switching working. I do get a quick black flash when switching, I know is because I am turning on and off the PPU, just wondering if this is the standard way or if there is a way around this?
Also, if I want to update just some background tiles, like the score for example, can I just update the value in my backgrounds .db(s) directly and that is it? Or does the PPU has to be turned off for this also?
Unfortunately, you are going to get the slight moment of black as the PPU is off at that time. When trying to render that many background tiles at one time, you have to disable the PPU.
For shorter lengths, the PPU does not need to be disabled, however, you still have to load the tiles during the NMI. I do this all of the time, especially in my current game I'm writing. These is only 1 8x8 sprite in the game, and its just an arrow to point to who's turn it is.
There is a spot in the game where I write 256 tiles to the background (1/4 of the screen) and I do turn off the PPU for that.
Here is some code from my current game, I never disable the PPU for any of those .db tables:
LDA #$05
STA TEXTLENGTH ;The length of the text being written to the screen (number of characters being written)
LDA #$0E
STA TEXTLOWBYTE
LDA #$21
STA TEXTHIGBYTE
LDA #LOW(PauseText)
STA TextPointer
LDA #HIGH(PauseText)
STA TextPointer+1
JSR LoadText
--------------------------------------------------------------------------------------------
LoadText:
LDA $2002 ; read PPU status to reset the high/low latch
LDA TEXTHIGBYTE
STA $2006 ; write the high byte
LDA TEXTLOWBYTE
STA $2006 ; write the low byte
LDY #$00 ; start y out at 0
LoadTextLoop:
LDA [TextPointer], y ; load data from address (background + the value in y)
STA $2007 ; write to PPU
INY ; y = y + 1
CPY TEXTLENGTH ; Compare Y to TEXTLENGTH
BNE LoadTextLoop ; Branch to LoadTextLoop if compare was Not Equal to zero
RTS
PauseText:
.db $19,$0A,$1E,$1C,$0E ;PAUSE
UnDrawPauseText:
.db $24,$24,$24,$24,$24,$24,$24,$24 ;Undraw Pause
MissText:
.db $16,$12,$1C,$1C ;MISS
Hit1Text:
.db $11,$12,$1D,$24,$01 ;HIT 1
Hit2Text:
.db $11,$12,$1D,$24,$02 ;HIT 2
Hit3Text:
.db $11,$12,$1D,$24,$03 ;HIT 3