forked from ThomasDickey/vttest-snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvt220.c
686 lines (604 loc) · 17.3 KB
/
vt220.c
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
/* $Id: vt220.c,v 1.39 2023/11/22 01:13:17 tom Exp $ */
/*
* Reference: VT220 Programmer Pocket Guide (EK-VT220-HR-002).
* Reference: VT220 Program Reference Manual (EK-VT220-RM-002).
*/
#include <vttest.h>
#include <ttymodes.h>
#include <draw.h>
#include <esc.h>
int
any_DSR(MENU_ARGS, const char *text, void (*explain) (char *report))
{
int row, col;
char *report;
unsigned pmode = (unsigned) ((*text == '?') ? 1 : 0);
vt_move(1, 1);
printxx("Testing DSR: %s\n", the_title);
set_tty_raw(TRUE);
set_tty_echo(FALSE);
do_csi("%s", text);
report = get_reply();
vt_move(row = 3, col = 10);
chrprint2(report, row, col);
if ((report = skip_csi(report)) != 0
&& strlen(report) > (1 + pmode)
&& (!pmode || (*report++ == '?'))) {
if (explain != 0)
(*explain) (report);
else
show_result(SHOW_SUCCESS);
} else {
show_result(SHOW_FAILURE);
}
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
static void
report_ok(const char *ref, const char *tst)
{
if ((tst = skip_csi_2(tst)) == 0)
tst = "?";
show_result(!strcmp(ref, tst) ? SHOW_SUCCESS : SHOW_FAILURE);
}
/*
* Request CSI ? 26 n keyboard dialect
* Response CSI ? 27; Ps n
*/
static void
show_KeyboardStatus(char *report)
{
int pos = 0;
int code;
int save;
const char *show = SHOW_FAILURE;
if (scanto(report, &pos, ';') == 27
&& (save = pos) != 0
&& (code = scan_any(report, &pos, 'n')) >= 0
&& (pos != save)) {
/* *INDENT-OFF* */
switch(code) {
case 1: show = "North American/ASCII"; break;
case 2: show = "British"; break;
case 3: show = "Flemish"; break;
case 4: show = "French Canadian"; break;
case 5: show = "Danish"; break;
case 6: show = "Finnish"; break;
case 7: show = "German"; break;
case 8: show = "Dutch"; break;
case 9: show = "Italian"; break;
case 10: show = "Swiss (French)"; break;
case 11: show = "Swiss (German)"; break;
case 12: show = "Swedish"; break;
case 13: show = "Norwegian/Danish"; break;
case 14: show = "French/Belgian"; break;
case 15: show = "Spanish Int."; break;
case 16: show = "Portuguese"; break; /* vt3XX */
case 17: show = "Katakana"; break; /* EK-VT382-RM-001 p 11-9 */
case 19: show = "Hebrew"; break; /* vt5XX: kermit says 14 */
case 22: show = "Greek"; break; /* vt5XX */
case 27: show = "Thai"; break; /* EK-VT38T-UG-001 p C-42 */
case 28: show = "Canadian (English)"; break; /* vt4XX */
case 29: show = "Turkish Q/Turkish"; break; /* vt5XX */
case 30: show = "Turkish F/Turkish"; break; /* vt5XX */
case 31: show = "Hungarian"; break; /* vt5XX */
case 32: show = "Spanish National"; break; /* vt4XX in PC mode */
case 33: show = "Slovak"; break; /* vt5XX */
case 34: show = "Czech"; break; /* vt5XX */
case 35: show = "Polish"; break; /* vt5XX */
case 36: show = "Romanian"; break; /* vt5XX */
case 38: show = "SCS"; break; /* vt5XX */
case 39: show = "Russian"; break; /* vt5XX */
case 40: show = "Latin American"; break; /* vt5XX */
default: show = "unknown";
}
/* *INDENT-ON* */
}
show_result("%s", show);
/*
* VT420 implements additional parameters past those reported by the VT220.
* see:
* EK-VT420-RM 002, p 239, 277
* EK-VT510-RM B01, p 4-30, 5-166
* EK-VT520-RM A01, p 4-28, 5-176
*/
save = pos;
code = scan_any(report, &pos, 'n');
if (save != pos) {
vt_move(5, 10);
/* *INDENT-OFF* */
switch(code) {
case 0: show = "keyboard ready"; break;
case 3: show = "no keyboard"; break;
case 8: show = "keyboard busy"; break;
default: show = "unknown keyboard status";
}
/* *INDENT-ON* */
show_result("%s", show);
vt_move(6, 10);
/* *INDENT-OFF* */
switch (scan_any(report, &pos, 'n')) {
case 0: show = "LK201/LK301"; break;
case 1: show = "LK401"; break;
case 2: show = "LK443/LK444"; break;
case 3: show = "LK421"; break;
case 4: show = "LK411/LK450"; break;
case 5: show = "PCXAL"; break;
default: show = "unknown keyboard type";
}
/* *INDENT-ON* */
show_result("%s", show);
}
}
static void
show_PrinterStatus(char *report)
{
int pos = 0;
int code = scanto(report, &pos, 'n');
const char *show;
/* *INDENT-OFF* */
switch (code) {
case 13: show = "No printer"; break;
case 10: show = "Printer ready"; break;
case 11: show = "Printer not ready"; break;
case 18: show = "Printer busy"; break;
case 19: show = "Printer assigned to other session"; break;
default: show = SHOW_FAILURE;
}
/* *INDENT-ON* */
show_result("%s", show);
}
static void
show_UDK_Status(char *report)
{
int pos = 0;
int code = scanto(report, &pos, 'n');
const char *show;
/* *INDENT-OFF* */
switch(code) {
case 20: show = "UDKs unlocked"; break;
case 21: show = "UDKs locked"; break;
default: show = SHOW_FAILURE;
}
/* *INDENT-ON* */
show_result("%s", show);
}
/* VT220 & up.
*/
static int
tst_S8C1T(MENU_ARGS)
{
int flag = input_8bits;
int pass;
char temp[80];
vt_move(1, 1);
println(the_title);
vt_move(5, 1);
println("This tests the VT200+ control sequence to direct the terminal to emit 8-bit");
println("control-sequences instead of <esc> sequences.");
set_tty_raw(TRUE);
set_tty_echo(FALSE);
for (pass = 0; pass < 2; pass++) {
char *report;
int row, col;
flag = !flag;
s8c1t(flag);
cup(1, 1);
dsr(6);
report = instr();
vt_move(row = 10 + pass * 3, col = 1);
sprintf(temp, "8-bit controls %s:", STR_ENABLED(flag));
printxx("%s", temp);
chrprint2(report, row, col + (int) strlen(temp));
report_ok("1;1R", report);
}
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/*
* Test DEC's selective-erase (set-protected area) by drawing a box of
* *'s that will remain, and a big X of *'s that gets cleared..
*/
static void
tst_DECSCA_selective(MENU_ARGS)
{
BOX inner;
if (make_box_params(&inner, 6, 20) == 0) {
int pass;
for (pass = 0; pass < 2; pass++) {
int i;
if (pass == 0)
decsca(1);
for (i = inner.top; i <= inner.bottom; i++) {
int j;
cup(i - 1, 1 + inner.left);
for (j = inner.left; j <= inner.right; j++) {
putchar('*');
}
}
if (pass == 0) {
int j;
decsca(0);
for (j = 0; j <= 2; j++) {
for (i = 1; i < inner.top - 1; i++) {
cup(i, inner.left - inner.top + (i + j) + 3);
putchar('*');
cup(i, inner.right + inner.top - (i + j) - 1);
putchar('*');
}
for (i = inner.bottom; i < max_lines; i++) {
cup(i, (inner.left + inner.bottom) - (i - j) + 1);
putchar('*');
cup(i, (inner.right - inner.bottom) + (i - j) + 1);
putchar('*');
}
cup((max_lines / 2) - 1, (min_cols / 2) - 1);
decsed(j);
}
for (i = inner.right + 1; i <= min_cols; i++) {
cup(inner.top + 1, 1 + i);
putchar('*');
cup(max_lines / 2 + 1, 1 + i);
putchar('*');
}
cup(max_lines / 2 + 1, 1 + min_cols / 2);
decsel(0); /* after the cursor */
for (i = 1; i < inner.left; i++) {
cup(inner.top + 1, 1 + i);
putchar('*');
cup(max_lines / 2 + 1, 1 + i);
putchar('*');
}
cup(max_lines / 2 + 1, 1 + min_cols / 2);
decsel(1); /* before the cursor */
cup(inner.top + 1, 1 + min_cols / 2);
decsel(2); /* the whole line */
vt_move(max_lines - 3, 1);
vt_clear(0);
println("If your terminal supports DEC protected areas (DECSCA, DECSED, DECSEL),");
println("there will be an solid box made of *'s in the middle of the screen.");
holdit();
}
}
} else {
vt_move(max_lines - 3, 1);
vt_clear(0);
println("The screen is too small for this test");
holdit();
}
}
static void
tst_DECSCA_edit_line(MENU_ARGS)
{
BOX outer;
BOX inner;
if (make_box_params(&outer, 0, 0) == 0 &&
make_box_params(&inner, 6, 20) == 0) {
int i;
decsca(1);
for (i = outer.top; i <= outer.bottom; i++) {
int j;
cup(i + 1, 1 + outer.left);
for (j = outer.left; j <= outer.right; j++) {
putchar((i >= inner.top &&
i <= inner.bottom &&
j >= inner.left &&
j <= inner.right) ? '*' : '#');
}
}
cup(inner.top - 2, max_cols);
ed(1);
cup(inner.bottom, 1);
ed(0);
for (i = outer.top; i <= outer.bottom; i++) {
cup(i + 1, inner.left);
el(1);
cup(i + 1, inner.right + 2);
el(0);
}
decsca(0);
vt_move(max_lines - 3, 1);
vt_clear(0);
println("If your terminal supports DEC protected areas (DECSCA, ignoring EL/ED),");
println("there will be an solid box made of *'s in the middle of the screen.");
} else {
vt_move(max_lines - 3, 1);
vt_clear(0);
println("The screen is too small for this test");
}
holdit();
}
static void
tst_DECSCA_edit_char(MENU_ARGS)
{
BOX outer;
BOX inner;
if (make_box_params(&outer, 0, 0) == 0 &&
make_box_params(&inner, 6, 20) == 0) {
int i;
decsca(1);
for (i = outer.top; i <= outer.bottom; i++) {
int j;
cup(i + 1, 1 + outer.left);
for (j = outer.left; j <= outer.right; j++) {
putchar((i >= inner.top &&
i <= inner.bottom &&
j >= inner.left &&
j <= inner.right) ? '*' : '#');
}
}
for (i = 1; i < inner.top - 1; ++i) {
cup(i, 1);
ech(min_cols);
}
for (i = inner.top; i <= inner.bottom; i++) {
cup(i - 1, 1);
ech(inner.left);
cup(i - 1, inner.right + 2);
if (i % 2) {
ich(19);
} else {
dch(19);
}
}
for (i = inner.bottom; i < outer.bottom; ++i) {
cup(i, 1);
dch(min_cols);
}
decsca(0);
vt_move(max_lines - 3, 1);
vt_clear(0);
println("If your terminal supports DEC protected areas (DECSCA, ignoring ECH/ICH/DCH),");
println("there will be an solid box made of *'s in the middle of the screen.");
} else {
vt_move(max_lines - 3, 1);
vt_clear(0);
println("The screen is too small for this test");
}
holdit();
}
static int
tst_DECSCA(MENU_ARGS)
{
tst_DECSCA_selective(PASS_ARGS);
tst_DECSCA_edit_line(PASS_ARGS);
tst_DECSCA_edit_char(PASS_ARGS);
return MENU_NOHOLD;
}
/*
* VT220 & up
*
* Test if the terminal can make the cursor invisible
*/
static int
tst_DECTCEM(MENU_ARGS)
{
vt_move(1, 1);
rm("?25");
println("The cursor should be invisible");
holdit();
sm("?25");
println("The cursor should be visible again");
return MENU_HOLD;
}
static int
tst_DECUDK(MENU_ARGS)
{
int key;
/* *INDENT-OFF* */
static struct {
int code;
const char *name;
} keytable[] = {
/* xterm programs these: */
{ 11, "F1" },
{ 12, "F2" },
{ 13, "F3" },
{ 14, "F4" },
{ 15, "F5" },
/* vt420 programs these: */
{ 17, "F6" },
{ 18, "F7" },
{ 19, "F8" },
{ 20, "F9" },
{ 21, "F10" },
{ 23, "F11" },
{ 24, "F12" },
{ 25, "F13" },
{ 26, "F14" },
{ 28, "F15" },
{ 29, "F16" },
{ 31, "F17" },
{ 32, "F18" },
{ 33, "F19" },
{ 34, "F20" } };
/* *INDENT-ON* */
for (key = 0; key < TABLESIZE(keytable); key++) {
char temp[80];
const char *s;
temp[0] = '\0';
for (s = keytable[key].name; *s; s++)
sprintf(temp + strlen(temp), "%02x", *s & 0xff);
do_dcs("1;1|%d/%s", keytable[key].code, temp);
}
vt_move(1, 1);
println(the_title);
println("Press 'q' to quit. Function keys should echo their labels.");
println("(On a DEC terminal you must press SHIFT as well).");
set_tty_raw(TRUE);
set_tty_echo(FALSE);
for (;;) {
int row, col;
char *report = instr();
if (*report == 'q')
break;
vt_move(row = 5, col = 10);
vt_clear(0);
chrprint2(report, row, col);
}
do_dcs("0"); /* clear all keys */
restore_ttymodes();
vt_move(max_lines - 1, 1);
return MENU_HOLD;
}
/* vt220 & up */
int
tst_DSR_keyboard(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "?26n", show_KeyboardStatus);
}
int
tst_DSR_printer(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "?15n", show_PrinterStatus);
}
int
tst_DSR_userkeys(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "?25n", show_UDK_Status);
}
static void
show_OperatingStatus(char *report)
{
int pos = 0;
int Ps1 = scan_any(report, &pos, 'n');
int Ps2 = scanto(report, &pos, 'n');
const char *show;
switch (Ps1) {
case 0:
show = "Terminal is in good operating condition";
break;
case 3:
show = "Terminal has a malfunction";
break;
default:
show = SHOW_FAILURE;
}
show_result(show, Ps2);
}
static int
tst_DSR_operating_status(MENU_ARGS)
{
return any_DSR(PASS_ARGS, "5n", show_OperatingStatus);
}
/*
* VT200 and up
*
* Test to ensure that 'ech' (erase character) is honored, with no parameter,
* explicit parameter, and longer than the screen width (to ensure that the
* terminal doesn't try to wrap-around the erasure).
*/
static int
tst_ECH(MENU_ARGS)
{
int i;
int last = max_lines - 4;
decaln();
for (i = 1; i <= max_lines; i++) {
cup(i, min_cols - i - 2);
do_csi("X"); /* make sure default-parameter works */
cup(i, min_cols - i - 1);
putchar('*');
ech(min_cols);
putchar('*'); /* this should be adjacent, in the upper-right corner */
}
vt_move(last, 1);
vt_clear(0);
vt_move(last, min_cols - (last + 10));
println("diagonal: ^^ (clear)");
println("ECH test: there should be E's with a gap before diagonal of **'s");
println("The lower-right diagonal region should be cleared. Nothing else.");
return MENU_HOLD;
}
/******************************************************************************/
int
tst_vt220_device_status(MENU_ARGS)
{
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Test Keyboard Status", tst_DSR_keyboard },
{ "Test Operating Status", tst_DSR_operating_status },
{ "Test Printer Status", tst_DSR_printer },
{ "Test UDK Status", tst_DSR_userkeys },
{ "", 0 }
};
/* *INDENT-ON* */
do {
vt_clear(2);
title(0);
printxx("VT220 Device Status Reports");
title(2);
println("Choose test type:");
} while (menu(my_menu));
return MENU_NOHOLD;
}
/******************************************************************************/
int
tst_vt220_screen(MENU_ARGS)
{
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Test Send/Receive mode (SRM)", tst_SRM },
{ "Test Visible/Invisible Cursor (DECTCEM)", tst_DECTCEM },
{ "Test Erase Char (ECH)", tst_ECH },
{ "Test Protected-Areas (DECSCA)", tst_DECSCA },
{ "", 0 }
};
/* *INDENT-ON* */
do {
vt_clear(2);
title(0);
printxx("VT220 Screen-Display Tests");
title(2);
println("Choose test type:");
} while (menu(my_menu));
return MENU_NOHOLD;
}
/******************************************************************************/
int
tst_vt220_reports(MENU_ARGS)
{
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Test Device Status Report (DSR)", tst_vt220_device_status },
{ "", 0 }
};
/* *INDENT-ON* */
do {
vt_clear(2);
__(title(0), printxx("VT220 Reports"));
__(title(2), println("Choose test type:"));
} while (menu(my_menu));
return MENU_NOHOLD;
}
/******************************************************************************/
int
tst_vt220(MENU_ARGS)
{
/* *INDENT-OFF* */
static MENU my_menu[] = {
{ "Exit", 0 },
{ "Test reporting functions", tst_vt220_reports },
{ "Test screen-display functions", tst_vt220_screen },
{ "Test 8-bit controls (S7C1T/S8C1T)", tst_S8C1T },
{ "Test Printer (MC)", tst_printing },
{ "Test Soft Character Sets (DECDLD)", tst_softchars },
{ "Test Soft Terminal Reset (DECSTR)", tst_DECSTR },
{ "Test User-Defined Keys (DECUDK)", tst_DECUDK },
{ "", 0 }
};
/* *INDENT-ON* */
do {
vt_clear(2);
title(0);
printxx("VT220 Tests");
title(2);
println("Choose test type:");
} while (menu(my_menu));
return MENU_NOHOLD;
}