-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlg.s
1380 lines (1328 loc) · 28.5 KB
/
dlg.s
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
define dlg_read_ptr $72 // used only when expanding dialog to buffer
define dlg_seek $778 // used to parse all pages of dialog
define vwf_draw_x $77A // canvas x
define vwf_draw_y $77C // canvas y
define vwf_seek $77E // where to write on canvas
define vwf_temp_0 $780 // write here whatever temp value
define vwf_temp_1 $782 // same as above
define vwf_line $784 // number of scanlines to render
define vwf_draw_x2 $788 // copy x value
define vwf_dma_srcl $78A
define vwf_dma_srch $78C
define vwf_dma_dst $78E
define vwf_dma_size $790
define vwf_jmp_x $792 // jumptable index
define dlg_buffer $704000 // where expanded dialog is stored
define vwf_canvas $7ee600 // canvas for proportional rendering
define w_spc 4 // width of a space (it's not in the width table)
define w_spc8 3 // width of a space for 8x8 font
//////////////////////////////
// CODE FOR NMI //
//////////////////////////////
Fld_DMA_trans:
php
phb
sep #$20 // A.8
lda.b #0 // bank = 0
pha
plb
lda.b #$80
sta $2115
lda.b #0
sta $420c
ldx {vwf_dma_dst} // destination
stx $2116
lda.b #1
sta $4300
lda.b #$18 // vram port
sta $4301
ldx {vwf_dma_srcl} // source pointer
stx $4302
lda {vwf_dma_srch} // source bank
sta $4304
ldx {vwf_dma_size} // size
stx $4305
lda.b #1
sta $420b // enable transfer
plb
plp
rts
Fld_loc_trans:
php
rep #$20 // A.16
// tilemap
lda.w #(loc_tmap_tbl & 0xffff) // source pointer
sta {vwf_dma_srcl}
lda.w #(loc_tmap_tbl >> 16) // source bank
sta {vwf_dma_srch}
lda.w #$2840 // destination
sta {vwf_dma_dst}
lda.w #(32*4*2) // size
sta {vwf_dma_size}
jsr Fld_DMA_trans
// tiles
lda.w #({vwf_canvas} & 0xffff) // source pointer
sta {vwf_dma_srcl}
lda.w #({vwf_canvas} >> 16) // source bank
sta {vwf_dma_srch}
lda.w #$2100 // destination
sta {vwf_dma_dst}
lda.w #(24*7*16) // size
sta {vwf_dma_size}
jsr Fld_DMA_trans
plp
rtl
Fld_dlg_trans_tmap:
php
rep #$20 // A.16
ldx #(dlg_tmap_tbl & 0xffff) // source pointer
stx {vwf_dma_srcl}
ldx #(dlg_tmap_tbl >> 16) // source bank
stx {vwf_dma_srch}
ldx #$2C00 // destination
stx {vwf_dma_dst}
ldx #(32*9*2) // size
stx {vwf_dma_size}
jsr Fld_DMA_trans
plp
rtl
Fld_dlg_trans_canvas:
php
rep #$20 // A.16
ldx #({vwf_canvas} & 0xffff) // source pointer
stx {vwf_dma_srcl}
ldx #({vwf_canvas} >> 16) // source bank
stx {vwf_dma_srch}
ldx #$2100 // destination
stx {vwf_dma_dst}
ldx #(24*7*16) // size
stx {vwf_dma_size}
jsr Fld_DMA_trans
plp
rtl
Fld_legend_pal:
rep #$20
-
lda.w #$4000 // blue
sta $CDD,x // color 1
sta $CDF,x // color 2
sta $CE1,x // color 3
txa
clc
adc.w #8 // next palette
tax
cmp.w #64
bne -
sep #$20
rtl
Fld_legend_pal_w:
sta $CE1,x
// halve yellow into gray
lsr
and.w #%0000000111101111
ora.w #%0100000000000000
sta $CDF,x // store attenuated color for shade
lda.w #0 // old code
rtl
// A.8 page
Fld_legend_dma:
php
cmp.b #0
bne .page1
+
rep #$20 // A.16
// tiles
lda.w #({vwf_canvas} & 0xffff) // source pointer
sta {vwf_dma_srcl}
lda.w #({vwf_canvas} >> 16) // source bank
sta {vwf_dma_srch}
lda.w #$2100 // destination
sta {vwf_dma_dst}
lda.w #(24*4*16) // size
sta {vwf_dma_size}
jsr Fld_DMA_trans
// tilemap
lda.w #(prol_tmap_tbl0 & 0xffff)// source pointer
sta {vwf_dma_srcl}
lda.w #(prol_tmap_tbl0 >> 16) // source bank
sta {vwf_dma_srch}
lda.w #$2C00 // destination
sta {vwf_dma_dst}
lda.w #(32*2*8) // size
sta {vwf_dma_size}
jsr Fld_DMA_trans
bra .end
.page1:
rep #$20 // A.16
// tiles
lda.w #({vwf_canvas} & 0xffff) // source pointer
sta {vwf_dma_srcl}
lda.w #({vwf_canvas} >> 16) // source bank
sta {vwf_dma_srch}
lda.w #$2400 // destination
sta {vwf_dma_dst}
lda.w #(24*4*16) // size
sta {vwf_dma_size}
jsr Fld_DMA_trans
// tilemap
lda.w #(prol_tmap_tbl1 & 0xffff)// source pointer
sta {vwf_dma_srcl}
lda.w #(prol_tmap_tbl1 >> 16) // source bank
sta {vwf_dma_srch}
lda.w #$2D00 // destination
sta {vwf_dma_dst}
lda.w #(32*2*8) // size
sta {vwf_dma_size}
jsr Fld_DMA_trans
.end:
plp
rtl
//////////////////////////////
// STRING HANDLING //
//////////////////////////////
Fld_dlg8_page:
stz {dlg_seek}
stz {dlg_seek}+1
jsr Fld_expand_dialog // copy dialog to buffer
Fld_dlg8_pages:
jsr Fld_vwf_clear_canvas
jsr Fld_parse_dialog8 // do the actual rendering
jsr Fld_vwf_flip_canvas
//jsr Fld_wait_NMI // wait next nmi
// enable canvas transfer
//lda.b #1
//sta $ed
rtl
Fld_dlg_page0:
stz {dlg_seek}
stz {dlg_seek}+1
jsr Fld_expand_dialog // copy dialog to buffer
Fld_dlg_pages:
jsr Fld_vwf_clear_canvas
jsr Fld_parse_dialog // do the actual rendering
jsr Fld_vwf_flip_canvas
jsr Fld_wait_NMI // wait next nmi
// enable canvas transfer
lda.b #1
sta $ed
rtl
Fld_ptr_bank1_0:
php
rep #$20
lda $B2
and.w #$00ff
sta $3D // index * 3
asl
adc $3D
tax
sep #$20
lda dialog_ptr1+0,x
sta {dlg_read_ptr}+0x700
lda dialog_ptr1+1,x
sta {dlg_read_ptr}+0x701
lda dialog_ptr1+2,x
sta {dlg_read_ptr}+0x702
plp
rtl
Fld_ptr_bank1_1:
php
rep #$20
lda $B2
and.w #$00ff
sta $3D // index * 3
asl
adc $3D
tax
sep #$20
lda dialog_ptr1+768,x
sta {dlg_read_ptr}+0x700
lda dialog_ptr1+769,x
sta {dlg_read_ptr}+0x701
lda dialog_ptr1+770,x
sta {dlg_read_ptr}+0x702
plp
rtl
Fld_ptr_bank2:
php
ldx $3D
rep #$20
lda dialog_pptr2,x
sta {vwf_temp_1} // store local pointer
lda $B2 // get index
and.w #$00ff
sta {vwf_temp_0} // index * 3
asl
adc {vwf_temp_0}
adc {vwf_temp_1}
tax
sep #$20
lda dialog_ptr2+0,x
sta {dlg_read_ptr}+0x700
lda dialog_ptr2+1,x
sta {dlg_read_ptr}+0x701
lda dialog_ptr2+2,x
sta {dlg_read_ptr}+0x702
plp
rtl
Fld_ptr_bank3:
php
rep #$20
lda $B2
and.w #$00ff
sta $3D // index * 3
asl
adc $3D
tax
lda dialog_ptr3+0,x
sta {dlg_read_ptr}+0x700
lda dialog_ptr3+1,x
sta {dlg_read_ptr}+0x701
lda dialog_ptr3+2,x
sta {dlg_read_ptr}+0x702
plp
rtl
Fld_parse_dialog:
php
sep #$20 // A.8
ldx {dlg_seek} // load any previous seek
stz {vwf_draw_x}
stz {vwf_draw_x}+1
stz {vwf_draw_y}
stz {vwf_draw_y}+1
-
lda {dlg_buffer},x
inx
cmp.b #0 // end
bne +
// treat end
lda.b #1 // send signal that this is the last window
sta $DE
bra .end
+
cmp.b #1 // line break
bne +
// treat line break
jsr Fld_vwf_carry_line
// check if we're above 4 lines of text
lda {vwf_draw_y}
cmp.b #56
bcc - // below 4 lines, keep going
bra .end
+
cmp.b #9 // new page
bne +
stz {vwf_draw_x}
stz {vwf_draw_x}+1
stz {vwf_draw_y}
stz {vwf_draw_y}+1
bra .end
+
cmp.b #3 // music
bne +
lda {dlg_buffer},x
inx
sta $1e01
lda.b #1
sta $1e00
jsl $48004
bra -
+
cmp.b #5 // delay
bne +
stz $619
asl
rol $619
asl
rol $619
asl
rol $619
sta $618
phx
ldx $618
stx $8f4
ldx.w #0
stx $8f6
plx
bra -
+
cmp.b #$a // centering
bne +
jsr Fld_center16
bra -
+
jsr Fld_vwf_draw_char
bra -
.end:
stx {dlg_seek} // store current seek
plp
rts
Fld_parse_dialog8:
php
sep #$20 // A.8
ldx {dlg_seek} // load any previous seek
stz {vwf_draw_x}
stz {vwf_draw_x}+1
stz {vwf_draw_y}
stz {vwf_draw_y}+1
-
lda {dlg_buffer},x
inx
cmp.b #0 // end
bne +
// treat end
lda.b #1 // send signal that this is the last window
sta $DE
bra .end
+
cmp.b #1 // line break
bne +
// treat line break
jsr Fld_vwf8_carry_line
// check if we're above 4 lines of text
lda {vwf_draw_y}
cmp.b #(8*4)
bcc - // below 4 lines, keep going
bra .end
+
cmp.b #$a // center
bne +
jsr Fld_center8
bra -
+
jsr Fld_vwf8_draw_char
bra -
.end:
stx {dlg_seek} // store current seek
plp
rts
//org $00B45B
// expands dialog to a buffer
Fld_expand_dialog:
// macros
define .write_ptr $75
define .buffer $774
// code
phd
// replace direct page
rep #$20
lda.w #$0700
tcd
sep #$20
// setup write buffer
ldx.w #({dlg_buffer} & 0xffff)
stx {.write_ptr}+0x700
lda.b #({dlg_buffer} >> 16)
sta {.write_ptr}+0x702
.loop:
jsr .read
cmp.b #9
bcs .char
tay // backup read character
rep #$20
and.w #$00ff
asl
tax
sep #$20
tya // restore character
jmp (.jmp_tbl,x)
.line: // 01
.auto: // 06
.page: // 09
.center: // 0a
.char: // 0b-ff
jsr .write
jmp .loop
.align: // 02
.music: // 03
.pause: // 05
jsr .write
jsr .read
jsr .write
jmp .loop
.name: // 04, expand name
jsr .read
asl
asl
asl
sta $618
stz $619
ldx $618
ldy $63D
stz $607
-
lda {ex_name_data},x
cmp.b #$ff // premature end of the string
beq .loop
jsr .write
inx
inc $607
lda $607
cmp.b #8 // max size of a name
bne -
bra .loop
.item: // 7, expand item
lda $8FB // item id
rep #$20
and.w #$00ff
asl
tax
lda .item_txt_data,x // load item pointer
inc // skip icon
tax
sep #$20
-
lda .item_txt_data,x // load character from item
beq + // end of string
jsr .write // write character read
inx
bra -
+
jmp .loop
.var: // 8, expand variable
lda $8f8
sta $630
lda $8f9
sta $631
lda $8fa
sta $632
jsr Fld_format_number_ex
ldx.w #0
.varloop:
lda $636,x
cmp.b #$80 // '0'
bne .varskip
inx
cpx.w #5
beq .varskip
jmp .varloop
.varskip:
lda $636,x
jsr .write
inx
cpx.w #6
bne .varskip
jmp .loop
.end: // 0
jsr .write
pld // restore dpage
rts
.item_txt_data:
incbin "item.bin"
.jmp_tbl:
dw .end, .line, .align, .music
dw .name, .pause, .auto, .item
dw .var, .page, .center
.read:
lda [{dlg_read_ptr}]
jsr .increase
rts
.write:
pha
sta [{.write_ptr}]
rep #$20
inc {.write_ptr}
sep #$20
pla
rts
.increase:
pha
rep #$20
lda {dlg_read_ptr}+0x700
inc
sta {dlg_read_ptr}+0x700
and.w #$8000
bne +
lda.w #$8000 // reset to bank start
sta {dlg_read_ptr}+0x700
sep #$20
inc {dlg_read_ptr}+0x702 // next bank
+
sep #$20
pla
rts
//////////////////////////////
// PROPORTIONAL RENDERING //
//////////////////////////////
// parameters:
// A.8 character to print
Fld_vwf_draw_char:
php
phx
phy
pha
cmp.b #$40 // check if it's a space
bne +
jmp .end // skip all rendering for spaces
+
cmp.b #$3F // check valid range of characters
bcs +
cmp.b #$D2
bcc +
lda.b #'?' // replace all unknown characters with '?'
+
// calculate seek on font
rep #$20 // A.16
and.w #$00ff
sec
sbc.w #'A' // align with font order
sta {vwf_temp_1} // char * 24
asl
clc
adc {vwf_temp_1}
asl
asl
asl
sta {vwf_temp_1}
jsr .calc_seek // calculate where to write
lda {vwf_draw_x} // calculate jump table index
and.w #$7 // x % 8 * 2
asl
sta {vwf_jmp_x}
lda.w #12*2 // process 12 scanlines (24 planes)
sta {vwf_line}
lda {vwf_temp_1} // reload font seek
tax
.line:
lda Fld_font16_dlg,x // load font plane
inx // plane++
and #$00ff
beq .skip // skip empty lines
xba
txy // preserve font seek
ldx {vwf_jmp_x}
jmp (.jtbl,x)
.lsr7:
lsr
.lsr6:
lsr
.lsr5:
lsr
.lsr4:
lsr
.lsr3:
lsr
.lsr2:
lsr
.lsr1:
lsr
.lsr0:
ldx {vwf_seek} // load where to write in buffer
sep #$20 // A.8
xba // shifted glyph
beq + // skip if empty
sta {vwf_temp_0}
lda {vwf_canvas},x // load previous plane data
ora {vwf_temp_0} // combine
sta {vwf_canvas},x // store combined plane
+
xba // overflow glyph
beq + // skip if empty
sta ({vwf_canvas}+112),x // write to next tile plane
+
tyx
.skip:
rep #$20 // A.16
inc {vwf_seek}
dec {vwf_line}
bne .line
.end:
sep #$20
pla
jsr Fld_vwf_get_char_w // x += width
clc
adc {vwf_draw_x}
sta {vwf_draw_x}
ply
plx
plp
rts
.jtbl:
dw .lsr0, .lsr1, .lsr2, .lsr3, .lsr4, .lsr5, .lsr6, .lsr7
// calculates seek on canvas
.calc_seek:
pha
php
rep #$20
lda {vwf_draw_y} // y * 2 + (x >> 3) * 7 * 16
asl
sta {vwf_seek}
lda {vwf_draw_x}
lsr
lsr
lsr
sta {vwf_temp_0}
asl
adc {vwf_temp_0}
asl
adc {vwf_temp_0}
asl
asl
asl
asl
adc {vwf_seek}
sta {vwf_seek}
plp
pla
rts
// parameters:
// A.8 character to print
Fld_vwf8_draw_char:
php
phx
phy
pha
cmp.b #$40 // check if it's a space
bne +
jmp .end // skip all rendering for spaces
+
// calculate seek on font
rep #$20 // A.16
and.w #$00ff
sec
sbc.w #$0f // align with font order
asl // char * 16
asl
asl
asl
sta {vwf_temp_1}
jsr .calc_seek // calculate where to write
lda {vwf_draw_x} // calculate jump table index
and.w #$7 // x % 8 * 2
asl
sta {vwf_jmp_x}
lda.w #8*2 // process 8 scanlines (16 planes)
sta {vwf_line}
lda {vwf_temp_1} // reload font seek
tax
.line:
lda font_name,x // load font plane
inx // plane++
and #$00ff
beq .skip // skip empty lines
xba
txy // preserve font seek
ldx {vwf_jmp_x}
jmp (.jtbl,x)
.lsr7:
lsr
.lsr6:
lsr
.lsr5:
lsr
.lsr4:
lsr
.lsr3:
lsr
.lsr2:
lsr
.lsr1:
lsr
.lsr0:
ldx {vwf_seek} // load where to write in buffer
sep #$20 // A.8
xba // shifted glyph
beq + // skip if empty
sta {vwf_temp_0}
lda {vwf_canvas},x // load previous plane data
ora {vwf_temp_0} // combine
sta {vwf_canvas},x // store combined plane
+
xba // overflow glyph
beq + // skip if empty
sta ({vwf_canvas}+16),x // write to next tile plane
+
tyx
.skip:
rep #$20 // A.16
inc {vwf_seek}
dec {vwf_line}
bne .line
.end:
sep #$20
pla
jsr Fld_vwf8_get_char_w // x += width
clc
adc {vwf_draw_x}
sta {vwf_draw_x}
ply
plx
plp
rts
.jtbl:
dw .lsr0, .lsr1, .lsr2, .lsr3, .lsr4, .lsr5, .lsr6, .lsr7
.calc_seek:
pha
php
rep #$20
//
lda {vwf_draw_x} // (x & 0xfff8) * 2 + y * 24 * 2
and.w #$fff8
asl
sta {vwf_seek}
lda {vwf_draw_y}
sta {vwf_temp_0} // * 3
asl
clc
adc {vwf_temp_0}
asl // * 8
asl
asl
asl
clc
adc {vwf_seek}
sta {vwf_seek}
plp
pla
rts
// returns width of a character
// parameters:
// A.8 character to retrieve
// returns
// A.8 width of character
Fld_vwf_get_char_w:
phx
cmp.b #$40 // space
bne .not_space
lda.b #{w_spc} // space width
bra .return
.not_space:
cmp.b #$3F // check below defined range
bcs +
cmp.b #$D2 // check above defined range
bcc +
lda.b #'?' // replace with valid character
+
sec
sbc.b #'A' // use 0x42-0xff range
tax
lda font16_wtbl,x
+
.return:
plx
rts
// returns width of a character
// parameters:
// A.8 character to retrieve
// returns
// A.8 width of character
Fld_vwf8_get_char_w:
phx
cmp.b #$40 // space
bne .not_space
lda.b #{w_spc8} // space width
bra .return
.not_space:
sec
sbc.b #$0f // use 0x0f-0xff range
xba
lda.b #0
xba
tax
lda font_namew,x
.return:
plx
rts
// clear render canvas
Fld_vwf_clear_canvas:
php
rep #$20
ldx.w #0
lda.w #0 // clear value
-
sta {vwf_canvas},x
inx
inx
cpx.w #(24*7*16) // if (x < sizeof(canvas))
bne -
plp
rts
// fixes bits to render canvas
Fld_vwf_flip_canvas:
php
rep #$20
ldx.w #0
-
lda {vwf_canvas},x
eor.w #$00ff
sta {vwf_canvas},x
inx
inx
cpx.w #(24*7*16) // if (x < sizeof(canvas))
bne -
plp
rts
Fld_vwf_carry_line:
stz {vwf_draw_x} // x = 0
stz {vwf_draw_x}+1
lda {vwf_draw_y} // y += 14
clc
adc.b #14
sta {vwf_draw_y}
rts
Fld_vwf8_carry_line:
stz {vwf_draw_x} // x = 0
stz {vwf_draw_x}+1
lda {vwf_draw_y} // y += 8
clc
adc.b #8
sta {vwf_draw_y}
rts
Fld_format_dlg:
ldx.w #0
stx {vwf_draw_x}
-
lda {dlg_buffer},x
inx
cmp.b #0 // end of string
beq .end
cmp.b #$40 // space
bne .ck_line
// is space, do prediction stuff
jsr Fld_width_next
cmp.b #1
beq .line // returned 1, it's a line carry now
lda #{w_spc} // load space width
bra .space
.ck_line:
cmp.b #1 // new line
bne .ck_align
// is line, reset x
.line:
stz {vwf_draw_x}
stz {vwf_draw_x}+1
bra -
.ck_align:
cmp.b #2 // align
bne .char
inx // skip aligner
.char:
txy
tax
lda font16_wtbl,x // load width to add
tyx
.space:
adc {vwf_draw_x}
sta {vwf_draw_x} // x+=read
bra -
.end:
rts
// X.16 current string seek
Fld_center8:
phx // preserve seek
php
sep #$20
stz {vwf_draw_x2}
stz {vwf_draw_x2}+1
-
lda {dlg_buffer},x // load character
cmp.b #0 // check end
beq +
cmp.b #1 // check line
beq +
inx
jsr Fld_vwf8_get_char_w
clc
adc {vwf_draw_x2} // w += vwf8[c]
sta {vwf_draw_x2}
bra -
+
rep #$20
lda.w #(24*8) // line width
sec
sbc {vwf_draw_x2} // (24*8 - width) / 2
lsr
sta {vwf_draw_x}
plp
plx // reload previous seek
rts
Fld_center16:
phx // preserve seek
php
sep #$20
stz {vwf_draw_x2}
stz {vwf_draw_x2}+1
-
lda {dlg_buffer},x // load character
cmp.b #0 // check end
beq +
cmp.b #1 // check line
beq +
inx
jsr Fld_vwf_get_char_w
clc
adc {vwf_draw_x2} // w += vwf8[c]
sta {vwf_draw_x2}
bra -
+
rep #$20
lda.w #(24*8) // line width
sec
sbc {vwf_draw_x2} // (24*8 - width) / 2
lsr
sta {vwf_draw_x}
plp
plx // reload previous seek