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