2013-08-29 16:39:21 -07:00
|
|
|
; Functions to copy data from ROM.
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functiondc9:: ; dc9
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
|
|
|
bit 7, a
|
|
|
|
jp z, Copy2bpp
|
|
|
|
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, BANK(Function104284)
|
|
|
|
rst Bankswitch
|
|
|
|
call Function104284
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ret
|
|
|
|
; ddc
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functionddc:: ; ddc
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
|
|
|
bit 7, a
|
|
|
|
jp z, Copy1bpp
|
|
|
|
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, BANK(Function1042b2)
|
|
|
|
rst Bankswitch
|
|
|
|
call Function1042b2
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ret
|
|
|
|
; def
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functiondef:: ; def
|
2013-08-29 16:39:21 -07:00
|
|
|
ld [hBuffer], a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, [hBuffer]
|
|
|
|
rst Bankswitch
|
|
|
|
call FarCopyBytesDouble
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
; dfd
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functiondfd:: ; dfd
|
2013-08-29 16:39:21 -07:00
|
|
|
dec c
|
|
|
|
ld a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
.asm_e09
|
|
|
|
ld a, d
|
|
|
|
ld [rHDMA1], a
|
|
|
|
ld a, e
|
|
|
|
and $f0
|
|
|
|
ld [rHDMA2], a
|
|
|
|
ld a, h
|
|
|
|
and $1f
|
|
|
|
ld [rHDMA3], a
|
|
|
|
ld a, l
|
|
|
|
and $f0
|
|
|
|
ld [rHDMA4], a
|
|
|
|
ld a, c
|
|
|
|
cp $8
|
|
|
|
jr c, .asm_e3c
|
|
|
|
sub $8
|
|
|
|
ld c, a
|
|
|
|
ld a, $f
|
|
|
|
ld [hDMATransfer], a
|
|
|
|
call DelayFrame
|
|
|
|
ld a, l
|
|
|
|
add $0
|
|
|
|
ld l, a
|
|
|
|
ld a, h
|
|
|
|
adc $1
|
|
|
|
ld h, a
|
|
|
|
ld a, e
|
|
|
|
add $0
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
adc $1
|
|
|
|
ld d, a
|
|
|
|
jr .asm_e09
|
|
|
|
|
|
|
|
.asm_e3c
|
|
|
|
ld a, c
|
|
|
|
and $7f
|
|
|
|
ld [hDMATransfer], a
|
|
|
|
call DelayFrame
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
; e4a
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functione4a:: ; e4a
|
2013-10-01 17:47:54 -07:00
|
|
|
callba Function14135
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e51
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functione51:: ; e51
|
2013-10-01 17:47:54 -07:00
|
|
|
callba Functionfb449
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e58
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functione58:: ; e58
|
2013-10-01 17:47:54 -07:00
|
|
|
callba Functionfb4be
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e5f
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functione5f:: ; e5f
|
2013-10-01 17:47:54 -07:00
|
|
|
callba Functionfb48a
|
|
|
|
callba Functionfb4b0
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e6c
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functione6c:: ; e6c
|
2013-10-01 17:47:54 -07:00
|
|
|
callba Functionfb4b0
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e73
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Functione73:: ; e73
|
2013-08-29 16:39:21 -07:00
|
|
|
push de
|
|
|
|
ld a, $0
|
|
|
|
call GetSRAMBank
|
|
|
|
push bc
|
|
|
|
ld de, $a000
|
|
|
|
ld a, b
|
|
|
|
call FarDecompress
|
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ld de, $a000
|
|
|
|
call Request2bpp
|
|
|
|
call CloseSRAM
|
|
|
|
ret
|
|
|
|
; e8d
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
FarCopyBytes:: ; e8d
|
2013-08-29 16:39:21 -07:00
|
|
|
; copy bc bytes from a:hl to de
|
|
|
|
|
|
|
|
ld [hBuffer], a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, [hBuffer]
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
call CopyBytes
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
; 0xe9b
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
FarCopyBytesDouble:: ; e9b
|
2013-08-29 16:39:21 -07:00
|
|
|
; Copy bc bytes from a:hl to bc*2 bytes at de,
|
|
|
|
; doubling each byte in the process.
|
|
|
|
|
|
|
|
ld [hBuffer], a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, [hBuffer]
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
; switcheroo, de <> hl
|
|
|
|
ld a, h
|
|
|
|
ld h, d
|
|
|
|
ld d, a
|
|
|
|
ld a, l
|
|
|
|
ld l, e
|
|
|
|
ld e, a
|
|
|
|
|
|
|
|
inc b
|
|
|
|
inc c
|
|
|
|
jr .dec
|
|
|
|
|
|
|
|
.loop
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
ld [hli], a
|
|
|
|
.dec
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
; 0xeba
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Request2bpp:: ; eba
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, [$ffd3]
|
|
|
|
push af
|
|
|
|
|
|
|
|
ld a, $8
|
|
|
|
ld [$ffd3], a
|
|
|
|
ld a, [InLinkBattle]
|
|
|
|
cp $4
|
|
|
|
jr nz, .asm_edc
|
|
|
|
ld a, [$ffe9]
|
|
|
|
and a
|
|
|
|
jr nz, .asm_edc
|
|
|
|
ld a, $6
|
|
|
|
ld [$ffd3], a
|
|
|
|
|
|
|
|
.asm_edc
|
|
|
|
ld a, e
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bppSource], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, d
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bppSource + 1], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, l
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bppDest], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, h
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bppDest + 1], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
.asm_eec
|
|
|
|
ld a, c
|
|
|
|
ld hl, $ffd3
|
|
|
|
cp [hl]
|
|
|
|
jr nc, .asm_f08
|
|
|
|
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bpp], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.wait
|
|
|
|
call DelayFrame
|
2013-09-01 12:24:07 -07:00
|
|
|
ld a, [Requested2bpp]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
|
|
|
jr nz, .wait
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [$ffd3], a
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.asm_f08
|
|
|
|
ld a, [$ffd3]
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bpp], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.asm_f0d
|
|
|
|
call DelayFrame
|
2013-09-01 12:24:07 -07:00
|
|
|
ld a, [Requested2bpp]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
|
|
|
jr nz, .asm_f0d
|
|
|
|
ld a, c
|
|
|
|
ld hl, $ffd3
|
|
|
|
sub [hl]
|
|
|
|
ld c, a
|
|
|
|
jr .asm_eec
|
|
|
|
; f1e
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Request1bpp:: ; f1e
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, [$ffd3]
|
|
|
|
push af
|
|
|
|
|
|
|
|
ld a, $8
|
|
|
|
ld [$ffd3], a
|
|
|
|
ld a, [InLinkBattle]
|
|
|
|
cp $4
|
|
|
|
jr nz, .asm_f40
|
|
|
|
ld a, [$ffe9]
|
|
|
|
and a
|
|
|
|
jr nz, .asm_f40
|
|
|
|
ld a, $6
|
|
|
|
ld [$ffd3], a
|
|
|
|
|
|
|
|
.asm_f40
|
|
|
|
ld a, e
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bppSource], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, d
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bppSource + 1], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, l
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bppDest], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, h
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bppDest + 1], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.asm_f50
|
|
|
|
ld a, c
|
|
|
|
ld hl, $ffd3
|
|
|
|
cp [hl]
|
|
|
|
jr nc, .asm_f6c
|
|
|
|
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bpp], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.wait
|
|
|
|
call DelayFrame
|
2013-09-01 12:24:07 -07:00
|
|
|
ld a, [Requested1bpp]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
|
|
|
jr nz, .wait
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [$ffd3], a
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.asm_f6c
|
|
|
|
ld a, [$ffd3]
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bpp], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.asm_f71
|
|
|
|
call DelayFrame
|
2013-09-01 12:24:07 -07:00
|
|
|
ld a, [Requested1bpp]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
|
|
|
jr nz, .asm_f71
|
|
|
|
ld a, c
|
|
|
|
ld hl, $ffd3
|
|
|
|
sub [hl]
|
|
|
|
ld c, a
|
|
|
|
jr .asm_f50
|
|
|
|
; f82
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Get2bpp:: ; f82
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
|
|
|
bit 7, a
|
|
|
|
jp nz, Request2bpp
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Copy2bpp:: ; f89
|
2013-08-29 16:39:21 -07:00
|
|
|
; copy c 2bpp tiles from b:de to hl
|
|
|
|
|
|
|
|
push hl
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
pop de
|
|
|
|
|
|
|
|
; bank
|
|
|
|
ld a, b
|
|
|
|
|
|
|
|
; bc = c * $10
|
|
|
|
push af
|
|
|
|
swap c
|
|
|
|
ld a, $f
|
|
|
|
and c
|
|
|
|
ld b, a
|
|
|
|
ld a, $f0
|
|
|
|
and c
|
|
|
|
ld c, a
|
|
|
|
pop af
|
|
|
|
|
|
|
|
jp FarCopyBytes
|
|
|
|
; f9d
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Get1bpp:: ; f9d
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
|
|
|
bit 7, a
|
|
|
|
jp nz, Request1bpp
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Copy1bpp:: ; fa4
|
2013-08-29 16:39:21 -07:00
|
|
|
; copy c 1bpp tiles from b:de to hl
|
|
|
|
|
|
|
|
push de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
|
|
|
|
; bank
|
|
|
|
ld a, b
|
|
|
|
|
|
|
|
; bc = c * $10 / 2
|
|
|
|
push af
|
|
|
|
ld h, 0
|
|
|
|
ld l, c
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop af
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
jp FarCopyBytesDouble
|
|
|
|
; fb6
|