-
Notifications
You must be signed in to change notification settings - Fork 11
/
dma.inc
44 lines (33 loc) · 1012 Bytes
/
dma.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
IF !DEF(DMA_INC)
; don't re-include this file if it's already been INCLUDE'd
DMA_INC = 1
DMA_ROUTINE = $FF80
dma_Copy2HRAM: MACRO
IF !DEF(MEMORY_ASM)
FAIL "include memory.asm before you use the dma_Copy2HRAM macro"
ENDC
; copies the dmacode to HIRAM. dmacode will get run each Vblank,
; and it is resposible for copying sprite data from ram to vram.
; dma_Copy2HRAM trashes all registers
; actual dma code preserves all registers
jr .copy_dma_into_memory\@
.dmacode\@
push af
ld a, OAMDATALOCBANK
ldh [rDMA], a
ld a, $28 ; countdown until DMA is finishes, then exit
.dma_wait\@ ;<-|
dec a ; | keep looping until DMA finishes
jr nz, .dma_wait\@ ; _|
pop af
reti ; if this were jumped to by the v-blank interrupt, we'd
; want to reti (re-enable interrupts).
.dmaend\@
.copy_dma_into_memory\@
ld de, DMA_ROUTINE
ld hl, .dmacode\@
ld bc, .dmaend\@ - .dmacode\@
; copies BC # of bytes from source (HL) to destination (DE)
call mem_Copy
ENDM
ENDC ; end definition of DMA.inc file