wsemul_vt100_subr.c revision 1.2 1 /* $NetBSD: wsemul_vt100_subr.c,v 1.2 1998/06/26 21:20:34 drochner Exp $ */
2
3 /*
4 * Copyright (c) 1998
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Matthias Drochner.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37
38 #include <dev/wscons/wsksymvar.h>
39 #include <dev/wscons/wsdisplayvar.h>
40 #include <dev/wscons/wsemulvar.h>
41 #include <dev/wscons/wsemul_vt100var.h>
42
43 static int vt100_selectattribute __P((struct wsemul_vt100_emuldata *,
44 int, int, int, long *));
45 static int vt100_ansimode __P((struct wsemul_vt100_emuldata *, int, int));
46 static int vt100_decmode __P((struct wsemul_vt100_emuldata *, int, int));
47 #define VTMODE_SET 33
48 #define VTMODE_RESET 44
49 #define VTMODE_REPORT 55
50
51 /*
52 * scroll up within scrolling region
53 */
54 void
55 wsemul_vt100_scrollup(edp, n)
56 struct wsemul_vt100_emuldata *edp;
57 int n;
58 {
59 int help;
60
61 if (n > edp->scrreg_nrows)
62 n = edp->scrreg_nrows;
63
64 help = edp->scrreg_nrows - n;
65 if (help > 0) {
66 (*edp->emulops->copyrows)(edp->emulcookie,
67 edp->scrreg_startrow + n,
68 edp->scrreg_startrow,
69 help);
70 if (edp->dblwid)
71 bcopy(&edp->dblwid[edp->scrreg_startrow + n],
72 &edp->dblwid[edp->scrreg_startrow],
73 help);
74 }
75 (*edp->emulops->eraserows)(edp->emulcookie,
76 edp->scrreg_startrow + help, n,
77 edp->defattr);
78 if (edp->dblwid)
79 bzero(&edp->dblwid[edp->scrreg_startrow + help], n);
80 CHECK_DW;
81 }
82
83 /*
84 * scroll down within scrolling region
85 */
86 void
87 wsemul_vt100_scrolldown(edp, n)
88 struct wsemul_vt100_emuldata *edp;
89 int n;
90 {
91 int help;
92
93 if (n > edp->scrreg_nrows)
94 n = edp->scrreg_nrows;
95
96 help = edp->scrreg_nrows - n;
97 if (help > 0) {
98 (*edp->emulops->copyrows)(edp->emulcookie,
99 edp->scrreg_startrow,
100 edp->scrreg_startrow + n,
101 help);
102 if (edp->dblwid)
103 bcopy(&edp->dblwid[edp->scrreg_startrow],
104 &edp->dblwid[edp->scrreg_startrow + n],
105 help);
106 }
107 (*edp->emulops->eraserows)(edp->emulcookie,
108 edp->scrreg_startrow, n,
109 edp->defattr);
110 if (edp->dblwid)
111 bzero(&edp->dblwid[edp->scrreg_startrow], n);
112 CHECK_DW;
113 }
114
115 /*
116 * erase in display
117 */
118 void
119 wsemul_vt100_ed(edp, arg)
120 struct wsemul_vt100_emuldata *edp;
121 int arg;
122 {
123 int n;
124
125 switch (arg) {
126 case 0: /* cursor to end */
127 ERASECOLS(edp->ccol, COLS_LEFT + 1, edp->defattr);
128 n = edp->nrows - edp->crow - 1;
129 if (n > 0) {
130 (*edp->emulops->eraserows)(edp->emulcookie,
131 edp->crow + 1, n,
132 edp->defattr);
133 if (edp->dblwid)
134 bzero(&edp->dblwid[edp->crow + 1], n);
135 }
136 break;
137 case 1: /* beginning to cursor */
138 if (edp->crow > 0) {
139 (*edp->emulops->eraserows)(edp->emulcookie,
140 0, edp->crow,
141 edp->defattr);
142 if (edp->dblwid)
143 bzero(&edp->dblwid[0], edp->crow);
144 }
145 ERASECOLS(0, edp->ccol + 1, edp->defattr);
146 break;
147 case 2: /* complete display */
148 (*edp->emulops->eraserows)(edp->emulcookie,
149 0, edp->nrows,
150 edp->defattr);
151 if (edp->dblwid)
152 bzero(&edp->dblwid[0], edp->nrows);
153 break;
154 default:
155 #ifdef VT100_PRINTUNKNOWN
156 printf("ed(%d) unknown\n", arg);
157 #endif
158 break;
159 }
160 CHECK_DW;
161 }
162
163 /*
164 * erase in line
165 */
166 void
167 wsemul_vt100_el(edp, arg)
168 struct wsemul_vt100_emuldata *edp;
169 int arg;
170 {
171 switch (arg) {
172 case 0: /* cursor to end */
173 ERASECOLS(edp->ccol, COLS_LEFT + 1, edp->defattr);
174 break;
175 case 1: /* beginning to cursor */
176 ERASECOLS(0, edp->ccol + 1, edp->defattr);
177 break;
178 case 2: /* complete line */
179 (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
180 0, edp->ncols,
181 edp->defattr);
182 break;
183 default:
184 #ifdef VT100_PRINTUNKNOWN
185 printf("el(%d) unknown\n", arg);
186 #endif
187 break;
188 }
189 }
190
191 /*
192 * handle commands after CSI (ESC[)
193 */
194 void
195 wsemul_vt100_handle_csi(edp, c)
196 struct wsemul_vt100_emuldata *edp;
197 u_char c;
198 {
199 int n, help, flags, fgcol, bgcol;
200 long attr;
201
202 #define A3(a, b, c) (((a) << 16) | ((b) << 8) | (c))
203 switch (A3(edp->modif1, edp->modif2, c)) {
204 case A3('>', '\0', 'c'): /* DA secondary */
205 wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID2,
206 sizeof(WSEMUL_VT_ID2));
207 break;
208
209 case A3('\0', '\0', 'J'): /* ED selective erase in display */
210 case A3('?', '\0', 'J'): /* DECSED selective erase in display */
211 wsemul_vt100_ed(edp, ARG(0));
212 break;
213 case A3('\0', '\0', 'K'): /* EL selective erase in line */
214 case A3('?', '\0', 'K'): /* DECSEL selective erase in line */
215 wsemul_vt100_el(edp, ARG(0));
216 break;
217 case A3('\0', '\0', 'h'): /* SM */
218 for (n = 0; n < edp->nargs; n++)
219 vt100_ansimode(edp, ARG(n), VTMODE_SET);
220 break;
221 case A3('?', '\0', 'h'): /* DECSM */
222 for (n = 0; n < edp->nargs; n++)
223 vt100_decmode(edp, ARG(n), VTMODE_SET);
224 break;
225 case A3('\0', '\0', 'l'): /* RM */
226 for (n = 0; n < edp->nargs; n++)
227 vt100_ansimode(edp, ARG(n), VTMODE_RESET);
228 break;;
229 case A3('?', '\0', 'l'): /* DECRM */
230 for (n = 0; n < edp->nargs; n++)
231 vt100_decmode(edp, ARG(n), VTMODE_RESET);
232 break;;
233 case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */
234 vt100_ansimode(edp, ARG(0), VTMODE_REPORT);
235 break;
236 case A3('?', '$', 'p'): /* DECRQM request mode DEC */
237 vt100_decmode(edp, ARG(0), VTMODE_REPORT);
238 break;
239 case A3('\0', '\0', 'i'): /* MC printer controller mode */
240 case A3('?', '\0', 'i'): /* MC printer controller mode */
241 switch (ARG(0)) {
242 case 0: /* print screen */
243 case 1: /* print cursor line */
244 case 4: /* off */
245 case 5: /* on */
246 #ifdef VT100_PRINTNOTIMPL
247 printf("CSI%di ignored\n", ARG(0));
248 #endif
249 break;
250 default:
251 #ifdef VT100_PRINTUNKNOWN
252 printf("CSI%di unknown\n", ARG(0));
253 #endif
254 break;
255 }
256 break;
257
258 #define A2(a, b) (((a) << 8) | (b))
259 case A2('!', 'p'): /* DECSTR soft reset VT300 only */
260 wsemul_vt100_reset(edp);
261 break;
262
263 case A2('"', 'p'): /* DECSCL */
264 switch (ARG(0)) {
265 case 61: /* VT100 mode (no further arguments!) */
266 break;
267 case 62:
268 case 63: /* VT300 mode */
269 break;
270 default:
271 #ifdef VT100_PRINTUNKNOWN
272 printf("CSI%d\"p unknown\n", ARG(0));
273 #endif
274 break;
275 }
276 switch (ARG(1)) {
277 case 0:
278 case 2: /* 8-bit controls */
279 #ifdef VT100_PRINTNOTIMPL
280 printf("CSI%d;%d\"p ignored\n", ARG(0), ARG(1));
281 #endif
282 break;
283 case 1: /* 7-bit controls */
284 break;
285 default:
286 #ifdef VT100_PRINTUNKNOWN
287 printf("CSI%d;%d\"p unknown\n", ARG(0), ARG(1));
288 #endif
289 break;
290 }
291 break;
292 case A2('"', 'q'): /* DECSCA select character attribute VT300 */
293 switch (ARG(0)) {
294 case 0:
295 case 1: /* erasable */
296 break;
297 case 2: /* not erasable */
298 #ifdef VT100_PRINTNOTIMPL
299 printf("CSI2\"q ignored\n");
300 #endif
301 break;
302 default:
303 #ifdef VT100_PRINTUNKNOWN
304 printf("CSI%d\"q unknown\n", ARG(0));
305 #endif
306 break;
307 }
308 break;
309
310 case A2('$', 'u'): /* DECRQTSR request terminal status report */
311 switch (ARG(0)) {
312 case 0: /* ignored */
313 break;
314 case 1: /* terminal state report */
315 #ifdef VT100_PRINTNOTIMPL
316 printf("CSI1$u ignored\n");
317 #endif
318 break;
319 default:
320 #ifdef VT100_PRINTUNKNOWN
321 printf("CSI%d$u unknown\n", ARG(0));
322 #endif
323 break;
324 }
325 break;
326 case A2('$', 'w'): /* DECRQPSR request presentation status report
327 (VT300 only) */
328 switch (ARG(0)) {
329 case 0: /* error */
330 break;
331 case 1: /* cursor information report */
332 #ifdef VT100_PRINTNOTIMPL
333 printf("CSI1$w ignored\n");
334 #endif
335 break;
336 case 2: /* tab stop report */
337 {
338 int i, n;
339 char buf[20];
340 KASSERT(edp->tabs != 0);
341 wsdisplay_emulinput(edp->cbcookie, "\033P2$u", 5);
342 for (i = 0; i < edp->ncols; i++)
343 if (edp->tabs[i]) {
344 n = sprintf(buf, "%s%d",
345 (i ? "/" : ""), i + 1);
346 wsdisplay_emulinput(edp->cbcookie,
347 buf, n);
348 }
349 }
350 wsdisplay_emulinput(edp->cbcookie, "\033\\", 2);
351 break;
352 default:
353 #ifdef VT100_PRINTUNKNOWN
354 printf("CSI%d$w unknown\n", ARG(0));
355 #endif
356 break;
357 }
358 break;
359 case A2('$', '}'): /* DECSASD select active status display */
360 switch (ARG(0)) {
361 case 0: /* main display */
362 case 1: /* status line */
363 #ifdef VT100_PRINTNOTIMPL
364 printf("CSI%d$} ignored\n", ARG(0));
365 #endif
366 break;
367 default:
368 #ifdef VT100_PRINTUNKNOWN
369 printf("CSI%d$} unknown\n", ARG(0));
370 #endif
371 break;
372 }
373 break;
374 case A2('$', '~'): /* DECSSDD select status line type */
375 switch (ARG(0)) {
376 case 0: /* none */
377 case 1: /* indicator */
378 case 2: /* host-writable */
379 #ifdef VT100_PRINTNOTIMPL
380 printf("CSI%d$~ ignored\n", ARG(0));
381 #endif
382 break;
383 default:
384 #ifdef VT100_PRINTUNKNOWN
385 printf("CSI%d$~ unknown\n", ARG(0));
386 #endif
387 break;
388 }
389 break;
390
391 case A2('&', 'u'): /* DECRQUPSS request user preferred
392 supplemental set */
393 wsdisplay_emulinput(edp->emulcookie, "\033P0!u%5\033\\", 9);
394 break;
395
396 case '@': /* ICH insert character VT300 only */
397 n = min(DEF1_ARG(0), COLS_LEFT + 1);
398 help = NCOLS - (edp->ccol + n);
399 if (help > 0)
400 COPYCOLS(edp->ccol, edp->ccol + n, help);
401 ERASECOLS(edp->ccol, n, edp->defattr);
402 break;
403 case 'A': /* CUU */
404 edp->crow -= min(DEF1_ARG(0), ROWS_ABOVE);
405 CHECK_DW;
406 break;
407 case 'B': /* CUD */
408 edp->crow += min(DEF1_ARG(0), ROWS_BELOW);
409 CHECK_DW;
410 break;
411 case 'C': /* CUF */
412 edp->ccol += min(DEF1_ARG(0), COLS_LEFT);
413 break;
414 case 'D': /* CUB */
415 edp->ccol -= min(DEF1_ARG(0), edp->ccol);
416 edp->flags &= ~VTFL_LASTCHAR;
417 break;
418 case 'H': /* CUP */
419 case 'f': /* HVP */
420 if (edp->flags & VTFL_DECOM)
421 edp->crow = edp->scrreg_startrow +
422 min(DEF1_ARG(0), edp->scrreg_nrows) - 1;
423 else
424 edp->crow = min(DEF1_ARG(0), edp->nrows) - 1;
425 CHECK_DW;
426 edp->ccol = min(DEF1_ARG(1), NCOLS) - 1;
427 edp->flags &= ~VTFL_LASTCHAR;
428 break;
429 case 'L': /* IL insert line */
430 case 'M': /* DL delete line */
431 n = min(DEF1_ARG(0), ROWS_BELOW + 1);
432 {
433 int savscrstartrow, savscrnrows;
434 savscrstartrow = edp->scrreg_startrow;
435 savscrnrows = edp->scrreg_nrows;
436 edp->scrreg_nrows -= ROWS_ABOVE;
437 edp->scrreg_startrow = edp->crow;
438 if (c == 'L')
439 wsemul_vt100_scrolldown(edp, n);
440 else
441 wsemul_vt100_scrollup(edp, n);
442 edp->scrreg_startrow = savscrstartrow;
443 edp->scrreg_nrows = savscrnrows;
444 }
445 break;
446 case 'P': /* DCH delete character */
447 n = min(DEF1_ARG(0), COLS_LEFT + 1);
448 help = NCOLS - (edp->ccol + n);
449 if (help > 0)
450 COPYCOLS(edp->ccol + n, edp->ccol, help);
451 ERASECOLS(NCOLS - n, n, edp->defattr);
452 break;
453 case 'X': /* ECH erase character */
454 n = min(DEF1_ARG(0), COLS_LEFT + 1);
455 ERASECOLS(edp->ccol, n, edp->defattr);
456 break;
457 case 'c': /* DA primary */
458 if (ARG(0) == 0)
459 wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID1,
460 sizeof(WSEMUL_VT_ID1));
461 break;
462 case 'g': /* TBC */
463 KASSERT(edp->tabs != 0);
464 switch (ARG(0)) {
465 case 0:
466 edp->tabs[edp->ccol] = 0;
467 break;
468 case 3:
469 bzero(edp->tabs, edp->ncols);
470 break;
471 default:
472 #ifdef VT100_PRINTUNKNOWN
473 printf("CSI%dg unknown\n", ARG(0));
474 #endif
475 break;
476 }
477 break;
478 case 'm': /* SGR select graphic rendition */
479 flags = edp->attrflags;
480 fgcol = edp->fgcol;
481 bgcol = edp->bgcol;
482 for (n = 0; n < edp->nargs; n++) {
483 switch (ARG(n)) {
484 case 0: /* reset */
485 attr = edp->defattr;
486 flags = 0;
487 fgcol = WSCOL_WHITE;
488 bgcol = WSCOL_BLACK;
489 if (n == edp->nargs - 1) {
490 edp->curattr = attr;
491 edp->attrflags = flags;
492 edp->fgcol = fgcol;
493 edp->bgcol = bgcol;
494 return;
495 }
496 break;
497 case 1: /* bold */
498 flags |= WSATTR_HILIT;
499 break;
500 case 4: /* underline */
501 flags |= WSATTR_UNDERLINE;
502 break;
503 case 5: /* blink */
504 flags |= WSATTR_BLINK;
505 break;
506 case 7: /* reverse */
507 flags |= WSATTR_REVERSE;
508 break;
509 case 22: /* ~bold VT300 only */
510 flags &= ~WSATTR_HILIT;
511 break;
512 case 24: /* ~underline VT300 only */
513 flags &= ~WSATTR_UNDERLINE;
514 break;
515 case 25: /* ~blink VT300 only */
516 flags &= ~WSATTR_BLINK;
517 break;
518 case 27: /* ~reverse VT300 only */
519 flags &= ~WSATTR_REVERSE;
520 break;
521 case 30: case 31: case 32: case 33:
522 case 34: case 35: case 36: case 37:
523 /* fg color */
524 flags |= WSATTR_WSCOLORS;
525 fgcol = ARG(n) - 30;
526 break;
527 case 40: case 41: case 42: case 43:
528 case 44: case 45: case 46: case 47:
529 /* bg color */
530 flags |= WSATTR_WSCOLORS;
531 bgcol = ARG(n) - 40;
532 break;
533 default:
534 #ifdef VT100_PRINTUNKNOWN
535 printf("CSI%dm unknown\n", ARG(n));
536 #endif
537 }
538 }
539 if (vt100_selectattribute(edp, flags, fgcol, bgcol, &attr)) {
540 #ifdef VT100_DEBUG
541 printf("error allocating attr %d/%d/%x\n",
542 fgcol, bgcol, flags);
543 #endif
544 } else {
545 edp->curattr = attr;
546 edp->attrflags = flags;
547 edp->fgcol = fgcol;
548 edp->bgcol = bgcol;
549 }
550 break;
551 case 'n': /* reports */
552 switch (ARG(0)) {
553 case 5: /* DSR operating status */
554 /* 0 = OK, 3 = malfunction */
555 wsdisplay_emulinput(edp->cbcookie, "\033[0n", 4);
556 break;
557 case 6: { /* DSR cursor position report */
558 char buf[20];
559 int row;
560 if (edp->flags & VTFL_DECOM)
561 row = ROWS_ABOVE;
562 else
563 row = edp->crow;
564 n = sprintf(buf, "\033[%d;%dR",
565 row + 1, edp->ccol + 1);
566 wsdisplay_emulinput(edp->cbcookie, buf, n);
567 }
568 break;
569 case 15: /* DSR printer status */
570 /* 13 = no printer, 10 = ready, 11 = not ready */
571 wsdisplay_emulinput(edp->cbcookie, "\033[?13n", 6);
572 break;
573 case 25: /* UDK status - VT300 only */
574 /* 20 = locked, 21 = unlocked */
575 wsdisplay_emulinput(edp->cbcookie, "\033[?21n", 6);
576 break;
577 case 26: /* keyboard dialect */
578 /* 1 = north american , 7 = german */
579 wsdisplay_emulinput(edp->cbcookie, "\033[?27;1n", 8);
580 break;
581 default:
582 #ifdef VT100_PRINTUNKNOWN
583 printf("CSI%dn unknown\n", ARG(0));
584 #endif
585 break;
586 }
587 break;
588 case 'r': /* DECSTBM set top/bottom margins */
589 if (ARG(0) == 0 && ARG(1) == 0) {
590 edp->scrreg_startrow = 0;
591 edp->scrreg_nrows = edp->nrows;
592 } else {
593 edp->scrreg_startrow = min(DEF1_ARG(0),
594 edp->nrows) - 1;
595 edp->scrreg_nrows = min(DEF1_ARG(1), edp->nrows) -
596 edp->scrreg_startrow;
597 }
598 edp->crow = ((edp->flags & VTFL_DECOM) ?
599 edp->scrreg_startrow : 0);
600 edp->ccol = 0;
601 break;
602 case 'y':
603 switch (ARG(0)) {
604 case 4: /* DECTST invoke confidence test */
605 /* ignore */
606 break;
607 default:
608 #ifdef VT100_PRINTUNKNOWN
609 printf("CSI%dy unknown\n", ARG(0));
610 #endif
611 break;
612 }
613 break;
614 default:
615 #ifdef VT100_PRINTUNKNOWN
616 printf("CSI%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
617 #endif
618 }
619 }
620
621 /*
622 * get an attribute from the graphics driver,
623 * try to find replacements if the desired appearance
624 * is not supported
625 */
626 static int
627 vt100_selectattribute(edp, flags, fgcol, bgcol, attr)
628 struct wsemul_vt100_emuldata *edp;
629 int flags, fgcol, bgcol;
630 long *attr;
631 {
632 if ((flags & WSATTR_HILIT) &&
633 !(edp->scrcapabilities & WSSCREEN_HILIT)) {
634 flags &= ~WSATTR_HILIT;
635 if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
636 fgcol = WSCOL_RED;
637 flags |= WSATTR_WSCOLORS;
638 } else {
639 #ifdef VT100_DEBUG
640 printf("bold ignored (impossible)\n");
641 #endif
642 }
643 }
644 if ((flags & WSATTR_UNDERLINE) &&
645 !(edp->scrcapabilities & WSSCREEN_UNDERLINE)) {
646 flags &= ~WSATTR_UNDERLINE;
647 if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
648 bgcol = WSCOL_BROWN;
649 flags &= ~WSATTR_UNDERLINE;
650 flags |= WSATTR_WSCOLORS;
651 } else {
652 #ifdef VT100_DEBUG
653 printf("underline ignored (impossible)\n");
654 #endif
655 }
656 }
657 if ((flags & WSATTR_BLINK) &&
658 !(edp->scrcapabilities & WSSCREEN_BLINK)) {
659 flags &= ~WSATTR_BLINK;
660 #ifdef VT100_DEBUG
661 printf("blink ignored (impossible)\n");
662 #endif
663 }
664 if ((flags & WSATTR_REVERSE) &&
665 !(edp->scrcapabilities & WSSCREEN_REVERSE)) {
666 flags &= ~WSATTR_REVERSE;
667 if (edp->scrcapabilities & WSSCREEN_WSCOLORS) {
668 int help;
669 help = bgcol;
670 bgcol = fgcol;
671 fgcol = help;
672 flags |= WSATTR_WSCOLORS;
673 } else {
674 #ifdef VT100_DEBUG
675 printf("reverse ignored (impossible)\n");
676 #endif
677 }
678 }
679 if ((flags & WSATTR_WSCOLORS) &&
680 !(edp->scrcapabilities & WSSCREEN_WSCOLORS)) {
681 flags &= ~WSATTR_WSCOLORS;
682 #ifdef VT100_DEBUG
683 printf("colors ignored (impossible)\n");
684 #endif
685 }
686 return ((*edp->emulops->alloc_attr)(edp->emulcookie,
687 fgcol, bgcol, flags,
688 attr));
689 }
690
691 /*
692 * handle device control sequences if the main state machine
693 * told so by setting edp->dcstype to a nonzero value
694 */
695 void
696 wsemul_vt100_handle_dcs(edp)
697 struct wsemul_vt100_emuldata *edp;
698 {
699 int i, pos;
700
701 switch (edp->dcstype) {
702 case 0: /* not handled */
703 return;
704 case DCSTYPE_TABRESTORE:
705 KASSERT(edp->tabs != 0);
706 bzero(edp->tabs, edp->ncols);
707 pos = 0;
708 for (i = 0; i < edp->dcspos; i++) {
709 char c = edp->dcsarg[i];
710 switch (c) {
711 case '0': case '1': case '2': case '3': case '4':
712 case '5': case '6': case '7': case '8': case '9':
713 pos = pos * 10 + (edp->dcsarg[i] - '0');
714 break;
715 case '/':
716 if (pos > 0)
717 edp->tabs[pos - 1] = 1;
718 pos = 0;
719 break;
720 default:
721 #ifdef VT100_PRINTUNKNOWN
722 printf("unknown char %c in DCS\n", c);
723 #endif
724 }
725 }
726 if (pos > 0)
727 edp->tabs[pos - 1] = 1;
728 break;
729 default:
730 panic("wsemul_vt100_handle_dcs: bad type %d", edp->dcstype);
731 }
732 edp->dcstype = 0;
733 }
734
735 static int
736 vt100_ansimode(edp, nr, op)
737 struct wsemul_vt100_emuldata *edp;
738 int nr, op;
739 {
740 int res = 0; /* default: unknown */
741
742 switch (nr) {
743 case 2: /* KAM keyboard locked/unlocked */
744 break;
745 case 3: /* CRM control representation */
746 break;
747 case 4: /* IRM insert/replace characters */
748 if (op == VTMODE_SET)
749 edp->flags |= VTFL_INSERTMODE;
750 else if (op == VTMODE_RESET)
751 edp->flags &= ~VTFL_INSERTMODE;
752 res = ((edp->flags & VTFL_INSERTMODE) ? 1 : 2);
753 break;
754 case 10: /* HEM horizontal editing (permanently reset) */
755 res = 4;
756 break;
757 case 12: /* SRM local echo off/on */
758 res = 4; /* permanently reset ??? */
759 break;
760 case 20: /* LNM newline = newline/linefeed */
761 break;
762 default:
763 #ifdef VT100_PRINTUNKNOWN
764 printf("ANSI mode %d unknown\n", nr);
765 #endif
766 }
767 return (res);
768 }
769
770 static int
771 vt100_decmode(edp, nr, op)
772 struct wsemul_vt100_emuldata *edp;
773 int nr, op;
774 {
775 int res = 0; /* default: unknown */
776
777 switch (nr) {
778 case 1: /* DECCKM application/nomal cursor keys */
779 if (op == VTMODE_SET)
780 edp->flags |= VTFL_APPLCURSOR;
781 else if (op == VTMODE_RESET)
782 edp->flags &= ~VTFL_APPLCURSOR;
783 res = ((edp->flags & VTFL_APPLCURSOR) ? 1 : 2);
784 break;
785 case 2: /* DECANM ANSI vt100/vt52 */
786 res = 3; /* permanently set ??? */
787 break;
788 case 3: /* DECCOLM 132/80 cols */
789 case 4: /* DECSCLM smooth/jump scroll */
790 case 5: /* DECSCNM light/dark background */
791 res = 4; /* all permanently reset ??? */
792 break;
793 case 6: /* DECOM move within/outside margins */
794 if (op == VTMODE_SET)
795 edp->flags |= VTFL_DECOM;
796 else if (op == VTMODE_RESET)
797 edp->flags &= ~VTFL_DECOM;
798 res = ((edp->flags & VTFL_DECOM) ? 1 : 2);
799 break;
800 case 7: /* DECAWM autowrap */
801 if (op == VTMODE_SET)
802 edp->flags |= VTFL_DECAWM;
803 else if (op == VTMODE_RESET)
804 edp->flags &= ~VTFL_DECAWM;
805 res = ((edp->flags & VTFL_DECAWM) ? 1 : 2);
806 break;
807 case 8: /* DECARM keyboard autorepeat */
808 break;
809 case 18: /* DECPFF print form feed */
810 break;
811 case 19: /* DECPEX printer extent: screen/scrolling region */
812 break;
813 case 25: /* DECTCEM text cursor on/off */
814 if (op == VTMODE_SET || op == VTMODE_RESET) {
815 edp->flags = (edp->flags & ~VTFL_CURSORON) |
816 ((op == VTMODE_SET) ? VTFL_CURSORON : 0);
817 (*edp->emulops->cursor)(edp->emulcookie,
818 (op == VTMODE_SET),
819 edp->crow, edp->ccol);
820 }
821 res = ((edp->flags & VTFL_CURSORON) ? 1 : 2);
822 break;
823 case 42: /* DECNRCM use 7-bit NRC /
824 7/8 bit from DEC multilingual or ISO-latin-1*/
825 if (op == VTMODE_SET)
826 edp->flags |= VTFL_NATCHARSET;
827 else if (op == VTMODE_RESET)
828 edp->flags &= ~VTFL_NATCHARSET;
829 res = ((edp->flags & VTFL_NATCHARSET) ? 1 : 2);
830 break;
831 case 66: /* DECNKM numeric keypad */
832 break;
833 case 68: /* DECKBUM keyboard usage data processing/typewriter */
834 break;
835 default:
836 #ifdef VT100_PRINTUNKNOWN
837 printf("DEC mode %d unknown\n", nr);
838 #endif
839 break;
840 }
841 return (res);
842 }
843