2013-08-29 16:39:21 -07:00
|
|
|
; Functions to copy data from ROM.
|
|
|
|
|
|
|
|
|
2015-11-04 12:35:29 -08:00
|
|
|
Get2bpp_2:: ; dc9
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
|
|
|
bit 7, a
|
|
|
|
jp z, Copy2bpp
|
|
|
|
|
2016-05-27 07:41:59 -07:00
|
|
|
homecall _Get2bpp
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
ret
|
|
|
|
; ddc
|
|
|
|
|
2015-11-04 12:35:29 -08:00
|
|
|
Get1bpp_2:: ; ddc
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
|
|
|
bit 7, a
|
|
|
|
jp z, Copy1bpp
|
|
|
|
|
2016-05-27 07:41:59 -07:00
|
|
|
homecall _Get1bpp
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
ret
|
|
|
|
; def
|
|
|
|
|
2015-11-04 12:35:29 -08:00
|
|
|
FarCopyBytesDouble_DoubleBankSwitch:: ; def
|
2013-08-29 16:39:21 -07:00
|
|
|
ld [hBuffer], a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, [hBuffer]
|
|
|
|
rst Bankswitch
|
2015-11-04 12:35:29 -08:00
|
|
|
|
2013-08-29 16:39:21 -07:00
|
|
|
call FarCopyBytesDouble
|
2015-11-04 12:35:29 -08:00
|
|
|
|
2013-08-29 16:39:21 -07:00
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
; dfd
|
|
|
|
|
2015-11-04 13:14:27 -08:00
|
|
|
OldDMATransfer:: ; 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
|
|
|
|
|
2015-07-20 22:52:46 -07:00
|
|
|
.loop
|
2015-11-04 13:14:27 -08:00
|
|
|
; load the source and target MSB and LSB
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, d
|
2015-11-04 13:14:27 -08:00
|
|
|
ld [rHDMA1], a ; source MSB
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, e
|
|
|
|
and $f0
|
2015-11-04 13:14:27 -08:00
|
|
|
ld [rHDMA2], a ; source LSB
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, h
|
|
|
|
and $1f
|
2015-11-04 13:14:27 -08:00
|
|
|
ld [rHDMA3], a ; target MSB
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, l
|
|
|
|
and $f0
|
2015-11-04 13:14:27 -08:00
|
|
|
ld [rHDMA4], a ; target LSB
|
|
|
|
; stop when c < 8
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, c
|
|
|
|
cp $8
|
2015-07-20 22:52:46 -07:00
|
|
|
jr c, .done
|
2015-11-04 13:14:27 -08:00
|
|
|
; decrease c by 8
|
2013-08-29 16:39:21 -07:00
|
|
|
sub $8
|
|
|
|
ld c, a
|
2015-11-04 13:14:27 -08:00
|
|
|
; DMA transfer state
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, $f
|
|
|
|
ld [hDMATransfer], a
|
|
|
|
call DelayFrame
|
2015-11-04 13:14:27 -08:00
|
|
|
; add $100 to hl and de
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, l
|
2017-12-25 10:40:10 -08:00
|
|
|
add LOW($100)
|
2013-08-29 16:39:21 -07:00
|
|
|
ld l, a
|
|
|
|
ld a, h
|
2017-12-25 10:40:10 -08:00
|
|
|
adc HIGH($100)
|
2013-08-29 16:39:21 -07:00
|
|
|
ld h, a
|
|
|
|
ld a, e
|
2017-12-25 10:40:10 -08:00
|
|
|
add LOW($100)
|
2013-08-29 16:39:21 -07:00
|
|
|
ld e, a
|
|
|
|
ld a, d
|
2017-12-25 10:40:10 -08:00
|
|
|
adc HIGH($100)
|
2013-08-29 16:39:21 -07:00
|
|
|
ld d, a
|
2015-07-20 22:52:46 -07:00
|
|
|
jr .loop
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2015-07-20 22:52:46 -07:00
|
|
|
.done
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, c
|
2015-11-04 13:14:27 -08:00
|
|
|
and $7f ; pretty silly, considering at most bits 0-2 would be set
|
2013-08-29 16:39:21 -07:00
|
|
|
ld [hDMATransfer], a
|
|
|
|
call DelayFrame
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
; e4a
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-04 13:14:27 -08:00
|
|
|
ReplaceKrisSprite:: ; e4a
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _ReplaceKrisSprite
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e51
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-04 13:14:27 -08:00
|
|
|
LoadStandardFont:: ; e51
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadStandardFont
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e58
|
|
|
|
|
2015-10-21 07:43:42 -07:00
|
|
|
LoadFontsBattleExtra:: ; e58
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadFontsBattleExtra
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e5f
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-04 13:14:27 -08:00
|
|
|
LoadFontsExtra:: ; e5f
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadFontsExtra1
|
|
|
|
farcall _LoadFontsExtra2
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e6c
|
|
|
|
|
2015-11-04 13:14:27 -08:00
|
|
|
LoadFontsExtra2:: ; e6c
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadFontsExtra2
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
; e73
|
|
|
|
|
2015-11-04 13:14:27 -08:00
|
|
|
DecompressRequest2bpp:: ; e73
|
2013-08-29 16:39:21 -07:00
|
|
|
push de
|
2015-08-19 21:51:04 -07:00
|
|
|
ld a, BANK(sScratch)
|
2013-08-29 16:39:21 -07:00
|
|
|
call GetSRAMBank
|
|
|
|
push bc
|
2015-11-04 13:14:27 -08:00
|
|
|
|
2015-08-19 21:51:04 -07:00
|
|
|
ld de, sScratch
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, b
|
|
|
|
call FarDecompress
|
2015-11-04 13:14:27 -08:00
|
|
|
|
2013-08-29 16:39:21 -07:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2015-11-04 13:14:27 -08:00
|
|
|
|
2015-08-19 21:51:04 -07:00
|
|
|
ld de, sScratch
|
2013-08-29 16:39:21 -07:00
|
|
|
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
|
2016-05-04 08:46:23 -07:00
|
|
|
ld [hli], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.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
|
2015-10-17 09:58:26 -07:00
|
|
|
; Load 2bpp at b:de to occupy c tiles of hl.
|
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
|
|
|
|
|
2015-11-05 11:06:03 -08:00
|
|
|
ld a, [hTilesPerCycle]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
|
|
|
ld a, $8
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hTilesPerCycle], a
|
2015-10-24 07:34:19 -07:00
|
|
|
|
2015-10-19 07:23:58 -07:00
|
|
|
ld a, [wLinkMode]
|
2015-10-24 07:34:19 -07:00
|
|
|
cp LINK_MOBILE
|
|
|
|
jr nz, .NotMobile
|
|
|
|
ld a, [hMobile]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nz, .NotMobile
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, $6
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hTilesPerCycle], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.NotMobile:
|
2013-08-29 16:39:21 -07:00
|
|
|
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
|
2015-10-17 09:58:26 -07:00
|
|
|
.loop
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, c
|
2015-11-05 11:06:03 -08:00
|
|
|
ld hl, hTilesPerCycle
|
2013-08-29 16:39:21 -07:00
|
|
|
cp [hl]
|
2015-10-17 09:58:26 -07:00
|
|
|
jr nc, .iterate
|
2013-08-29 16:39:21 -07:00
|
|
|
|
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
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hTilesPerCycle], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
2015-10-17 09:58:26 -07:00
|
|
|
.iterate
|
2015-11-05 11:06:03 -08:00
|
|
|
ld a, [hTilesPerCycle]
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested2bpp], a
|
2015-10-24 07:34:19 -07:00
|
|
|
|
2015-10-17 09:58:26 -07:00
|
|
|
.wait2
|
2013-08-29 16:39:21 -07:00
|
|
|
call DelayFrame
|
2013-09-01 12:24:07 -07:00
|
|
|
ld a, [Requested2bpp]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
2015-10-17 09:58:26 -07:00
|
|
|
jr nz, .wait2
|
2015-10-24 07:34:19 -07:00
|
|
|
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, c
|
2015-11-05 11:06:03 -08:00
|
|
|
ld hl, hTilesPerCycle
|
2013-08-29 16:39:21 -07:00
|
|
|
sub [hl]
|
|
|
|
ld c, a
|
2015-10-17 09:58:26 -07:00
|
|
|
jr .loop
|
2013-08-29 16:39:21 -07:00
|
|
|
; f1e
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Request1bpp:: ; f1e
|
2015-11-05 11:06:03 -08:00
|
|
|
; Load 1bpp at b:de to occupy c tiles of hl.
|
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
|
|
|
|
|
2015-11-05 11:06:03 -08:00
|
|
|
ld a, [hTilesPerCycle]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
|
|
|
|
|
|
|
ld a, $8
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hTilesPerCycle], a
|
2015-10-19 07:23:58 -07:00
|
|
|
ld a, [wLinkMode]
|
2015-10-24 07:34:19 -07:00
|
|
|
cp LINK_MOBILE
|
2015-10-17 09:58:26 -07:00
|
|
|
jr nz, .NotMobile
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [hMobile]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
2015-10-17 09:58:26 -07:00
|
|
|
jr nz, .NotMobile
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, $6
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hTilesPerCycle], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.NotMobile:
|
2013-08-29 16:39:21 -07:00
|
|
|
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
|
2015-10-17 09:58:26 -07:00
|
|
|
.loop
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, c
|
2015-11-05 11:06:03 -08:00
|
|
|
ld hl, hTilesPerCycle
|
2013-08-29 16:39:21 -07:00
|
|
|
cp [hl]
|
2015-10-17 09:58:26 -07:00
|
|
|
jr nc, .iterate
|
2013-08-29 16:39:21 -07:00
|
|
|
|
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
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hTilesPerCycle], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
2015-10-17 09:58:26 -07:00
|
|
|
.iterate
|
2015-11-05 11:06:03 -08:00
|
|
|
ld a, [hTilesPerCycle]
|
2013-09-01 12:24:07 -07:00
|
|
|
ld [Requested1bpp], a
|
2015-10-17 09:58:26 -07:00
|
|
|
|
|
|
|
.wait2
|
2013-08-29 16:39:21 -07:00
|
|
|
call DelayFrame
|
2013-09-01 12:24:07 -07:00
|
|
|
ld a, [Requested1bpp]
|
2013-08-29 16:39:21 -07:00
|
|
|
and a
|
2015-10-17 09:58:26 -07:00
|
|
|
jr nz, .wait2
|
|
|
|
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, c
|
2015-11-05 11:06:03 -08:00
|
|
|
ld hl, hTilesPerCycle
|
2013-08-29 16:39:21 -07:00
|
|
|
sub [hl]
|
|
|
|
ld c, a
|
2015-10-17 09:58:26 -07:00
|
|
|
jr .loop
|
2013-08-29 16:39:21 -07:00
|
|
|
; 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
|
2016-05-10 09:31:49 -07:00
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
2013-08-29 16:39:21 -07:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop af
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
jp FarCopyBytesDouble
|
|
|
|
; fb6
|