2022-06-06 21:25:42 +00:00
|
|
|
DEF TILES_PER_CYCLE EQU 8
|
|
|
|
DEF MOBILE_TILES_PER_CYCLE EQU 6
|
2020-02-21 22:48:51 +00:00
|
|
|
|
2020-05-18 15:59:48 +00:00
|
|
|
Get2bppViaHDMA::
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rLCDC]
|
|
|
|
bit rLCDC_ENABLE, a
|
|
|
|
jp z, Copy2bpp
|
|
|
|
|
2020-05-18 00:59:15 +00:00
|
|
|
homecall HDMATransfer2bpp
|
2020-02-21 22:48:51 +00:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2020-05-18 15:59:48 +00:00
|
|
|
Get1bppViaHDMA::
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rLCDC]
|
|
|
|
bit rLCDC_ENABLE, a
|
|
|
|
jp z, Copy1bpp
|
|
|
|
|
2020-05-18 00:59:15 +00:00
|
|
|
homecall HDMATransfer1bpp
|
2020-02-21 22:48:51 +00:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
FarCopyBytesDouble_DoubleBankSwitch::
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [hROMBank]
|
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2020-02-21 22:48:51 +00:00
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
call FarCopyBytesDouble
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
|
2020-06-21 20:27:43 +00:00
|
|
|
SafeHDMATransfer: ; unreferenced
|
2020-02-21 22:48:51 +00:00
|
|
|
dec c
|
|
|
|
ldh a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ldh [hBGMapMode], a
|
|
|
|
ldh a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
.loop
|
|
|
|
; load the source and target MSB and LSB
|
|
|
|
ld a, d
|
|
|
|
ldh [rHDMA1], a ; source MSB
|
|
|
|
ld a, e
|
|
|
|
and $f0
|
|
|
|
ldh [rHDMA2], a ; source LSB
|
|
|
|
ld a, h
|
|
|
|
and $1f
|
|
|
|
ldh [rHDMA3], a ; target MSB
|
|
|
|
ld a, l
|
|
|
|
and $f0
|
|
|
|
ldh [rHDMA4], a ; target LSB
|
2020-06-16 19:49:32 +00:00
|
|
|
; stop when c < TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
ld a, c
|
2020-06-16 19:49:32 +00:00
|
|
|
cp TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
jr c, .done
|
2020-06-16 19:49:32 +00:00
|
|
|
; decrease c by TILES_PER_CYCLE
|
|
|
|
sub TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
ld c, a
|
|
|
|
; DMA transfer state
|
|
|
|
ld a, $f
|
|
|
|
ldh [hDMATransfer], a
|
|
|
|
call DelayFrame
|
|
|
|
; add $100 to hl and de
|
|
|
|
ld a, l
|
|
|
|
add LOW($100)
|
|
|
|
ld l, a
|
|
|
|
ld a, h
|
|
|
|
adc HIGH($100)
|
|
|
|
ld h, a
|
|
|
|
ld a, e
|
|
|
|
add LOW($100)
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
adc HIGH($100)
|
|
|
|
ld d, a
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.done
|
|
|
|
ld a, c
|
|
|
|
and $7f ; pretty silly, considering at most bits 0-2 would be set
|
|
|
|
ldh [hDMATransfer], a
|
|
|
|
call DelayFrame
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ldh [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
2020-06-16 23:38:00 +00:00
|
|
|
UpdatePlayerSprite::
|
|
|
|
farcall _UpdatePlayerSprite
|
2020-02-21 22:48:51 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
LoadStandardFont::
|
|
|
|
farcall _LoadStandardFont
|
|
|
|
ret
|
|
|
|
|
|
|
|
LoadFontsBattleExtra::
|
|
|
|
farcall _LoadFontsBattleExtra
|
|
|
|
ret
|
|
|
|
|
|
|
|
LoadFontsExtra::
|
|
|
|
farcall _LoadFontsExtra1
|
|
|
|
farcall _LoadFontsExtra2
|
|
|
|
ret
|
|
|
|
|
2020-10-26 19:45:57 +00:00
|
|
|
LoadFontsExtra2: ; unreferenced
|
2020-02-21 22:48:51 +00:00
|
|
|
farcall _LoadFontsExtra2
|
|
|
|
ret
|
|
|
|
|
|
|
|
DecompressRequest2bpp::
|
|
|
|
push de
|
|
|
|
ld a, BANK(sScratch)
|
2020-06-17 21:03:38 +00:00
|
|
|
call OpenSRAM
|
2020-02-21 22:48:51 +00:00
|
|
|
push bc
|
|
|
|
|
|
|
|
ld de, sScratch
|
|
|
|
ld a, b
|
|
|
|
call FarDecompress
|
|
|
|
|
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
|
|
|
|
ld de, sScratch
|
|
|
|
call Request2bpp
|
|
|
|
call CloseSRAM
|
|
|
|
ret
|
|
|
|
|
|
|
|
FarCopyBytes::
|
|
|
|
; copy bc bytes from a:hl to de
|
|
|
|
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [hROMBank]
|
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2020-02-21 22:48:51 +00:00
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
call CopyBytes
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
|
|
|
|
FarCopyBytesDouble:
|
|
|
|
; Copy bc bytes from a:hl to bc*2 bytes at de,
|
|
|
|
; doubling each byte in the process.
|
|
|
|
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [hROMBank]
|
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2020-02-21 22:48:51 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
Request2bpp::
|
|
|
|
; Load 2bpp at b:de to occupy c tiles of hl.
|
|
|
|
ldh a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ldh [hBGMapMode], a
|
|
|
|
|
|
|
|
ldh a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ldh a, [hTilesPerCycle]
|
|
|
|
push af
|
2020-06-16 19:49:32 +00:00
|
|
|
ld a, TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [hTilesPerCycle], a
|
|
|
|
|
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_MOBILE
|
|
|
|
jr nz, .NotMobile
|
|
|
|
ldh a, [hMobile]
|
|
|
|
and a
|
|
|
|
jr nz, .NotMobile
|
2020-06-16 19:49:32 +00:00
|
|
|
ld a, MOBILE_TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [hTilesPerCycle], a
|
|
|
|
|
|
|
|
.NotMobile:
|
|
|
|
ld a, e
|
|
|
|
ld [wRequested2bppSource], a
|
|
|
|
ld a, d
|
|
|
|
ld [wRequested2bppSource + 1], a
|
|
|
|
ld a, l
|
|
|
|
ld [wRequested2bppDest], a
|
|
|
|
ld a, h
|
|
|
|
ld [wRequested2bppDest + 1], a
|
|
|
|
.loop
|
|
|
|
ld a, c
|
|
|
|
ld hl, hTilesPerCycle
|
|
|
|
cp [hl]
|
2020-06-16 19:49:32 +00:00
|
|
|
jr nc, .cycle
|
2020-02-21 22:48:51 +00:00
|
|
|
|
2020-10-26 19:45:57 +00:00
|
|
|
ld [wRequested2bppSize], a
|
2020-02-21 22:48:51 +00:00
|
|
|
.wait
|
|
|
|
call DelayFrame
|
2020-10-26 19:45:57 +00:00
|
|
|
ld a, [wRequested2bppSize]
|
2020-02-21 22:48:51 +00:00
|
|
|
and a
|
|
|
|
jr nz, .wait
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ldh [hTilesPerCycle], a
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ldh [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
2020-06-16 19:49:32 +00:00
|
|
|
.cycle
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [hTilesPerCycle]
|
2020-10-26 19:45:57 +00:00
|
|
|
ld [wRequested2bppSize], a
|
2020-02-21 22:48:51 +00:00
|
|
|
|
|
|
|
.wait2
|
|
|
|
call DelayFrame
|
2020-10-26 19:45:57 +00:00
|
|
|
ld a, [wRequested2bppSize]
|
2020-02-21 22:48:51 +00:00
|
|
|
and a
|
|
|
|
jr nz, .wait2
|
|
|
|
|
|
|
|
ld a, c
|
|
|
|
ld hl, hTilesPerCycle
|
|
|
|
sub [hl]
|
|
|
|
ld c, a
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
Request1bpp::
|
|
|
|
; Load 1bpp at b:de to occupy c tiles of hl.
|
|
|
|
ldh a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ldh [hBGMapMode], a
|
|
|
|
|
|
|
|
ldh a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ldh a, [hTilesPerCycle]
|
|
|
|
push af
|
2020-06-16 19:49:32 +00:00
|
|
|
ld a, TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [hTilesPerCycle], a
|
|
|
|
|
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_MOBILE
|
|
|
|
jr nz, .NotMobile
|
|
|
|
ldh a, [hMobile]
|
|
|
|
and a
|
|
|
|
jr nz, .NotMobile
|
2020-06-16 19:49:32 +00:00
|
|
|
ld a, MOBILE_TILES_PER_CYCLE
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [hTilesPerCycle], a
|
|
|
|
|
|
|
|
.NotMobile:
|
|
|
|
ld a, e
|
|
|
|
ld [wRequested1bppSource], a
|
|
|
|
ld a, d
|
|
|
|
ld [wRequested1bppSource + 1], a
|
|
|
|
ld a, l
|
|
|
|
ld [wRequested1bppDest], a
|
|
|
|
ld a, h
|
|
|
|
ld [wRequested1bppDest + 1], a
|
|
|
|
.loop
|
|
|
|
ld a, c
|
|
|
|
ld hl, hTilesPerCycle
|
|
|
|
cp [hl]
|
2020-06-16 19:49:32 +00:00
|
|
|
jr nc, .cycle
|
2020-02-21 22:48:51 +00:00
|
|
|
|
2020-10-26 19:45:57 +00:00
|
|
|
ld [wRequested1bppSize], a
|
2020-02-21 22:48:51 +00:00
|
|
|
.wait
|
|
|
|
call DelayFrame
|
2020-10-26 19:45:57 +00:00
|
|
|
ld a, [wRequested1bppSize]
|
2020-02-21 22:48:51 +00:00
|
|
|
and a
|
|
|
|
jr nz, .wait
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ldh [hTilesPerCycle], a
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ldh [hBGMapMode], a
|
|
|
|
ret
|
|
|
|
|
2020-06-16 19:49:32 +00:00
|
|
|
.cycle
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [hTilesPerCycle]
|
2020-10-26 19:45:57 +00:00
|
|
|
ld [wRequested1bppSize], a
|
2020-02-21 22:48:51 +00:00
|
|
|
|
|
|
|
.wait2
|
|
|
|
call DelayFrame
|
2020-10-26 19:45:57 +00:00
|
|
|
ld a, [wRequested1bppSize]
|
2020-02-21 22:48:51 +00:00
|
|
|
and a
|
|
|
|
jr nz, .wait2
|
|
|
|
|
|
|
|
ld a, c
|
|
|
|
ld hl, hTilesPerCycle
|
|
|
|
sub [hl]
|
|
|
|
ld c, a
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
Get2bpp::
|
2020-06-29 23:35:47 +00:00
|
|
|
; copy c 2bpp tiles from b:de to hl
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rLCDC]
|
|
|
|
bit rLCDC_ENABLE, a
|
|
|
|
jp nz, Request2bpp
|
2020-06-21 22:33:31 +00:00
|
|
|
; fallthrough
|
2020-02-21 22:48:51 +00:00
|
|
|
|
|
|
|
Copy2bpp:
|
|
|
|
push hl
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
pop de
|
|
|
|
|
|
|
|
; bank
|
|
|
|
ld a, b
|
|
|
|
|
2020-06-16 19:49:32 +00:00
|
|
|
; bc = c * LEN_2BPP_TILE
|
2020-02-21 22:48:51 +00:00
|
|
|
push af
|
|
|
|
swap c
|
|
|
|
ld a, $f
|
|
|
|
and c
|
|
|
|
ld b, a
|
|
|
|
ld a, $f0
|
|
|
|
and c
|
|
|
|
ld c, a
|
|
|
|
pop af
|
|
|
|
|
|
|
|
jp FarCopyBytes
|
|
|
|
|
|
|
|
Get1bpp::
|
2020-06-29 23:35:47 +00:00
|
|
|
; copy c 1bpp tiles from b:de to hl
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rLCDC]
|
|
|
|
bit rLCDC_ENABLE, a
|
|
|
|
jp nz, Request1bpp
|
2020-06-21 22:33:31 +00:00
|
|
|
; fallthrough
|
2020-02-21 22:48:51 +00:00
|
|
|
|
|
|
|
Copy1bpp::
|
|
|
|
push de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
|
|
|
|
; bank
|
|
|
|
ld a, b
|
|
|
|
|
2020-06-16 19:49:32 +00:00
|
|
|
; bc = c * LEN_1BPP_TILE
|
2020-02-21 22:48:51 +00:00
|
|
|
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
|