Skip to content

Instantly share code, notes, and snippets.

@niconii
Last active September 9, 2018 03:01
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/296c03811787f54e48723917736d5268 to your computer and use it in GitHub Desktop.
Save niconii/296c03811787f54e48723917736d5268 to your computer and use it in GitHub Desktop.
Example for clearing SNES WRAM using DMA
zero:
.db $00
; assuming A is 8-bit, X/Y are 16-bit
clear_wram:
; From fixed CPU address to IO register,
; transfer unit is one byte
lda #%00001000
sta DMAP0 ; $4300
lda #$80 ; to WRAM (via $2180)
sta BBAD0 ; $4301
ldx #zero ; from zero
stx A1T0L ; $4302-4303
lda #^zero ; bank of zero
sta A1B0 ; $4304
stz DAS0L ; transfer $10000 bytes
stz DAS0H ; $4305-$4306
stz WMADDL ; start at WRAM address $00000 ($7e0000)
stz WMADDM ; $2181-$2183
stz WMADDH
lda #%00000001 ; run DMA channel 0
sta MDMAEN ; first to clear $7e0000-$7effff...
sta MDMAEN ; then again to clear $7f0000-$7fffff
; And we're done. We'd return here, but we... kinda wiped out
; the stack in the process of clearing WRAM, so...
jmp main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment