Skip to content

Commit

Permalink
Use a conditional ret to return from compact OAM DMA procedure (gbd…
Browse files Browse the repository at this point in the history
…ev#458)

Using a plain `ret`, this procedure will begin to return before the OAM
DMA transfer is complete, corrupting the return address.
  • Loading branch information
tertu-m authored and avivace committed Jun 21, 2023
1 parent 579048e commit 310078e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/OAM_DMA_Transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ If HRAM is tight, this more compact procedure saves 5 bytes of HRAM
at the cost of a few cycles spent jumping to the tail in HRAM.

```rgbasm
run_dma: ; This part is in ROM
run_dma: ; This part must be in ROM.
ld a, HIGH(start address)
ld bc, $2846 ; B: wait time; C: LOW($FF46)
jp run_dma_tail
run_dma_tail: ; This part is in HRAM
run_dma_tail: ; This part must be in HRAM.
ldh [c], a
.wait
dec b
jr nz, .wait
ret
ret z ; Conditional `ret` is 1 cycle slower, which avoids
; reading from the stack on the last cycle of DMA.
```

If starting a mid-frame transfer, wait for Mode 0 first
Expand Down

0 comments on commit 310078e

Please sign in to comment.