-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfurryrpg_text.inc.asm
2488 lines (1795 loc) · 52.6 KB
/
furryrpg_text.inc.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
;==========================================================================================
;
; "FURRY RPG" (WORKING TITLE)
; (c) 2023 by Ramsis a.k.a. ManuLöwe (https://manuloewe.de/)
;
; *** TEXT ENGINE ***
;
;==========================================================================================
; *********************** Dialogue test section ************************
DialogueTest:
.ACCU 8
.INDEX 16
lda #$80 ; enter forced blank
sta RAM_INIDISP
ResetSprites
wai
DisableIRQs
; .IFNDEF NOMUSIC
; jsl music_stop ; stop music in case it's playing
; stz MSU_CONTROL ; stop MSU1 track in case it's playing
; .ENDIF
stz <DP2.HDMA_Channels ; disable HDMA
stz HDMAEN
ldx #loword(RAM.BG3Tilemap) ; clear BG3 text
stx WMADDL
stz WMADDH
DMA_CH0 $08, SRC_Zeroes, WMDATA, 1024
ldx #loword(RAM.HDMA_BackgrPlayfield) ; set WRAM address to playfield HDMA background
stx WMADDL
stz WMADDH ; array is in bank $7E
DMA_CH0 $08, SRC_Zeroes, WMDATA, 704 ; clear HDMA table in case it was used before
lda #$80 ; increment VRAM address by 1 after writing to $2119
sta VMAIN
jsr LoadTextBoxBorderTiles ; prepare text box
jsr MakeTextBoxTilemapBG1
jsr MakeTextBoxTilemapBG2
Accu16
; lda #0 ; make text box background black in case it was used before
; ldx #0
;- sta RAM.HDMA_BackgrTextBox, x
; inx
; inx
; cpx #192
; bne -
ldx #0 ; put HDMA table into WRAM
- lda.l SRC_HDMA_ResetBGScroll, x
sta LO8.HDMA_BG_Scroll, x
inx
inx
cpx #16
bne -
Accu8
; HDMA channel 3: color math
lda #$02 ; transfer mode (2 bytes --> $2132)
sta DMAP3
lda #$32 ; PPU register $2132 (color math subscreen backdrop color)
sta BBAD3
ldx #LO8.HDMA_ColorMath
stx A1T3L
lda #$7E ; table in WRAM expected
sta A1B3
; HDMA channel 4: BG1 scroll registers
lda #$07 ; transfer mode (2 bytes --> $210D, 2 bytes --> $210E)
sta DMAP4
lda #$0D ; PPU reg. $210D
sta BBAD4
ldx #LO8.HDMA_BG_Scroll
stx A1T4L
lda #$7E
sta A1B4
; HDMA channel 5: BG2 scroll registers
lda #$07 ; transfer mode (2 bytes --> $210F, 2 bytes --> $2110)
sta DMAP5
lda #$0F ; PPU reg. $210F
sta BBAD5
ldx #LO8.HDMA_BG_Scroll
stx A1T5L
lda #$7E
sta A1B5
; Set up RAM mirror registers
lda #$01|$08 ; set BG Mode 1, BG3 priority
sta RAM_BGMODE
lda #%00000011 ; 8×8 (small) / 16×16 (large) sprites, character data at $6000 (multiply address bits [0-2] by $2000)
sta RAM_OBSEL
lda #$50 ; VRAM address for BG1 tilemap: $5000, size: 32×32 tiles
sta RAM_BG1SC
lda #$58 ; VRAM address for BG2 tilemap: $5800, size: 32×32 tiles
sta RAM_BG2SC
lda #$48 ; VRAM address for BG3 tilemap: $4800
sta RAM_BG3SC
lda #$00 ; VRAM address for BG1 and BG2 character data: $0000
sta RAM_BG12NBA
lda #$04 ; VRAM address for BG3 character data: $4000 (ignore BG4 bits)
sta RAM_BG34NBA
; Misc. settings
lda #%00010111 ; turn on BG1/2/3 + sprites on mainscreen and subscreen
sta RAM_TM
sta RAM_TM
SetNMI kNMI_Area ; use area NMI handler
Accu16
lda #228 ; dot number for interrupt (256 = too late, 204 = too early)
sta HTIMEL
lda #224 ; scanline number for interrupt (last scanline for now)
sta VTIMEL
Accu8
sta <DP2.TextBoxVIRQ ; save scanline no.
SetIRQ kVIRQ_Area ; use area IRQ handler
lda RDNMI ; clear NMI flag
lda #$81 ; enable Vblank NMI + Auto Joypad Read
sta LO8.NMITIMEN
sta NMITIMEN
cli ; re-enable interrupts
PrintString 2, 2, kTextBG3, "DIALOGUE TEST" ; print some on-screen help
PrintString 4, 2, kTextBG3, "Dpad r/l: next/prev string"
PrintString 5, 12, kTextBG3, "(hold Y for speed)"
PrintString 6, 2, kTextBG3, "Dpad up/dn: change language"
PrintString 7, 2, kTextBG3, "R/L: +/-50 strings"
PrintString 8, 2, kTextBG3, "A: make selection"
lda #%00011111 ; make sure BG1/2/3 lo/hi tilemaps get updated
tsb <DP2.DMA_Updates
tsb <DP2.DMA_Updates+1
WaitFrames 4 ; give some time for screen refresh
lda #$0F ; turn screen back on
sta RAM_INIDISP
jsr InitDialogTextBox ; initialize text box
@DialogueTestLoop:
PrintString 10, 2, kTextBG3, "GameLanguage = $" ; print some text-box-related variables
PrintHexNum <DP2.GameLanguage
PrintString 11, 2, kTextBG3, "TextPointerNo = $"
PrintHexNum <DP2.TextPointerNo+1
PrintHexNum <DP2.TextPointerNo
lda #%00010000 ; make sure BG3 lo/hi tilemaps get updated
tsb <DP2.DMA_Updates
tsb <DP2.DMA_Updates+1
WaitFrames 1
lda LO8.NMITIMEN
sta NMITIMEN
bit <DP2.TextBoxStatus ; check if text box is active (MSB set)
bpl @NoTextBox
jsr ProcDialogTextBox
@NoTextBox:
; Check for dpad up = next language
lda <DP2.Joy1New+1
and #%00001000
beq @DpadUpDone
lda <DP2.TextBoxSelection
and #$0F
bne @DpadUpDone
lda #kLang_Ger
sta <DP2.GameLanguage
jsr InitDialogTextBox@NextDialog
@DpadUpDone:
; Check for dpad down = previous language
lda <DP2.Joy1New+1
and #%00000100
beq @DpadDownDone
lda <DP2.TextBoxSelection
and #$0F
bne @DpadUpDone
lda #kLang_Eng
sta <DP2.GameLanguage
jsr InitDialogTextBox@NextDialog
@DpadDownDone:
; Check for Y + dpad right = fast forward text pointers
lda <DP2.Joy1Press+1 ; Y pressed, check for dpad right
and #%01000001
cmp #%01000001
beq @NextTextPointer
; Check for Y + dpad left = fast rewind text pointers
lda <DP2.Joy1Press+1 ; Y pressed, check for dpad right
and #%01000010
cmp #%01000010
beq @PrevTextPointer
; Check for dpad left = previous text pointer
lda <DP2.Joy1New+1
and #%00000010
beq @DpadLeftDone
@PrevTextPointer:
Accu16
lda <DP2.TextPointerNo ; decrement text pointer
sec
sbc #1
bpl +
lda #0
+ sta <DP2.TextPointerNo
Accu8
jsr InitDialogTextBox@NextDialog
@DpadLeftDone:
; Check for dpad right = next text pointer
lda <DP2.Joy1New+1
and #%00000001
beq @DpadRightDone
@NextTextPointer:
Accu16
lda <DP2.TextPointerNo ; increment text pointer
clc
adc #1
cmp #_sizeof_PTR_DialogEng/2
bcc +
lda #_sizeof_PTR_DialogEng/2-1
+ sta <DP2.TextPointerNo
Accu8
jsr InitDialogTextBox@NextDialog
@DpadRightDone:
; Check for A button
bit <DP2.Joy1New
bpl @AButtonDone
bit <DP2.TextBoxStatus ; check if text box is active (MSB set)
bmi @AButtonDone
jsr InitDialogTextBox@NextDialog
@AButtonDone:
; Check for L button = text pointers -= 50
lda <DP2.Joy1New
and #%00100000
beq @LButtonDone
Accu16
lda <DP2.TextPointerNo ; decrement text pointer
cmp #50
bcs +
lda #0
bra ++
+; sec ; never mind, carry is already set
sbc #50
++ sta <DP2.TextPointerNo
Accu8
jsr InitDialogTextBox@NextDialog
@LButtonDone:
; Check for R button = text pointers += 50
lda <DP2.Joy1New
and #%00010000
beq @RButtonDone
Accu16
lda <DP2.TextPointerNo ; increment text pointer
cmp #_sizeof_PTR_DialogEng/2-50
bcc +
lda #_sizeof_PTR_DialogEng/2-1
bra ++
+; clc ; never mind, carry is already clear
adc #50
++ sta <DP2.TextPointerNo
Accu8
jsr InitDialogTextBox@NextDialog
@RButtonDone:
; Check for Start button = return to debug menu
lda <DP2.Joy1Press+1
and #%00010000
beq @StartButtonDone
stz <DP2.TextBoxStatus ; reset text box status
lda #$80 ; enter forced blank
sta RAM_INIDISP
lda #%00110000 ; clear IRQ enable bits
trb LO8.NMITIMEN
WaitFrames 1
jmp DebugMenu
@StartButtonDone:
jmp @DialogueTestLoop
; ************************ Dialogue text engine ************************
LoadTextBoxBorderTiles:
.ACCU 8
.INDEX 16
ldx #VRAM_BG2_Tiles + $80 ; set VRAM address for BG2 font tiles (+ 16 empty tiles)
stx VMADDL
ldx #$0010 ; upper left corner (1) (see font GFX for tile numbers, whereby 1 tile = $10 bytes)
jsr WriteFontTileToVRAM
ldx #$0020 ; upper left corner (2) / upper border (1)
jsr WriteFontTileToVRAM
ldx #$0020 ; upper border (2) / upper right corner (1)
jsr WriteFontTileToVRAM
ldx #$0030 ; upper right corner (2)
jsr WriteFontTileToVRAM
ldx #$0040 ; left border (1)
jsr WriteFontTileToVRAM
ldx #$0200 ; left border (2) / right border (1) (can be any empty tile, using space tile for now)
jsr WriteFontTileToVRAM
ldx #$0050 ; right border (2)
jsr WriteFontTileToVRAM
ldx #$0060 ; lower left corner (1)
jsr WriteFontTileToVRAM
ldx #$0070 ; lower left corner (2) / lower border (1)
jsr WriteFontTileToVRAM
ldx #$0070 ; lower border (2) / lower right corner (1)
jsr WriteFontTileToVRAM
ldx #$0080 ; lower right corner (2)
jsr WriteFontTileToVRAM
ldx #$0000 ; black tile (1) (for left and right screen edges)
jsr WriteFontTileToVRAM
ldx #$0000 ; black tile (2)
jsr WriteFontTileToVRAM
rts
InitDialogTextBox:
; Prepare selection bar & set shadow PPU regs/misc. parameters
ldx #$0000
- lda.l SRC_HDMA_ColMathDialogSel, x
sta LO8.HDMA_ColorMath, x
inx
cpx #_sizeof_SRC_HDMA_ColMathDialogSel
bne -
lda #%00010000 ; set color math enable bits (4-5) to "MathWindow"
sta RAM_CGWSEL
lda #%00100011 ; enable color math on BG1/2 & mainscreen backdrop
sta RAM_CGADSUB
lda #50 ; color "window" left pos
sta RAM_WH0
lda #244 ; color "window" right pos
sta RAM_WH1
lda #%00100000 ; color math window 1 area = outside (why does this work??)
sta RAM_WOBJSEL
Accu16
lda #%0000001100000011 ; turn on BG1/2 only (i.e., disable BG3 and sprites) for text box
sta LO8.TextBox_TSTM
lda LO8.HDMA_BG_Scroll+1 ; copy BG scroll reg values to second half of playfield
sta LO8.HDMA_BG_Scroll+6
lda LO8.HDMA_BG_Scroll+3
sta LO8.HDMA_BG_Scroll+8
; stz LO8.HDMA_BG_Scroll+11 ; reset scrolling parameters for text box area
; lda #$00FF
; sta LO8.HDMA_BG_Scroll+13
Accu8
lda #97 ; set initial size of playfield BG to fill the whole screen (127 + 97 = 224)
sta LO8.HDMA_BG_Scroll+5
stz LO8.HDMA_BG_Scroll+10
@NextDialog:
; lda #%00110100 ; (re)activate HDMA ch. 2 (backdrop color), 4, 5 (BG scrolling regs)
; tsb <DP2.HDMA_Channels
lda <DP2.HDMA_Channels
and #%11110111 ; disable HDMA channel 3 (color math) in case of previously active selection // FIXME for CM on playfield!!
ora #%00110100 ; (re)activate HDMA ch. 2 (backdrop color), 4, 5 (BG scrolling regs)
sta <DP2.HDMA_Channels
lda #%00110000 ; (re)enable IRQ at H=$4207 and V=$4209
tsb LO8.NMITIMEN
lda #%00000010 ; set "clear text box" flag in case it was used before
sta <DP2.TextBoxStatus
stz <DP2.TextBoxSelection ; reset selection bits
WaitFrames 1
lda #:PTR_DialogEng
clc ; add language constant to get the correct text bank
adc <DP2.GameLanguage
sta <DP2.DiagStringBank
lda <DP2.GameLanguage ; check language again for the right pointer table
bne +
Accu16
lda <DP2.TextPointerNo
asl a
tax
lda.l PTR_DialogEng, x ; DP2.GameLanguage is 0 --> English
bra ++
+ ;cmp #kLang_Ger ; German language selected?
; bne Somewhere ; for even more languages/text banks
Accu16
lda <DP2.TextPointerNo
asl a
tax
lda.l PTR_DialogGer, x ; DP2.GameLanguage is 1 --> German
++ sta <DP2.DiagStringAddress
stz <DP2.DiagStringPos ; reset string position/index
Accu8
lda #%10000000 ; set "text box active" flag
sta <DP2.TextBoxStatus
rts
ProcDialogTextBox: ; if the text box is active, then this routine must be called once per frame
bit <DP2.TextBoxStatus ; check status
bvs @Wait ; "wait" flag set or not?
lda <DP2.TextBoxStatus ; check status again
bit #%00000100 ; "kill text box" flag set?
bne @KillTextBox
@CurrentString:
lda <DP2.DiagStringPos+1 ; text box opening animation should only kick in after portrait and BG control codes have been processed, so check string position
bne + ; if high byte <> 0, don't bother, and continue processing string
lda <DP2.DiagStringPos
cmp #6 ; string pointer variable (16-bit) must be >=6
bcc +
lda <DP2.TextBoxVIRQ ; before printing the string, make sure the opening animation has completed
cmp #176
beq +
jsr TextBoxAnimationOpen
bra @TextBoxDone ; if text box wasn't fully visible, jump out
+ jsr ProcessNextText
bra @TextBoxDone
@Wait: ; wait for some player input
lda <DP2.TextBoxSelection ; check if any selection bit is set
bit #%00001111
beq @WaitForButtonA
jsr TextBoxHandleSelection
bra @TextBoxDone
@WaitForButtonA: ; usual wait condition: wait for player confirmation
bit <DP2.Joy1New ; wait for player to press the A button (MSB)
bpl @TextBoxDone
lda #%01000000 ; A pressed, clear "wait" flag
trb <DP2.TextBoxStatus
bra @TextBoxDone
@KillTextBox:
lda <DP2.TextBoxVIRQ
cmp #224
beq +
jsr TextBoxAnimationClose
bra @TextBoxDone
+ lda #%00110000 ; text box completely removed, clear IRQ enable bits
trb LO8.NMITIMEN
lda #%00110100 ; deactivate used HDMA channels
trb <DP2.HDMA_Channels
lda #%00000010 ; set "clear text box" flag only
sta <DP2.TextBoxStatus
; Accu16
; lda LO8.HDMA_BG_Scroll+1 ; restore scrolling parameters // possibly needed on areas with vertical scrolling
; sta LO8.HDMA_BG_Scroll+11
; lda LO8.HDMA_BG_Scroll+3
; sta LO8.HDMA_BG_Scroll+13
; Accu8
@TextBoxDone:
rts
TextBoxHandleSelection:
lda <DP2.HDMA_Channels ; check if HDMA channel 3 (color math) is already enabled
and #%00001000
bne @WaitForInput
; Determine text box line the selection starts on, and pre-load Accu with appropriate multiple of 8, i.e. Accu = (sel_start_line - 1) * 8, using a bit-manipulating loop
lda #0 ; pre-load Accu with 0, use RSH to find the line the selection starts on
xba ; preserve inital value
lda <DP2.TextBoxSelection
- lsr a ; test DP2.TextBoxSelection bits from LSB onwards
xba ; switch back to target Accu value
bcs + ; jump out as soon as first set bit found
adc #8 ; bit was clear, add 8 to target Accu value // carry always clear at this point, so no need for clc before the adc
xba ; switch back to next-higher selection bit
bra - ; rinse and repeat until first set bit found
+ clc
adc #kTextBoxColMath1st
sta LO8.HDMA_ColorMath+3
sta <DP2.TextBoxSelMin
stz <DP2.TextBoxSelMax
lda <DP2.TextBoxSelection
lsr a ; count no. of selection options available (4 max.)
bcc +
inc <DP2.TextBoxSelMax
+ lsr a
bcc +
inc <DP2.TextBoxSelMax
+ lsr a
bcc +
inc <DP2.TextBoxSelMax
+ lsr a
bcc +
inc <DP2.TextBoxSelMax
+ lda <DP2.TextBoxSelMax ; DP2.TextBoxSelMax = (no. of options - 1) * 8 + DP2.TextBoxSelMin
dec a
asl a
asl a
asl a
clc
adc <DP2.TextBoxSelMin
sta <DP2.TextBoxSelMax
lda #%00001000 ; enable HDMA channel 3 (color math)
tsb <DP2.HDMA_Channels
bra @JumpOut ; wait for selection bar to appear before checking buttons on next iteration
@WaitForInput:
; Check for dpad up
lda <DP2.Joy1New+1
and #%00001000
beq @DpadUpDone
lda LO8.HDMA_ColorMath+3 ; move selection bar 8 scanlines up
sec
sbc #8
cmp <DP2.TextBoxSelMin
bcs +
lda <DP2.TextBoxSelMin
+ sta LO8.HDMA_ColorMath+3
@DpadUpDone:
; Check for dpad down
lda <DP2.Joy1New+1
and #%00000100
beq @DpadDownDone
lda LO8.HDMA_ColorMath+3 ; move selection bar 8 scanlines down
clc
adc #8
cmp <DP2.TextBoxSelMax
bcc +
lda <DP2.TextBoxSelMax
+ sta LO8.HDMA_ColorMath+3
@DpadDownDone:
; Check for A button = make selection
lda <DP2.Joy1New
bpl @JumpOut
lda LO8.HDMA_ColorMath+3 ; determine selection made by checking position of selection bar
sec
sbc #kTextBoxColMath1st ; subtract start of 1st line
lsr a ; divide by 8 as each line is 8 pixels high
lsr a
lsr a
Accu16 ; Accu A contains a value of $00, $01, $02, or $03 at this point
and #$00FF ; clear garbage in high byte
tax ; and use as a counter
Accu8
lda #%00010000 ; assume selection made on line 1 for now = set bit 4 (a)
- dex ; decrement counter
bmi + ; counter was zero --> don't shift bit (any more)
asl a ; shift selection bit as many times as needed
bra -
+ sta <DP2.TextBoxSelection ; store user selection bit in upper nibble (bits 0-3 clear)
lda #%00001000 ; disable HDMA channel 3 (color math) // FIXME for CM on playfield!!
trb <DP2.HDMA_Channels
@JumpOut:
rts
ProcessNextText:
Accu16
@NextStringByte:
lda <DP2.DiagStringPos
tay ; transfer string position to Y index
inc a ; increment to next ASCII string character
sta <DP2.DiagStringPos ; (N.B.: inc a, sta dp is 1 cycle faster than inc dp)
Accu8
lda [<DP2.DiagStringAddress], y ; read current byte of string
beq @EndOfString ; NUL terminator, stop processing string
cmp #$FF ; check for control code, this hex value has to match the upper byte of the two-byte entries starting from $FF00 in tbl_dialog_*.inc.asm
beq @ControlCode
@NormalText: ; process normal text
Accu16
and #$00FF ; remove garbage in high byte
sta <DP2.DiagASCIIChar ; save ASCII char no.
bit <DP2.DiagTextEffect-1 ; put MSB of DP2.DiagTextEffect (an 8-bit variable) into MSB of (currently 16-bit) accumulator
bmi + ; MSB set --> use routine for bold font
jsr ProcessVWFTiles ; otherwise, use normal font routine
bra ++
+ jsr ProcessVWFTilesBold
++ Accu16
lda <DP2.VWF_BufferIndex ; check if 2 buffer tiles full
cmp #32 ; 2 tiles × 16 = buffer index
bcc @NextStringByte ; buffer not full yet, continue reading string // ADDME/ADDFEATURE @JumpOut instead for slower text speed
Accu8
lda #%00000001 ; set "VWF buffer full" bit
tsb <DP2.TextBoxStatus
WaitFrames 1
Accu16
FlushVWFTileBuffer2
IncDiagTileDataCounter ; increment tile data counter to next 16×8 tile
Accu8
bra @JumpOut
@ControlCode:
Accu16
lda <DP2.DiagStringPos ; increment string position to actual control code byte
tay
inc a
sta <DP2.DiagStringPos
lda [<DP2.DiagStringAddress], y ; read control code
and #$00FF ; clear garbage in high byte
asl a ; use control code as jump index
tax
Accu8
jmp (PTR_ProcessDiagCC, x) ; control codes do rts, where applicable
@EndOfString: ; CC_End encountered
bit <DP2.DiagTextEffect ; check sub-string flag
bvc @StringFinished
lda LO8.DiagStringBank ; sub-string finished, restore current string bank
sta <DP2.DiagStringBank
Accu16
lda LO8.DiagStringAddress ; restore string address and offset/pointer
sta <DP2.DiagStringAddress
lda LO8.DiagStringPos
sta <DP2.DiagStringPos
Accu8
lda #%01000000 ; clear sub-string flag
trb <DP2.DiagTextEffect
bra @JumpOut
@StringFinished: ; string completely finished
Accu16 ; flush buffer and reset status parameters
lda <DP2.VWF_BitsUsed ; check two variables for a non-zero value
ora <DP2.VWF_BufferIndex
beq +
Accu8 ; if either (bit counter <> 0) or (VWF buffer index <> 0) ...
lda #%00000001 ; ... set "VWF buffer full" bit
tsb <DP2.TextBoxStatus
WaitFrames 1
Accu16
FlushVWFTileBuffer2
+ Accu8
lda #%01000100 ; set "wait" and "kill text box" status flags
tsb <DP2.TextBoxStatus
stz <DP2.DiagTileDataCounter ; clear tile data counter
stz <DP2.DiagTileDataCounter+1
@JumpOut:
rts
PTR_ProcessDiagCC: ; self-reminder: Order of table entries has to match lower byte of the two-byte entries starting from $FF00 in tbl_dialog_*.inc.asm
.DW Process_CC_BoxBG
.DW Process_CC_ClearTextBox
.DW Process_CC_Indent
.DW Process_CC_Jump
.DW Process_CC_NewLine
.DW Process_CC_Portrait
.DW Process_CC_Selection
.DW Process_CC_SubHex
.DW Process_CC_SubInt8
.DW Process_CC_SubInt16
.DW Process_CC_SubString
.DW Process_CC_ToggleBold
Process_CC_BoxBG:
Accu16
lda <DP2.DiagStringPos ; increment string position to number of BG color gradient
tay
inc a
sta <DP2.DiagStringPos
Accu8
lda [<DP2.DiagStringAddress], y ; read BG color gradient number
ora #$80 ; set "change text box background" bit
sta <DP2.TextBoxBG
rts ; aka bra/jmp ProcessNextText@JumpOut
Process_CC_ClearTextBox:
Accu16
lda <DP2.VWF_BitsUsed ; check two variables for a non-zero value
ora <DP2.VWF_BufferIndex
beq +
Accu8 ; if either (bit counter <> 0) or (VWF buffer index <> 0) ...
lda #%00000001 ; ... set "VWF buffer full" bit
tsb <DP2.TextBoxStatus
WaitFrames 1
Accu16
FlushVWFTileBuffer2
+ Accu8
lda #%01000010 ; set "wait", "clear text box" status flags
tsb <DP2.TextBoxStatus
stz <DP2.DiagTileDataCounter ; reset tile counter
stz <DP2.DiagTileDataCounter+1
rts
Process_CC_Indent:
Accu16
IncDiagTileDataCounter ; skip one 16×8 tile
Accu8
rts
Process_CC_Jump:
iny ; increment string pointer to address of new string
Accu16
lda [<DP2.DiagStringAddress], y ; read 16-bit address
tax ; store temporarily in X (we still need to read the bank byte from [DiagStringAddress] so we can't overwrite it just yet)
Accu8
iny ; increment string pointer to bank of new string
iny
lda [<DP2.DiagStringAddress], y ; read bank
sta <DP2.DiagStringBank ; store bank
stx <DP2.DiagStringAddress ; store address
stz <DP2.DiagStringPos ; reset string position/index
stz <DP2.DiagStringPos+1
rts
Process_CC_NewLine:
lda #%00000001 ; set "VWF buffer full" bit
tsb <DP2.TextBoxStatus
WaitFrames 1
Accu16
FlushVWFTileBuffer2
IncDiagTileDataCounter ; increment tile data counter before checking for current text box line, this ensures that very short strings (using less than a full 16×8 tile) on lines 2 or 3 won't get simply overwritten by succeeding dialogue
lda #46*8 ; check what line we've been on: line 1?
cmp <DP2.DiagTileDataCounter ; (line 2 starts at 46*8)
bcs +
lda #92*8 ; line 2?
cmp <DP2.DiagTileDataCounter ; (line 3 starts at 92*8)
bcs +
lda #138*8 ; otherwise, go to line 4
+ sta <DP2.DiagTileDataCounter
stz <DP2.VWF_BitsUsed ; lastly, reset VWF bit counter
Accu8
rts ; do nothing if carriage return requested after exactly 23 (16×8) tiles
Process_CC_Portrait:
iny ; increment string pointer to portrait no.
lda [<DP2.DiagStringAddress], y ; read portrait no. (0-127)
ora #$80 ; set "change portrait" bit
sta <DP2.TextBoxCharPortrait ; save to "change portrait" request variable
Accu16
inc <DP2.DiagStringPos ; advance ASCII string position/index
Accu8
rts
Process_CC_Selection:
Accu16
lda <DP2.DiagTileDataCounter ; selection required, check what line we've been on
cmp #46*8 ; line 1?
bcs +
lda #%0000000000000001
bra ++
+ cmp #92*8 ; line 2?
bcs +
lda #%0000000000000010
bra ++
+ cmp #138*8 ; line 3?
bcs +
lda #%0000000000000100
bra ++
+ lda #%0000000000001000 ; else, line 4
++ Accu8
tsb <DP2.TextBoxSelection
rts
Process_CC_SubHex:
iny ; increment string pointer to address of byte to print in hex
lda [<DP2.DiagStringAddress], y ; read address (low byte)
sta <DP2.DataAddress
iny
lda [<DP2.DiagStringAddress], y ; high byte
sta <DP2.DataAddress+1
iny
lda [<DP2.DiagStringAddress], y ; bank
sta <DP2.DataBank
iny ; advance string pointer to byte after address
sty LO8.DiagStringPos ; save current string pointer
; Process actual hex byte, i.e. make it into a WRAM sub-string
lda [<DP2.DataAddress] ; load byte to print in hex
pha
lsr a ; do upper nibble first