-
Notifications
You must be signed in to change notification settings - Fork 806
/
load_pics.asm
491 lines (457 loc) · 7.34 KB
/
load_pics.asm
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
GetUnownLetter:
; Return Unown letter in wUnownLetter based on DVs at hl
; Take the middle 2 bits of each DV and place them in order:
; atk def spd spc
; .ww..xx. .yy..zz.
; atk
ld a, [hl]
and %01100000
sla a
ld b, a
; def
ld a, [hli]
and %00000110
swap a
srl a
or b
ld b, a
; spd
ld a, [hl]
and %01100000
swap a
sla a
or b
ld b, a
; spc
ld a, [hl]
and %00000110
srl a
or b
; Divide by 10 to get 0-25
ldh [hDividend + 3], a
xor a
ldh [hDividend], a
ldh [hDividend + 1], a
ldh [hDividend + 2], a
ld a, $ff / NUM_UNOWN + 1
ldh [hDivisor], a
ld b, 4
call Divide
; Increment to get 1-26
ldh a, [hQuotient + 3]
inc a
ld [wUnownLetter], a
ret
GetMonFrontpic:
ld a, [wCurPartySpecies]
ld [wCurSpecies], a
call IsAPokemon
ret c
ldh a, [rSVBK]
push af
call _GetFrontpic
pop af
ldh [rSVBK], a
ret
GetAnimatedFrontpic:
ld a, [wCurPartySpecies]
ld [wCurSpecies], a
call IsAPokemon
ret c
ldh a, [rSVBK]
push af
xor a
ldh [hBGMapMode], a
call _GetFrontpic
call GetAnimatedEnemyFrontpic
pop af
ldh [rSVBK], a
ret
_GetFrontpic:
push de
call GetBaseData
ld a, [wBasePicSize]
and $f
ld b, a
push bc
call GetFrontpicPointer
ld a, BANK(wDecompressEnemyFrontpic)
ldh [rSVBK], a
ld a, b
ld de, wDecompressEnemyFrontpic
call FarDecompress
pop bc
ld hl, wDecompressScratch
ld de, wDecompressEnemyFrontpic
call PadFrontpic
pop hl
push hl
ld de, wDecompressScratch
ld c, 7 * 7
ldh a, [hROMBank]
ld b, a
call Get2bpp
pop hl
ret
GetFrontpicPointer:
ld a, [wCurPartySpecies]
cp UNOWN
jr z, .unown
ld a, [wCurPartySpecies]
ld d, BANK(PokemonPicPointers)
jr .ok
.unown
ld a, [wUnownLetter]
ld d, BANK(UnownPicPointers)
.ok
; These are assumed to be at the same address in their respective banks.
assert PokemonPicPointers == UnownPicPointers
ld hl, PokemonPicPointers
dec a
ld bc, 6
call AddNTimes
ld a, d
call GetFarByte
call FixPicBank
push af
inc hl
ld a, d
call GetFarWord
pop bc
ret
GetAnimatedEnemyFrontpic:
ld a, BANK(vTiles3)
ldh [rVBK], a
push hl
ld de, wDecompressScratch
ld c, 7 * 7
ldh a, [hROMBank]
ld b, a
call Get2bpp
pop hl
ld de, 7 * 7 tiles
add hl, de
push hl
ld a, BANK(wBasePicSize)
ld hl, wBasePicSize
call GetFarWRAMByte
pop hl
and $f
ld de, wDecompressEnemyFrontpic + 5 * 5 tiles
ld c, 5 * 5
cp 5
jr z, .got_dims
ld de, wDecompressEnemyFrontpic + 6 * 6 tiles
ld c, 6 * 6
cp 6
jr z, .got_dims
ld de, wDecompressEnemyFrontpic + 7 * 7 tiles
ld c, 7 * 7
.got_dims
push hl
push bc
call LoadFrontpicTiles
pop bc
pop hl
ld de, wDecompressScratch
ldh a, [hROMBank]
ld b, a
call Get2bpp
xor a
ldh [rVBK], a
ret
LoadFrontpicTiles:
ld hl, wDecompressScratch
swap c
ld a, c
and $f
ld b, a
ld a, c
and $f0
ld c, a
push bc
call LoadOrientedFrontpic
pop bc
.loop
push bc
ld c, 0
call LoadOrientedFrontpic
pop bc
dec b
jr nz, .loop
ret
GetMonBackpic:
ld a, [wCurPartySpecies]
call IsAPokemon
ret c
ld a, [wCurPartySpecies]
ld b, a
ld a, [wUnownLetter]
ld c, a
ldh a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ldh [rSVBK], a
push de
; These are assumed to be at the same address in their respective banks.
assert PokemonPicPointers == UnownPicPointers
ld hl, PokemonPicPointers
ld a, b
ld d, BANK(PokemonPicPointers)
cp UNOWN
jr nz, .ok
ld a, c
ld d, BANK(UnownPicPointers)
.ok
dec a
ld bc, 6
call AddNTimes
ld bc, 3
add hl, bc
ld a, d
call GetFarByte
call FixPicBank
push af
inc hl
ld a, d
call GetFarWord
ld de, wDecompressScratch
pop af
call FarDecompress
ld hl, wDecompressScratch
ld c, 6 * 6
call FixBackpicAlignment
pop hl
ld de, wDecompressScratch
ldh a, [hROMBank]
ld b, a
call Get2bpp
pop af
ldh [rSVBK], a
ret
FixPicBank:
; This is a thing for some reason.
DEF PICS_FIX EQU $36
EXPORT PICS_FIX
push hl
push bc
sub BANK("Pics 1") - PICS_FIX
ld c, a
ld b, 0
ld hl, .PicsBanks
add hl, bc
ld a, [hl]
pop bc
pop hl
ret
.PicsBanks:
db BANK("Pics 1") ; BANK("Pics 1") + 0
db BANK("Pics 2") ; BANK("Pics 1") + 1
db BANK("Pics 3") ; BANK("Pics 1") + 2
db BANK("Pics 4") ; BANK("Pics 1") + 3
db BANK("Pics 5") ; BANK("Pics 1") + 4
db BANK("Pics 6") ; BANK("Pics 1") + 5
db BANK("Pics 7") ; BANK("Pics 1") + 6
db BANK("Pics 8") ; BANK("Pics 1") + 7
db BANK("Pics 9") ; BANK("Pics 1") + 8
db BANK("Pics 10") ; BANK("Pics 1") + 9
db BANK("Pics 11") ; BANK("Pics 1") + 10
db BANK("Pics 12") ; BANK("Pics 1") + 11
db BANK("Pics 13") ; BANK("Pics 1") + 12
db BANK("Pics 14") ; BANK("Pics 1") + 13
db BANK("Pics 15") ; BANK("Pics 1") + 14
db BANK("Pics 16") ; BANK("Pics 1") + 15
db BANK("Pics 17") ; BANK("Pics 1") + 16
db BANK("Pics 18") ; BANK("Pics 1") + 17
db BANK("Pics 19") ; BANK("Pics 1") + 18
db BANK("Pics 20") ; BANK("Pics 1") + 19
db BANK("Pics 21") ; BANK("Pics 1") + 20
db BANK("Pics 22") ; BANK("Pics 1") + 21
db BANK("Pics 23") ; BANK("Pics 1") + 22
db BANK("Pics 24") ; BANK("Pics 1") + 23
GSIntro_GetMonFrontpic: ; unreferenced
ld a, c
push de
ld hl, PokemonPicPointers
dec a
ld bc, 6
call AddNTimes
ld a, BANK(PokemonPicPointers)
call GetFarByte
call FixPicBank
push af
inc hl
ld a, BANK(PokemonPicPointers)
call GetFarWord
pop af
pop de
call FarDecompress
ret
GetTrainerPic:
ld a, [wTrainerClass]
and a
ret z
cp NUM_TRAINER_CLASSES + 1
ret nc
call WaitBGMap
xor a
ldh [hBGMapMode], a
ld hl, TrainerPicPointers
ld a, [wTrainerClass]
dec a
ld bc, 3
call AddNTimes
ldh a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ldh [rSVBK], a
push de
ld a, BANK(TrainerPicPointers)
call GetFarByte
call FixPicBank
push af
inc hl
ld a, BANK(TrainerPicPointers)
call GetFarWord
pop af
ld de, wDecompressScratch
call FarDecompress
pop hl
ld de, wDecompressScratch
ld c, 7 * 7
ldh a, [hROMBank]
ld b, a
call Get2bpp
pop af
ldh [rSVBK], a
call WaitBGMap
ld a, 1
ldh [hBGMapMode], a
ret
DecompressGet2bpp:
; Decompress lz data from b:hl to wDecompressScratch, then copy it to address de.
ldh a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ldh [rSVBK], a
push de
push bc
ld a, b
ld de, wDecompressScratch
call FarDecompress
pop bc
ld de, wDecompressScratch
pop hl
ldh a, [hROMBank]
ld b, a
call Get2bpp
pop af
ldh [rSVBK], a
ret
FixBackpicAlignment:
push de
push bc
ld a, [wBoxAlignment]
and a
jr z, .keep_dims
ld a, c
cp 7 * 7
ld de, 7 * 7 tiles
jr z, .got_dims
cp 6 * 6
ld de, 6 * 6 tiles
jr z, .got_dims
ld de, 5 * 5 tiles
.got_dims
ld a, [hl]
ld b, 0
ld c, 8
.loop
rra
rl b
dec c
jr nz, .loop
ld a, b
ld [hli], a
dec de
ld a, e
or d
jr nz, .got_dims
.keep_dims
pop bc
pop de
ret
PadFrontpic:
; pads frontpic to fill 7x7 box
ld a, b
cp 6
jr z, .six
cp 5
jr z, .five
.seven_loop
ld c, 7 << 4
call LoadOrientedFrontpic
dec b
jr nz, .seven_loop
ret
.six
ld c, 7 << 4
xor a
call .Fill
.six_loop
ld c, (7 - 6) << 4
xor a
call .Fill
ld c, 6 << 4
call LoadOrientedFrontpic
dec b
jr nz, .six_loop
ret
.five
ld c, 7 << 4
xor a
call .Fill
.five_loop
ld c, (7 - 5) << 4
xor a
call .Fill
ld c, 5 << 4
call LoadOrientedFrontpic
dec b
jr nz, .five_loop
ld c, 7 << 4
xor a
call .Fill
ret
.Fill:
ld [hli], a
dec c
jr nz, .Fill
ret
LoadOrientedFrontpic:
ld a, [wBoxAlignment]
and a
jr nz, .x_flip
.left_loop
ld a, [de]
inc de
ld [hli], a
dec c
jr nz, .left_loop
ret
.x_flip
push bc
.right_loop
ld a, [de]
inc de
ld b, a
xor a
rept 8
rr b
rla
endr
ld [hli], a
dec c
jr nz, .right_loop
pop bc
ret