2020-02-21 14:48:51 -08: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 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
SwapBytes::
|
|
|
|
; swap bc bytes between hl and de
|
|
|
|
.Loop:
|
|
|
|
; stash [hl] away on the stack
|
|
|
|
ld a, [hl]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
2015-11-04 12:35:29 -08:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; copy a byte from [de] to [hl]
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
2015-11-04 12:35:29 -08:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; retrieve the previous value of [hl]; put it in [de]
|
2013-08-29 16:39:21 -07:00
|
|
|
pop af
|
2020-02-21 14:48:51 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; handle loop stuff
|
|
|
|
dec bc
|
2013-08-29 16:39:21 -07:00
|
|
|
ld a, b
|
2020-02-21 14:48:51 -08:00
|
|
|
or c
|
|
|
|
jr nz, .Loop
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2020-02-21 14:48:51 -08: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 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
GetFarByte::
|
|
|
|
; retrieve a single byte from a:hl, and return it in a.
|
|
|
|
; bankswitch to new bank
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hStackBank], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hROMBank]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hStackBank]
|
2013-08-29 16:39:21 -07:00
|
|
|
rst Bankswitch
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; get byte from new bank
|
|
|
|
ld a, [hl]
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hFarByte], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; bankswitch to previous bank
|
2013-08-29 16:39:21 -07:00
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; return retrieved value in a
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hFarByte]
|
2020-02-21 14:48:51 -08:00
|
|
|
ret
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
GetFarHalfword::
|
|
|
|
; retrieve a halfword from a:hl, and return it in hl.
|
|
|
|
; bankswitch to new bank
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hStackBank], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hROMBank]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hStackBank]
|
2013-08-29 16:39:21 -07:00
|
|
|
rst Bankswitch
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; get halfword from new bank, put it in hl
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
; bankswitch to previous bank and return
|
2013-08-29 16:39:21 -07:00
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
FarCopyWRAM::
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hStackBank], a
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh a, [rSVBK]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hStackBank]
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh [rSVBK], a
|
2013-08-29 16:39:21 -07:00
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
call CopyBytes
|
2013-08-29 16:39:21 -07:00
|
|
|
|
|
|
|
pop af
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh [rSVBK], a
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
GetFarWRAMByte::
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hStackBank], a
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh a, [rSVBK]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hStackBank]
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ld a, [hl]
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hFarByte], a
|
2013-08-29 16:39:21 -07:00
|
|
|
pop af
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh [rSVBK], a
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hFarByte]
|
2013-08-29 16:39:21 -07:00
|
|
|
ret
|
|
|
|
|
2020-02-21 14:48:51 -08:00
|
|
|
GetFarWRAMWord::
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh [hStackBank], a
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh a, [rSVBK]
|
2013-08-29 16:39:21 -07:00
|
|
|
push af
|
2020-04-06 09:52:46 -07:00
|
|
|
ldh a, [hStackBank]
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2013-08-29 16:39:21 -07:00
|
|
|
pop af
|
2020-02-21 14:48:51 -08:00
|
|
|
ldh [rSVBK], a
|
|
|
|
ret
|