Skip to content

Instantly share code, notes, and snippets.

@niconii
Last active September 9, 2018 03:01
Show Gist options
  • Select an option

  • Save niconii/296c03811787f54e48723917736d5268 to your computer and use it in GitHub Desktop.

Select an option

Save niconii/296c03811787f54e48723917736d5268 to your computer and use it in GitHub Desktop.

Revisions

  1. niconii revised this gist Sep 9, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion clear_wram.asm
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ clear_wram:
    ldx #zero ; from zero
    stx A1T0L ; $4302-4303
    lda #.bank(zero)
    lda #^zero ; bank of zero
    sta A1B0 ; $4304
    stz DAS0L ; transfer $10000 bytes
  2. niconii created this gist Sep 9, 2018.
    33 changes: 33 additions & 0 deletions clear_wram.asm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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 #.bank(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