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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
IsTilePassable::
; sets carry if tile is passable, resets carry otherwise
homecall_sf _IsTilePassable
ret
FarCopyDataDouble::
; Expand bc bytes of 1bpp image data
; from a:de to 2bpp data at hl.
ld [wFarCopyDataSavedROMBank], a
ldh a, [hLoadedROMBank]
push af
ld a, [wFarCopyDataSavedROMBank]
call BankswitchCommon
ld a, h ; swap hl and de
ld h, d
ld d, a
ld a, l
ld l, e
ld e, a
ld a, b
and a
jr z, .eightbitcopyamount
ld a, c
and a ; multiple of $100
jr z, .expandloop ; if so, do not increment b because the first instance of dec c results in underflow
.eightbitcopyamount
inc b
.expandloop
ld a, [de]
inc de
ld [hli], a
ld [hli], a
dec c
jr nz, .expandloop
dec b
jr nz, .expandloop
pop af
call BankswitchCommon
ret
CopyVideoData::
; Wait for the next VBlank, then copy c 2bpp
; tiles from b:de to hl, 8 tiles at a time.
; This takes c/8 frames.
ldh a, [hAutoBGTransferEnabled]
push af
xor a ; disable auto-transfer while copying
ldh [hAutoBGTransferEnabled], a
ldh a, [hLoadedROMBank]
push af
ld a, b
call BankswitchCommon
ld a, e
ldh [hVBlankCopySource], a
ld a, d
ldh [hVBlankCopySource + 1], a
ld a, l
ldh [hVBlankCopyDest], a
ld a, h
ldh [hVBlankCopyDest + 1], a
.loop
ld a, c
cp 8
jr nc, .keepgoing
.done
ldh [hVBlankCopySize], a
call DelayFrame
pop af
call BankswitchCommon
pop af
ldh [hAutoBGTransferEnabled], a
ret
.keepgoing
ld a, 8
ldh [hVBlankCopySize], a
call DelayFrame
ld a, c
sub 8
ld c, a
jr .loop
CopyVideoDataDouble::
; Wait for the next VBlank, then copy c 1bpp
; tiles from b:de to hl, 8 tiles at a time.
; This takes c/8 frames.
ldh a, [hAutoBGTransferEnabled]
push af
xor a ; disable auto-transfer while copying
ldh [hAutoBGTransferEnabled], a
ldh a, [hLoadedROMBank]
push af
ld a, b
call BankswitchCommon
ld a, e
ldh [hVBlankCopyDoubleSource], a
ld a, d
ldh [hVBlankCopyDoubleSource + 1], a
ld a, l
ldh [hVBlankCopyDoubleDest], a
ld a, h
ldh [hVBlankCopyDoubleDest + 1], a
.loop
ld a, c
cp 8
jr nc, .keepgoing
.done
ldh [hVBlankCopyDoubleSize], a
call DelayFrame
pop af
call BankswitchCommon
pop af
ldh [hAutoBGTransferEnabled], a
ret
.keepgoing
ld a, 8
ldh [hVBlankCopyDoubleSize], a
call DelayFrame
ld a, c
sub 8
ld c, a
jr .loop
FillMemory::
push af
ld a, b
and a
jr z, .eightbitcopyamount
ld a, c
and a
jr z, .mulitpleof0x100
.eightbitcopyamount
inc b
.mulitpleof0x100
pop af
.loop
ld [hli], a
dec c
jr nz, .loop
dec b
jr nz, .loop
ret
GetFarByte::
; get a byte from a:hl
; and return it in a
push bc
ld b, a
ldh a, [hLoadedROMBank]
push af
ld a, b
call BankswitchCommon
ld b, [hl]
pop af
call BankswitchCommon
ld a, b
pop bc
ret
ClearScreenArea::
; Clear tilemap area cxb at hl.
ld a, " " ; blank tile
ld de, 20 ; screen width
.y
push hl
push bc
.x
ld [hli], a
dec c
jr nz, .x
pop bc
pop hl
add hl, de
dec b
jr nz, .y
ret
CopyScreenTileBufferToVRAM::
; Copy wTileMap to the BG Map starting at b * $100.
; This is done in thirds of 6 rows, so it takes 3 frames.
ld c, 6
ld hl, $600 * 0
decoord 0, 6 * 0
call .setup
call DelayFrame
ld hl, $600 * 1
decoord 0, 6 * 1
call .setup
call DelayFrame
ld hl, $600 * 2
decoord 0, 6 * 2
call .setup
jp DelayFrame
.setup
ld a, d
ldh [hVBlankCopyBGSource+1], a
call GetRowColAddressBgMap
ld a, l
ldh [hVBlankCopyBGDest], a
ld a, h
ldh [hVBlankCopyBGDest+1], a
ld a, c
ldh [hVBlankCopyBGNumRows], a
ld a, e
ldh [hVBlankCopyBGSource], a
ret
ClearScreen::
; Clear wTileMap, then wait
; for the bg map to update.
ld bc, 20 * 18
inc b
hlcoord 0, 0
ld a, " "
.loop
ld [hli], a
dec c
jr nz, .loop
dec b
jr nz, .loop
jp Delay3
|