wsemul_vt100.c revision 1.6 1 /* $NetBSD: wsemul_vt100.c,v 1.6 1998/06/29 21:10:53 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 #include <sys/time.h>
38 #include <sys/malloc.h>
39 #include <sys/fcntl.h>
40
41 #include <dev/wscons/wsconsio.h>
42 #include <dev/wscons/wsdisplayvar.h>
43 #include <dev/wscons/wsemulvar.h>
44 #include <dev/wscons/wsemul_vt100var.h>
45 #include <dev/wscons/ascii.h>
46
47 #include "opt_wskernattr.h"
48
49 void *wsemul_vt100_cnattach __P((const struct wsscreen_descr *, void *,
50 int, int, long));
51 void *wsemul_vt100_attach __P((int console, const struct wsscreen_descr *,
52 void *, int, int, void *, long));
53 void wsemul_vt100_output __P((void *cookie, const u_char *data, u_int count,
54 int));
55 void wsemul_vt100_detach __P((void *cookie, u_int *crowp, u_int *ccolp));
56
57 const struct wsemul_ops wsemul_vt100_ops = {
58 "vt100",
59 wsemul_vt100_cnattach,
60 wsemul_vt100_attach,
61 wsemul_vt100_output,
62 wsemul_vt100_translate,
63 wsemul_vt100_detach,
64 };
65
66 struct wsemul_vt100_emuldata wsemul_vt100_console_emuldata;
67
68 static void wsemul_vt100_init __P((struct wsemul_vt100_emuldata *,
69 const struct wsscreen_descr *,
70 void *, int, int, long));
71
72 static u_int wsemul_vt100_output_normal __P((struct wsemul_vt100_emuldata *,
73 u_char, int));
74 typedef u_int vt100_handler __P((struct wsemul_vt100_emuldata *, u_char));
75 static vt100_handler
76 wsemul_vt100_output_esc,
77 wsemul_vt100_output_csi,
78 wsemul_vt100_output_scs94,
79 wsemul_vt100_output_scs94_percent,
80 wsemul_vt100_output_scs96,
81 wsemul_vt100_output_scs96_percent,
82 wsemul_vt100_output_esc_hash,
83 wsemul_vt100_output_esc_spc,
84 wsemul_vt100_output_string,
85 wsemul_vt100_output_string_esc,
86 wsemul_vt100_output_dcs,
87 wsemul_vt100_output_dcs_dollar;
88
89 #define VT100_EMUL_STATE_NORMAL 0 /* normal processing */
90 #define VT100_EMUL_STATE_ESC 1 /* got ESC */
91 #define VT100_EMUL_STATE_CSI 2 /* got CSI (ESC[) */
92 #define VT100_EMUL_STATE_SCS94 3 /* got ESC{()*+} */
93 #define VT100_EMUL_STATE_SCS94_PERCENT 4 /* got ESC{()*+}% */
94 #define VT100_EMUL_STATE_SCS96 5 /* got ESC{-./} */
95 #define VT100_EMUL_STATE_SCS96_PERCENT 6 /* got ESC{-./}% */
96 #define VT100_EMUL_STATE_ESC_HASH 7 /* got ESC# */
97 #define VT100_EMUL_STATE_ESC_SPC 8 /* got ESC<SPC> */
98 #define VT100_EMUL_STATE_STRING 9 /* waiting for ST (ESC\) */
99 #define VT100_EMUL_STATE_STRING_ESC 10 /* waiting for ST, got ESC */
100 #define VT100_EMUL_STATE_DCS 11 /* got DCS (ESC P) */
101 #define VT100_EMUL_STATE_DCS_DOLLAR 12 /* got DCS<p>$ */
102
103 vt100_handler *vt100_output[] = {
104 wsemul_vt100_output_esc,
105 wsemul_vt100_output_csi,
106 wsemul_vt100_output_scs94,
107 wsemul_vt100_output_scs94_percent,
108 wsemul_vt100_output_scs96,
109 wsemul_vt100_output_scs96_percent,
110 wsemul_vt100_output_esc_hash,
111 wsemul_vt100_output_esc_spc,
112 wsemul_vt100_output_string,
113 wsemul_vt100_output_string_esc,
114 wsemul_vt100_output_dcs,
115 wsemul_vt100_output_dcs_dollar,
116 };
117
118 static void
119 wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr)
120 struct wsemul_vt100_emuldata *edp;
121 const struct wsscreen_descr *type;
122 void *cookie;
123 int ccol, crow;
124 long defattr;
125 {
126 edp->emulops = type->textops;
127 edp->emulcookie = cookie;
128 edp->scrcapabilities = type->capabilities;
129 edp->nrows = type->nrows;
130 edp->ncols = type->ncols;
131 edp->crow = crow;
132 edp->ccol = ccol;
133 edp->defattr = defattr;
134 }
135
136 void *
137 wsemul_vt100_cnattach(type, cookie, ccol, crow, defattr)
138 const struct wsscreen_descr *type;
139 void *cookie;
140 int ccol, crow;
141 long defattr;
142 {
143 struct wsemul_vt100_emuldata *edp;
144 #if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
145 defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
146 int res;
147 #endif
148
149 edp = &wsemul_vt100_console_emuldata;
150 wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
151 #ifdef DIAGNOSTIC
152 edp->console = 1;
153 #endif
154 edp->cbcookie = NULL;
155
156 #if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
157 defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
158 #ifndef WS_KERNEL_FG
159 #define WS_KERNEL_FG WSCOL_WHITE
160 #endif
161 #ifndef WS_KERNEL_BG
162 #define WS_KERNEL_BG WSCOL_BLACK
163 #endif
164 #ifndef WS_KERNEL_COLATTR
165 #define WS_KERNEL_COLATTR 0
166 #endif
167 #ifndef WS_KERNEL_MONOATTR
168 #define WS_KERNEL_MONOATTR 0
169 #endif
170 if (type->capabilities & WSSCREEN_WSCOLORS)
171 res = (*edp->emulops->alloc_attr)(cookie,
172 WS_KERNEL_FG, WS_KERNEL_BG,
173 WS_KERNEL_COLATTR | WSATTR_WSCOLORS,
174 &edp->kernattr);
175 else
176 res = (*edp->emulops->alloc_attr)(cookie, 0, 0,
177 WS_KERNEL_MONOATTR,
178 &edp->kernattr);
179 if (res)
180 #endif
181 edp->kernattr = defattr;
182
183 edp->tabs = 0;
184 edp->dblwid = 0;
185 edp->dw = 0;
186 edp->dcsarg = 0;
187 edp->isolatin1tab = edp->decgraphtab = edp->dectechtab = 0;
188 edp->nrctab = 0;
189 wsemul_vt100_reset(edp);
190 return (edp);
191 }
192
193 void *
194 wsemul_vt100_attach(console, type, cookie, ccol, crow, cbcookie, defattr)
195 int console;
196 const struct wsscreen_descr *type;
197 void *cookie;
198 int ccol, crow;
199 void *cbcookie;
200 long defattr;
201 {
202 struct wsemul_vt100_emuldata *edp;
203
204 if (console) {
205 edp = &wsemul_vt100_console_emuldata;
206 #ifdef DIAGNOSTIC
207 KASSERT(edp->console == 1);
208 #endif
209 } else {
210 edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
211 wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
212 #ifdef DIAGNOSTIC
213 edp->console = 0;
214 #endif
215 }
216 edp->cbcookie = cbcookie;
217
218 edp->tabs = malloc(edp->ncols, M_DEVBUF, M_NOWAIT);
219 edp->dblwid = malloc(edp->nrows, M_DEVBUF, M_NOWAIT);
220 bzero(edp->dblwid, edp->nrows);
221 edp->dw = 0;
222 edp->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_NOWAIT);
223 edp->isolatin1tab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
224 edp->decgraphtab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
225 edp->dectechtab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
226 edp->nrctab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
227 vt100_initchartables(edp);
228 wsemul_vt100_reset(edp);
229 return (edp);
230 }
231
232 void
233 wsemul_vt100_detach(cookie, crowp, ccolp)
234 void *cookie;
235 u_int *crowp, *ccolp;
236 {
237 struct wsemul_vt100_emuldata *edp = cookie;
238
239 *crowp = edp->crow;
240 *ccolp = edp->ccol;
241 #define f(ptr) if (ptr) {free(ptr, M_DEVBUF); ptr = 0;}
242 f(edp->tabs)
243 f(edp->dblwid)
244 f(edp->dcsarg)
245 f(edp->isolatin1tab)
246 f(edp->decgraphtab)
247 f(edp->dectechtab)
248 f(edp->nrctab)
249 #undef f
250 if (edp != &wsemul_vt100_console_emuldata)
251 free(edp, M_DEVBUF);
252 }
253
254 void
255 wsemul_vt100_reset(edp)
256 struct wsemul_vt100_emuldata *edp;
257 {
258 int i;
259
260 edp->state = VT100_EMUL_STATE_NORMAL;
261 edp->flags = VTFL_DECAWM | VTFL_CURSORON;
262 edp->curattr = edp->defattr;
263 edp->attrflags = 0;
264 edp->fgcol = WSCOL_WHITE;
265 edp->bgcol = WSCOL_BLACK;
266 edp->scrreg_startrow = 0;
267 edp->scrreg_nrows = edp->nrows;
268 if (edp->tabs) {
269 bzero(edp->tabs, edp->ncols);
270 for (i = 8; i < edp->ncols; i += 8)
271 edp->tabs[i] = 1;
272 }
273 edp->dcspos = 0;
274 edp->dcstype = 0;
275 edp->chartab_G[0] = 0;
276 edp->chartab_G[1] = edp->nrctab; /* ??? */
277 edp->chartab_G[2] = edp->isolatin1tab;
278 edp->chartab_G[3] = edp->isolatin1tab;
279 edp->chartab0 = 0;
280 edp->chartab1 = 2;
281 edp->sschartab = 0;
282 }
283
284 /*
285 * now all the state machine bits
286 */
287
288 static u_int
289 wsemul_vt100_output_normal(edp, c, kernel)
290 struct wsemul_vt100_emuldata *edp;
291 u_char c;
292 int kernel;
293 {
294 u_int newstate = VT100_EMUL_STATE_NORMAL;
295 u_int n, dc;
296 u_int *ct;
297
298 switch (c) {
299 case ASCII_NUL:
300 /* ignore */
301 break;
302 case ASCII_BEL:
303 wsdisplay_emulbell(edp->cbcookie);
304 break;
305 case ASCII_BS:
306 if (edp->ccol > 0) {
307 edp->ccol--;
308 edp->flags &= ~VTFL_LASTCHAR;
309 }
310 break;
311 case ASCII_CR:
312 edp->ccol = 0;
313 edp->flags &= ~VTFL_LASTCHAR;
314 break;
315 case ASCII_HT:
316 if (edp->tabs) {
317 if (!COLS_LEFT)
318 break;
319 for (n = edp->ccol + 1; n < NCOLS - 1; n++)
320 if (edp->tabs[n])
321 break;
322 } else {
323 n = edp->ccol + min(8 - (edp->ccol & 7), COLS_LEFT);
324 }
325 ERASECOLS(edp->ccol, n - edp->ccol,
326 kernel ? edp->kernattr : edp->curattr);
327 edp->ccol = n;
328 break;
329 case ASCII_SO: /* LS1 */
330 edp->chartab0 = 1;
331 break;
332 case ASCII_SI: /* LS0 */
333 edp->chartab0 = 0;
334 break;
335 case ASCII_ESC:
336 #ifdef DIAGNOSTIC
337 if (kernel)
338 panic("ESC in kernel output");
339 #endif
340 newstate = VT100_EMUL_STATE_ESC;
341 break;
342 #if 0
343 case CSI: /* 8-bit */
344 edp->nargs = 0;
345 bzero(edp->args, sizeof (edp->args));
346 edp->modif1 = edp->modif2 = '\0';
347 newstate = VT100_EMUL_STATE_CSI;
348 break;
349 case DCS: /* 8-bit */
350 edp->nargs = 0;
351 bzero(edp->args, sizeof (edp->args));
352 newstate = VT100_EMUL_STATE_DCS;
353 break;
354 #endif
355 default: /* normal character */
356 if ((edp->flags & (VTFL_LASTCHAR | VTFL_DECAWM)) ==
357 (VTFL_LASTCHAR | VTFL_DECAWM)) {
358 if (ROWS_BELOW > 0) {
359 edp->crow++;
360 CHECK_DW;
361 } else
362 wsemul_vt100_scrollup(edp, 1);
363 edp->ccol = 0;
364 edp->flags &= ~VTFL_LASTCHAR;
365 }
366
367 if (c & 0x80) {
368 c &= 0x7f;
369 ct = edp->chartab_G[edp->chartab1];
370 } else {
371 if (edp->sschartab) {
372 ct = edp->chartab_G[edp->sschartab];
373 edp->sschartab = 0;
374 } else
375 ct = edp->chartab_G[edp->chartab0];
376 }
377 dc = (ct ? ct[c] : c);
378
379 if ((edp->flags & VTFL_INSERTMODE) && COLS_LEFT)
380 COPYCOLS(edp->ccol, edp->ccol + 1, COLS_LEFT);
381
382 (*edp->emulops->putchar)(edp->emulcookie, edp->crow,
383 edp->ccol << edp->dw, dc,
384 kernel ? edp->kernattr : edp->curattr);
385
386 if (COLS_LEFT)
387 edp->ccol++;
388 else
389 edp->flags |= VTFL_LASTCHAR;
390 break;
391 case ASCII_LF:
392 case ASCII_VT:
393 case ASCII_FF:
394 if (ROWS_BELOW > 0) {
395 edp->crow++;
396 CHECK_DW;
397 } else
398 wsemul_vt100_scrollup(edp, 1);
399 break;
400 }
401
402 return (newstate);
403 }
404
405 static u_int
406 wsemul_vt100_output_esc(edp, c)
407 struct wsemul_vt100_emuldata *edp;
408 u_char c;
409 {
410 u_int newstate = VT100_EMUL_STATE_NORMAL;
411 int i;
412
413 switch (c) {
414 case '[': /* CSI */
415 edp->nargs = 0;
416 bzero(edp->args, sizeof (edp->args));
417 edp->modif1 = edp->modif2 = '\0';
418 newstate = VT100_EMUL_STATE_CSI;
419 break;
420 case '7': /* DECSC */
421 edp->savedcursor_row = edp->crow;
422 edp->savedcursor_col = edp->ccol;
423 edp->savedattr = edp->curattr;
424 edp->savedattrflags = edp->attrflags;
425 edp->savedfgcol = edp->fgcol;
426 edp->savedbgcol = edp->bgcol;
427 for (i = 0; i < 4; i++)
428 edp->savedchartab_G[i] = edp->chartab_G[i];
429 edp->savedchartab0 = edp->chartab0;
430 edp->savedchartab1 = edp->chartab1;
431 break;
432 case '8': /* DECRC */
433 edp->crow = edp->savedcursor_row;
434 edp->ccol = edp->savedcursor_col;
435 edp->curattr = edp->savedattr;
436 edp->attrflags = edp->savedattrflags;
437 edp->fgcol = edp->savedfgcol;
438 edp->bgcol = edp->savedbgcol;
439 for (i = 0; i < 4; i++)
440 edp->chartab_G[i] = edp->savedchartab_G[i];
441 edp->chartab0 = edp->savedchartab0;
442 edp->chartab1 = edp->savedchartab1;
443 break;
444 case '=': /* DECKPAM application mode */
445 edp->flags |= VTFL_APPLKEYPAD;
446 break;
447 case '>': /* DECKPNM numeric mode */
448 edp->flags &= ~VTFL_APPLKEYPAD;
449 break;
450 case 'E': /* NEL */
451 edp->ccol = 0;
452 /* FALLTHRU */
453 case 'D': /* IND */
454 if (ROWS_BELOW > 0) {
455 edp->crow++;
456 CHECK_DW;
457 break;
458 }
459 wsemul_vt100_scrollup(edp, 1);
460 break;
461 case 'H': /* HTS */
462 KASSERT(edp->tabs != 0);
463 edp->tabs[edp->ccol] = 1;
464 break;
465 case '~': /* LS1R */
466 edp->chartab1 = 1;
467 break;
468 case 'n': /* LS2 */
469 edp->chartab0 = 2;
470 break;
471 case '}': /* LS2R */
472 edp->chartab1 = 2;
473 break;
474 case 'o': /* LS3 */
475 edp->chartab0 = 3;
476 break;
477 case '|': /* LS3R */
478 edp->chartab1 = 3;
479 break;
480 case 'N': /* SS2 */
481 edp->sschartab = 2;
482 break;
483 case 'O': /* SS3 */
484 edp->sschartab = 3;
485 break;
486 case 'M': /* RI */
487 if (ROWS_ABOVE > 0) {
488 edp->crow--;
489 CHECK_DW;
490 break;
491 }
492 wsemul_vt100_scrolldown(edp, 1);
493 break;
494 case 'P': /* DCS */
495 edp->nargs = 0;
496 bzero(edp->args, sizeof (edp->args));
497 newstate = VT100_EMUL_STATE_DCS;
498 break;
499 case 'c': /* RIS */
500 wsemul_vt100_reset(edp);
501 wsemul_vt100_ed(edp, 2);
502 edp->ccol = edp->crow = 0;
503 break;
504 case '(': case ')': case '*': case '+': /* SCS */
505 edp->designating = c - '(';
506 newstate = VT100_EMUL_STATE_SCS94;
507 break;
508 case '-': case '.': case '/': /* SCS */
509 edp->designating = c - '-' + 1;
510 newstate = VT100_EMUL_STATE_SCS96;
511 break;
512 case '#':
513 newstate = VT100_EMUL_STATE_ESC_HASH;
514 break;
515 case ' ': /* 7/8 bit */
516 newstate = VT100_EMUL_STATE_ESC_SPC;
517 break;
518 case ']': /* OSC operating system command */
519 case '^': /* PM privacy message */
520 case '_': /* APC application program command */
521 /* ignored */
522 newstate = VT100_EMUL_STATE_STRING;
523 break;
524 case '<': /* exit VT52 mode - ignored */
525 break;
526 default:
527 #ifdef VT100_PRINTUNKNOWN
528 printf("ESC%c unknown\n", c);
529 #endif
530 break;
531 }
532
533 return (newstate);
534 }
535
536 static u_int
537 wsemul_vt100_output_scs94(edp, c)
538 struct wsemul_vt100_emuldata *edp;
539 u_char c;
540 {
541 u_int newstate = VT100_EMUL_STATE_NORMAL;
542
543 switch (c) {
544 case '%': /* probably DEC supplemental graphic */
545 newstate = VT100_EMUL_STATE_SCS94_PERCENT;
546 break;
547 case 'A': /* british / national */
548 edp->chartab_G[edp->designating] = edp->nrctab;
549 break;
550 case 'B': /* ASCII */
551 edp->chartab_G[edp->designating] = 0;
552 break;
553 case '<': /* user preferred supplemental */
554 /* XXX not really "user" preferred */
555 edp->chartab_G[edp->designating] = edp->isolatin1tab;
556 break;
557 case '0': /* DEC special graphic */
558 edp->chartab_G[edp->designating] = edp->decgraphtab;
559 break;
560 case '>': /* DEC tech */
561 edp->chartab_G[edp->designating] = edp->dectechtab;
562 break;
563 default:
564 #ifdef VT100_PRINTUNKNOWN
565 printf("ESC%c%c unknown\n", edp->designating + '(', c);
566 #endif
567 break;
568 }
569 return (newstate);
570 }
571
572 static u_int
573 wsemul_vt100_output_scs94_percent(edp, c)
574 struct wsemul_vt100_emuldata *edp;
575 u_char c;
576 {
577 switch (c) {
578 case '5': /* DEC supplemental graphic */
579 /* XXX there are differences */
580 edp->chartab_G[edp->designating] = edp->isolatin1tab;
581 break;
582 default:
583 #ifdef VT100_PRINTUNKNOWN
584 printf("ESC%c%%%c unknown\n", edp->designating + '(', c);
585 #endif
586 break;
587 }
588 return (VT100_EMUL_STATE_NORMAL);
589 }
590
591 static u_int
592 wsemul_vt100_output_scs96(edp, c)
593 struct wsemul_vt100_emuldata *edp;
594 u_char c;
595 {
596 u_int newstate = VT100_EMUL_STATE_NORMAL;
597 int nrc;
598
599 switch (c) {
600 case '%': /* probably portugese */
601 newstate = VT100_EMUL_STATE_SCS96_PERCENT;
602 break;
603 case 'A': /* ISO-latin-1 supplemental */
604 edp->chartab_G[edp->designating] = edp->isolatin1tab;
605 break;
606 case '4': /* dutch */
607 nrc = 1;
608 goto setnrc;
609 case '5': case 'C': /* finnish */
610 nrc = 2;
611 goto setnrc;
612 case 'R': /* french */
613 nrc = 3;
614 goto setnrc;
615 case 'Q': /* french canadian */
616 nrc = 4;
617 goto setnrc;
618 case 'K': /* german */
619 nrc = 5;
620 goto setnrc;
621 case 'Y': /* italian */
622 nrc = 6;
623 goto setnrc;
624 case 'E': case '6': /* norwegian / danish */
625 nrc = 7;
626 goto setnrc;
627 case 'Z': /* spanish */
628 nrc = 9;
629 goto setnrc;
630 case '7': case 'H': /* swedish */
631 nrc = 10;
632 goto setnrc;
633 case '=': /* swiss */
634 nrc = 11;
635 setnrc:
636 vt100_setnrc(edp, nrc); /* what table ??? */
637 break;
638 default:
639 #ifdef VT100_PRINTUNKNOWN
640 printf("ESC%c%c unknown\n", edp->designating + '-' - 1, c);
641 #endif
642 break;
643 }
644 return (newstate);
645 }
646
647 static u_int
648 wsemul_vt100_output_scs96_percent(edp, c)
649 struct wsemul_vt100_emuldata *edp;
650 u_char c;
651 {
652 switch (c) {
653 case '6': /* portugese */
654 vt100_setnrc(edp, 8);
655 break;
656 default:
657 #ifdef VT100_PRINTUNKNOWN
658 printf("ESC%c%%%c unknown\n", edp->designating + '-', c);
659 #endif
660 break;
661 }
662 return (VT100_EMUL_STATE_NORMAL);
663 }
664
665 static u_int
666 wsemul_vt100_output_esc_spc(edp, c)
667 struct wsemul_vt100_emuldata *edp;
668 u_char c;
669 {
670 switch (c) {
671 case 'F': /* 7-bit controls */
672 case 'G': /* 8-bit controls */
673 #ifdef VT100_PRINTNOTIMPL
674 printf("ESC<SPC>%c ignored\n", c);
675 #endif
676 break;
677 default:
678 #ifdef VT100_PRINTUNKNOWN
679 printf("ESC<SPC>%c unknown\n", c);
680 #endif
681 break;
682 }
683 return (VT100_EMUL_STATE_NORMAL);
684 }
685
686 static u_int
687 wsemul_vt100_output_string(edp, c)
688 struct wsemul_vt100_emuldata *edp;
689 u_char c;
690 {
691 switch (c) {
692 case ASCII_ESC: /* might be a string end */
693 return (VT100_EMUL_STATE_STRING_ESC);
694 #if 0
695 case ST: /* string end 8-bit */
696 wsemul_vt100_handle_dcs(edp);
697 return (VT100_EMUL_STATE_NORMAL);
698 #endif
699 default:
700 if (edp->dcstype && edp->dcspos < DCS_MAXLEN)
701 edp->dcsarg[edp->dcspos++] = c;
702 }
703 return (VT100_EMUL_STATE_STRING);
704 }
705
706 static u_int
707 wsemul_vt100_output_string_esc(edp, c)
708 struct wsemul_vt100_emuldata *edp;
709 u_char c;
710 {
711 if (c == '\\') { /* ST complete */
712 wsemul_vt100_handle_dcs(edp);
713 return (VT100_EMUL_STATE_NORMAL);
714 } else
715 return (VT100_EMUL_STATE_STRING);
716 }
717
718 static u_int
719 wsemul_vt100_output_dcs(edp, c)
720 struct wsemul_vt100_emuldata *edp;
721 u_char c;
722 {
723 u_int newstate = VT100_EMUL_STATE_DCS;
724
725 switch (c) {
726 case '0': case '1': case '2': case '3': case '4':
727 case '5': case '6': case '7': case '8': case '9':
728 /* argument digit */
729 if (edp->nargs > VT100_EMUL_NARGS - 1)
730 break;
731 edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
732 (c - '0');
733 break;
734 case ';': /* argument terminator */
735 edp->nargs++;
736 break;
737 default:
738 edp->nargs++;
739 if (edp->nargs > VT100_EMUL_NARGS) {
740 #ifdef VT100_DEBUG
741 printf("vt100: too many arguments\n");
742 #endif
743 edp->nargs = VT100_EMUL_NARGS;
744 }
745 newstate = VT100_EMUL_STATE_STRING;
746 switch (c) {
747 case '$':
748 newstate = VT100_EMUL_STATE_DCS_DOLLAR;
749 break;
750 case '{': /* DECDLD soft charset */
751 case '!': /* DECRQUPSS user preferred supplemental set */
752 /* 'u' must follow - need another state */
753 case '|': /* DECUDK program F6..F20 */
754 #ifdef VT100_PRINTNOTIMPL
755 printf("DCS%c ignored\n", c);
756 #endif
757 break;
758 default:
759 #ifdef VT100_PRINTUNKNOWN
760 printf("DCS%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
761 #endif
762 break;
763 }
764 }
765
766 return (newstate);
767 }
768
769 static u_int
770 wsemul_vt100_output_dcs_dollar(edp, c)
771 struct wsemul_vt100_emuldata *edp;
772 u_char c;
773 {
774 switch (c) {
775 case 'p': /* DECRSTS terminal state restore */
776 case 'q': /* DECRQSS control function request */
777 #ifdef VT100_PRINTNOTIMPL
778 printf("DCS$%c ignored\n", c);
779 #endif
780 break;
781 case 't': /* DECRSPS restore presentation state */
782 switch (ARG(0)) {
783 case 0: /* error */
784 break;
785 case 1: /* cursor information restore */
786 #ifdef VT100_PRINTNOTIMPL
787 printf("DCS1$t ignored\n");
788 #endif
789 break;
790 case 2: /* tab stop restore */
791 edp->dcspos = 0;
792 edp->dcstype = DCSTYPE_TABRESTORE;
793 break;
794 default:
795 #ifdef VT100_PRINTUNKNOWN
796 printf("DCS%d$t unknown\n", ARG(0));
797 #endif
798 break;
799 }
800 break;
801 default:
802 #ifdef VT100_PRINTUNKNOWN
803 printf("DCS$%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
804 #endif
805 break;
806 }
807 return (VT100_EMUL_STATE_STRING);
808 }
809
810 static u_int
811 wsemul_vt100_output_esc_hash(edp, c)
812 struct wsemul_vt100_emuldata *edp;
813 u_char c;
814 {
815 int i;
816
817 switch (c) {
818 case '5': /* DECSWL single width, single height */
819 if (edp->dw) {
820 for (i = 0; i < edp->ncols / 2; i++)
821 (*edp->emulops->copycols)(edp->emulcookie,
822 edp->crow,
823 2 * i, i, 1);
824 (*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
825 i, edp->ncols - i,
826 edp->defattr);
827 edp->dblwid[edp->crow] = 0;
828 edp->dw = 0;
829 }
830 break;
831 case '6': /* DECDWL double width, single height */
832 case '3': /* DECDHL double width, double height, top half */
833 case '4': /* DECDHL double width, double height, bottom half */
834 if (!edp->dw) {
835 for (i = edp->ncols / 2 - 1; i >= 0; i--)
836 (*edp->emulops->copycols)(edp->emulcookie,
837 edp->crow,
838 i, 2 * i, 1);
839 for (i = 0; i < edp->ncols / 2; i++)
840 (*edp->emulops->erasecols)(edp->emulcookie,
841 edp->crow,
842 2 * i + 1, 1,
843 edp->defattr);
844 edp->dblwid[edp->crow] = 1;
845 edp->dw = 1;
846 if (edp->ccol > (edp->ncols >> 1) - 1)
847 edp->ccol = (edp->ncols >> 1) - 1;
848 }
849 break;
850 case '8': { /* DECALN */
851 int i, j;
852 for (i = 0; i < edp->nrows; i++)
853 for (j = 0; j < edp->ncols; j++)
854 (*edp->emulops->putchar)(edp->emulcookie, i, j,
855 'E', edp->curattr);
856 }
857 edp->ccol = 0;
858 edp->crow = 0;
859 break;
860 default:
861 #ifdef VT100_PRINTUNKNOWN
862 printf("ESC#%c unknown\n", c);
863 #endif
864 break;
865 }
866 return (VT100_EMUL_STATE_NORMAL);
867 }
868
869 static u_int
870 wsemul_vt100_output_csi(edp, c)
871 struct wsemul_vt100_emuldata *edp;
872 u_char c;
873 {
874 u_int newstate = VT100_EMUL_STATE_CSI;
875
876 switch (c) {
877 case '0': case '1': case '2': case '3': case '4':
878 case '5': case '6': case '7': case '8': case '9':
879 /* argument digit */
880 if (edp->nargs > VT100_EMUL_NARGS - 1)
881 break;
882 edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
883 (c - '0');
884 break;
885 case ';': /* argument terminator */
886 edp->nargs++;
887 break;
888 case '?': /* DEC specific */
889 case '>': /* DA query */
890 edp->modif1 = c;
891 break;
892 case '!':
893 case '"':
894 case '$':
895 case '&':
896 edp->modif2 = c;
897 break;
898 default: /* end of escape sequence */
899 edp->nargs++;
900 if (edp->nargs > VT100_EMUL_NARGS) {
901 #ifdef VT100_DEBUG
902 printf("vt100: too many arguments\n");
903 #endif
904 edp->nargs = VT100_EMUL_NARGS;
905 }
906 wsemul_vt100_handle_csi(edp, c);
907 newstate = VT100_EMUL_STATE_NORMAL;
908 break;
909 }
910 return (newstate);
911 }
912
913 void
914 wsemul_vt100_output(cookie, data, count, kernel)
915 void *cookie;
916 const u_char *data;
917 u_int count;
918 int kernel;
919 {
920 struct wsemul_vt100_emuldata *edp = cookie;
921
922 #ifdef DIAGNOSTIC
923 if (kernel && !edp->console)
924 panic("wsemul_vt100_output: kernel output, not console");
925 #endif
926
927 /* XXX */
928 (*edp->emulops->cursor)(edp->emulcookie, 0,
929 edp->crow, edp->ccol << edp->dw);
930 for (; count > 0; data++, count--) {
931 if (edp->state == VT100_EMUL_STATE_NORMAL || kernel) {
932 edp->state = wsemul_vt100_output_normal(edp, *data,
933 kernel);
934 continue;
935 }
936 #ifdef DIAGNOSTIC
937 if (edp->state > sizeof(vt100_output) / sizeof(vt100_output[0]))
938 panic("wsemul_vt100: invalid state %d\n", edp->state);
939 #endif
940 edp->state = vt100_output[edp->state - 1](edp, *data);
941 }
942 /* XXX */
943 (*edp->emulops->cursor)(edp->emulcookie, edp->flags & VTFL_CURSORON,
944 edp->crow, edp->ccol << edp->dw);
945 }
946