forked from Rangi42/polishedcrystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.asm
618 lines (567 loc) · 8.85 KB
/
text.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
ClearSpeechBox::
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
lb bc, TEXTBOX_INNERH - 1, TEXTBOX_INNERW
ClearBox::
; Fill a c*b box at hl with blank tiles.
ld a, " "
FillBoxWithByte::
.row
push bc
push hl
.col
ld [hli], a
dec c
jr nz, .col
pop hl
ld bc, SCREEN_WIDTH
add hl, bc
pop bc
dec b
jr nz, .row
ret
ClearScreen::
ld a, PAL_BG_TEXT
hlcoord 0, 0, wAttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
rst ByteFill
ClearTileMap::
; Fill wTileMap with blank tiles.
hlcoord 0, 0
ld a, " "
ld bc, wTileMapEnd - wTileMap
rst ByteFill
; Update the BG Map.
ldh a, [rLCDC]
bit 7, a
ret z
jmp ApplyTilemapInVBlank
SpeechTextbox::
; Standard textbox.
hlcoord TEXTBOX_X, TEXTBOX_Y
lb bc, TEXTBOX_INNERH, TEXTBOX_INNERW
Textbox::
; Draw a text box at hl with room for
; b lines of c characters each.
; Places a border around the textbox,
; then switches the palette to the
; text black-and-white scheme.
push bc
push hl
call TextboxBorder
pop hl
pop bc
; fallthrough
TextboxPalette::
; Fill text box width c height b at hl with pal 7
ld de, wAttrMap - wTileMap
add hl, de
inc b
inc b
inc c
inc c
ld a, PAL_BG_TEXT
jr FillBoxWithByte
TextBoxCharacters:
rawchar "┌─┐" ; top
rawchar "│ │" ; middle
rawchar "└─┘" ; bottom
TextboxBorder::
ld de, TextBoxCharacters
; fallthrough
CreateBoxBorders::
; Top
call .PlaceRow
jr .row
.row_loop
dec de
dec de
dec de
.row
call .PlaceRow
dec b
jr nz, .row_loop
; Bottom row (fallthrough)
.PlaceRow:
push hl
ld a, [de]
inc de
ld [hli], a
ld a, [de]
inc de
call .PlaceChars
ld a, [de]
inc de
ld [hl], a
pop hl
push bc
ld bc, SCREEN_WIDTH
add hl, bc
pop bc
ret
.PlaceChars:
; Place char a c times.
push bc
.loop
ld [hli], a
dec c
jr nz, .loop
pop bc
ret
PrintText::
call SetUpTextbox
PrintTextNoBox::
push hl
call ClearSpeechBox
pop hl
PrintTextboxText::
bccoord TEXTBOX_INNERX, TEXTBOX_INNERY
PlaceWholeStringInBoxAtOnce::
ld a, [wTextboxFlags]
push af
set 1, a
ld [wTextboxFlags], a
call DoTextUntilTerminator
pop af
ld [wTextboxFlags], a
ret
SetUpTextbox::
push hl
call SpeechTextbox
call UpdateSprites
call ApplyTilemap
pop hl
ret
_PlaceString::
push hl
PlaceNextChar::
; charmap order: commands, then ngrams, then specials, then literals
ld a, [de]
cp BATTLEEXTRA_GFX_START
jr nc, _PlaceLiteralChar
cp "@"
jr nc, _PlaceSpecialChar
cp NGRAMS_START
jr nc, _PlaceNgramChar
dec de
jmp FinishString
SpaceChar::
ld a, " "
_PlaceLiteralChar:
ld [hli], a
call PrintLetterDelay
NextChar::
inc de
jr PlaceNextChar
_PlaceNgramChar:
sub NGRAMS_START
push de
push hl
add a
ld e, a
ld d, 0
ld hl, NgramStrings
add hl, de
ld a, [hli]
ld d, [hl]
ld e, a
pop hl
jmp PlaceCommandCharacter
_PlaceSpecialChar:
sub "@"
push hl
add a
ld c, a
ld b, 0
ld hl, SpecialCharacters
add hl, bc
ld a, [hli]
ld b, [hl]
ld c, a
pop hl
_bc_::
push bc
ret
SpecialCharacters:
dw FinishString ; "@"
dw SpaceChar ; "¯"
dw LineBreak ; "<LNBRK>"
dw NextLineChar ; "<NEXT>"
dw LineChar ; "<LINE>"
dw ContText ; "<CONT>"
dw Paragraph ; "<PARA>"
dw DoneText ; "<DONE>"
dw PromptText ; "<PROMPT>"
dw PlaceTargetsName ; "<TARGET>"
dw PlaceUsersName ; "<USER>"
dw PlaceEnemysName ; "<ENEMY>"
NextLineChar::
ld a, [wTextboxFlags]
bit NO_LINE_SPACING_F, a
ld bc, SCREEN_WIDTH * 2
jr z, LineBreak.ok
LineBreak::
ld bc, SCREEN_WIDTH
.ok
pop hl
add hl, bc
push hl
jr NextChar
LineChar::
pop hl
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
push hl
jr NextChar
ContText::
ld a, [wLinkMode]
or a
call z, LoadBlinkingCursor
call Text_WaitBGMap
push de
call ButtonSound
ld a, [wLinkMode]
or a
call z, UnloadBlinkingCursor
call TextScroll
call TextScroll
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
pop de
jr NextChar
Paragraph::
push de
ld a, [wLinkMode]
cp LINK_COLOSSEUM
call nz, LoadBlinkingCursor
call Text_WaitBGMap
call ButtonSound
call ClearSpeechBox
call UnloadBlinkingCursor
ld a, [wOptions1]
and AUTOSCROLL_MASK
cp AUTOSCROLL_AORB
ld c, 20
jr z, .got_delay
bit NO_TEXT_SCROLL, a
jr nz, .got_delay
and %11
jr z, .got_delay
ld c, 5
.loop
dec a
jr z, .got_delay
sla c
jr .loop
.got_delay
call DelayFrames
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
pop de
jmp NextChar
PromptText::
push de
ld a, [wLinkMode]
cp LINK_COLOSSEUM
call nz, LoadBlinkingCursor
call Text_WaitBGMap
call ButtonSound
ld a, [wLinkMode]
cp LINK_COLOSSEUM
call nz, UnloadBlinkingCursor
pop de
; fallthrough
DoneText::
pop hl
dec de
ret
PlaceTargetsName::
ldh a, [hBattleTurn]
xor 1
jr _PlaceBattleNickname
PlaceUsersName::
ldh a, [hBattleTurn]
; fallthrough
_PlaceBattleNickname:
push de
ld de, wBattleMonNickname
and a
jr z, PlaceCommandCharacter
ld de, .EnemyText
rst PlaceString
ld h, b
ld l, c
ld de, wEnemyMonNickname
jr PlaceCommandCharacter
.EnemyText:
db "Foe" ; fallthrough, no " @"
SpaceText::
db " " ; fallthrough, no "@"
EmptyString::
db "@"
PlaceEnemysName::
push de
ld de, wOTClassName
ld a, [wLinkMode]
and a
jr nz, PlaceCommandCharacter
rst PlaceString
ld h, b
ld l, c
ld de, SpaceText
rst PlaceString
push bc
farcall Battle_GetTrainerName
pop hl
ld de, wStringBuffer1
; fallthrough
PlaceCommandCharacter::
rst PlaceString
ld h, b
ld l, c
pop de
jmp NextChar
TextScroll::
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
decoord TEXTBOX_INNERX, TEXTBOX_INNERY - 1
ld a, TEXTBOX_INNERH - 1
.col
push af
ld c, TEXTBOX_INNERW
.row
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .row
inc de
inc de
inc hl
inc hl
pop af
dec a
jr nz, .col
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
ld a, " "
ld bc, TEXTBOX_INNERW
rst ByteFill
ld c, 5
jmp DelayFrames
Text_WaitBGMap::
push bc
ldh a, [hOAMUpdate]
push af
ld a, 1
ldh [hOAMUpdate], a
call ApplyTilemapInVBlank
pop af
ldh [hOAMUpdate], a
pop bc
ret
LoadBlinkingCursor::
ld a, "▼"
ldcoord_a 18, 17
ret
UnloadBlinkingCursor::
lda_coord 17, 17
ldcoord_a 18, 17
ret
FarString::
ld b, a
ldh a, [hROMBank]
push af
ld a, b
rst Bankswitch
rst PlaceString
pop af
rst Bankswitch
ret
DoTextUntilTerminator::
ld a, [hli]
cp "@"
ret z
cp "<DONE>"
ret z
cp "<PROMPT>"
ret z
call .TextCommand
jr DoTextUntilTerminator
.TextCommand:
cp NGRAMS_START
jr nc, _ImplicitlyStartedText
push hl
ld e, a
ld d, 0
ld hl, TextCommands
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
pop hl
push de
ret
TextCommands::
table_width 2, TextCommands
dw TextCommand_START ; $00 <START>
dw TextCommand_RAM ; $01 <RAM>
dw TextCommand_PROMPT_BUTTON ; $02 <WAIT>
dw TextCommand_ASM ; $03 <ASM>
dw TextCommand_DECIMAL ; $04 <NUM>
dw TextCommand_PAUSE ; $05 <PAUSE>
dw TextCommand_SOUND ; $06 <SOUND>
dw TextCommand_DAY ; $07 <DAY>
dw TextCommand_FAR ; $08 <FAR>
assert_table_length NGRAMS_START
_ImplicitlyStartedText:
dec hl
TextCommand_START::
; write text until "@"
ld d, h
ld e, l
ld h, b
ld l, c
rst PlaceString
ld h, d
ld l, e
inc hl
ret
TextCommand_RAM::
; write text from a ram address
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
push hl
ld h, b
ld l, c
rst PlaceString
pop hl
ret
TextCommand_FAR::
; write text from a different bank
ldh a, [hROMBank]
push af
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, [hli]
rst Bankswitch
push hl
ld h, d
ld l, e
call DoTextUntilTerminator
pop hl
pop af
rst Bankswitch
ret
TextCommand_PROMPT_BUTTON::
; wait for button press; show arrow
push hl
ld a, [wLinkMode]
cp LINK_COLOSSEUM
call nz, LoadBlinkingCursor
push bc
call ButtonSound
pop bc
ld a, [wLinkMode]
cp LINK_COLOSSEUM
call nz, UnloadBlinkingCursor
pop hl
ret
TextCommand_ASM::
bit 7, h
jr nz, .not_rom
jp hl
.not_rom
ld [hl], "@"
ret
TextCommand_DECIMAL::
; print a decimal number
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
or PRINTNUM_DELAY | PRINTNUM_LEFTALIGN
ld b, a
call PrintNum
FinishString:
ld b, h
ld c, l
pop hl
ret
TextCommand_PAUSE::
; wait for button press or 30 frames
push hl
push bc
call GetJoypad
ldh a, [hJoyDown]
and A_BUTTON | B_BUTTON
jr nz, .done
ld c, 30
call DelayFrames
.done
pop bc
pop hl
ret
TextCommand_SOUND::
; play a sound effect
ld a, [hli]
push hl
push de
push bc
ld e, a
ld d, 0
call PlaySFX
call WaitSFX
jmp PopBCDEHL
TextCommand_DAY::
; print the day of the week
call GetWeekday
PrintDayOfWeek::
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
rst PlaceString
ld h, b
ld l, c
ld de, .Day
rst PlaceString
pop hl
ret
.Days:
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@"
ClearText::
text_start
done