-
Notifications
You must be signed in to change notification settings - Fork 826
/
pokegear.asm
2923 lines (2674 loc) · 48.7 KB
/
pokegear.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
; Pokégear cards
const_def
const POKEGEARCARD_CLOCK ; 0
const POKEGEARCARD_MAP ; 1
const POKEGEARCARD_PHONE ; 2
const POKEGEARCARD_RADIO ; 3
DEF NUM_POKEGEAR_CARDS EQU const_value
DEF PHONE_DISPLAY_HEIGHT EQU 4
; PokegearJumptable.Jumptable indexes
const_def
const POKEGEARSTATE_CLOCKINIT ; 0
const POKEGEARSTATE_CLOCKJOYPAD ; 1
const POKEGEARSTATE_MAPCHECKREGION ; 2
const POKEGEARSTATE_JOHTOMAPINIT ; 3
const POKEGEARSTATE_JOHTOMAPJOYPAD ; 4
const POKEGEARSTATE_KANTOMAPINIT ; 5
const POKEGEARSTATE_KANTOMAPJOYPAD ; 6
const POKEGEARSTATE_PHONEINIT ; 7
const POKEGEARSTATE_PHONEJOYPAD ; 8
const POKEGEARSTATE_MAKEPHONECALL ; 9
const POKEGEARSTATE_FINISHPHONECALL ; a
const POKEGEARSTATE_RADIOINIT ; b
const POKEGEARSTATE_RADIOJOYPAD ; c
PokeGear:
ld hl, wOptions
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
ldh a, [hInMenu]
push af
ld a, $1
ldh [hInMenu], a
ld a, [wStateFlags]
push af
xor a
ld [wStateFlags], a
call .InitTilemap
call DelayFrame
.loop
call UpdateTime
call JoyTextDelay
ld a, [wJumptableIndex]
bit JUMPTABLE_EXIT_F, a
jr nz, .done
call PokegearJumptable
farcall PlaySpriteAnimations
call DelayFrame
jr .loop
.done
ld de, SFX_READ_TEXT_2
call PlaySFX
call WaitSFX
pop af
ld [wStateFlags], a
pop af
ldh [hInMenu], a
pop af
ld [wOptions], a
call ClearBGPalettes
xor a ; LOW(vBGMap0)
ldh [hBGMapAddress], a
ld a, HIGH(vBGMap0)
ldh [hBGMapAddress + 1], a
ld a, SCREEN_HEIGHT_PX
ldh [hWY], a
call ExitPokegearRadio_HandleMusic
ret
.InitTilemap:
call ClearBGPalettes
call ClearTilemap
call ClearSprites
call DisableLCD
xor a
ldh [hSCY], a
ldh [hSCX], a
ld a, $7
ldh [hWX], a
call Pokegear_LoadGFX
farcall ClearSpriteAnims
call InitPokegearModeIndicatorArrow
ld a, 8
call SkipMusic
ld a, LCDC_DEFAULT
ldh [rLCDC], a
call TownMap_InitCursorAndPlayerIconPositions
xor a
ld [wJumptableIndex], a ; POKEGEARSTATE_CLOCKINIT
ld [wPokegearCard], a ; POKEGEARCARD_CLOCK
ld [wPokegearMapRegion], a ; JOHTO_REGION
ld [wUnusedPokegearByte], a
ld [wPokegearPhoneScrollPosition], a
ld [wPokegearPhoneCursorPosition], a
ld [wPokegearPhoneSelectedPerson], a
ld [wPokegearRadioChannelBank], a
ld [wPokegearRadioChannelAddr], a
ld [wPokegearRadioChannelAddr + 1], a
call Pokegear_InitJumptableIndices
call InitPokegearTilemap
ld b, SCGB_POKEGEAR_PALS
call GetSGBLayout
call SetDefaultBGPAndOBP
ldh a, [hCGB]
and a
ret z
ld a, %11100100
call DmgToCgbObjPal0
ret
Pokegear_LoadGFX:
call ClearVBank1
ld hl, TownMapGFX
ld de, vTiles2
ld a, BANK(TownMapGFX)
call FarDecompress
ld hl, PokegearGFX
ld de, vTiles2 tile $30
ld a, BANK(PokegearGFX)
call FarDecompress
ld hl, PokegearSpritesGFX
ld de, vTiles0
ld a, BANK(PokegearSpritesGFX)
call Decompress
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
cp LANDMARK_FAST_SHIP
jr z, .ssaqua
farcall GetPlayerIcon
push de
ld h, d
ld l, e
ld a, b
; standing sprite
push af
ld de, vTiles0 tile $10
ld bc, 4 tiles
call FarCopyBytes
pop af
pop hl
; walking sprite
ld de, 12 tiles
add hl, de
ld de, vTiles0 tile $14
ld bc, 4 tiles
call FarCopyBytes
ret
.ssaqua
ld hl, FastShipGFX
ld de, vTiles0 tile $10
ld bc, 8 tiles
call CopyBytes
ret
FastShipGFX:
INCBIN "gfx/pokegear/fast_ship.2bpp"
InitPokegearModeIndicatorArrow:
depixel 4, 2, 4, 0
ld a, SPRITE_ANIM_OBJ_POKEGEAR_ARROW
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $0
ret
AnimatePokegearModeIndicatorArrow:
ld hl, wPokegearCard
ld e, [hl]
ld d, 0
ld hl, .XCoords
add hl, de
ld a, [hl]
ld hl, SPRITEANIMSTRUCT_XOFFSET
add hl, bc
ld [hl], a
ret
.XCoords:
db $00 ; POKEGEARCARD_CLOCK
db $10 ; POKEGEARCARD_MAP
db $20 ; POKEGEARCARD_PHONE
db $30 ; POKEGEARCARD_RADIO
TownMap_GetCurrentLandmark:
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
cp LANDMARK_SPECIAL
ret nz
ld a, [wBackupMapGroup]
ld b, a
ld a, [wBackupMapNumber]
ld c, a
call GetWorldMapLocation
ret
TownMap_InitCursorAndPlayerIconPositions:
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
cp LANDMARK_FAST_SHIP
jr z, .FastShip
cp LANDMARK_SPECIAL
jr nz, .LoadLandmark
ld a, [wBackupMapGroup]
ld b, a
ld a, [wBackupMapNumber]
ld c, a
call GetWorldMapLocation
.LoadLandmark:
ld [wPokegearMapPlayerIconLandmark], a
ld [wPokegearMapCursorLandmark], a
ret
.FastShip:
ld [wPokegearMapPlayerIconLandmark], a
ld a, LANDMARK_NEW_BARK_TOWN
ld [wPokegearMapCursorLandmark], a
ret
Pokegear_InitJumptableIndices:
ld a, POKEGEARSTATE_CLOCKINIT
ld [wJumptableIndex], a
xor a ; POKEGEARCARD_CLOCK
ld [wPokegearCard], a
ret
InitPokegearTilemap:
xor a
ldh [hBGMapMode], a
hlcoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
ld a, $4f
call ByteFill
ld a, [wPokegearCard]
maskbits NUM_POKEGEAR_CARDS
add a
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld de, .return_from_jumptable
push de
jp hl
.return_from_jumptable
call Pokegear_FinishTilemap
farcall TownMapPals
ld a, [wPokegearMapRegion]
and a
jr nz, .kanto_0
xor a ; LOW(vBGMap0)
ldh [hBGMapAddress], a
ld a, HIGH(vBGMap0)
ldh [hBGMapAddress + 1], a
call .UpdateBGMap
ld a, SCREEN_HEIGHT_PX
jr .finish
.kanto_0
xor a ; LOW(vBGMap1)
ldh [hBGMapAddress], a
ld a, HIGH(vBGMap1)
ldh [hBGMapAddress + 1], a
call .UpdateBGMap
xor a
.finish
ldh [hWY], a
; swap region maps
ld a, [wPokegearMapRegion]
maskbits NUM_REGIONS
xor 1
ld [wPokegearMapRegion], a
ret
.UpdateBGMap:
ldh a, [hCGB]
and a
jr z, .dmg
ld a, $2
ldh [hBGMapMode], a
ld c, 3
call DelayFrames
.dmg
call WaitBGMap
ret
.Jumptable:
; entries correspond to POKEGEARCARD_* constants
dw .Clock
dw .Map
dw .Phone
dw .Radio
.Clock:
ld de, ClockTilemapRLE
call Pokegear_LoadTilemapRLE
hlcoord 12, 1
ld de, .switch
call PlaceString
hlcoord 0, 12
lb bc, 4, 18
call Textbox
call Pokegear_UpdateClock
ret
.switch
db " SWITCH▶@"
.Map:
ld a, [wPokegearMapPlayerIconLandmark]
cp LANDMARK_FAST_SHIP
jr z, .johto
cp KANTO_LANDMARK
jr nc, .kanto
.johto
ld e, 0
jr .ok
.kanto
ld e, 1
.ok
farcall PokegearMap
ld a, $07
ld bc, SCREEN_WIDTH - 2
hlcoord 1, 2
call ByteFill
hlcoord 0, 2
ld [hl], $06
hlcoord 19, 2
ld [hl], $17
ld a, [wPokegearMapCursorLandmark]
call PokegearMap_UpdateLandmarkName
ret
.Radio:
ld de, RadioTilemapRLE
call Pokegear_LoadTilemapRLE
hlcoord 0, 12
lb bc, 4, 18
call Textbox
ret
.Phone:
ld de, PhoneTilemapRLE
call Pokegear_LoadTilemapRLE
hlcoord 0, 12
lb bc, 4, 18
call Textbox
call .PlacePhoneBars
call PokegearPhone_UpdateDisplayList
ret
.PlacePhoneBars:
hlcoord 17, 1
ld a, $3c
ld [hli], a
inc a
ld [hl], a
hlcoord 17, 2
inc a
ld [hli], a
call GetMapPhoneService
and a
ret nz
hlcoord 18, 2
ld [hl], $3f
ret
Pokegear_FinishTilemap:
hlcoord 0, 0
ld bc, $8
ld a, $4f
call ByteFill
hlcoord 0, 1
ld bc, $8
ld a, $4f
call ByteFill
ld de, wPokegearFlags
ld a, [de]
bit POKEGEAR_MAP_CARD_F, a
call nz, .PlaceMapIcon
ld a, [de]
bit POKEGEAR_PHONE_CARD_F, a
call nz, .PlacePhoneIcon
ld a, [de]
bit POKEGEAR_RADIO_CARD_F, a
call nz, .PlaceRadioIcon
hlcoord 0, 0
ld a, $46
call .PlacePokegearCardIcon
ret
.PlaceMapIcon:
hlcoord 2, 0
ld a, $40
jr .PlacePokegearCardIcon
.PlacePhoneIcon:
hlcoord 4, 0
ld a, $44
jr .PlacePokegearCardIcon
.PlaceRadioIcon:
hlcoord 6, 0
ld a, $42
.PlacePokegearCardIcon:
ld [hli], a
inc a
ld [hld], a
ld bc, $14
add hl, bc
add $f
ld [hli], a
inc a
ld [hld], a
ret
PokegearJumptable:
jumptable .Jumptable, wJumptableIndex
.Jumptable:
; entries correspond to POKEGEARSTATE_* constants
dw PokegearClock_Init
dw PokegearClock_Joypad
dw PokegearMap_CheckRegion
dw PokegearMap_Init
dw PokegearMap_JohtoMap
dw PokegearMap_Init
dw PokegearMap_KantoMap
dw PokegearPhone_Init
dw PokegearPhone_Joypad
dw PokegearPhone_MakePhoneCall
dw PokegearPhone_FinishPhoneCall
dw PokegearRadio_Init
dw PokegearRadio_Joypad
PokegearClock_Init:
call InitPokegearTilemap
ld hl, PokegearPressButtonText
call PrintText
ld hl, wJumptableIndex
inc [hl]
call ExitPokegearRadio_HandleMusic
ret
PokegearClock_Joypad:
call .UpdateClock
ld hl, hJoyLast
ld a, [hl]
and A_BUTTON | B_BUTTON | START | SELECT
jr nz, .quit
ld a, [hl]
and D_RIGHT
ret z
ld a, [wPokegearFlags]
bit POKEGEAR_MAP_CARD_F, a
jr z, .no_map_card
ld c, POKEGEARSTATE_MAPCHECKREGION
ld b, POKEGEARCARD_MAP
jr .done
.no_map_card
ld a, [wPokegearFlags]
bit POKEGEAR_PHONE_CARD_F, a
jr z, .no_phone_card
ld c, POKEGEARSTATE_PHONEINIT
ld b, POKEGEARCARD_PHONE
jr .done
.no_phone_card
ld a, [wPokegearFlags]
bit POKEGEAR_RADIO_CARD_F, a
ret z
ld c, POKEGEARSTATE_RADIOINIT
ld b, POKEGEARCARD_RADIO
.done
call Pokegear_SwitchPage
ret
.quit
ld hl, wJumptableIndex
set JUMPTABLE_EXIT_F, [hl]
ret
.UpdateClock:
xor a
ldh [hBGMapMode], a
call Pokegear_UpdateClock
ld a, $1
ldh [hBGMapMode], a
ret
Pokegear_UpdateClock:
hlcoord 3, 5
lb bc, 5, 14
call ClearBox
ldh a, [hHours]
ld b, a
ldh a, [hMinutes]
ld c, a
decoord 6, 8
farcall PrintHoursMins
ld hl, .GearTodayText
bccoord 6, 6
call PrintTextboxTextAt
ret
db "ごぜん@"
db "ごご@"
.GearTodayText:
text_far _GearTodayText
text_end
PokegearMap_CheckRegion:
ld a, [wPokegearMapPlayerIconLandmark]
cp LANDMARK_FAST_SHIP
jr z, .johto
cp KANTO_LANDMARK
jr nc, .kanto
.johto
ld a, POKEGEARSTATE_JOHTOMAPINIT
jr .done
ret
.kanto
ld a, POKEGEARSTATE_KANTOMAPINIT
.done
ld [wJumptableIndex], a
call ExitPokegearRadio_HandleMusic
ret
PokegearMap_Init:
call InitPokegearTilemap
ld a, [wPokegearMapPlayerIconLandmark]
call PokegearMap_InitPlayerIcon
ld a, [wPokegearMapCursorLandmark]
call PokegearMap_InitCursor
ld a, c
ld [wPokegearMapCursorObjectPointer], a
ld a, b
ld [wPokegearMapCursorObjectPointer + 1], a
ld hl, wJumptableIndex
inc [hl]
ret
PokegearMap_KantoMap:
call TownMap_GetKantoLandmarkLimits
jr PokegearMap_ContinueMap
PokegearMap_JohtoMap:
ld d, LANDMARK_SILVER_CAVE
ld e, LANDMARK_NEW_BARK_TOWN
PokegearMap_ContinueMap:
ld hl, hJoyLast
ld a, [hl]
and B_BUTTON
jr nz, .cancel
ld a, [hl]
and D_RIGHT
jr nz, .right
ld a, [hl]
and D_LEFT
jr nz, .left
call .DPad
ret
.right
ld a, [wPokegearFlags]
bit POKEGEAR_PHONE_CARD_F, a
jr z, .no_phone
ld c, POKEGEARSTATE_PHONEINIT
ld b, POKEGEARCARD_PHONE
jr .done
.no_phone
ld a, [wPokegearFlags]
bit POKEGEAR_RADIO_CARD_F, a
ret z
ld c, POKEGEARSTATE_RADIOINIT
ld b, POKEGEARCARD_RADIO
jr .done
.left
ld c, POKEGEARSTATE_CLOCKINIT
ld b, POKEGEARCARD_CLOCK
.done
call Pokegear_SwitchPage
ret
.cancel
ld hl, wJumptableIndex
set JUMPTABLE_EXIT_F, [hl]
ret
.DPad:
ld hl, hJoyLast
ld a, [hl]
and D_UP
jr nz, .up
ld a, [hl]
and D_DOWN
jr nz, .down
ret
.up
ld hl, wPokegearMapCursorLandmark
ld a, [hl]
cp d
jr c, .wrap_around_up
ld a, e
dec a
ld [hl], a
.wrap_around_up
inc [hl]
jr .done_dpad
.down
ld hl, wPokegearMapCursorLandmark
ld a, [hl]
cp e
jr nz, .wrap_around_down
ld a, d
inc a
ld [hl], a
.wrap_around_down
dec [hl]
.done_dpad
ld a, [wPokegearMapCursorLandmark]
call PokegearMap_UpdateLandmarkName
ld a, [wPokegearMapCursorObjectPointer]
ld c, a
ld a, [wPokegearMapCursorObjectPointer + 1]
ld b, a
ld a, [wPokegearMapCursorLandmark]
call PokegearMap_UpdateCursorPosition
ret
PokegearMap_InitPlayerIcon:
push af
depixel 0, 0
ld b, SPRITE_ANIM_OBJ_RED_WALK
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .got_gender
ld b, SPRITE_ANIM_OBJ_BLUE_WALK
.got_gender
ld a, b
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $10
pop af
ld e, a
push bc
farcall GetLandmarkCoords
pop bc
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld [hl], e
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld [hl], d
ret
PokegearMap_InitCursor:
push af
depixel 0, 0
ld a, SPRITE_ANIM_OBJ_POKEGEAR_ARROW
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $04
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
ld [hl], SPRITE_ANIM_FUNC_NULL
pop af
push bc
call PokegearMap_UpdateCursorPosition
pop bc
ret
PokegearMap_UpdateLandmarkName:
push af
hlcoord 8, 0
lb bc, 2, 12
call ClearBox
pop af
ld e, a
push de
farcall GetLandmarkName
pop de
farcall TownMap_ConvertLineBreakCharacters
hlcoord 8, 0
ld [hl], $34
ret
PokegearMap_UpdateCursorPosition:
push bc
ld e, a
farcall GetLandmarkCoords
pop bc
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld [hl], e
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld [hl], d
ret
TownMap_GetKantoLandmarkLimits:
ld a, [wStatusFlags]
bit STATUSFLAGS_HALL_OF_FAME_F, a
jr z, .not_hof
ld d, LANDMARK_ROUTE_28
ld e, LANDMARK_PALLET_TOWN
ret
.not_hof
ld d, LANDMARK_ROUTE_28
ld e, LANDMARK_VICTORY_ROAD
ret
PokegearRadio_Init:
call InitPokegearTilemap
depixel 4, 10, 4, 4
ld a, SPRITE_ANIM_OBJ_RADIO_TUNING_KNOB
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $08
call _UpdateRadioStation
ld hl, wJumptableIndex
inc [hl]
ret
PokegearRadio_Joypad:
ld hl, hJoyLast
ld a, [hl]
and B_BUTTON
jr nz, .cancel
ld a, [hl]
and D_LEFT
jr nz, .left
ld a, [wPokegearRadioChannelAddr]
ld l, a
ld a, [wPokegearRadioChannelAddr + 1]
ld h, a
ld a, [wPokegearRadioChannelBank]
and a
ret z
rst FarCall
ret
.left
ld a, [wPokegearFlags]
bit POKEGEAR_PHONE_CARD_F, a
jr z, .no_phone
ld c, POKEGEARSTATE_PHONEINIT
ld b, POKEGEARCARD_PHONE
jr .switch_page
.no_phone
ld a, [wPokegearFlags]
bit POKEGEAR_MAP_CARD_F, a
jr z, .no_map
ld c, POKEGEARSTATE_MAPCHECKREGION
ld b, POKEGEARCARD_MAP
jr .switch_page
.no_map
ld c, POKEGEARSTATE_CLOCKINIT
ld b, POKEGEARCARD_CLOCK
.switch_page
call Pokegear_SwitchPage
ret
.cancel
ld hl, wJumptableIndex
set JUMPTABLE_EXIT_F, [hl]
ret
PokegearPhone_Init:
ld hl, wJumptableIndex
inc [hl]
xor a
ld [wPokegearPhoneScrollPosition], a
ld [wPokegearPhoneCursorPosition], a
ld [wPokegearPhoneSelectedPerson], a
call InitPokegearTilemap
call ExitPokegearRadio_HandleMusic
ld hl, PokegearAskWhoCallText
call PrintText
ret
PokegearPhone_Joypad:
ld hl, hJoyPressed
ld a, [hl]
and B_BUTTON
jr nz, .b
ld a, [hl]
and A_BUTTON
jr nz, .a
ld hl, hJoyLast
ld a, [hl]
and D_LEFT
jr nz, .left
ld a, [hl]
and D_RIGHT
jr nz, .right
call PokegearPhone_GetDPad
ret
.left
ld a, [wPokegearFlags]
bit POKEGEAR_MAP_CARD_F, a
jr z, .no_map
ld c, POKEGEARSTATE_MAPCHECKREGION
ld b, POKEGEARCARD_MAP
jr .switch_page
.no_map
ld c, POKEGEARSTATE_CLOCKINIT
ld b, POKEGEARCARD_CLOCK
jr .switch_page
.right
ld a, [wPokegearFlags]
bit POKEGEAR_RADIO_CARD_F, a
ret z
ld c, POKEGEARSTATE_RADIOINIT
ld b, POKEGEARCARD_RADIO
.switch_page
call Pokegear_SwitchPage
ret
.b
ld hl, wJumptableIndex
set JUMPTABLE_EXIT_F, [hl]
ret
.a
ld hl, wPhoneList
ld a, [wPokegearPhoneScrollPosition]
ld e, a
ld d, 0
add hl, de
ld a, [wPokegearPhoneCursorPosition]
ld e, a
ld d, 0
add hl, de
ld a, [hl]
and a
ret z
ld [wPokegearPhoneSelectedPerson], a
hlcoord 1, 4
ld a, [wPokegearPhoneCursorPosition]
ld bc, SCREEN_WIDTH * 2
call AddNTimes
ld [hl], "▷"
call PokegearPhoneContactSubmenu
jr c, .quit_submenu
ld hl, wJumptableIndex
inc [hl]
ret
.quit_submenu
ld a, POKEGEARSTATE_PHONEJOYPAD
ld [wJumptableIndex], a
ret
PokegearPhone_MakePhoneCall:
call GetMapPhoneService
and a
jr nz, .no_service
ld hl, wOptions
res NO_TEXT_SCROLL, [hl]
xor a
ldh [hInMenu], a
ld de, SFX_CALL
call PlaySFX
ld hl, .GearEllipseText
call PrintText
call WaitSFX
ld de, SFX_CALL
call PlaySFX
ld hl, .GearEllipseText
call PrintText
call WaitSFX
ld a, [wPokegearPhoneSelectedPerson]
ld b, a
call MakePhoneCallFromPokegear
ld c, 10
call DelayFrames
ld hl, wOptions
set NO_TEXT_SCROLL, [hl]
ld a, $1
ldh [hInMenu], a
call PokegearPhone_UpdateCursor
ld hl, wJumptableIndex
inc [hl]
ret
.no_service
farcall Phone_NoSignal
ld hl, .GearOutOfServiceText
call PrintText
ld a, POKEGEARSTATE_PHONEJOYPAD
ld [wJumptableIndex], a
ld hl, PokegearAskWhoCallText
call PrintText
ret
.GearEllipseText:
text_far _GearEllipseText
text_end
.GearOutOfServiceText:
text_far _GearOutOfServiceText
text_end
PokegearPhone_FinishPhoneCall:
ldh a, [hJoyPressed]
and A_BUTTON | B_BUTTON
ret z
farcall HangUp
ld a, POKEGEARSTATE_PHONEJOYPAD
ld [wJumptableIndex], a
ld hl, PokegearAskWhoCallText
call PrintText
ret
PokegearPhone_GetDPad:
ld hl, hJoyLast
ld a, [hl]
and D_UP
jr nz, .up
ld a, [hl]
and D_DOWN
jr nz, .down
ret
.up
ld hl, wPokegearPhoneCursorPosition
ld a, [hl]
and a
jr z, .scroll_page_up
dec [hl]
jr .done_joypad_same_page
.scroll_page_up
ld hl, wPokegearPhoneScrollPosition
ld a, [hl]
and a
ret z
dec [hl]
jr .done_joypad_update_page
.down
ld hl, wPokegearPhoneCursorPosition
ld a, [hl]
cp PHONE_DISPLAY_HEIGHT - 1
jr nc, .scroll_page_down
inc [hl]
jr .done_joypad_same_page
.scroll_page_down
ld hl, wPokegearPhoneScrollPosition
ld a, [hl]
cp CONTACT_LIST_SIZE - PHONE_DISPLAY_HEIGHT
ret nc
inc [hl]
jr .done_joypad_update_page
.done_joypad_same_page
xor a
ldh [hBGMapMode], a
call PokegearPhone_UpdateCursor
call WaitBGMap
ret
.done_joypad_update_page
xor a
ldh [hBGMapMode], a