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