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