daily pastebin goal
68%
SHARE
TWEET

Untitled

puchiedarcy Jun 21st, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top