Skip to content

Instantly share code, notes, and snippets.

@niconii
Created September 10, 2018 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niconii/f2872415f2eca82b82706a9f35259673 to your computer and use it in GitHub Desktop.
Save niconii/f2872415f2eca82b82706a9f35259673 to your computer and use it in GitHub Desktop.
Example SNES main loop
reset:
; initialize everything...
main:
; update game state...
; process sprites in a copy of OAM stored in WRAM...
; other stuff...
inc ReadyFlag ; signal that we're done processing for this frame
spin:
lda ReadyFlag ; wait until flag is cleared by NMI routine
bne spin
jmp main
nmi:
; save registers...
; set A to 8-bit and XY to 16-bit...
lda ReadyFlag ; if main loop not ready, skip to end
beq nmi_end
; turn on forced blank in case we take too long
; DMA to OAM...
; update graphics...
; poll controllers...
; other stuff...
; turn off forced blank
stz ReadyFlag ; since graphics were updated, clear flag
nmi_end:
; restore registers...
rti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment