Even though I make sure I always turn off PPU after NMI, I still have scroll showing garbage from the other nametable for one frame (in Mesen).
I wait for NMI using standard approach with the flag
I set this flag at the end of the NMI (and reset scroll at the end of NMI as that helped me with some glitches).
In "ppu_Off" code I reset the flag in case we are past v-blank and wait for NMI again.
What am I doing wrong? Should I do something before/after putting #0 into the PPU_MASK?
Thank you
I wait for NMI using standard approach with the flag
Code:
.proc ppu_WaitForNmiDone
@forever:
lda ppu_nmi_done ; Execute main loop once per frame
beq @forever
lda #0
sta ppu_nmi_done ; Reset the flag
rts
.endproc
@forever:
lda ppu_nmi_done ; Execute main loop once per frame
beq @forever
lda #0
sta ppu_nmi_done ; Reset the flag
rts
.endproc
I set this flag at the end of the NMI (and reset scroll at the end of NMI as that helped me with some glitches).
Code:
nmi:
pushseg
; Write to OAM DMA
lda ppu_needOam
beq @oamEnd
mova ppu_needOam, #0 ; reset OAM flag
lda #<ppu_oam
sta PPU_SPR_ADDR
lda #>ppu_oam
sta APU_SPR_DMA
@oamEnd:
; Fix scroll
mova PPU_SCROLL, ppu_scrollx
mova PPU_SCROLL, ppu_scrolly
@end:
lda #1
sta ppu_nmi_done
popseg
rti
pushseg
; Write to OAM DMA
lda ppu_needOam
beq @oamEnd
mova ppu_needOam, #0 ; reset OAM flag
lda #<ppu_oam
sta PPU_SPR_ADDR
lda #>ppu_oam
sta APU_SPR_DMA
@oamEnd:
; Fix scroll
mova PPU_SCROLL, ppu_scrollx
mova PPU_SCROLL, ppu_scrolly
@end:
lda #1
sta ppu_nmi_done
popseg
rti
In "ppu_Off" code I reset the flag in case we are past v-blank and wait for NMI again.
Code:
.proc ppu_Off
lda #0 ; reset nmi flag
sta ppu_nmi_done
jsr ppu_WaitForNmiDone
lda #0
sta ppu_needOam
lda #0
sta PPU_MASK
rts
.endproc
lda #0 ; reset nmi flag
sta ppu_nmi_done
jsr ppu_WaitForNmiDone
lda #0
sta ppu_needOam
lda #0
sta PPU_MASK
rts
.endproc
What am I doing wrong? Should I do something before/after putting #0 into the PPU_MASK?
Thank you