-
Notifications
You must be signed in to change notification settings - Fork 0
/
vt100.csi.S
934 lines (756 loc) · 10.8 KB
/
vt100.csi.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
lst off
cas se
rel
xc
xc
use vt.equ
use debug
mx %11
ext reset_tab,reset_all_tabs
ext recalc_cursor,recalc_cursor_x,recalc_cursor_y
ext erase_line_0,erase_line_1,erase_line_2
ext erase_screen_0,erase_screen_1,erase_screen_2
ext update_sgr
ext write_modem,write_modem_str
vt100_csi ent
debug vt100_csi
* 0123456789;ycnlhgrqJKmABCDHf
* based on testing -
* everything except '0' - '?' and control chars
* will finish.
* '?' only matters for h/l
* a misplaced ? (or anything in '0' - '?', except 0-9;)
* will cancel the sequence AFTER it's finished.
* < = > ? are allowed as an initial modifier but only '?' is private
* a mis-placed < = > ? will prevent 0x20-0x2f from terminating the sequence.
ldx #st_vt100
stx state
stz pcount
stz parms
stz parms+1 ; some assume 2 parms.
stz pmod
* tay ; save for modifier
cmp #:MIN
blt :rts
cmp #:MAX+1
bge :rts
sec
sbc #:MIN
asl
tax
jmp (:table,x)
*
:rts rts
:MIN equ 48
:MAX equ 121
:table
dw :digit ; 0
dw :digit ; 1
dw :digit ; 2
dw :digit ; 3
dw :digit ; 4
dw :digit ; 5
dw :digit ; 6
dw :digit ; 7
dw :digit ; 8
dw :digit ; 9
dw digit ; :
dw semi
dw :xmod ; <
dw :xmod ; =
dw :xmod ; >
dw :modifier ; ?
dw :rts ; @
dw csi_A ; A
dw csi_B ; B
dw csi_C ; C
dw csi_D ; D
dw :rts ; E
dw :rts ; F
dw :rts ; G
dw csi_H ; H
dw :rts ; I
dw csi_J ; J
dw csi_K ; K
dw :rts ; L
dw :rts ; M
dw :rts ; N
dw :rts ; O
dw :rts ; P
dw :rts ; Q
dw :rts ; R
dw :rts ; S
dw :rts ; T
dw :rts ; U
dw :rts ; V
dw :rts ; W
dw :rts ; X
dw :rts ; Y
dw :rts ; Z
dw :rts ; [
dw :rts ; \
dw :rts ; ]
dw :rts ; ^
dw :rts ; _
dw :rts ; `
dw :rts ; a
dw :rts ; b
dw csi_c ; c
dw :rts ; d
dw :rts ; e
dw csi_f ; f
dw csi_g ; g
dw csi_h ; h
dw :rts ; i
dw :rts ; j
dw :rts ; k
dw csi_l ; l
dw csi_m ; m
dw csi_n ; n
dw :rts ; o
dw :rts ; p
dw csi_q ; q
dw csi_r ; r
dw :rts ; s
dw :rts ; t
dw :rts ; u
dw :rts ; v
dw :rts ; w
dw :rts ; x
dw csi_y ; y
:digit
ldx #st_vt100_csi_2
stx state
lsr ; undo asl
sta parms
rts
:modifier
ldx #st_vt100_csi_2
stx state
lda #$80
sta pmod
rts
:xmod
* ignored.
ldx #st_vt100_csi_2
stx state
rts
vt100_csi_bad ent
cmp #'@'
blt :rts
ldx #st_vt100
stx state
:rts rts
vt100_csi_2 ent
debug vt100_csi_2
ldx #st_vt100
stx state
cmp #:MIN
blt :rts
cmp #:MAX+1
bge :rts
sec
sbc #:MIN
asl
tax
jmp (:table,x)
:rts rts
:MIN equ 48
:MAX equ 121
:table
dw digit ; 0
dw digit ; 1
dw digit ; 2
dw digit ; 3
dw digit ; 4
dw digit ; 5
dw digit ; 6
dw digit ; 7
dw digit ; 8
dw digit ; 9
dw digit ; :
dw semi
dw :modifier ; <
dw :modifier ; =
dw :modifier ; >
dw :modifier ; ?
dw :rts ; @
dw csi_A ; A
dw csi_B ; B
dw csi_C ; C
dw csi_D ; D
dw :rts ; E
dw :rts ; F
dw :rts ; G
dw csi_H ; H
dw :rts ; I
dw csi_J ; J
dw csi_K ; K
dw :rts ; L
dw :rts ; M
dw :rts ; N
dw :rts ; O
dw :rts ; P
dw :rts ; Q
dw :rts ; R
dw :rts ; S
dw :rts ; T
dw :rts ; U
dw :rts ; V
dw :rts ; W
dw :rts ; X
dw :rts ; Y
dw :rts ; Z
dw :rts ; [
dw :rts ; \
dw :rts ; ]
dw :rts ; ^
dw :rts ; _
dw :rts ; `
dw :rts ; a
dw :rts ; b
dw csi_c ; c
dw :rts ; d
dw :rts ; e
dw csi_f ; f
dw csi_g ; g
dw csi_h ; h
dw :rts ; i
dw :rts ; j
dw :rts ; k
dw csi_l ; l
dw csi_m ; m
dw csi_n ; n
dw :rts ; o
dw :rts ; p
dw csi_q ; q
dw csi_r ; r
dw :rts ; s
dw :rts ; t
dw :rts ; u
dw :rts ; v
dw :rts ; w
dw csi_x ; x
dw csi_y ; y
:modifier
ldx #st_vt100_csi_bad
stx state
rts
semi
ldx #st_vt100_csi_2
stx state
ldx pcount
cpx #MAX_PCOUNT
bge :big
inx
stx pcount
:big stz parms,x
:rts rts
* parameter digit. clamped to 255 (250+ rounds up to 255)
* in 132 is the largest valid parameter so this is ok.
digit
ldx #st_vt100_csi_2
stx state
lsr ; undo asl
sta r0
ldx pcount
lda parms,x
* cmp #255
* beq :rts
cmp #25
bge :v
tay
lda :mult,y
* clc ; cleared via cmp
adc r0
sta parms,x
:rts
rts
:v
lda #$255
sta parms,x
rts
:mult db 0,10,20,30,40,50,60,70,80,90
db 100,110,120,130,140,150,160,170,180,190
db 200,210,220,230,240,250
csi_h
; esc [ ... h (vt100)
; esc [ ? ... h (private)
ldy #$80
bra mode_common
csi_l
; esc [ ... l (vt100)
; esc [ ? ... l (private)
ldy #0
mode_common
inc pcount
ldx #0
:loop lda parms,x
cmp #:MIN
blt :next
cmp #:MAX+1
bge :next
phx
asl
tax
jsr (:table,x)
plx
:next inx
cpx pcount
blt :loop
:rts rts
:MIN equ 0
:MAX equ 20
:table
dw :rts ; error
dw mode_DECCKM
dw mode_DECANM
dw mode_DECCOLM ; DECCOLM
dw mode_4 ; DECSCLM
dw mode_DECSCNM
dw mode_DECOM
dw mode_DECAWM
dw mode_DECARM
dw :rts ; DECINLM
dw :rts ; 10
dw :rts ; 11
dw mode_12 ; 12
dw :rts ; 13
dw :rts ; 14
dw :rts ; 15
dw :rts ; 16
dw :rts ; 17
dw :rts ; 18
dw :rts ; 19
dw mode_LNM
*:mask dw 0,$40,$40,$40,$40,$40,$40,$40,$40,$40
* dw 0,0,0,0,0,0,0,0,0,0,0
mode_DECCKM
bit pmod
bpl :rts
sty DECCKM
:rts rts
mode_DECANM
bit pmod
bpl :rts
sty DECANM
cpy #0
bne :rts
* switch to vt52 mode
ldx #st_vt52
stx state
:rts rts
mode_DECCOLM
* 80/132 mode.
* vt102 guide states:
* NOTE: When you change the number of columns per line, the screen is erased.
* This also sets the scrolling region for full screen (24 lines).
*
* based on testing, this always clears the screen and resets x/y, regardless of current mode.
*
bit pmod
bpl :rts
sty DECCOLM
lda #0
sta DECTM
lda #23
sta DECBM
stz x
stz y
* TODO - does this also reset the origin mode?
phy
jsr recalc_cursor
jsr erase_screen_2
ply
:rts rts
mode_4
* ? 4 = DECSCLM
* 4 = IRM (vt102)
do BUILD=102
bit pmod
bmi :rts
:irm
sty IRM
fin
:rts rts
mode_12
* ? 12 = unused
* 12 = SRM (vt102)
do BUILD=102
bit pmod
bmi :rts
sty SRM
fin
:rts rts
mode_DECSCNM
bit pmod
bpl :rts
* todo - invert on-screen characters? swap foreground/background colors in control panel?
sty DECSCNM
:rts rts
mode_DECOM
bit pmod
bpl :rts
sty DECOM
; move to the new home position
stz x
stz y
cpy #0
beq :rts
lda DECTM
sta y
phy
jsr recalc_cursor
ply
:rts rts
mode_DECAWM
bit pmod
bpl :rts
sty DECAWM
:rts rts
mode_DECARM
bit pmod
bpl :rts
sty DECARM
:rts rts
mode_LNM
bit pmod
bmi :rts
sty LNM
:rts rts
csi_m
* esc [ ... m
* 0 - attributes off
* 1 - bold
* 4 - underscore
* 5 - blink
* 7 - inverted
inc pcount
ldx #0
:loop lda parms,x
cmp #8
bge :next
tay
lda SGR
and :and,y
ora :or,y
sta SGR
:next inx
cpx pcount
blt :loop
jmp update_sgr
:and db $00,$ff,$ff,$ff,$ff,$ff,$ff,$ff
:or db %0000_0000,%0000_0010,%0000_0000,%0000_0000
db %0001_0000,%0010_0000,%0000_0000,%1000_0000
csi_g
* ESC [ g, ESC [ 0 g - clear tab at column
* ESC [ 3 g - clear all tabs
lda parms
beq :0
cmp #3
beq :3
rts
:0 ldx x
jmp reset_tab
:3 jmp reset_all_tabs
p1 mac
lda parms
bne ok
lda #1
ok sta parms
<<<
* cursor movement.
* if private mode, no effect.
csi_A
* up
* if cursor is outside the scrolling region, it is not locked to the scrolling region.
bit pmod
bmi :rts
p1
lda y
cmp DECTM
beq :rts
bcc :simple
sec
sbc parms
bcc :top
cmp DECTM
* bcc :top
* bra :sta
bcs :sta
:top lda DECTM
bra :sta
:rts rts
:simple
* lda y
sec
sbc parms
* bcc :0 ; clear indicate underflow.
bcc :sta
:0 lda #0
:sta sta y
jmp recalc_cursor_y
csi_B
* down
bit pmod
bmi :rts
p1
lda y
cmp DECBM
beq :rts
bge :simple
clc
adc parms
bcs :bottom ; overflow
cmp DECBM
bcc :sta
:bottom lda DECBM
bra :sta
:rts rts
:simple
clc
adc parms
bcs :23 ; overflow
cmp #24
bcc :sta
:23 lda #23
:sta sta y
jmp recalc_cursor_y
csi_C
* right
* in column 80, no effect.
bit pmod
bmi :rts
lda x
cmp #79
bcs :rts
p1
lda x
* and #$7f
clc
adc parms
bcs :79 ; overflow
cmp #80
bcc :sta
:79 lda #79
:sta sta x
jmp recalc_cursor_x
:rts rts
csi_D
* left
bit pmod
bmi :rts
p1
lda x
and #$7f
sec
sbc parms
* bcc :0 ; underflow
bcs :sta
:0 lda #0
:sta sta x
jmp recalc_cursor_x
:rts rts
csi_f
csi_H ; direct cursor addressing
debug csi_H
* honors origin
* large numbers are clamped
* 0 or 1 treated as 1 (1-based counting)
* based on testing, esc [ 253-255 H will position outside the scrolling
* region when DECOM is active (to first 3 lines, respectively)
* this is not emulated.
* y
lda parms
beq :yy
dec
:yy bit DECOM
bmi :org
cmp #23
blt :yyy
lda #23
:yyy sta y
bra :x
:org
clc
adc DECTM
cmp DECBM
blt :org1
lda DECBM
:org1 sta y
* x
:x
ldx parms+1
beq :xx
dex
:xx
cpx #79
blt :xxx
ldx #79
:xxx stx x
jmp recalc_cursor
csi_r ; scrolling region
debug csi_r
* based on testing
* esc [ n r (no second parmeter) is equivalent to esc [ n ; 24 r
* esc [ r sets scrolling region to 1 ; 24 ( in accordance with above )
* 24 is assumed value for second parameter
* invalid parameters exit without updating
* based on testing, row parameters are not affected by DECOM.
lda parms
beq :p1
dec parms
:p1
lda parms+1
beq :p2
dec parms+1
bra :check
:p2 lda #23
sta parms+1
:check
* 23 max
ldx parms+0
cpx #23+1
bge :rts
ldx parms+1
cpx #23+1
bge :rts
* must be at least 1 line
lda parms+1
sec
sbc parms
beq :rts
bmi :rts
* move cursor to origin.
lda parms
sta DECTM
sta y
lda parms+1
sta DECBM
stz x
bit DECOM
bmi :j
stz y
:j jmp recalc_cursor
:rts rts
csi_J ; erase screen
lda parms
cmp #2+1
bcs :rts
asl
tax
jmp (:table,x)
:rts rts
:table
dw erase_screen_0
dw erase_screen_1
dw erase_screen_2
csi_K ; erase line
lda parms
cmp #2+1
bcs :rts
asl
tax
jmp (:table,x)
:rts rts
:table
dw erase_line_0
dw erase_line_1
dw erase_line_2
csi_q ; LEDs
rts
csi_n ; status report
bit LOCAL
bmi :rts
lda parms
cmp #5
beq :dsr
cmp #6
beq :cpr
:rts rts
:dsr ; report status
lda #ESC
jsr write_modem
lda #'['
jsr write_modem
lda #'0'
jsr write_modem
lda #'n'
jmp write_modem
:cpr ; cursor report
* returned y is in terms of DECOM.
lda #ESC
jsr write_modem
lda #'['
jsr write_modem
lda y
bit DECOM
bpl :y
sec
sbc DECTM
:y inc
jsr write_digit
lda #';'
jsr write_modem
lda x
inc
jsr write_digit
lda #'R'
jmp write_modem
write_digit
* digit must be in the range 1-80
cmp #10
bcs :multi
:0 ora #'0'
jmp write_modem
:multi
ldx #8
]loop cmp :table,x
bcs :ok
dex
bra ]loop
:ok sec
sbc :table,x
pha ; save
txa
ora #'0'
jsr write_modem
pla
bra :0
:table db 0,10,20,30,40,50,60,70,80
csi_c ; what are you?
* DA - Device Attributes
mx %11
php
rep #$10 ; long x/y
ldy #:response
jsr write_modem_str
plp
rts
do BUILD=100
:response asc 1b,'[?1;0c',00 ; No options.
fin
do BUILD=102
:response asc 1b,'[?1;6c',00 ; No options.
fin
csi_y ; invoke confidence test
* ???
rts
csi_x ; request terminal parameters
* DECREQTPARM – Request Terminal Parameters
mx %11
lda parms
cmp #2
bcs :rts
inc
inc
ora #'0'
sta :response+2
php
rep #$10 ; long x/y
ldy #:response
jsr write_modem_str
plp
:rts rts
:response asc 1b,'[x;1;1;112;112;1;0x',00 ; no parity, 8-bits, 9600/9600, 16x multiplier, no stp flags.
sav vt100.csi.L