1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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
ret
GetFarByte::
; retrieve a single byte from a:hl, and return it in a.
; bankswitch to new bank
ld [wTempBank], a
ldh a, [hROMBank]
push af
ld a, [wTempBank]
rst Bankswitch
; get byte from new bank
ld a, [hl]
ld [wFarByte], a
; bankswitch to previous bank
pop af
rst Bankswitch
; return retrieved value in a
ld a, [wFarByte]
ret
GetFarHalfword::
; retrieve a halfword from a:hl, and return it in hl.
; bankswitch to new bank
ld [wTempBank], a
ldh a, [hROMBank]
push af
ld a, [wTempBank]
rst Bankswitch
; get halfword from new bank, put it in hl
ld a, [hli]
ld h, [hl]
ld l, a
; bankswitch to previous bank and return
pop af
rst Bankswitch
ret
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
ret
|