Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gameLoop: ; all RESET/POWER-ON/one-time code is above this.
- inc sleeping ; set "sleeping" variable to 1
- waitNmiEnd:
- lda sleeping
- bne waitNmiEnd ; infinite loop until "sleeping" is 0 (set by NMI)
- ; this ensures the game loop executes 1 per frame
- ; game code
- ldx $0204
- inx ; move a sprite y-pos by 1
- stx $0204
- jmp gameLoop ; done with 1 frame of game logic loop back to top and wait for next frame
- nmi: ; at ANY MOMENT the PPU will literally *interrupt* any line of the game loop above
- pha
- tya
- pha
- txa
- pha ; push all registers on stack so we can pop them off later
- ; this is important b/c the game loop could have been right in the middle of using them (potentially)
- ; NMI code here
- lda #$00
- sta $2003
- lda #$02
- sta $4014 ; redraw sprite OAM
- ; End NMI code
- lda #$00
- sta sleeping ; set sleeping variable to 0 to tell game loop we did our draw updates during VBLANK
- pla
- tax
- pla
- tay
- pla ; pop/pull register values back
- rti ; return from interrupt aka go back to game loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement