Debian Codegraph @

vt520.c

raw
1 /* $Id: vt520.c,v 1.28 2024/12/05 00:43:14 tom Exp $ */
2
3 /*
4 * Reference: VT520/VT525 Video Terminal Programmer Information
5 * (EK-VT520-RM.A01)
6 */
7 #include <vttest.h>
8 #include <draw.h>
9 #include <esc.h>
10 #include <ttymodes.h>
11
12 /******************************************************************************/
13
14 static struct {
15 int code;
16 const char *text;
17 } tbl_decscusr[] = {
18
19 {
20 1, "The cursor should be a blinking rectangle"
21 },
22 {
23 0, "The cursor should be a blinking rectangle"
24 },
25 {
26 2, "The cursor should be a nonblinking rectangle"
27 },
28 {
29 3, "The cursor should be a blinking underline"
30 },
31 {
32 4, "The cursor should be a nonblinking underline"
33 },
34 {
35 5, "xterm: The cursor should be a blinking vertical bar"
36 },
37 {
38 6, "xterm: The cursor should be a nonblinking vertical bar"
39 },
40 {
41 2, "The cursor should be a rectangle again"
42 }
43 };
44
45 /******************************************************************************/
46 static int
47 tst_vt520_cursor(MENU_ARGS)
48 {
49 /* *INDENT-OFF* */
50 static MENU my_menu[] = {
51 { "Exit", NULL },
52 { "Test VT420 features", tst_vt420_cursor },
53 { origin_mode_mesg, toggle_DECOM },
54 { lrmm_mesg, toggle_LRMM },
55 { tb_marg_mesg, toggle_STBM },
56 { lr_marg_mesg, toggle_SLRM },
57 { txt_override_color, toggle_color_mode, },
58 { "Test Character-Position-Absolute (HPA)", tst_HPA },
59 { "Test Cursor-Back-Tab (CBT)", tst_CBT },
60 { "Test Cursor-Character-Absolute (CHA)", tst_CHA },
61 { "Test Cursor-Horizontal-Index (CHT)", tst_CHT },
62 { "Test Horizontal-Position-Relative (HPR)", tst_HPR },
63 { "Test Line-Position-Absolute (VPA)", tst_VPA },
64 { "Test Next-Line (CNL)", tst_CNL },
65 { "Test Previous-Line (CPL)", tst_CPL },
66 { "Test Vertical-Position-Relative (VPR)", tst_VPR },
67 { "", NULL }
68 };
69 /* *INDENT-ON* */
70
71 setup_vt420_cursor(PASS_ARGS);
72
73 do {
74 vt_clear(2);
75 __(title(0), printxx("VT520 Cursor-Movement"));
76 __(title(2), println("Choose test type:"));
77 menus_vt420_cursor();
78 } while (menu(my_menu));
79
80 finish_vt420_cursor(PASS_ARGS);
81
82 return MENU_NOHOLD;
83 }
84
85 /******************************************************************************/
86 /*
87 * VT500 & up
88 *
89 * Test if terminal can control whether the screen is cleared when changing
90 * DECCOLM.
91 */
92 static int
93 tst_DECNCSM(MENU_ARGS)
94 {
95 int last = max_lines - 4;
96 char temp[80];
97
98 decaln();
99 deccolm(FALSE);
100 vt_move(last, 1);
101 ruler(last, min_cols);
102 vt_clear(0);
103 sprintf(temp, "Screen should be cleared (%d-columns)", min_cols);
104 println(temp);
105 holdit();
106
107 decaln();
108 deccolm(TRUE);
109 vt_move(last, 1);
110 ruler(last, max_cols);
111 vt_clear(0);
112 sprintf(temp, "Screen should be cleared (%d-columns)", max_cols);
113 println(temp);
114 holdit();
115
116 decncsm(TRUE);
117
118 decaln();
119 deccolm(FALSE);
120 vt_move(last, 1);
121 ruler(last, min_cols);
122 vt_clear(0);
123 sprintf(temp, "Screen should be filled (%d-columns)", min_cols);
124 println(temp);
125 holdit();
126
127 decaln();
128 deccolm(TRUE);
129 vt_move(last, 1);
130 ruler(last, max_cols);
131 vt_clear(0);
132 sprintf(temp, "Screen should be filled (%d of %d-columns)", min_cols, max_cols);
133 println(temp);
134 holdit();
135
136 decncsm(FALSE);
137 deccolm(FALSE);
138 vt_move(last, 1);
139 ruler(last, min_cols);
140 vt_clear(0);
141 sprintf(temp, "Screen should be cleared (%d-columns)", min_cols);
142 println(temp);
143
144 return MENU_HOLD;
145 }
146
147 /******************************************************************************/
148
149 static void
150 decscusr(int parm)
151 {
152 do_csi("%d q", parm);
153 }
154
155 /*
156 * VT500 & up
157 *
158 * Test if the terminal can change the cursor's appearance
159 */
160 static int
161 tst_DECSCUSR(MENU_ARGS)
162 {
163 size_t n;
164
165 vt_move(1, 1);
166 for (n = 0; n < TABLESIZE(tbl_decscusr); ++n) {
167 if (n != 0)
168 holdit();
169 decscusr(tbl_decscusr[n].code);
170 println(tbl_decscusr[n].text);
171 }
172 return MENU_HOLD;
173 }
174
175 /******************************************************************************/
176
177 #define A_BOLD (1 << 1)
178 #define A_UNDERLINE (1 << 4)
179 #define A_BLINK (1 << 5)
180 #define A_REVERSE (1 << 7)
181
182 /*
183 * VT525 display alternate text colors
184 */
185 static int
186 tst_DECATC(MENU_ARGS)
187 {
188 /* *INDENT-OFF* */
189 static struct {
190 int attr;
191 } table[] = {
192 { 0, },
193 { A_BOLD, },
194 { A_REVERSE, },
195 { A_UNDERLINE, },
196 { A_BLINK, },
197 { A_BOLD | A_REVERSE, },
198 { A_BOLD | A_UNDERLINE, },
199 { A_BOLD | A_BLINK, },
200 { A_REVERSE | A_UNDERLINE, },
201 { A_REVERSE | A_BLINK, },
202 { A_UNDERLINE | A_BLINK, },
203 { A_BOLD | A_REVERSE | A_UNDERLINE, },
204 { A_BOLD | A_REVERSE | A_BLINK, },
205 { A_BOLD | A_UNDERLINE | A_BLINK, },
206 { A_REVERSE | A_UNDERLINE | A_BLINK, },
207 { A_BOLD | A_REVERSE | A_UNDERLINE | A_BLINK, },
208 };
209 /* *INDENT-ON* */
210 size_t n;
211
212 vt_move(1, 1);
213 println(the_title);
214 /* this test assumes that an application has used DECATC, etc., to set up
215 * suitable colors, and simply displays what has been set up.
216 */
217 for (n = 0; n < TABLESIZE(table); ++n) {
218 char buffer[80];
219
220 vt_move((int) n + 3, 10);
221 decstglt(1);
222 printxx("%2d ", (int) n);
223 if (table[n].attr & A_BOLD)
224 sgr("1");
225 if (table[n].attr & A_REVERSE)
226 sgr("7");
227 if (table[n].attr & A_UNDERLINE)
228 sgr("4");
229 if (table[n].attr & A_BLINK)
230 sgr("5");
231 printxx(" Testing ");
232 sgr("0");
233 decstglt(3);
234 *buffer = '\0';
235 if (table[n].attr & A_BOLD)
236 strcat(buffer, " bold");
237 if (table[n].attr & A_REVERSE)
238 strcat(buffer, " reverse");
239 if (table[n].attr & A_UNDERLINE)
240 strcat(buffer, " underline");
241 if (table[n].attr & A_BLINK)
242 strcat(buffer, " blink");
243 if (buffer[0] == 0)
244 strcpy(buffer, " normal text");
245 buffer[1] = (char) toupper(CharOf(buffer[1]));
246 printxx("%s", buffer);
247 }
248 vt_move(max_lines - 1, 1);
249 return MENU_HOLD;
250 }
251
252 /******************************************************************************/
253
254 static int
255 rpt_DECCRTST(MENU_ARGS)
256 {
257 return any_decrqss(the_title, "-q");
258 }
259
260 static int
261 rpt_DECDLDA(MENU_ARGS)
262 {
263 return any_decrqss(the_title, ",z");
264 }
265
266 static int
267 rpt_DECSEST(MENU_ARGS)
268 {
269 return any_decrqss(the_title, "-r");
270 }
271
272 static int
273 rpt_DECSCP(MENU_ARGS)
274 {
275 return any_decrqss(the_title, "*u");
276 }
277
278 static int
279 rpt_DECSCS(MENU_ARGS)
280 {
281 return any_decrqss(the_title, "*r");
282 }
283
284 static int
285 rpt_DECSDPT(MENU_ARGS)
286 {
287 return any_decrqss(the_title, ")p");
288 }
289
290 static int
291 rpt_DECSDDT(MENU_ARGS)
292 {
293 return any_decrqss(the_title, "$q");
294 }
295
296 static int
297 rpt_DECSFC(MENU_ARGS)
298 {
299 return any_decrqss(the_title, "*s");
300 }
301
302 static int
303 rpt_DECSPRTT(MENU_ARGS)
304 {
305 return any_decrqss(the_title, "$s");
306 }
307
308 static int
309 rpt_DECSRFR(MENU_ARGS)
310 {
311 return any_decrqss(the_title, "\"t");
312 }
313
314 static int
315 rpt_DECSPPCS(MENU_ARGS)
316 {
317 return any_decrqss(the_title, "*p");
318 }
319
320 static int
321 rpt_DECSSL(MENU_ARGS)
322 {
323 return any_decrqss(the_title, "p");
324 }
325
326 static int
327 rpt_DECSPMA(MENU_ARGS)
328 {
329 return any_decrqss(the_title, ",x");
330 }
331
332 static int
333 rpt_DECSPP(MENU_ARGS)
334 {
335 return any_decrqss(the_title, "+w");
336 }
337
338 static int
339 rpt_DECSSCLS(MENU_ARGS)
340 {
341 return any_decrqss(the_title, " p");
342 }
343
344 static int
345 rpt_DECSTRL(MENU_ARGS)
346 {
347 return any_decrqss(the_title, "\"u");
348 }
349
350 /******************************************************************************/
351
352 static int
353 rpt_DECATC(MENU_ARGS)
354 {
355 static const char *attributes[] =
356 {
357 "normal",
358 "bold",
359 "reverse",
360 "underline",
361 "blink",
362 "bold reverse",
363 "bold underline",
364 "bold blink",
365 "reverse underline",
366 "reverse blink",
367 "underline blink",
368 "bold reverse underline",
369 "bold reverse blink",
370 "bold underline blink",
371 "reverse underline blink",
372 "bold reverse underline blink"
373 };
374
375 int ps1;
376 int row, col;
377 const char *show;
378 const char *suffix = ",}";
379
380 vt_move(1, 1);
381 printxx("Testing DECRQSS: %s\n", the_title);
382
383 set_tty_raw(TRUE);
384 set_tty_echo(FALSE);
385
386 reset_decstbm();
387 reset_decslrm();
388
389 row = 3;
390 col = 10;
391
392 for (ps1 = 0; ps1 < 16; ++ps1) {
393 char func[80];
394 char *report;
395 int fail = 1;
396 int qps, qfg, qbg;
397
398 sprintf(func, "%d%s", ps1, suffix);
399
400 decrqss(func);
401 report = get_reply();
402
403 vt_move(row, col);
404 chrprint2(report, row++, col);
405
406 switch (parse_decrqss(report, suffix)) {
407 case 1:
408 show = "ok (valid request)";
409 if (sscanf(report, "%d;%d;%d", &qps, &qfg, &qbg) == 3
410 && qps == ps1
411 && qfg >= 0 && qfg < 16
412 && qbg >= 0 && qbg < 16) {
413 fail = 0;
414 show = attributes[ps1];
415 }
416 break;
417 case 0:
418 show = "invalid request";
419 break;
420 default:
421 show = SHOW_FAILURE;
422 break;
423 }
424 show_result("%s", show);
425 if (fail)
426 break;
427 }
428
429 restore_ttymodes();
430 vt_move(max_lines - 1, 1);
431 return MENU_HOLD;
432 }
433
434 static int
435 rpt_DECAC(MENU_ARGS)
436 {
437 static const char *attributes[] =
438 {
439 "normal text",
440 "window frame",
441 };
442
443 int ps1;
444 int row, col;
445 const char *show;
446 const char *suffix = ",|";
447
448 vt_move(1, 1);
449 printxx("Testing DECRQSS: %s\n", the_title);
450
451 set_tty_raw(TRUE);
452 set_tty_echo(FALSE);
453
454 reset_decstbm();
455 reset_decslrm();
456
457 row = 3;
458 col = 10;
459
460 for (ps1 = 1; ps1 <= 2; ++ps1) {
461 char func[80];
462 char *report;
463 int fail = 1;
464 int qps, qfg, qbg;
465
466 sprintf(func, "%d%s", ps1, suffix);
467
468 decrqss(func);
469 report = get_reply();
470
471 vt_move(row, col);
472 chrprint2(report, row++, col);
473
474 switch (parse_decrqss(report, suffix)) {
475 case 1:
476 show = "ok (valid request)";
477 if (sscanf(report, "%d;%d;%d", &qps, &qfg, &qbg) == 3
478 && qps == ps1
479 && qfg >= 0 && qfg < 16
480 && qbg >= 0 && qbg < 16) {
481 fail = 0;
482 show = attributes[ps1 - 1];
483 }
484 break;
485 case 0:
486 show = "invalid request";
487 break;
488 default:
489 show = SHOW_FAILURE;
490 break;
491 }
492 show_result("%s", show);
493 if (fail)
494 break;
495 }
496
497 restore_ttymodes();
498 vt_move(max_lines - 1, 1);
499 return MENU_HOLD;
500 }
501
502 static int
503 rpt_DECARR(MENU_ARGS)
504 {
505 return any_decrqss(the_title, "-p");
506 }
507
508 static int
509 rpt_DECSTGLT(MENU_ARGS)
510 {
511 return any_decrqss(the_title, "){");
512 }
513
514 static int
515 rpt_DECSZS(MENU_ARGS)
516 {
517 return any_decrqss(the_title, ",{");
518 }
519
520 static int
521 rpt_DECSCUSR(MENU_ARGS)
522 {
523 size_t n;
524
525 vt_move(1, 1);
526 for (n = 0; n < TABLESIZE(tbl_decscusr); ++n) {
527 char expected[10];
528 if (n != 0)
529 holdit();
530 vt_clear(2);
531 decscusr(tbl_decscusr[n].code);
532 sprintf(expected, "%d", tbl_decscusr[n].code ? tbl_decscusr[n].code : 1);
533 (void) any_decrqss2(tbl_decscusr[n].text, " q", expected);
534 }
535 return MENU_HOLD;
536 }
537
538 static int
539 rpt_DECSKCV(MENU_ARGS)
540 {
541 return any_decrqss(the_title, " r");
542 }
543
544 static int
545 rpt_DECSLCK(MENU_ARGS)
546 {
547 return any_decrqss(the_title, " v");
548 }
549
550 static int
551 rpt_DECSMBV(MENU_ARGS)
552 {
553 return any_decrqss(the_title, " u");
554 }
555
556 static int
557 rpt_DECSWBV(MENU_ARGS)
558 {
559 return any_decrqss(the_title, " t");
560 }
561
562 static int
563 rpt_DECTME(MENU_ARGS)
564 {
565 return any_decrqss(the_title, " ~");
566 }
567
568 static int
569 rpt_DECUS(MENU_ARGS)
570 {
571 return any_decrqss(the_title, ",y");
572 }
573
574 static int
575 tst_VT510_DECRQSS(MENU_ARGS)
576 {
577 /* *INDENT-OFF* */
578 static MENU my_menu[] = {
579 { "Exit", NULL },
580 { "Test VT420 features (DECRQSS)", tst_vt420_DECRQSS },
581 { "Select Communication Port (DECSCP)", rpt_DECSCP },
582 { "Select Communication Speed (DECSCS)", rpt_DECSCS },
583 { "Select Digital Printed Data Type (DECSDPT)", rpt_DECSDPT },
584 { "Select Disconnect Delay Time (DECSDDT)", rpt_DECSDDT },
585 { "Select Flow Control Type (DECSFC)", rpt_DECSFC },
586 { "Select Printer Type (DECSPRTT)", rpt_DECSPRTT },
587 { "Select ProPrinter Character Set (DECSPPCS)", rpt_DECSPPCS },
588 { "Select Refresh Rate Selection (DECSRFR)", rpt_DECSRFR },
589 { "Select Set-Up Language (DECSSL)", rpt_DECSSL },
590 { "Set Cursor Style (DECSCUSR)", rpt_DECSCUSR },
591 { "Set Key Click Volume (DECSKCV)", rpt_DECSKCV },
592 { "Set Lock Key Style (DECSLCK)", rpt_DECSLCK },
593 { "Set Margin Bell Volume (DECSMBV)", rpt_DECSMBV },
594 { "Set Port Parameter (DECSPP)", rpt_DECSPP },
595 { "Set Scroll Speed (DECSSCLS)", rpt_DECSSCLS },
596 { "Set Transmit Rate Limit (DECSTRL)", rpt_DECSTRL },
597 { "Set Warning Bell Volume (DECSWBV)", rpt_DECSWBV },
598 { "", NULL }
599 };
600 /* *INDENT-ON* */
601
602 do {
603 vt_clear(2);
604 __(title(0), printxx("VT510 Status-Strings Reports"));
605 __(title(2), println("Choose test type:"));
606 } while (menu(my_menu));
607 return MENU_NOHOLD;
608 }
609
610 int
611 tst_vt520_DECRQSS(MENU_ARGS)
612 {
613 /* *INDENT-OFF* */
614 static MENU my_menu[] = {
615 { "Exit", NULL },
616 { "Test VT510 features (DECRQSS)", tst_VT510_DECRQSS },
617 { "Alternate Text Color (DECATC)", rpt_DECATC },
618 { "Assign Color (DECAC)", rpt_DECAC },
619 { "CRT Saver Timing (DECCRTST)", rpt_DECCRTST },
620 { "Down Line Load Allocation (DECDLDA)", rpt_DECDLDA },
621 { "Energy Save Timing (DECSEST)", rpt_DECSEST },
622 { "Select Auto Repeat Rate (DECARR)", rpt_DECARR },
623 { "Select Color Lookup Table (DECSTGLT)", rpt_DECSTGLT },
624 { "Select Zero Symbol (DECSZS)", rpt_DECSZS },
625 { "Session Page Memory Allocation (DECSPMA)", rpt_DECSPMA },
626 { "Terminal Mode Emulation (DECTME)", rpt_DECTME },
627 { "Update Session (DECUS)", rpt_DECUS },
628 { "", NULL }
629 };
630 /* *INDENT-ON* */
631
632 do {
633 vt_clear(2);
634 __(title(0), printxx("VT520 Status-Strings Reports"));
635 __(title(2), println("Choose test type:"));
636 } while (menu(my_menu));
637 return MENU_NOHOLD;
638 }
639
640 /******************************************************************************/
641
642 static int
643 tst_VT520_report_presentation(MENU_ARGS)
644 {
645 /* *INDENT-OFF* */
646 static MENU my_menu[] = {
647 { "Exit", NULL },
648 { "Test VT420 features", tst_vt420_report_presentation },
649 { "Request Mode (DECRQM)/Report Mode (DECRPM)", tst_DECRPM },
650 { "Status-String Report (DECRQSS)", tst_vt520_DECRQSS },
651 { "", NULL }
652 };
653 /* *INDENT-ON* */
654
655 int old_DECRPM = set_DECRPM(5);
656
657 do {
658 vt_clear(2);
659 __(title(0), printxx("VT520 Presentation State Reports"));
660 __(title(2), println("Choose test type:"));
661 } while (menu(my_menu));
662 set_DECRPM(old_DECRPM);
663 return MENU_NOHOLD;
664 }
665
666 int
667 tst_vt520_reports(MENU_ARGS)
668 {
669 /* *INDENT-OFF* */
670 static MENU my_menu[] = {
671 { "Exit", NULL },
672 { "Test VT420 features", tst_vt420_reports },
673 { "Test Presentation State Reports", tst_VT520_report_presentation },
674 { "Test Device Status Reports (DSR)", tst_vt420_device_status },
675 { "", NULL }
676 };
677 /* *INDENT-ON* */
678
679 do {
680 vt_clear(2);
681 __(title(0), printxx("VT520 Reports"));
682 __(title(2), println("Choose test type:"));
683 } while (menu(my_menu));
684 return MENU_NOHOLD;
685 }
686
687 /******************************************************************************/
688
689 static int
690 tst_vt520_screen(MENU_ARGS)
691 {
692 /* *INDENT-OFF* */
693 static MENU my_menu[] = {
694 { "Exit", NULL },
695 { "Test No Clear on Column Change (DECNCSM)", tst_DECNCSM },
696 { "Test Set Cursor Style (DECSCUSR)", tst_DECSCUSR },
697 { "Test Alternate Text Color (DECATC)", tst_DECATC },
698 { "", NULL }
699 };
700 /* *INDENT-ON* */
701
702 do {
703 vt_clear(2);
704 __(title(0), printxx("VT520 Screen-Display Tests"));
705 __(title(2), println("Choose test type:"));
706 } while (menu(my_menu));
707 return MENU_NOHOLD;
708 }
709
710 /******************************************************************************/
711
712 /*
713 * These apply only to VT500's & above.
714 */
715 int
716 tst_vt520(MENU_ARGS)
717 {
718 /* *INDENT-OFF* */
719 static MENU my_menu[] = {
720 { "Exit", NULL },
721 { "Test VT420 features", tst_vt420 },
722 { "Test cursor-movement", tst_vt520_cursor },
723 { "Test editing sequences", not_impl },
724 { "Test keyboard-control", not_impl },
725 { "Test reporting functions", tst_vt520_reports },
726 { "Test screen-display functions", tst_vt520_screen },
727 { "", NULL }
728 };
729 /* *INDENT-ON* */
730
731 do {
732 vt_clear(2);
733 __(title(0), printxx("VT520 Tests"));
734 __(title(2), println("Choose test type:"));
735 } while (menu(my_menu));
736 return MENU_NOHOLD;
737 }