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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
; Functions to copy data from ROM.
Get2bpp_2:: ; dc9
ld a, [rLCDC]
bit 7, a
jp z, Copy2bpp
ld a, [hROMBank]
push af
ld a, BANK(_Get2bpp)
rst Bankswitch
call _Get2bpp
pop af
rst Bankswitch
ret
; ddc
Get1bpp_2:: ; ddc
ld a, [rLCDC]
bit 7, a
jp z, Copy1bpp
ld a, [hROMBank]
push af
ld a, BANK(_Get1bpp)
rst Bankswitch
call _Get1bpp
pop af
rst Bankswitch
ret
; def
FarCopyBytesDouble_DoubleBankSwitch:: ; def
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call FarCopyBytesDouble
pop af
rst Bankswitch
ret
; dfd
OldDMATransfer:: ; dfd
dec c
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
.loop
; load the source and target MSB and LSB
ld a, d
ld [rHDMA1], a ; source MSB
ld a, e
and $f0
ld [rHDMA2], a ; source LSB
ld a, h
and $1f
ld [rHDMA3], a ; target MSB
ld a, l
and $f0
ld [rHDMA4], a ; target LSB
; stop when c < 8
ld a, c
cp $8
jr c, .done
; decrease c by 8
sub $8
ld c, a
; DMA transfer state
ld a, $f
ld [hDMATransfer], a
call DelayFrame
; add $100 to hl and de
ld a, l
add $100 % $100
ld l, a
ld a, h
adc $100 / $100
ld h, a
ld a, e
add $100 % $100
ld e, a
ld a, d
adc $100 / $100
ld d, a
jr .loop
.done
ld a, c
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
ReplaceKrisSprite:: ; e4a
callba _ReplaceKrisSprite
ret
; e51
LoadStandardFont:: ; e51
callba _LoadStandardFont
ret
; e58
LoadFontsBattleExtra:: ; e58
callba _LoadFontsBattleExtra
ret
; e5f
LoadFontsExtra:: ; e5f
callba _LoadFontsExtra1
callba _LoadFontsExtra2
ret
; e6c
LoadFontsExtra2:: ; e6c
callba _LoadFontsExtra2
ret
; e73
DecompressRequest2bpp:: ; e73
push de
ld a, BANK(sScratch)
call GetSRAMBank
push bc
ld de, sScratch
ld a, b
call FarDecompress
pop bc
pop hl
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
rept 2
ld [hli], a
endr
.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
ld a, [hTilesPerCycle]
push af
ld a, $8
ld [hTilesPerCycle], a
ld a, [wLinkMode]
cp LINK_MOBILE
jr nz, .NotMobile
ld a, [hMobile]
and a
jr nz, .NotMobile
ld a, $6
ld [hTilesPerCycle], a
.NotMobile:
ld a, e
ld [Requested2bppSource], a
ld a, d
ld [Requested2bppSource + 1], a
ld a, l
ld [Requested2bppDest], a
ld a, h
ld [Requested2bppDest + 1], a
.loop
ld a, c
ld hl, hTilesPerCycle
cp [hl]
jr nc, .iterate
ld [Requested2bpp], a
.wait
call DelayFrame
ld a, [Requested2bpp]
and a
jr nz, .wait
pop af
ld [hTilesPerCycle], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.iterate
ld a, [hTilesPerCycle]
ld [Requested2bpp], a
.wait2
call DelayFrame
ld a, [Requested2bpp]
and a
jr nz, .wait2
ld a, c
ld hl, hTilesPerCycle
sub [hl]
ld c, a
jr .loop
; f1e
Request1bpp:: ; f1e
; 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
ld a, [hTilesPerCycle]
push af
ld a, $8
ld [hTilesPerCycle], a
ld a, [wLinkMode]
cp LINK_MOBILE
jr nz, .NotMobile
ld a, [hMobile]
and a
jr nz, .NotMobile
ld a, $6
ld [hTilesPerCycle], a
.NotMobile:
ld a, e
ld [Requested1bppSource], a
ld a, d
ld [Requested1bppSource + 1], a
ld a, l
ld [Requested1bppDest], a
ld a, h
ld [Requested1bppDest + 1], a
.loop
ld a, c
ld hl, hTilesPerCycle
cp [hl]
jr nc, .iterate
ld [Requested1bpp], a
.wait
call DelayFrame
ld a, [Requested1bpp]
and a
jr nz, .wait
pop af
ld [hTilesPerCycle], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.iterate
ld a, [hTilesPerCycle]
ld [Requested1bpp], a
.wait2
call DelayFrame
ld a, [Requested1bpp]
and a
jr nz, .wait2
ld a, c
ld hl, hTilesPerCycle
sub [hl]
ld c, a
jr .loop
; f82
Get2bpp:: ; f82
ld a, [rLCDC]
bit 7, 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]
bit 7, 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
rept 3
add hl, hl
endr
ld b, h
ld c, l
pop af
pop hl
jp FarCopyBytesDouble
; fb6
|