2020-02-21 22:48:51 +00:00
|
|
|
CopyBytes::
|
|
|
|
; copy bc bytes from hl to de
|
|
|
|
inc b ; we bail the moment b hits 0, so include the last run
|
|
|
|
inc c ; same thing; include last byte
|
|
|
|
jr .HandleLoop
|
|
|
|
.CopyByte:
|
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
.HandleLoop:
|
|
|
|
dec c
|
|
|
|
jr nz, .CopyByte
|
|
|
|
dec b
|
|
|
|
jr nz, .CopyByte
|
2013-08-29 23:39:21 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
SwapBytes::
|
|
|
|
; swap bc bytes between hl and de
|
|
|
|
.Loop:
|
|
|
|
; stash [hl] away on the stack
|
|
|
|
ld a, [hl]
|
2013-08-29 23:39:21 +00:00
|
|
|
push af
|
2015-11-04 20:35:29 +00:00
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; copy a byte from [de] to [hl]
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
2015-11-04 20:35:29 +00:00
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; retrieve the previous value of [hl]; put it in [de]
|
2013-08-29 23:39:21 +00:00
|
|
|
pop af
|
2020-02-21 22:48:51 +00:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
2013-08-29 23:39:21 +00:00
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; handle loop stuff
|
|
|
|
dec bc
|
2013-08-29 23:39:21 +00:00
|
|
|
ld a, b
|
2020-02-21 22:48:51 +00:00
|
|
|
or c
|
|
|
|
jr nz, .Loop
|
2013-08-29 23:39:21 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
ByteFill::
|
|
|
|
; fill bc bytes with the value of a, starting at hl
|
|
|
|
inc b ; we bail the moment b hits 0, so include the last run
|
|
|
|
inc c ; same thing; include last byte
|
|
|
|
jr .HandleLoop
|
|
|
|
.PutByte:
|
|
|
|
ld [hli], a
|
|
|
|
.HandleLoop:
|
|
|
|
dec c
|
|
|
|
jr nz, .PutByte
|
|
|
|
dec b
|
|
|
|
jr nz, .PutByte
|
2013-08-29 23:39:21 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
GetFarByte::
|
|
|
|
; retrieve a single byte from a:hl, and return it in a.
|
|
|
|
; bankswitch to new bank
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-08-29 23:39:21 +00:00
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2013-08-29 23:39:21 +00:00
|
|
|
rst Bankswitch
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; get byte from new bank
|
|
|
|
ld a, [hl]
|
2020-04-06 16:52:46 +00:00
|
|
|
ldh [hFarByte], a
|
2013-08-29 23:39:21 +00:00
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; bankswitch to previous bank
|
2013-08-29 23:39:21 +00:00
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; return retrieved value in a
|
2020-04-06 16:52:46 +00:00
|
|
|
ldh a, [hFarByte]
|
2020-02-21 22:48:51 +00:00
|
|
|
ret
|
2013-08-29 23:39:21 +00:00
|
|
|
|
2021-01-09 20:16:05 +00:00
|
|
|
GetFarWord::
|
|
|
|
; retrieve a word from a:hl, and return it in hl.
|
2020-02-21 22:48:51 +00:00
|
|
|
; bankswitch to new bank
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-08-29 23:39:21 +00:00
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2013-08-29 23:39:21 +00:00
|
|
|
rst Bankswitch
|
|
|
|
|
2021-01-09 20:16:05 +00:00
|
|
|
; get word from new bank, put it in hl
|
2020-02-21 22:48:51 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2013-08-29 23:39:21 +00:00
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
; bankswitch to previous bank and return
|
2013-08-29 23:39:21 +00:00
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
FarCopyWRAM::
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rSVBK]
|
2013-08-29 23:39:21 +00:00
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [rSVBK], a
|
2013-08-29 23:39:21 +00:00
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
call CopyBytes
|
2013-08-29 23:39:21 +00:00
|
|
|
|
|
|
|
pop af
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [rSVBK], a
|
2013-08-29 23:39:21 +00:00
|
|
|
ret
|
|
|
|
|
2020-02-21 22:48:51 +00:00
|
|
|
GetFarWRAMByte::
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rSVBK]
|
2013-08-29 23:39:21 +00:00
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ld a, [hl]
|
2020-04-06 16:52:46 +00:00
|
|
|
ldh [hFarByte], a
|
2013-08-29 23:39:21 +00:00
|
|
|
pop af
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [rSVBK], a
|
2020-04-06 16:52:46 +00:00
|
|
|
ldh a, [hFarByte]
|
2013-08-29 23:39:21 +00:00
|
|
|
ret
|
|
|
|
|
2020-06-21 22:33:31 +00:00
|
|
|
GetFarWRAMWord:: ; unreferenced
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh [hTempBank], a
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh a, [rSVBK]
|
2013-08-29 23:39:21 +00:00
|
|
|
push af
|
2020-04-06 17:02:23 +00:00
|
|
|
ldh a, [hTempBank]
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2013-08-29 23:39:21 +00:00
|
|
|
pop af
|
2020-02-21 22:48:51 +00:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ret
|