-
Notifications
You must be signed in to change notification settings - Fork 806
/
pokedex.asm
2579 lines (2345 loc) · 45 KB
/
pokedex.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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Pokedex_RunJumptable.Jumptable indexes
const_def
const DEXSTATE_MAIN_SCR
const DEXSTATE_UPDATE_MAIN_SCR
const DEXSTATE_DEX_ENTRY_SCR
const DEXSTATE_UPDATE_DEX_ENTRY_SCR
const DEXSTATE_REINIT_DEX_ENTRY_SCR
const DEXSTATE_SEARCH_SCR
const DEXSTATE_UPDATE_SEARCH_SCR
const DEXSTATE_OPTION_SCR
const DEXSTATE_UPDATE_OPTION_SCR
const DEXSTATE_SEARCH_RESULTS_SCR
const DEXSTATE_UPDATE_SEARCH_RESULTS_SCR
const DEXSTATE_UNOWN_MODE
const DEXSTATE_UPDATE_UNOWN_MODE
const DEXSTATE_EXIT
DEF POKEDEX_SCX EQU 5
EXPORT POKEDEX_SCX
Pokedex:
ldh a, [hWX]
ld l, a
ldh a, [hWY]
ld h, a
push hl
ldh a, [hSCX]
push af
ld hl, wOptions
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
ld a, [wStateFlags]
push af
xor a
ld [wStateFlags], a
ldh a, [hInMenu]
push af
ld a, $1
ldh [hInMenu], a
xor a
ldh [hMapAnims], a
call InitPokedex
call DelayFrame
.main
call JoyTextDelay
ld a, [wJumptableIndex]
bit 7, a
jr nz, .exit
call Pokedex_RunJumptable
call DelayFrame
jr .main
.exit
ld de, SFX_READ_TEXT_2
call PlaySFX
call WaitSFX
call ClearSprites
ld a, [wCurDexMode]
ld [wLastDexMode], a
pop af
ldh [hInMenu], a
pop af
ld [wStateFlags], a
pop af
ld [wOptions], a
pop af
ldh [hSCX], a
pop hl
ld a, l
ldh [hWX], a
ld a, h
ldh [hWY], a
ret
InitPokedex:
call ClearBGPalettes
call ClearSprites
call ClearTilemap
call Pokedex_LoadGFX
ld hl, wPokedexDataStart
ld bc, wPokedexDataEnd - wPokedexDataStart
xor a
call ByteFill
xor a
ld [wJumptableIndex], a
ld [wPrevDexEntryJumptableIndex], a
ld [wPrevDexEntryBackup], a
ld [wUnusedPokedexByte], a
call Pokedex_CheckUnlockedUnownMode
ld a, [wLastDexMode]
ld [wCurDexMode], a
call Pokedex_OrderMonsByMode
call Pokedex_InitCursorPosition
call Pokedex_GetLandmark
farcall DrawDexEntryScreenRightEdge
call Pokedex_ResetBGMapMode
ret
Pokedex_CheckUnlockedUnownMode:
ld a, [wStatusFlags]
bit STATUSFLAGS_UNOWN_DEX_F, a
jr nz, .unlocked
xor a
ld [wUnlockedUnownMode], a
ret
.unlocked
ld a, TRUE
ld [wUnlockedUnownMode], a
ret
Pokedex_InitCursorPosition:
ld hl, wPokedexOrder
ld a, [wPrevDexEntry]
and a
jr z, .done
cp NUM_POKEMON + 1
jr nc, .done
ld b, a
ld a, [wDexListingEnd]
cp $8
jr c, .only_one_page
sub $7
ld c, a
.loop1
ld a, b
cp [hl]
jr z, .done
inc hl
ld a, [wDexListingScrollOffset]
inc a
ld [wDexListingScrollOffset], a
dec c
jr nz, .loop1
.only_one_page
ld c, $7
.loop2
ld a, b
cp [hl]
jr z, .done
inc hl
ld a, [wDexListingCursor]
inc a
ld [wDexListingCursor], a
dec c
jr nz, .loop2
.done
ret
Pokedex_GetLandmark:
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
cp LANDMARK_SPECIAL
jr nz, .load
ld a, [wBackupMapGroup]
ld b, a
ld a, [wBackupMapNumber]
ld c, a
call GetWorldMapLocation
.load
ld [wDexCurLocation], a
ret
Pokedex_RunJumptable:
ld a, [wJumptableIndex]
ld hl, .Jumptable
call Pokedex_LoadPointer
jp hl
.Jumptable:
; entries correspond to DEXSTATE_* constants
dw Pokedex_InitMainScreen
dw Pokedex_UpdateMainScreen
dw Pokedex_InitDexEntryScreen
dw Pokedex_UpdateDexEntryScreen
dw Pokedex_ReinitDexEntryScreen
dw Pokedex_InitSearchScreen
dw Pokedex_UpdateSearchScreen
dw Pokedex_InitOptionScreen
dw Pokedex_UpdateOptionScreen
dw Pokedex_InitSearchResultsScreen
dw Pokedex_UpdateSearchResultsScreen
dw Pokedex_InitUnownMode
dw Pokedex_UpdateUnownMode
dw Pokedex_Exit
Pokedex_IncrementDexPointer:
ld hl, wJumptableIndex
inc [hl]
ret
Pokedex_Exit:
ld hl, wJumptableIndex
set 7, [hl]
ret
Pokedex_InitMainScreen:
xor a
ldh [hBGMapMode], a
call ClearSprites
xor a
hlcoord 0, 0, wAttrmap
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
call ByteFill
farcall DrawPokedexListWindow
hlcoord 0, 17
ld de, String_START_SEARCH
call Pokedex_PlaceString
ld a, 7
ld [wDexListingHeight], a
call Pokedex_PrintListing
call Pokedex_SetBGMapMode_3ifDMG_4ifCGB
call Pokedex_ResetBGMapMode
call Pokedex_DrawMainScreenBG
ld a, POKEDEX_SCX
ldh [hSCX], a
ld a, [wCurDexMode]
cp DEXMODE_OLD
ld a, $4a
jr z, .okay
ld a, $47
.okay
ldh [hWX], a
xor a
ldh [hWY], a
call WaitBGMap
call Pokedex_ResetBGMapMode
ld a, -1
ld [wCurPartySpecies], a
ld a, SCGB_POKEDEX
call Pokedex_GetSGBLayout
call Pokedex_UpdateCursorOAM
farcall DrawPokedexListWindow
hlcoord 0, 17
ld de, String_START_SEARCH
call Pokedex_PlaceString
ld a, 7
ld [wDexListingHeight], a
call Pokedex_PrintListing
call Pokedex_IncrementDexPointer
ret
Pokedex_UpdateMainScreen:
ld hl, hJoyPressed
ld a, [hl]
and B_BUTTON
jr nz, .b
ld a, [hl]
and A_BUTTON
jr nz, .a
ld a, [hl]
and SELECT
jr nz, .select
ld a, [hl]
and START
jr nz, .start
call Pokedex_ListingHandleDPadInput
ret nc
call Pokedex_UpdateCursorOAM
xor a
ldh [hBGMapMode], a
call Pokedex_PrintListing
call Pokedex_SetBGMapMode3
call Pokedex_ResetBGMapMode
ret
.a
call Pokedex_GetSelectedMon
call Pokedex_CheckSeen
ret z
ld a, DEXSTATE_DEX_ENTRY_SCR
ld [wJumptableIndex], a
ld a, DEXSTATE_MAIN_SCR
ld [wPrevDexEntryJumptableIndex], a
ret
.select
call Pokedex_BlackOutBG
ld a, DEXSTATE_OPTION_SCR
ld [wJumptableIndex], a
xor a
ldh [hSCX], a
ld a, $a7
ldh [hWX], a
call DelayFrame
ret
.start
call Pokedex_BlackOutBG
ld a, DEXSTATE_SEARCH_SCR
ld [wJumptableIndex], a
xor a
ldh [hSCX], a
ld a, $a7
ldh [hWX], a
call DelayFrame
ret
.b
ld a, DEXSTATE_EXIT
ld [wJumptableIndex], a
ret
Pokedex_InitDexEntryScreen:
call LowVolume
xor a ; page 1
ld [wPokedexStatus], a
xor a
ldh [hBGMapMode], a
call ClearSprites
call Pokedex_LoadCurrentFootprint
call Pokedex_DrawDexEntryScreenBG
call Pokedex_InitArrowCursor
call Pokedex_GetSelectedMon
ld [wPrevDexEntry], a
farcall DisplayDexEntry
call Pokedex_DrawFootprint
call WaitBGMap
ld a, $a7
ldh [hWX], a
call Pokedex_GetSelectedMon
ld [wCurPartySpecies], a
ld a, SCGB_POKEDEX
call Pokedex_GetSGBLayout
ld a, [wCurPartySpecies]
call PlayMonCry
call Pokedex_IncrementDexPointer
ret
Pokedex_UpdateDexEntryScreen:
ld de, DexEntryScreen_ArrowCursorData
call Pokedex_MoveArrowCursor
ld hl, hJoyPressed
ld a, [hl]
and B_BUTTON
jr nz, .return_to_prev_screen
vc_hook Forbid_printing_Pokedex
ld a, [hl]
and A_BUTTON
jr nz, .do_menu_action
call Pokedex_NextOrPreviousDexEntry
ret nc
call Pokedex_IncrementDexPointer
ret
.do_menu_action
ld a, [wDexArrowCursorPosIndex]
ld hl, DexEntryScreen_MenuActionJumptable
call Pokedex_LoadPointer
jp hl
.return_to_prev_screen
ld a, [wLastVolume]
and a
jr z, .max_volume
ld a, MAX_VOLUME
ld [wLastVolume], a
.max_volume
call MaxVolume
ld a, [wPrevDexEntryJumptableIndex]
ld [wJumptableIndex], a
ret
Pokedex_Page:
ld a, [wPokedexStatus]
xor 1 ; toggle page
ld [wPokedexStatus], a
call Pokedex_GetSelectedMon
ld [wPrevDexEntry], a
farcall DisplayDexEntry
call WaitBGMap
ret
Pokedex_ReinitDexEntryScreen:
; Reinitialize the Pokédex entry screen after changing the selected mon.
call Pokedex_BlackOutBG
xor a ; page 1
ld [wPokedexStatus], a
xor a
ldh [hBGMapMode], a
call Pokedex_DrawDexEntryScreenBG
call Pokedex_InitArrowCursor
call Pokedex_LoadCurrentFootprint
call Pokedex_GetSelectedMon
ld [wPrevDexEntry], a
farcall DisplayDexEntry
call Pokedex_DrawFootprint
call Pokedex_LoadSelectedMonTiles
call WaitBGMap
call Pokedex_GetSelectedMon
ld [wCurPartySpecies], a
ld a, SCGB_POKEDEX
call Pokedex_GetSGBLayout
ld a, [wCurPartySpecies]
call PlayMonCry
ld hl, wJumptableIndex
dec [hl]
ret
DexEntryScreen_ArrowCursorData:
db D_RIGHT | D_LEFT, 4
dwcoord 1, 17 ; PAGE
dwcoord 6, 17 ; AREA
dwcoord 11, 17 ; CRY
dwcoord 15, 17 ; PRNT
DexEntryScreen_MenuActionJumptable:
dw Pokedex_Page
dw .Area
dw .Cry
dw .Print
.Area:
call Pokedex_BlackOutBG
xor a
ldh [hSCX], a
call DelayFrame
ld a, $7
ldh [hWX], a
ld a, $90
ldh [hWY], a
call Pokedex_GetSelectedMon
ld a, [wDexCurLocation]
ld e, a
predef Pokedex_GetArea
call Pokedex_BlackOutBG
call DelayFrame
xor a
ldh [hBGMapMode], a
ld a, $90
ldh [hWY], a
ld a, POKEDEX_SCX
ldh [hSCX], a
call DelayFrame
call Pokedex_RedisplayDexEntry
call Pokedex_LoadSelectedMonTiles
call WaitBGMap
call Pokedex_GetSelectedMon
ld [wCurPartySpecies], a
ld a, SCGB_POKEDEX
call Pokedex_GetSGBLayout
ret
.Cry:
; BUG: Playing Entei's Pokédex cry can distort Raikou's and Suicune's (see docs/bugs_and_glitches.md)
call Pokedex_GetSelectedMon
ld a, [wTempSpecies]
call GetCryIndex
ld e, c
ld d, b
call PlayCry
ret
.Print:
call Pokedex_ApplyPrintPals
xor a
ldh [hSCX], a
ld a, [wPrevDexEntryBackup]
push af
ld a, [wPrevDexEntryJumptableIndex]
push af
ld a, [wJumptableIndex]
push af
farcall PrintDexEntry
pop af
ld [wJumptableIndex], a
pop af
ld [wPrevDexEntryJumptableIndex], a
pop af
ld [wPrevDexEntryBackup], a
call ClearBGPalettes
call DisableLCD
call Pokedex_LoadInvertedFont
call Pokedex_RedisplayDexEntry
call EnableLCD
call WaitBGMap
ld a, POKEDEX_SCX
ldh [hSCX], a
call Pokedex_ApplyUsualPals
ret
Pokedex_RedisplayDexEntry:
call Pokedex_DrawDexEntryScreenBG
call Pokedex_GetSelectedMon
farcall DisplayDexEntry
call Pokedex_DrawFootprint
ret
Pokedex_InitOptionScreen:
xor a
ldh [hBGMapMode], a
call ClearSprites
call Pokedex_DrawOptionScreenBG
call Pokedex_InitArrowCursor
; point cursor to the current dex mode (modes == menu item indexes)
ld a, [wCurDexMode]
ld [wDexArrowCursorPosIndex], a
call Pokedex_DisplayModeDescription
call WaitBGMap
ld a, SCGB_POKEDEX_SEARCH_OPTION
call Pokedex_GetSGBLayout
call Pokedex_IncrementDexPointer
ret
Pokedex_UpdateOptionScreen:
ld a, [wUnlockedUnownMode]
and a
jr nz, .okay
ld de, .NoUnownModeArrowCursorData
jr .okay2
.okay
ld de, .ArrowCursorData
.okay2
call Pokedex_MoveArrowCursor
call c, Pokedex_DisplayModeDescription
ld hl, hJoyPressed
ld a, [hl]
and SELECT | B_BUTTON
jr nz, .return_to_main_screen
ld a, [hl]
and A_BUTTON
jr nz, .do_menu_action
ret
.do_menu_action
ld a, [wDexArrowCursorPosIndex]
ld hl, .MenuActionJumptable
call Pokedex_LoadPointer
jp hl
.return_to_main_screen
call Pokedex_BlackOutBG
ld a, DEXSTATE_MAIN_SCR
ld [wJumptableIndex], a
ret
.NoUnownModeArrowCursorData:
db D_UP | D_DOWN, 3
dwcoord 2, 4 ; NEW
dwcoord 2, 6 ; OLD
dwcoord 2, 8 ; ABC
.ArrowCursorData:
db D_UP | D_DOWN, 4
dwcoord 2, 4 ; NEW
dwcoord 2, 6 ; OLD
dwcoord 2, 8 ; ABC
dwcoord 2, 10 ; UNOWN
.MenuActionJumptable:
dw .MenuAction_NewMode
dw .MenuAction_OldMode
dw .MenuAction_ABCMode
dw .MenuAction_UnownMode
.MenuAction_NewMode:
ld b, DEXMODE_NEW
jr .ChangeMode
.MenuAction_OldMode:
ld b, DEXMODE_OLD
jr .ChangeMode
.MenuAction_ABCMode:
ld b, DEXMODE_ABC
.ChangeMode:
ld a, [wCurDexMode]
cp b
jr z, .skip_changing_mode ; Skip if new mode is same as current.
ld a, b
ld [wCurDexMode], a
call Pokedex_OrderMonsByMode
call Pokedex_DisplayChangingModesMessage
xor a
ld [wDexListingScrollOffset], a
ld [wDexListingCursor], a
call Pokedex_InitCursorPosition
.skip_changing_mode
call Pokedex_BlackOutBG
ld a, DEXSTATE_MAIN_SCR
ld [wJumptableIndex], a
ret
.MenuAction_UnownMode:
call Pokedex_BlackOutBG
ld a, DEXSTATE_UNOWN_MODE
ld [wJumptableIndex], a
ret
Pokedex_InitSearchScreen:
xor a
ldh [hBGMapMode], a
call ClearSprites
call Pokedex_DrawSearchScreenBG
call Pokedex_InitArrowCursor
ld a, NORMAL + 1
ld [wDexSearchMonType1], a
xor a
ld [wDexSearchMonType2], a
call Pokedex_PlaceSearchScreenTypeStrings
xor a
ld [wDexSearchSlowpokeFrame], a
farcall DoDexSearchSlowpokeFrame
call WaitBGMap
ld a, SCGB_POKEDEX_SEARCH_OPTION
call Pokedex_GetSGBLayout
call Pokedex_IncrementDexPointer
ret
Pokedex_UpdateSearchScreen:
ld de, .ArrowCursorData
call Pokedex_MoveArrowCursor
call Pokedex_UpdateSearchMonType
call c, Pokedex_PlaceSearchScreenTypeStrings
ld hl, hJoyPressed
ld a, [hl]
and START | B_BUTTON
jr nz, .cancel
ld a, [hl]
and A_BUTTON
jr nz, .do_menu_action
ret
.do_menu_action
ld a, [wDexArrowCursorPosIndex]
ld hl, .MenuActionJumptable
call Pokedex_LoadPointer
jp hl
.cancel
call Pokedex_BlackOutBG
ld a, DEXSTATE_MAIN_SCR
ld [wJumptableIndex], a
ret
.ArrowCursorData:
db D_UP | D_DOWN, 4
dwcoord 2, 4 ; TYPE 1
dwcoord 2, 6 ; TYPE 2
dwcoord 2, 13 ; BEGIN SEARCH
dwcoord 2, 15 ; CANCEL
.MenuActionJumptable:
dw .MenuAction_MonSearchType
dw .MenuAction_MonSearchType
dw .MenuAction_BeginSearch
dw .MenuAction_Cancel
.MenuAction_MonSearchType:
call Pokedex_NextSearchMonType
call Pokedex_PlaceSearchScreenTypeStrings
ret
.MenuAction_BeginSearch:
call Pokedex_SearchForMons
farcall AnimateDexSearchSlowpoke
ld a, [wDexSearchResultCount]
and a
jr nz, .show_search_results
; No mon with matching types was found.
call Pokedex_OrderMonsByMode
call Pokedex_DisplayTypeNotFoundMessage
xor a
ldh [hBGMapMode], a
call Pokedex_DrawSearchScreenBG
call Pokedex_InitArrowCursor
call Pokedex_PlaceSearchScreenTypeStrings
call WaitBGMap
ret
.show_search_results
ld [wDexListingEnd], a
ld a, [wDexListingScrollOffset]
ld [wDexListingScrollOffsetBackup], a
ld a, [wDexListingCursor]
ld [wDexListingCursorBackup], a
ld a, [wPrevDexEntry]
ld [wPrevDexEntryBackup], a
xor a
ld [wDexListingScrollOffset], a
ld [wDexListingCursor], a
call Pokedex_BlackOutBG
ld a, DEXSTATE_SEARCH_RESULTS_SCR
ld [wJumptableIndex], a
ret
.MenuAction_Cancel:
call Pokedex_BlackOutBG
ld a, DEXSTATE_MAIN_SCR
ld [wJumptableIndex], a
ret
Pokedex_InitSearchResultsScreen:
xor a
ldh [hBGMapMode], a
xor a
hlcoord 0, 0, wAttrmap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
call Pokedex_SetBGMapMode4
call Pokedex_ResetBGMapMode
farcall DrawPokedexSearchResultsWindow
call Pokedex_PlaceSearchResultsTypeStrings
ld a, 4
ld [wDexListingHeight], a
call Pokedex_PrintListing
call Pokedex_SetBGMapMode3
call Pokedex_ResetBGMapMode
call Pokedex_DrawSearchResultsScreenBG
ld a, POKEDEX_SCX
ldh [hSCX], a
ld a, $4a
ldh [hWX], a
xor a
ldh [hWY], a
call WaitBGMap
call Pokedex_ResetBGMapMode
farcall DrawPokedexSearchResultsWindow
call Pokedex_PlaceSearchResultsTypeStrings
call Pokedex_UpdateSearchResultsCursorOAM
ld a, -1
ld [wCurPartySpecies], a
ld a, SCGB_POKEDEX
call Pokedex_GetSGBLayout
call Pokedex_IncrementDexPointer
ret
Pokedex_UpdateSearchResultsScreen:
ld hl, hJoyPressed
ld a, [hl]
and B_BUTTON
jr nz, .return_to_search_screen
ld a, [hl]
and A_BUTTON
jr nz, .go_to_dex_entry
call Pokedex_ListingHandleDPadInput
ret nc
call Pokedex_UpdateSearchResultsCursorOAM
xor a
ldh [hBGMapMode], a
call Pokedex_PrintListing
call Pokedex_SetBGMapMode3
call Pokedex_ResetBGMapMode
ret
.go_to_dex_entry
call Pokedex_GetSelectedMon
call Pokedex_CheckSeen
ret z
ld a, DEXSTATE_DEX_ENTRY_SCR
ld [wJumptableIndex], a
ld a, DEXSTATE_SEARCH_RESULTS_SCR
ld [wPrevDexEntryJumptableIndex], a
ret
.return_to_search_screen
ld a, [wDexListingScrollOffsetBackup]
ld [wDexListingScrollOffset], a
ld a, [wDexListingCursorBackup]
ld [wDexListingCursor], a
ld a, [wPrevDexEntryBackup]
ld [wPrevDexEntry], a
call Pokedex_BlackOutBG
call ClearSprites
call Pokedex_OrderMonsByMode
ld a, DEXSTATE_SEARCH_SCR
ld [wJumptableIndex], a
xor a
ldh [hSCX], a
ld a, $a7
ldh [hWX], a
ret
Pokedex_InitUnownMode:
call Pokedex_LoadUnownFont
call Pokedex_DrawUnownModeBG
xor a
ld [wDexCurUnownIndex], a
call Pokedex_LoadUnownFrontpicTiles
call Pokedex_UnownModePlaceCursor
farcall PrintUnownWord
call WaitBGMap
ld a, SCGB_POKEDEX_UNOWN_MODE
call Pokedex_GetSGBLayout
call Pokedex_IncrementDexPointer
ret
Pokedex_UpdateUnownMode:
ld hl, hJoyPressed
ld a, [hl]
and A_BUTTON | B_BUTTON
jr nz, .a_b
call Pokedex_UnownModeHandleDPadInput
ret
.a_b
call Pokedex_BlackOutBG
ld a, DEXSTATE_OPTION_SCR
ld [wJumptableIndex], a
call DelayFrame
call Pokedex_CheckSGB
jr nz, .decompress
farcall LoadSGBPokedexGFX2
jr .done
.decompress
ld hl, PokedexLZ
ld de, vTiles2 tile $31
lb bc, BANK(PokedexLZ), 58
call DecompressRequest2bpp
.done
ret
Pokedex_UnownModeHandleDPadInput:
ld hl, hJoyLast
ld a, [hl]
and D_RIGHT
jr nz, .right
ld a, [hl]
and D_LEFT
jr nz, .left
ret
.right
ld a, [wDexUnownCount]
ld e, a
ld hl, wDexCurUnownIndex
ld a, [hl]
inc a
cp e
ret nc
ld a, [hl]
inc [hl]
jr .update
.left
ld hl, wDexCurUnownIndex
ld a, [hl]
and a
ret z
ld a, [hl]
dec [hl]
.update
push af
xor a
ldh [hBGMapMode], a
pop af
call Pokedex_UnownModeEraseCursor
call Pokedex_LoadUnownFrontpicTiles
call Pokedex_UnownModePlaceCursor
farcall PrintUnownWord
ld a, $1
ldh [hBGMapMode], a
call DelayFrame
call DelayFrame
ret
Pokedex_UnownModeEraseCursor:
ld c, " "
jr Pokedex_UnownModeUpdateCursorGfx
Pokedex_UnownModePlaceCursor:
ld a, [wDexCurUnownIndex]
ld c, FIRST_UNOWN_CHAR + NUM_UNOWN ; diamond cursor
Pokedex_UnownModeUpdateCursorGfx:
ld e, a
ld d, 0
ld hl, UnownModeLetterAndCursorCoords + 2
rept 4
add hl, de
endr
ld a, [hli]
ld h, [hl]
ld l, a
ld [hl], c
ret
Pokedex_NextOrPreviousDexEntry:
ld a, [wDexListingCursor]
ld [wBackupDexListingCursor], a
ld a, [wDexListingScrollOffset]
ld [wBackupDexListingPage], a
ld hl, hJoyLast
ld a, [hl]
and D_UP
jr nz, .up
ld a, [hl]
and D_DOWN
jr nz, .down
and a
ret
.up
ld a, [wDexListingHeight]
ld d, a
ld a, [wDexListingEnd]
ld e, a
call Pokedex_ListingMoveCursorUp
jr nc, .nope
call Pokedex_GetSelectedMon
call Pokedex_CheckSeen
jr nz, .yep
jr .up
.down
ld a, [wDexListingHeight]
ld d, a
ld a, [wDexListingEnd]
ld e, a
call Pokedex_ListingMoveCursorDown
jr nc, .nope
call Pokedex_GetSelectedMon
call Pokedex_CheckSeen
jr nz, .yep
jr .down
.yep
scf
ret
.nope
ld a, [wBackupDexListingCursor]
ld [wDexListingCursor], a
ld a, [wBackupDexListingPage]
ld [wDexListingScrollOffset], a
and a
ret
Pokedex_ListingHandleDPadInput:
; Handles D-pad input for a list of Pokémon.
ld a, [wDexListingHeight]
ld d, a
ld a, [wDexListingEnd]
ld e, a
ld hl, hJoyLast
ld a, [hl]
and D_UP
jr nz, Pokedex_ListingMoveCursorUp
ld a, [hl]
and D_DOWN
jr nz, Pokedex_ListingMoveCursorDown
ld a, d
cp e
jr nc, Pokedex_ListingPosStayedSame
ld a, [hl]
and D_LEFT
jr nz, Pokedex_ListingMoveUpOnePage
ld a, [hl]
and D_RIGHT
jr nz, Pokedex_ListingMoveDownOnePage
jr Pokedex_ListingPosStayedSame
Pokedex_ListingMoveCursorUp:
ld hl, wDexListingCursor
ld a, [hl]
and a
jr z, .try_scrolling
dec [hl]
jr Pokedex_ListingPosChanged
.try_scrolling
ld hl, wDexListingScrollOffset
ld a, [hl]
and a
jr z, Pokedex_ListingPosStayedSame
dec [hl]
jr Pokedex_ListingPosChanged
Pokedex_ListingMoveCursorDown:
ld hl, wDexListingCursor
ld a, [hl]