Advertisement
puchiedarcy

Untitled

Jun 21st, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. gameLoop: ; all RESET/POWER-ON/one-time code is above this.
  2. inc sleeping ; set "sleeping" variable to 1
  3. waitNmiEnd:
  4. lda sleeping
  5. bne waitNmiEnd ; infinite loop until "sleeping" is 0 (set by NMI)
  6. ; this ensures the game loop executes 1 per frame
  7.  
  8. ; game code
  9. ldx $0204
  10. inx ; move a sprite y-pos by 1
  11. stx $0204
  12.  
  13. jmp gameLoop ; done with 1 frame of game logic loop back to top and wait for next frame
  14.  
  15. nmi: ; at ANY MOMENT the PPU will literally *interrupt* any line of the game loop above
  16. pha
  17. tya
  18. pha
  19. txa
  20. pha ; push all registers on stack so we can pop them off later
  21. ; this is important b/c the game loop could have been right in the middle of using them (potentially)
  22.  
  23. ; NMI code here
  24. lda #$00
  25. sta $2003
  26. lda #$02
  27. sta $4014 ; redraw sprite OAM
  28. ; End NMI code
  29.  
  30. lda #$00
  31. sta sleeping ; set sleeping variable to 0 to tell game loop we did our draw updates during VBLANK
  32.  
  33. pla
  34. tax
  35. pla
  36. tay
  37. pla ; pop/pull register values back
  38.  
  39. rti ; return from interrupt aka go back to game loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement