pokecrystal-board/home/copy.asm

422 lines
5.0 KiB
NASM
Raw Normal View History

; Functions to copy data from ROM.
2015-11-04 12:35:29 -08:00
Get2bpp_2:: ; dc9
ld a, [rLCDC]
2017-12-29 09:53:21 -08:00
bit rLCDC_ENABLE, a
jp z, Copy2bpp
2016-05-27 07:41:59 -07:00
homecall _Get2bpp
ret
; ddc
2015-11-04 12:35:29 -08:00
Get1bpp_2:: ; ddc
ld a, [rLCDC]
2017-12-29 09:53:21 -08:00
bit rLCDC_ENABLE, a
jp z, Copy1bpp
2016-05-27 07:41:59 -07:00
homecall _Get1bpp
ret
; def
2015-11-04 12:35:29 -08:00
FarCopyBytesDouble_DoubleBankSwitch:: ; def
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
2015-11-04 12:35:29 -08:00
call FarCopyBytesDouble
2015-11-04 12:35:29 -08:00
pop af
rst Bankswitch
ret
; dfd
2015-11-04 13:14:27 -08:00
OldDMATransfer:: ; dfd
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
ld a, d
2015-11-04 13:14:27 -08:00
ld [rHDMA1], a ; source MSB
ld a, e
and $f0
2015-11-04 13:14:27 -08:00
ld [rHDMA2], a ; source LSB
ld a, h
and $1f
2015-11-04 13:14:27 -08:00
ld [rHDMA3], a ; target MSB
ld a, l
and $f0
2015-11-04 13:14:27 -08:00
ld [rHDMA4], a ; target LSB
; stop when c < 8
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
sub $8
ld c, a
2015-11-04 13:14:27 -08:00
; DMA transfer state
ld a, $f
ld [hDMATransfer], a
call DelayFrame
2015-11-04 13:14:27 -08:00
; 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
2015-07-20 22:52:46 -07:00
jr .loop
2015-07-20 22:52:46 -07:00
.done
ld a, c
2015-11-04 13:14:27 -08:00
and $7f ; pretty silly, considering at most bits 0-2 would be set
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
ret
; e51
2015-11-04 13:14:27 -08:00
LoadStandardFont:: ; e51
2017-12-24 09:47:30 -08:00
farcall _LoadStandardFont
ret
; e58
LoadFontsBattleExtra:: ; e58
2017-12-24 09:47:30 -08:00
farcall _LoadFontsBattleExtra
ret
; e5f
2015-11-04 13:14:27 -08:00
LoadFontsExtra:: ; e5f
2017-12-24 09:47:30 -08:00
farcall _LoadFontsExtra1
farcall _LoadFontsExtra2
ret
; e6c
2015-11-04 13:14:27 -08:00
LoadFontsExtra2:: ; e6c
2017-12-24 09:47:30 -08:00
farcall _LoadFontsExtra2
ret
; e73
2015-11-04 13:14:27 -08:00
DecompressRequest2bpp:: ; e73
push de
ld a, BANK(sScratch)
call GetSRAMBank
push bc
2015-11-04 13:14:27 -08:00
ld de, sScratch
ld a, b
call FarDecompress
2015-11-04 13:14:27 -08:00
pop bc
pop hl
2015-11-04 13:14:27 -08:00
ld de, sScratch
call Request2bpp
call CloseSRAM
ret
; e8d
FarCopyBytes:: ; e8d
; 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
FarCopyBytesDouble:: ; e9b
; 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
Request2bpp:: ; eba
; Load 2bpp at b:de to occupy c tiles of hl.
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]
push af
ld a, $8
2015-11-05 11:06:03 -08:00
ld [hTilesPerCycle], a
2015-10-24 07:34:19 -07:00
ld a, [wLinkMode]
2015-10-24 07:34:19 -07:00
cp LINK_MOBILE
jr nz, .NotMobile
ld a, [hMobile]
and a
2015-10-24 07:34:19 -07:00
jr nz, .NotMobile
ld a, $6
2015-11-05 11:06:03 -08:00
ld [hTilesPerCycle], a
.NotMobile:
ld a, e
2018-01-23 14:39:09 -08:00
ld [wRequested2bppSource], a
ld a, d
2018-01-23 14:39:09 -08:00
ld [wRequested2bppSource + 1], a
ld a, l
2018-01-23 14:39:09 -08:00
ld [wRequested2bppDest], a
ld a, h
2018-01-23 14:39:09 -08:00
ld [wRequested2bppDest + 1], a
.loop
ld a, c
2015-11-05 11:06:03 -08:00
ld hl, hTilesPerCycle
cp [hl]
jr nc, .iterate
2018-01-23 14:39:09 -08:00
ld [wRequested2bpp], a
.wait
call DelayFrame
2018-01-23 14:39:09 -08:00
ld a, [wRequested2bpp]
and a
jr nz, .wait
pop af
2015-11-05 11:06:03 -08:00
ld [hTilesPerCycle], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.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
.wait2
call DelayFrame
2018-01-23 14:39:09 -08:00
ld a, [wRequested2bpp]
and a
jr nz, .wait2
2015-10-24 07:34:19 -07:00
ld a, c
2015-11-05 11:06:03 -08:00
ld hl, hTilesPerCycle
sub [hl]
ld c, a
jr .loop
; f1e
Request1bpp:: ; f1e
2015-11-05 11:06:03 -08:00
; Load 1bpp at b:de to occupy c tiles of hl.
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]
push af
ld a, $8
2015-11-05 11:06:03 -08:00
ld [hTilesPerCycle], a
ld a, [wLinkMode]
2015-10-24 07:34:19 -07:00
cp LINK_MOBILE
jr nz, .NotMobile
2015-10-24 07:34:19 -07:00
ld a, [hMobile]
and a
jr nz, .NotMobile
ld a, $6
2015-11-05 11:06:03 -08:00
ld [hTilesPerCycle], a
.NotMobile:
ld a, e
2018-01-23 14:39:09 -08:00
ld [wRequested1bppSource], a
ld a, d
2018-01-23 14:39:09 -08:00
ld [wRequested1bppSource + 1], a
ld a, l
2018-01-23 14:39:09 -08:00
ld [wRequested1bppDest], a
ld a, h
2018-01-23 14:39:09 -08:00
ld [wRequested1bppDest + 1], a
.loop
ld a, c
2015-11-05 11:06:03 -08:00
ld hl, hTilesPerCycle
cp [hl]
jr nc, .iterate
2018-01-23 14:39:09 -08:00
ld [wRequested1bpp], a
.wait
call DelayFrame
2018-01-23 14:39:09 -08:00
ld a, [wRequested1bpp]
and a
jr nz, .wait
pop af
2015-11-05 11:06:03 -08:00
ld [hTilesPerCycle], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.iterate
2015-11-05 11:06:03 -08:00
ld a, [hTilesPerCycle]
2018-01-23 14:39:09 -08:00
ld [wRequested1bpp], a
.wait2
call DelayFrame
2018-01-23 14:39:09 -08:00
ld a, [wRequested1bpp]
and a
jr nz, .wait2
ld a, c
2015-11-05 11:06:03 -08:00
ld hl, hTilesPerCycle
sub [hl]
ld c, a
jr .loop
; f82
Get2bpp:: ; f82
ld a, [rLCDC]
2017-12-29 09:53:21 -08:00
bit rLCDC_ENABLE, a
jp nz, Request2bpp
Copy2bpp:: ; f89
; 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
Get1bpp:: ; f9d
ld a, [rLCDC]
2017-12-29 09:53:21 -08:00
bit rLCDC_ENABLE, a
jp nz, Request1bpp
Copy1bpp:: ; fa4
; 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