These days I'm experimenting with the samples Blarg was nice enough to provide in a different thread in the nesdev forum and I'm very grateful.
I'm cut/pasting code here and there, see what happens, make it fail to learn more etc. All seems to be going well and now I have something showing on the screen.
But now something is puzzling me. The code bellow allow you to scroll the screen:
Everything is fine except if I comment the "enable background display" and "PPUCTRL should be rewritten with last value", everything is still going fine in an emulator (I don't have any way to test it on the real hardware yet).
My question is: why do you need these lines? Are they just code that you need to use for it to work on the real thing? I don't see why I would need to reactivate the Background/NNI flag every time unless I need to change how the background/NMI behave?
I'm cut/pasting code here and there, see what happens, make it fail to learn more etc. All seems to be going well and now I have something showing on the screen.
But now something is puzzling me. The code bellow allow you to scroll the screen:
Code:
; Waits for NMI then scrolls background to X,Y
; Preserved: X, Y
set_scroll:
; Wait for next NMI. You should NOT use wait_vbl for timing,
; since it will occasionally wait TWICE as long, causing
; scrolling to be choppy (try it and see).
jsr wait_nmi
-->; Enable background display
lda #%00001000
sta PPUMASK
-->; PPUCTRL should be rewritten with last value
lda #PPUCTRL_NMI
sta PPUCTRL
; Set X and Y scroll position
stx PPUSCROLL
sty PPUSCROLL
rts
; Preserved: X, Y
set_scroll:
; Wait for next NMI. You should NOT use wait_vbl for timing,
; since it will occasionally wait TWICE as long, causing
; scrolling to be choppy (try it and see).
jsr wait_nmi
-->; Enable background display
lda #%00001000
sta PPUMASK
-->; PPUCTRL should be rewritten with last value
lda #PPUCTRL_NMI
sta PPUCTRL
; Set X and Y scroll position
stx PPUSCROLL
sty PPUSCROLL
rts
Everything is fine except if I comment the "enable background display" and "PPUCTRL should be rewritten with last value", everything is still going fine in an emulator (I don't have any way to test it on the real hardware yet).
My question is: why do you need these lines? Are they just code that you need to use for it to work on the real thing? I don't see why I would need to reactivate the Background/NNI flag every time unless I need to change how the background/NMI behave?