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
|
BORDER_WIDTH EQU 2
TEXTBOX_WIDTH EQU SCREEN_WIDTH
TEXTBOX_INNERW EQU TEXTBOX_WIDTH - BORDER_WIDTH
TEXTBOX_HEIGHT EQU 6
TEXTBOX_INNERH EQU TEXTBOX_HEIGHT - BORDER_WIDTH
TEXTBOX_X EQU 0
TEXTBOX_INNERX EQU TEXTBOX_X + 1
TEXTBOX_Y EQU SCREEN_HEIGHT - TEXTBOX_HEIGHT
TEXTBOX_INNERY EQU TEXTBOX_Y + 2
TEXTBOX_PAL EQU 7
ClearBox:: ; ebd (0:0ebd)
ld a, $7f
FillBoxWithByte::
ld de, SCREEN_WIDTH
.row
push hl
push bc
.col
ld [hli], a
dec c
jr nz, .col
pop bc
pop hl
add hl, de
dec b
jr nz, .row
ret
ClearTileMap::
ld hl, wTileMap
ld a, $7f
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
ld a, [rLCDC]
bit 7, a
ret z
jp WaitBGMap
FillScreenWithTextboxPal::
ld a, $7
hlcoord 0, 0, wAttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
jr ClearTileMap
TextBox:: ; eef (0:0eef)
push bc
push hl
call TextBoxBorder
pop hl
pop bc
jr TextBoxPalette
TextBoxBorder:: ; ef8 (0:0ef8)
push hl
ld a, "┌"
ld [hli], a
inc a
call TextBoxBorder_PlaceTiles
inc a
ld [hl], a
pop hl
; Middle
ld de, SCREEN_WIDTH
add hl, de
.row
push hl
ld a, "│"
ld [hli], a
ld a, " "
call TextBoxBorder_PlaceTiles
ld [hl], "│"
pop hl
ld de, SCREEN_WIDTH
add hl, de
dec b
jr nz, .row
; Bottom
ld a, "└"
ld [hli], a
ld a, "─"
call TextBoxBorder_PlaceTiles
ld [hl], "┘"
ret
TextBoxBorder_PlaceTiles:: ; f25 (0:0f25)
ld d, c
.loop
ld [hli], a
dec d
jr nz, .loop
ret
TextBoxPalette
ld de, wAttrMap - wTileMap
add hl, de
inc b
inc b
inc c
inc c
ld a, TEXTBOX_PAL
.col
push bc
push hl
.row
ld [hli], a
dec c
jr nz, .row
pop hl
ld de, SCREEN_WIDTH
add hl, de
pop bc
dec b
jr nz, .col
ret
SpeechTextBox:: ; f45 (0:0f45)
hlcoord 0, 12
ld b, $4
ld c, $12
jp TextBox
TestText::
text "ゲームフりーク!"
done
RadioTerminator:: ; 1052
ld hl, .stop
ret
.stop db "@"
PrintText::
call SetUpTextBox
bccoord 1, 14
call PlaceHLTextAtBC
ret
SetUpTextBox:: ; f68 (0:0f68)
push hl
call SpeechTextBox
call UpdateSprites
call ApplyTilemap
pop hl
ret
PlaceString:: ; f74 (0:0f74)
push hl
PlaceNextChar:: ; f75 (0:0f75)
ld a, [de]
cp "@"
jr nz, CheckDict
ld b, h
ld c, l
pop hl
ret
pop de
NextChar:: ; f7f (0:0f7f)
inc de
jp PlaceNextChar
CheckDict
dict: macro
if \1 == 0
and a
else
cp \1
endc
jp z, \2
endm
dict2: macro
cp \1
jr nz, ._\@
ld a, \2
._\@:
endm
dict "<LINE>", LineChar
dict "<NEXT>", NextLineChar
dict $00, NullChar
dict $4c, Char4C
dict $4b, Char4B
dict "<PARA>", Paragraph
dict "<MOM>", PrintMomsName
dict "<PLAYER>", PrintPlayerName
dict "<RIVAL>", PrintRivalName
dict $35, Char35
dict $36, Char36
dict $37, Char37
dict "<RED>", PrintRedsName
dict "<GREEN>", PrintGreensName
dict "#", PlacePOKe
dict "<PC>", PCChar
dict "<ROCKET>", RocketChar
dict "<TM>", TMChar
dict "<TRNER>", TrainerChar
dict $23, PlaceKougeki
dict "<LNBRK>", HalfLineChar
dict "<CONT>", ContText
dict "<......>", SixDotsChar
dict "<DONE>", DoneText
dict "<PROMPT>", PromptText
dict "<PKMN>", PlacePKMN
dict "<POKE>", PlacePOKE
dict $25, NextChar
dict2 $1f, " "
dict "<DEXEND>", PlaceDexEnd
dict "<TARGET>", PlaceMoveTargetsName
dict "<USER>", PlaceMoveUsersName
dict "<ENEMY>", PlaceEnemysName
cp $e4
jr z, .diacritic
cp $e5
jr nz, .not_diacritic
.diacritic
ld b, a
call Diacritic
jp NextChar
.not_diacritic
cp $60
jr nc, .place
cp $40
jr nc, .handakuten
cp $20
jr nc, .daku1
add $80
jr .daku2
.daku1
add $90
.daku2
ld b, $e5
call Diacritic
jr .place
.handakuten
cp $44
jr nc, .han1
add $59
jr .han2
.han1
add $86
.han2
ld b, $e4
call Diacritic
.place
ld [hli], a
call Function31e2
jp NextChar
print_name: macro
push de
ld de, \1
jp PlaceCommandCharacter
endm
PrintMomsName:: print_name wMomsName ; 1066 (0:1066)
PrintPlayerName:: print_name wPlayersName ; 106d (0:106d)
PrintRivalName:: print_name wRivalsName ; 1074 (0:1074)
PrintRedsName:: print_name wRedsName ; 107b (0:107b)
PrintGreensName:: print_name wGreensName ; 1082 (0:1082)
TrainerChar:: print_name TrainerCharText ; 1089 (0:1089)
TMChar:: print_name TMCharText ; 1090 (0:1090)
PCChar:: print_name PCCharText ; 1097 (0:1097)
RocketChar:: print_name RocketCharText ; 109e (0:109e)
PlacePOKe:: print_name POKeCharText ; 10a5 (0:10a5)
PlaceKougeki:: print_name KougekiText ; 10ac (0:10ac)
SixDotsChar:: print_name SixDotsCharText ; 10b3 (0:10b3)
PlacePKMN:: print_name PKMNText ; 10ba (0:10ba)
PlacePOKE:: print_name POKEText ; 10c1 (0:10c1)
Char35:: print_name Char35Text ; 10c8 (0:10c8)
Char36:: print_name Char36Text ; 10cf (0:10cf)
Char37:: print_name Char37Text ; 10d6 (0:10d6)
PlaceMoveTargetsName:: ; 10dd (0:10dd)
ld a, [hBattleTurn]
xor $1
jr PlaceMonsName
PlaceMoveUsersName:: ; 10e3 (0:10e3)
ld a, [hBattleTurn]
PlaceMonsName::
push de
and a
jr nz, .enemy
ld de, wBattleMonNick
jr PlaceCommandCharacter
.enemy
ld de, EnemyText
call PlaceString
ld h, b
ld l, c
ld de, wEnemyMonNick
jr PlaceCommandCharacter
PlaceEnemysName:: ; 10fb (0:10fb)
push de
ld a, [wLinkMode]
and a
jr nz, .linkbattle
ld a, [wTrainerClass]
cp RIVAL1
jr z, .rival
cp RIVAL2
jr z, .rival
ld de, wOTClassName
call PlaceString
ld h, b
ld l, c
ld de, String116a
call PlaceString
push bc
callab Battle_GetTrainerName
pop hl
ld de, wStringBuffer1
jr PlaceCommandCharacter
.rival
ld de, wRivalsName
jr PlaceCommandCharacter
.linkbattle
ld de, wOTClassName
jr PlaceCommandCharacter
PlaceCommandCharacter:: ; 1132 (0:1132)
call PlaceString
ld h, b
ld l, c
pop de
jp NextChar
TMCharText:: ; 113b (0:113b)
db "TM@"
TrainerCharText:: ; 113e (0:113e)
db "TRAINER@"
PCCharText:: ; 1146 (0:1146)
db "PC@"
RocketCharText:: ; 1149 (0:1149)
db "ROCKET@"
POKeCharText:: ; 1150 (0:1150)
db "POKé@"
KougekiText:: ; 1155 (0:1155)
db "こうげき@"
SixDotsCharText:: ; 115a (0:115a)
db "……@"
EnemyText:: ; 115d (0:115d)
db "Enemy @"
PKMNText:: ; 1164 (0:1164)
db "<PK><MN>@"
POKEText:: ; 1167 (0:1167)
db "<PO><KE>@"
String116a:: ; 116a (0:116a)
db " @"
Char35Text:: ; 116c (0:116c)
Char36Text:: ; 116c (0:116c)
Char37Text:: ; 116c (0:116c)
db "@"
NextLineChar:: ; 116d (0:116d)
pop hl
ld bc, SCREEN_WIDTH * 2
add hl, bc
push hl
jp NextChar
HalfLineChar:: ; 1176 (0:1176)
pop hl
ld bc, SCREEN_WIDTH
add hl, bc
push hl
jp NextChar
LineChar:: ; 117f (0:117f)
pop hl
hlcoord 1, 16
push hl
jp NextChar
Paragraph:: ; 1187 (0:1187)
push de
ld a, [wLinkMode]
cp $3
jr z, .asm_1192
call LoadBlinkingCursor
.asm_1192
call Text_WaitBGMap
call ButtonSound
hlcoord 1, 14
lb bc, 3, 18
call ClearBox
call UnloadBlinkingCursor
ld c, 20
call DelayFrames
hlcoord 1, 14
pop de
jp NextChar
Char4B:: ; 11b0 (0:11b0)
ld a, [wLinkMode]
or a
jr nz, .link_battle
call LoadBlinkingCursor
.link_battle
call Text_WaitBGMap
push de
call ButtonSound
pop de
ld a, [wLinkMode]
or a
call z, UnloadBlinkingCursor
Char4C:: ; 11c8 (0:11c8)
push de
call TextScroll
call TextScroll
hlcoord 1, 16
pop de
jp NextChar
ContText:: ; 11d6 (0:11d6)
push de
ld de, .cont
ld b, h
ld c, l
call PlaceString
ld h, b
ld l, c
pop de
jp NextChar
.cont db $4b, "@"
PlaceDexEnd:: ; 11e7 (0:11e7)
ld [hl], "."
pop hl
ret
PromptText:: ; 11eb (0:11eb)
ld a, [wLinkMode]
cp LINK_COLOSSEUM
jr z, .ok
call LoadBlinkingCursor
.ok
call Text_WaitBGMap
call ButtonSound
ld a, [wLinkMode]
cp $3
jr z, DoneText
call UnloadBlinkingCursor
DoneText:: ; 1205 (0:1205)
pop hl
ld de, .stop
dec de
ret
.stop db "@"
NullChar:: ; 120c (0:120c)
ld b, h
ld c, l
pop hl
ld de, .ErrorText
dec de
ret
.ErrorText
deciram hObjectStructIndexBuffer, 1, 2
text "エラー"
done
TextScroll:: ; 121d (0:121d)
hlcoord 0, 14
decoord 0, 13
ld bc, 3 * SCREEN_WIDTH
call CopyBytes
hlcoord 1, 16
ld a, " "
ld bc, 18
call ByteFill
ld c, 5
call DelayFrames
ret
Text_WaitBGMap:: ; 123a (0:123a)
push bc
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
call WaitBGMap
pop af
ld [hOAMUpdate], a
pop bc
ret
Diacritic:: ; 124a (0:124a)
push af
push hl
ld a, b
ld bc, -SCREEN_WIDTH
add hl, bc
ld [hl], a
pop hl
pop af
ret
LoadBlinkingCursor:: ; 1255 (0:1255)
ld a, "▼"
Coorda 18, 17
ret
UnloadBlinkingCursor:: ; 125b (0:125b)
ld a, "─"
Coorda 18, 17
ret
FarString::
ld b, a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
call PlaceString
pop af
rst Bankswitch
ret
PokeFluteTerminatorCharacter::
ld hl, .stop
ret
.stop db "@"
PlaceHLTextAtBC:: ; 1272 (0:1272)
ld a, [wTextBoxFlags]
push af
set 1, a
ld [wTextBoxFlags], a
call DoTextUntilTerminator
pop af
ld [wTextBoxFlags], a
ret
DoTextUntilTerminator:: ; 1283 (0:1283)
ld a, [hli]
cp "@"
ret z
call TextCommand
jr DoTextUntilTerminator
TextCommand:: ; 128c (0:128c)
push hl
push bc
ld c, a
ld b, $0
ld hl, TextCommands
add hl, bc
add hl, bc
ld e, [hl]
inc hl
ld d, [hl]
pop bc
pop hl
push de
ret
TextCommands:: ; 129d (0:129d)
dw Text_TX
dw Text_TX_RAM
dw Text_TX_BCD
dw Text_TX_MOVE
dw Text_TX_BOX
dw Text_TX_LOW
dw Text_WAIT_BUTTON
dw Text_TX_SCROLL
dw Text_TX_ASM
dw Text_TX_NUM
dw Text_TX_EXIT
dw Text_TX_SFX
dw Text_TX_DOTS
dw Text_TX_0D
dw Text_TX_SFX
dw Text_TX_SFX
dw Text_TX_SFX
dw Text_TX_SFX
dw Text_TX_SFX
dw Text_TX_SFX
dw Text_TX_BUFFER
dw Text_TX_DAY
dw Text_TX_FAR
Text_TX:: ; 12cb (0:12cb)
ld d, h
ld e, l
ld h, b
ld l, c
call PlaceString
ld h, d
ld l, e
inc hl
ret
Text_TX_RAM:: ; 12d6 (0:12d6)
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
push hl
ld h, b
ld l, c
call PlaceString
pop hl
ret
Text_TX_FAR:: ; 12e2 (0:12e2)
ld a, [hROMBank]
push af
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, [hli]
ld [hROMBank], a
ld [MBC3RomBank], a
push hl
ld h, d
ld l, e
call DoTextUntilTerminator
pop hl
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
ret
Text_TX_BCD:: ; 12fd (0:12fd)
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, [hli]
push hl
ld h, b
ld l, c
ld c, a
call PrintBCDNumber
ld b, h
ld c, l
pop hl
ret
Text_TX_MOVE:: ; 130d (0:130d)
ld a, [hli]
ld [wcfd6], a
ld c, a
ld a, [hli]
ld [wcfd7], a
ld b, a
ret
Text_TX_BOX:: ; 1318 (0:1318)
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
push hl
ld h, d
ld l, e
call TextBox
pop hl
ret
Text_TX_LOW:: ; 1328 (0:1328)
bccoord 1, 16
ret
Text_WAIT_BUTTON:: ; 132c (0:132c)
ld a, [wLinkMode]
cp LINK_COLOSSEUM
jp z, Text_TX_0D
push hl
call LoadBlinkingCursor
push bc
call ButtonSound
pop bc
call UnloadBlinkingCursor
pop hl
ret
Text_TX_SCROLL:: ; 1342 (0:1342)
push hl
call UnloadBlinkingCursor
call TextScroll
call TextScroll
pop hl
bccoord 1, 16
ret
Text_TX_ASM:: ; 1351 (0:1351)
jp [hl]
Text_TX_NUM:: ; 1352 (0:1352)
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, [hli]
push hl
ld h, b
ld l, c
ld b, a
and $f
ld c, a
ld a, b
and $f0
swap a
set 6, a
ld b, a
call PrintNum
ld b, h
ld c, l
pop hl
ret
Text_TX_EXIT:: ; 136d (0:136d)
push hl
push bc
call GetJoypad
ld a, [hJoyDown]
and A_BUTTON | B_BUTTON
jr nz, .skip
ld c, 30
call DelayFrames
.skip
pop bc
pop hl
ret
Text_TX_SFX:: ; 1380 (0:1380)
push bc
dec hl
ld a, [hli]
ld b, a
push hl
ld hl, TextSFX
.loop
ld a, [hli]
cp -1
jr z, .done
cp b
jr z, .sound
inc hl
inc hl
jr .loop
.sound
push de
ld e, [hl]
inc hl
ld d, [hl]
call PlaySFX
call WaitSFX
pop de
.done
pop hl
pop bc
ret
Text_TX_CRY
push de
ld e, [hl]
inc hl
ld d, [hl]
call PlayCry
pop de
pop hl
pop bc
ret
TextSFX:: ; 13ad (0:13ad)
dbw TX_SOUND_0B, SFX_DEX_FANFARE_50_79
dbw TX_SOUND_12, SFX_FANFARE
dbw TX_SOUND_0E, SFX_DEX_FANFARE_20_49
dbw TX_SOUND_0F, SFX_ITEM
dbw TX_SOUND_10, SFX_CAUGHT_MON
dbw TX_SOUND_11, SFX_DEX_FANFARE_80_109
dbw TX_SOUND_13, SFX_SLOT_MACHINE_START
db -1
Text_TX_DOTS:: ; 13c3 (0:13c3)
ld a, [hli]
ld d, a
push hl
ld h, b
ld l, c
.loop
push de
ld a, "…"
ld [hli], a
call GetJoypad
ld a, [hJoyDown]
and A_BUTTON | B_BUTTON
jr nz, .next
ld c, 10
call DelayFrames
.next
pop de
dec d
jr nz, .loop
ld b, h
ld c, l
pop hl
ret
Text_TX_0D:: ; 13e2 (0:13e2)
push hl
push bc
call ButtonSound
pop bc
pop hl
ret
Text_TX_BUFFER:: ; 13ea (0:13ea)
ld a, [hli]
push hl
ld e, a
ld d, $0
ld hl, StringBufferPointers
add hl, de
add hl, de
ld a, BANK(StringBufferPointers)
call GetFarHalfword
ld d, h
ld e, l
ld h, b
ld l, c
call PlaceString
pop hl
ret
Text_TX_DAY:: ; 1402 (0:1402)
call GetWeekday
push hl
push bc
ld c, a
ld b, $0
ld hl, .Days
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ld d, h
ld e, l
pop hl
call PlaceString
ld h, b
ld l, c
ld de, .Day
call PlaceString
pop hl
ret
.Days: ; 1422 (0:1422)
dw .Sun
dw .Mon
dw .Tues
dw .Wednes
dw .Thurs
dw .Fri
dw .Satur
.Sun: db "SUN@"
.Mon: db "MON@"
.Tues: db "TUES@"
.Wednes: db "WEDNES@"
.Thurs: db "THURS@"
.Fri: db "FRI@"
.Satur: db "SATUR@"
.Day: db "DAY@"
|