Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/menus/pokedex.asm
1271 views
1
ShowPokedexMenu:
2
call GBPalWhiteOut
3
call ClearScreen
4
call UpdateSprites
5
ld a, [wListScrollOffset]
6
push af
7
xor a
8
ld [wCurrentMenuItem], a
9
ld [wListScrollOffset], a
10
ld [wLastMenuItem], a
11
inc a
12
ld [wPokedexNum], a
13
ldh [hJoy7], a
14
.setUpGraphics
15
ld b, SET_PAL_GENERIC
16
call RunPaletteCommand
17
callfar LoadPokedexTilePatterns
18
.doPokemonListMenu
19
ld hl, wTopMenuItemY
20
ld a, 3
21
ld [hli], a ; top menu item Y
22
xor a
23
ld [hli], a ; top menu item X
24
inc a
25
ld [wMenuWatchMovingOutOfBounds], a
26
inc hl
27
inc hl
28
ld a, 6
29
ld [hli], a ; max menu item ID
30
ld [hl], PAD_LEFT | PAD_RIGHT | PAD_B | PAD_A
31
call HandlePokedexListMenu
32
jr c, .goToSideMenu ; if the player chose a pokemon from the list
33
.exitPokedex
34
xor a
35
ld [wMenuWatchMovingOutOfBounds], a
36
ld [wCurrentMenuItem], a
37
ld [wLastMenuItem], a
38
ldh [hJoy7], a
39
ld [wUnusedOverrideSimulatedJoypadStatesIndex], a
40
ld [wOverrideSimulatedJoypadStatesMask], a
41
pop af
42
ld [wListScrollOffset], a
43
call GBPalWhiteOutWithDelay3
44
call RunDefaultPaletteCommand
45
jp ReloadMapData
46
.goToSideMenu
47
call HandlePokedexSideMenu
48
dec b
49
jr z, .exitPokedex ; if the player chose Quit
50
dec b
51
jr z, .doPokemonListMenu ; if pokemon not seen or player pressed B button
52
jp .setUpGraphics ; if pokemon data or area was shown
53
54
; handles the menu on the lower right in the pokedex screen
55
; OUTPUT:
56
; b = reason for exiting menu
57
; 00: showed pokemon data or area
58
; 01: the player chose Quit
59
; 02: the pokemon has not been seen yet or the player pressed the B button
60
HandlePokedexSideMenu:
61
call PlaceUnfilledArrowMenuCursor
62
ld a, [wCurrentMenuItem]
63
push af
64
ld b, a
65
ld a, [wLastMenuItem]
66
push af
67
ld a, [wListScrollOffset]
68
push af
69
add b
70
inc a
71
ld [wPokedexNum], a
72
ld a, [wPokedexNum]
73
push af
74
ld a, [wDexMaxSeenMon]
75
push af ; this doesn't need to be preserved
76
ld hl, wPokedexSeen
77
call IsPokemonBitSet
78
ld b, 2
79
jr z, .exitSideMenu
80
call PokedexToIndex
81
ld hl, wTopMenuItemY
82
ld a, 10
83
ld [hli], a ; top menu item Y
84
ld a, 15
85
ld [hli], a ; top menu item X
86
xor a
87
ld [hli], a ; current menu item ID
88
inc hl
89
ld a, 3
90
ld [hli], a ; max menu item ID
91
;ld a, PAD_A | PAD_B
92
ld [hli], a ; menu watched keys (A button and B button)
93
xor a
94
ld [hli], a ; old menu item ID
95
ld [wMenuWatchMovingOutOfBounds], a
96
.handleMenuInput
97
call HandleMenuInput
98
bit B_PAD_B, a
99
ld b, 2
100
jr nz, .buttonBPressed
101
ld a, [wCurrentMenuItem]
102
and a
103
jr z, .choseData
104
dec a
105
jr z, .choseCry
106
dec a
107
jr z, .choseArea
108
.choseQuit
109
ld b, 1
110
.exitSideMenu
111
pop af
112
ld [wDexMaxSeenMon], a
113
pop af
114
ld [wPokedexNum], a
115
pop af
116
ld [wListScrollOffset], a
117
pop af
118
ld [wLastMenuItem], a
119
pop af
120
ld [wCurrentMenuItem], a
121
push bc
122
hlcoord 0, 3
123
ld de, 20
124
lb bc, " ", 13
125
call DrawTileLine ; cover up the menu cursor in the pokemon list
126
pop bc
127
ret
128
129
.buttonBPressed
130
push bc
131
hlcoord 15, 10
132
ld de, 20
133
lb bc, " ", 7
134
call DrawTileLine ; cover up the menu cursor in the side menu
135
pop bc
136
jr .exitSideMenu
137
138
.choseData
139
call ShowPokedexDataInternal
140
ld b, 0
141
jr .exitSideMenu
142
143
; play pokemon cry
144
.choseCry
145
ld a, [wPokedexNum]
146
call GetCryData
147
call PlaySound
148
jr .handleMenuInput
149
150
.choseArea
151
predef LoadTownMap_Nest ; display pokemon areas
152
ld b, 0
153
jr .exitSideMenu
154
155
; handles the list of pokemon on the left of the pokedex screen
156
; sets carry flag if player presses A, unsets carry flag if player presses B
157
HandlePokedexListMenu:
158
xor a
159
ldh [hAutoBGTransferEnabled], a
160
; draw the horizontal line separating the seen and owned amounts from the menu
161
hlcoord 15, 8
162
ld a, "─"
163
ld [hli], a
164
ld [hli], a
165
ld [hli], a
166
ld [hli], a
167
ld [hli], a
168
hlcoord 14, 0
169
ld [hl], $71 ; vertical line tile
170
hlcoord 14, 1
171
call DrawPokedexVerticalLine
172
hlcoord 14, 9
173
call DrawPokedexVerticalLine
174
ld hl, wPokedexSeen
175
ld b, wPokedexSeenEnd - wPokedexSeen
176
call CountSetBits
177
ld de, wNumSetBits
178
hlcoord 16, 3
179
lb bc, 1, 3
180
call PrintNumber ; print number of seen pokemon
181
ld hl, wPokedexOwned
182
ld b, wPokedexOwnedEnd - wPokedexOwned
183
call CountSetBits
184
ld de, wNumSetBits
185
hlcoord 16, 6
186
lb bc, 1, 3
187
call PrintNumber ; print number of owned pokemon
188
hlcoord 16, 2
189
ld de, PokedexSeenText
190
call PlaceString
191
hlcoord 16, 5
192
ld de, PokedexOwnText
193
call PlaceString
194
hlcoord 1, 1
195
ld de, PokedexContentsText
196
call PlaceString
197
hlcoord 16, 10
198
ld de, PokedexMenuItemsText
199
call PlaceString
200
; find the highest pokedex number among the pokemon the player has seen
201
ld hl, wPokedexSeenEnd - 1
202
ld b, (wPokedexSeenEnd - wPokedexSeen) * 8 + 1
203
.maxSeenPokemonLoop
204
ld a, [hld]
205
ld c, 8
206
.maxSeenPokemonInnerLoop
207
dec b
208
sla a
209
jr c, .storeMaxSeenPokemon
210
dec c
211
jr nz, .maxSeenPokemonInnerLoop
212
jr .maxSeenPokemonLoop
213
214
.storeMaxSeenPokemon
215
ld a, b
216
ld [wDexMaxSeenMon], a
217
.loop
218
xor a
219
ldh [hAutoBGTransferEnabled], a
220
hlcoord 4, 2
221
lb bc, 14, 10
222
call ClearScreenArea
223
hlcoord 1, 3
224
ld a, [wListScrollOffset]
225
ld [wPokedexNum], a
226
ld d, 7
227
ld a, [wDexMaxSeenMon]
228
cp 7
229
jr nc, .printPokemonLoop
230
ld d, a
231
dec a
232
ld [wMaxMenuItem], a
233
; loop to print pokemon pokedex numbers and names
234
; if the player has owned the pokemon, it puts a pokeball beside the name
235
.printPokemonLoop
236
ld a, [wPokedexNum]
237
inc a
238
ld [wPokedexNum], a
239
push af
240
push de
241
push hl
242
ld de, -SCREEN_WIDTH
243
add hl, de
244
ld de, wPokedexNum
245
lb bc, LEADING_ZEROES | 1, 3
246
call PrintNumber
247
ld de, SCREEN_WIDTH
248
add hl, de
249
dec hl
250
push hl
251
ld hl, wPokedexOwned
252
call IsPokemonBitSet
253
pop hl
254
ld a, " "
255
jr z, .writeTile
256
ld a, $72 ; pokeball tile
257
.writeTile
258
ld [hl], a ; put a pokeball next to pokemon that the player has owned
259
push hl
260
ld hl, wPokedexSeen
261
call IsPokemonBitSet
262
jr nz, .getPokemonName ; if the player has seen the pokemon
263
ld de, .dashedLine ; print a dashed line in place of the name if the player hasn't seen the pokemon
264
jr .skipGettingName
265
.dashedLine ; for unseen pokemon in the list
266
db "----------@"
267
.getPokemonName
268
call PokedexToIndex
269
call GetMonName
270
.skipGettingName
271
pop hl
272
inc hl
273
call PlaceString
274
pop hl
275
ld bc, 2 * SCREEN_WIDTH
276
add hl, bc
277
pop de
278
pop af
279
ld [wPokedexNum], a
280
dec d
281
jr nz, .printPokemonLoop
282
ld a, 01
283
ldh [hAutoBGTransferEnabled], a
284
call Delay3
285
call GBPalNormal
286
call HandleMenuInput
287
bit B_PAD_B, a
288
jp nz, .buttonBPressed
289
.checkIfUpPressed
290
bit B_PAD_UP, a
291
jr z, .checkIfDownPressed
292
.upPressed ; scroll up one row
293
ld a, [wListScrollOffset]
294
and a
295
jp z, .loop
296
dec a
297
ld [wListScrollOffset], a
298
jp .loop
299
.checkIfDownPressed
300
bit B_PAD_DOWN, a
301
jr z, .checkIfRightPressed
302
.downPressed ; scroll down one row
303
ld a, [wDexMaxSeenMon]
304
cp 7
305
jp c, .loop ; can't if the list is shorter than 7
306
sub 7
307
ld b, a
308
ld a, [wListScrollOffset]
309
cp b
310
jp z, .loop
311
inc a
312
ld [wListScrollOffset], a
313
jp .loop
314
.checkIfRightPressed
315
bit B_PAD_RIGHT, a
316
jr z, .checkIfLeftPressed
317
.rightPressed ; scroll down 7 rows
318
ld a, [wDexMaxSeenMon]
319
cp 7
320
jp c, .loop ; can't if the list is shorter than 7
321
sub 6
322
ld b, a
323
ld a, [wListScrollOffset]
324
add 7
325
ld [wListScrollOffset], a
326
cp b
327
jp c, .loop
328
dec b
329
ld a, b
330
ld [wListScrollOffset], a
331
jp .loop
332
.checkIfLeftPressed ; scroll up 7 rows
333
bit B_PAD_LEFT, a
334
jr z, .buttonAPressed
335
.leftPressed
336
ld a, [wListScrollOffset]
337
sub 7
338
ld [wListScrollOffset], a
339
jp nc, .loop
340
xor a
341
ld [wListScrollOffset], a
342
jp .loop
343
.buttonAPressed
344
scf
345
ret
346
.buttonBPressed
347
and a
348
ret
349
350
DrawPokedexVerticalLine:
351
ld c, 9 ; height of line
352
ld de, SCREEN_WIDTH
353
ld a, $71 ; vertical line tile
354
.loop
355
ld [hl], a
356
add hl, de
357
xor 1 ; toggle between vertical line tile and box tile
358
dec c
359
jr nz, .loop
360
ret
361
362
PokedexSeenText:
363
db "SEEN@"
364
365
PokedexOwnText:
366
db "OWN@"
367
368
PokedexContentsText:
369
db "CONTENTS@"
370
371
PokedexMenuItemsText:
372
db "DATA"
373
next "CRY"
374
next "AREA"
375
next "QUIT@"
376
377
; tests if a pokemon's bit is set in the seen or owned pokemon bit fields
378
; INPUT:
379
; [wPokedexNum] = pokedex number
380
; hl = address of bit field
381
IsPokemonBitSet:
382
ld a, [wPokedexNum]
383
dec a
384
ld c, a
385
ld b, FLAG_TEST
386
predef FlagActionPredef
387
ld a, c
388
and a
389
ret
390
391
; function to display pokedex data from outside the pokedex
392
ShowPokedexData:
393
call GBPalWhiteOutWithDelay3
394
call ClearScreen
395
call UpdateSprites
396
callfar LoadPokedexTilePatterns ; load pokedex tiles
397
398
; function to display pokedex data from inside the pokedex
399
ShowPokedexDataInternal:
400
ld hl, wStatusFlags2
401
set BIT_NO_AUDIO_FADE_OUT, [hl]
402
ld a, $33 ; 3/7 volume
403
ldh [rAUDVOL], a
404
call GBPalWhiteOut ; zero all palettes
405
call ClearScreen
406
ld a, [wPokedexNum]
407
ld [wCurPartySpecies], a
408
push af
409
ld b, SET_PAL_POKEDEX
410
call RunPaletteCommand
411
pop af
412
ld [wPokedexNum], a
413
ldh a, [hTileAnimations]
414
push af
415
xor a
416
ldh [hTileAnimations], a
417
418
hlcoord 0, 0
419
ld de, 1
420
lb bc, $64, SCREEN_WIDTH
421
call DrawTileLine ; draw top border
422
423
hlcoord 0, 17
424
ld b, $6f
425
call DrawTileLine ; draw bottom border
426
427
hlcoord 0, 1
428
ld de, 20
429
lb bc, $66, $10
430
call DrawTileLine ; draw left border
431
432
hlcoord 19, 1
433
ld b, $67
434
call DrawTileLine ; draw right border
435
436
ld a, $63 ; upper left corner tile
437
ldcoord_a 0, 0
438
ld a, $65 ; upper right corner tile
439
ldcoord_a 19, 0
440
ld a, $6c ; lower left corner tile
441
ldcoord_a 0, 17
442
ld a, $6e ; lower right corner tile
443
ldcoord_a 19, 17
444
445
hlcoord 0, 9
446
ld de, PokedexDataDividerLine
447
call PlaceString ; draw horizontal divider line
448
449
hlcoord 9, 6
450
ld de, HeightWeightText
451
call PlaceString
452
453
call GetMonName
454
hlcoord 9, 2
455
call PlaceString
456
457
ld hl, PokedexEntryPointers
458
ld a, [wPokedexNum]
459
dec a
460
ld e, a
461
ld d, 0
462
add hl, de
463
add hl, de
464
ld a, [hli]
465
ld e, a
466
ld d, [hl] ; de = address of pokedex entry
467
468
hlcoord 9, 4
469
call PlaceString ; print species name
470
471
ld h, b
472
ld l, c
473
push de
474
ld a, [wPokedexNum]
475
push af
476
call IndexToPokedex
477
478
hlcoord 2, 8
479
ld a, "№"
480
ld [hli], a
481
ld a, "<DOT>"
482
ld [hli], a
483
ld de, wPokedexNum
484
lb bc, LEADING_ZEROES | 1, 3
485
call PrintNumber ; print pokedex number
486
487
ld hl, wPokedexOwned
488
call IsPokemonBitSet
489
pop af
490
ld [wPokedexNum], a
491
ld a, [wCurPartySpecies]
492
ld [wCurSpecies], a
493
pop de
494
495
push af
496
push bc
497
push de
498
push hl
499
500
call Delay3
501
call GBPalNormal
502
call GetMonHeader ; load pokemon picture location
503
hlcoord 1, 1
504
call LoadFlippedFrontSpriteByMonIndex ; draw pokemon picture
505
ld a, [wCurPartySpecies]
506
call PlayCry
507
508
pop hl
509
pop de
510
pop bc
511
pop af
512
513
ld a, c
514
and a
515
jp z, .waitForButtonPress ; if the pokemon has not been owned, don't print the height, weight, or description
516
inc de ; de = address of feet (height)
517
ld a, [de] ; reads feet, but a is overwritten without being used
518
hlcoord 12, 6
519
lb bc, 1, 2
520
call PrintNumber ; print feet (height)
521
ld a, "′"
522
ld [hl], a
523
inc de
524
inc de ; de = address of inches (height)
525
hlcoord 15, 6
526
lb bc, LEADING_ZEROES | 1, 2
527
call PrintNumber ; print inches (height)
528
ld a, "″"
529
ld [hl], a
530
; now print the weight (note that weight is stored in tenths of pounds internally)
531
inc de
532
inc de
533
inc de ; de = address of upper byte of weight
534
push de
535
; put weight in big-endian order at hDexWeight
536
ld hl, hDexWeight
537
ld a, [hl] ; save existing value of [hDexWeight]
538
push af
539
ld a, [de] ; a = upper byte of weight
540
ld [hli], a ; store upper byte of weight in [hDexWeight]
541
ld a, [hl] ; save existing value of [hDexWeight + 1]
542
push af
543
dec de
544
ld a, [de] ; a = lower byte of weight
545
ld [hl], a ; store lower byte of weight in [hDexWeight + 1]
546
ld de, hDexWeight
547
hlcoord 11, 8
548
lb bc, 2, 5 ; 2 bytes, 5 digits
549
call PrintNumber ; print weight
550
hlcoord 14, 8
551
ldh a, [hDexWeight + 1]
552
sub 10
553
ldh a, [hDexWeight]
554
sbc 0
555
jr nc, .next
556
ld [hl], "0" ; if the weight is less than 10, put a 0 before the decimal point
557
.next
558
inc hl
559
ld a, [hli]
560
ld [hld], a ; make space for the decimal point by moving the last digit forward one tile
561
ld [hl], "<DOT>" ; decimal point tile
562
pop af
563
ldh [hDexWeight + 1], a ; restore original value of [hDexWeight + 1]
564
pop af
565
ldh [hDexWeight], a ; restore original value of [hDexWeight]
566
pop hl
567
inc hl ; hl = address of pokedex description text
568
bccoord 1, 11
569
ld a, %10
570
ldh [hClearLetterPrintingDelayFlags], a
571
call TextCommandProcessor ; print pokedex description text
572
xor a
573
ldh [hClearLetterPrintingDelayFlags], a
574
.waitForButtonPress
575
call JoypadLowSensitivity
576
ldh a, [hJoy5]
577
and PAD_A | PAD_B
578
jr z, .waitForButtonPress
579
pop af
580
ldh [hTileAnimations], a
581
call GBPalWhiteOut
582
call ClearScreen
583
call RunDefaultPaletteCommand
584
call LoadTextBoxTilePatterns
585
call GBPalNormal
586
ld hl, wStatusFlags2
587
res BIT_NO_AUDIO_FADE_OUT, [hl]
588
ld a, $77 ; max volume
589
ldh [rAUDVOL], a
590
ret
591
592
HeightWeightText:
593
db "HT ?′??″"
594
next "WT ???lb@"
595
596
; XXX does anything point to this?
597
PokeText:
598
db "#@"
599
600
; horizontal line that divides the pokedex text description from the rest of the data
601
PokedexDataDividerLine:
602
db $68, $69, $6B, $69, $6B, $69, $6B, $69, $6B, $6B
603
db $6B, $6B, $69, $6B, $69, $6B, $69, $6B, $69, $6A
604
db "@"
605
606
; draws a line of tiles
607
; INPUT:
608
; b = tile ID
609
; c = number of tile ID's to write
610
; de = amount to destination address after each tile (1 for horizontal, 20 for vertical)
611
; hl = destination address
612
DrawTileLine:
613
push bc
614
push de
615
.loop
616
ld [hl], b
617
add hl, de
618
dec c
619
jr nz, .loop
620
pop de
621
pop bc
622
ret
623
624
INCLUDE "data/pokemon/dex_entries.asm"
625
626
PokedexToIndex:
627
; converts the Pokédex number at [wPokedexNum] to an index
628
push bc
629
push hl
630
ld a, [wPokedexNum]
631
ld b, a
632
ld c, 0
633
ld hl, PokedexOrder
634
635
.loop ; go through the list until we find an entry with a matching dex number
636
inc c
637
ld a, [hli]
638
cp b
639
jr nz, .loop
640
641
ld a, c
642
ld [wPokedexNum], a
643
pop hl
644
pop bc
645
ret
646
647
IndexToPokedex:
648
; converts the index number at [wPokedexNum] to a Pokédex number
649
push bc
650
push hl
651
ld a, [wPokedexNum]
652
dec a
653
ld hl, PokedexOrder
654
ld b, 0
655
ld c, a
656
add hl, bc
657
ld a, [hl]
658
ld [wPokedexNum], a
659
pop hl
660
pop bc
661
ret
662
663
INCLUDE "data/pokemon/dex_order.asm"
664
665