Skip to content

Commit 310078e

Browse files
tertu-mavivace
authored andcommitted
Use a conditional ret to return from compact OAM DMA procedure (#458)
Using a plain `ret`, this procedure will begin to return before the OAM DMA transfer is complete, corrupting the return address.
1 parent 579048e commit 310078e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/OAM_DMA_Transfer.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,19 @@ If HRAM is tight, this more compact procedure saves 5 bytes of HRAM
7575
at the cost of a few cycles spent jumping to the tail in HRAM.
7676

7777
```rgbasm
78-
run_dma: ; This part is in ROM
78+
run_dma: ; This part must be in ROM.
7979
ld a, HIGH(start address)
8080
ld bc, $2846 ; B: wait time; C: LOW($FF46)
8181
jp run_dma_tail
8282
83-
run_dma_tail: ; This part is in HRAM
83+
84+
run_dma_tail: ; This part must be in HRAM.
8485
ldh [c], a
8586
.wait
8687
dec b
8788
jr nz, .wait
88-
ret
89+
ret z ; Conditional `ret` is 1 cycle slower, which avoids
90+
; reading from the stack on the last cycle of DMA.
8991
```
9092

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

0 commit comments

Comments
 (0)