2013-08-29 16:39:21 -07:00
|
|
|
; Functions to copy data from ROM.
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Get2bpp_2::
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
2017-12-29 09:53:21 -08:00
|
|
|
bit rLCDC_ENABLE, a
|
2013-08-29 16:39:21 -07:00
|
|
|
jp z, Copy2bpp
|
|
|
|
|
2016-05-27 07:41:59 -07:00
|
|
|
homecall _Get2bpp
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Get1bpp_2::
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
2017-12-29 09:53:21 -08:00
|
|
|
bit rLCDC_ENABLE, a
|
2013-08-29 16:39:21 -07:00
|
|
|
jp z, Copy1bpp
|
|
|
|
|
2016-05-27 07:41:59 -07:00
|
|
|
homecall _Get1bpp
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FarCopyBytesDouble_DoubleBankSwitch::
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
OldDMATransfer::
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ReplaceKrisSprite::
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _ReplaceKrisSprite
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LoadStandardFont::
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadStandardFont
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LoadFontsBattleExtra::
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadFontsBattleExtra
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LoadFontsExtra::
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadFontsExtra1
|
|
|
|
farcall _LoadFontsExtra2
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LoadFontsExtra2::
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _LoadFontsExtra2
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DecompressRequest2bpp::
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FarCopyBytes::
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FarCopyBytesDouble::
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Request2bpp::
|
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
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested2bppSource], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, d
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested2bppSource + 1], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, l
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested2bppDest], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, h
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested2bppDest + 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
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested2bpp], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.wait
|
|
|
|
call DelayFrame
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wRequested2bpp]
|
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]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested2bpp], 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
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wRequested2bpp]
|
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
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Request1bpp::
|
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
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested1bppSource], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, d
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested1bppSource + 1], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, l
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested1bppDest], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, h
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested1bppDest + 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
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested1bpp], a
|
2013-08-29 16:39:21 -07:00
|
|
|
.wait
|
|
|
|
call DelayFrame
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wRequested1bpp]
|
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]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wRequested1bpp], a
|
2015-10-17 09:58:26 -07:00
|
|
|
|
|
|
|
.wait2
|
2013-08-29 16:39:21 -07:00
|
|
|
call DelayFrame
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wRequested1bpp]
|
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
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Get2bpp::
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
2017-12-29 09:53:21 -08:00
|
|
|
bit rLCDC_ENABLE, a
|
2013-08-29 16:39:21 -07:00
|
|
|
jp nz, Request2bpp
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Copy2bpp::
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Get1bpp::
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, [rLCDC]
|
2017-12-29 09:53:21 -08:00
|
|
|
bit rLCDC_ENABLE, a
|
2013-08-29 16:39:21 -07:00
|
|
|
jp nz, Request1bpp
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Copy1bpp::
|
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
|