Home | History | Annotate | Line # | Download | only in wscons
wsemul_vt100.c revision 1.1
      1  1.1  drochner /* $NetBSD: wsemul_vt100.c,v 1.1 1998/06/20 19:17:47 drochner 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.1  drochner 
     35  1.1  drochner #include <sys/param.h>
     36  1.1  drochner #include <sys/systm.h>
     37  1.1  drochner #include <sys/time.h>
     38  1.1  drochner #include <sys/malloc.h>
     39  1.1  drochner #include <sys/fcntl.h>
     40  1.1  drochner 
     41  1.1  drochner #include <dev/wscons/wsconsio.h>
     42  1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     43  1.1  drochner #include <dev/wscons/wsemulvar.h>
     44  1.1  drochner #include <dev/wscons/wsemul_vt100var.h>
     45  1.1  drochner #include <dev/wscons/ascii.h>
     46  1.1  drochner 
     47  1.1  drochner #include "opt_wskernattr.h"
     48  1.1  drochner 
     49  1.1  drochner void	*wsemul_vt100_cnattach __P((const struct wsscreen_descr *, void *,
     50  1.1  drochner 				  int, int, long));
     51  1.1  drochner void	*wsemul_vt100_attach __P((int console, const struct wsscreen_descr *,
     52  1.1  drochner 				  void *, int, int, void *, long));
     53  1.1  drochner void	wsemul_vt100_output __P((void *cookie, const u_char *data, u_int count,
     54  1.1  drochner 				 int));
     55  1.1  drochner void	wsemul_vt100_detach __P((void *cookie, u_int *crowp, u_int *ccolp));
     56  1.1  drochner 
     57  1.1  drochner const struct wsemul_ops wsemul_vt100_ops = {
     58  1.1  drochner 	"vt100",
     59  1.1  drochner 	wsemul_vt100_cnattach,
     60  1.1  drochner 	wsemul_vt100_attach,
     61  1.1  drochner 	wsemul_vt100_output,
     62  1.1  drochner 	wsemul_vt100_translate,
     63  1.1  drochner 	wsemul_vt100_detach,
     64  1.1  drochner };
     65  1.1  drochner 
     66  1.1  drochner struct wsemul_vt100_emuldata wsemul_vt100_console_emuldata;
     67  1.1  drochner 
     68  1.1  drochner static void wsemul_vt100_init __P((struct wsemul_vt100_emuldata *,
     69  1.1  drochner 				   const struct wsscreen_descr *,
     70  1.1  drochner 				   void *, int, int, long));
     71  1.1  drochner 
     72  1.1  drochner static u_int wsemul_vt100_output_normal __P((struct wsemul_vt100_emuldata *,
     73  1.1  drochner 					     u_char, int));
     74  1.1  drochner typedef u_int vt100_handler __P((struct wsemul_vt100_emuldata *, u_char));
     75  1.1  drochner static vt100_handler
     76  1.1  drochner wsemul_vt100_output_esc,
     77  1.1  drochner wsemul_vt100_output_csi,
     78  1.1  drochner wsemul_vt100_output_csi_qm,
     79  1.1  drochner wsemul_vt100_output_scs94,
     80  1.1  drochner wsemul_vt100_output_scs94_percent,
     81  1.1  drochner wsemul_vt100_output_scs96,
     82  1.1  drochner wsemul_vt100_output_scs96_percent,
     83  1.1  drochner wsemul_vt100_output_hash,
     84  1.1  drochner wsemul_vt100_output_esc_spc,
     85  1.1  drochner wsemul_vt100_output_csi_gt,
     86  1.1  drochner wsemul_vt100_output_string,
     87  1.1  drochner wsemul_vt100_output_string_esc,
     88  1.1  drochner wsemul_vt100_output_csi_dq,
     89  1.1  drochner wsemul_vt100_output_dcs,
     90  1.1  drochner wsemul_vt100_output_csi_dollar,
     91  1.1  drochner wsemul_vt100_output_csi_qm_dollar,
     92  1.1  drochner wsemul_vt100_output_csi_amp,
     93  1.1  drochner wsemul_vt100_output_csi_em,
     94  1.1  drochner wsemul_vt100_output_dcs_dollar;
     95  1.1  drochner 
     96  1.1  drochner #define	VT100_EMUL_STATE_NORMAL		0	/* normal processing */
     97  1.1  drochner #define	VT100_EMUL_STATE_ESC		1	/* got ESC */
     98  1.1  drochner #define	VT100_EMUL_STATE_CSI		2	/* got CSI (ESC[) */
     99  1.1  drochner #define	VT100_EMUL_STATE_CSI_QM		3	/* got CSI? */
    100  1.1  drochner #define	VT100_EMUL_STATE_SCS94		4	/* got ESC{()*+} */
    101  1.1  drochner #define	VT100_EMUL_STATE_SCS94_PERCENT	5	/* got ESC{()*+}% */
    102  1.1  drochner #define	VT100_EMUL_STATE_SCS96		6	/* got ESC{-./} */
    103  1.1  drochner #define	VT100_EMUL_STATE_SCS96_PERCENT	7	/* got ESC{-./}% */
    104  1.1  drochner #define	VT100_EMUL_STATE_HASH		8	/* got ESC# */
    105  1.1  drochner #define	VT100_EMUL_STATE_ESC_SPC	9	/* got ESC<SPC> */
    106  1.1  drochner #define	VT100_EMUL_STATE_CSI_GT		10	/* got CSI> */
    107  1.1  drochner #define	VT100_EMUL_STATE_STRING		11	/* waiting for ST (ESC\) */
    108  1.1  drochner #define	VT100_EMUL_STATE_STRING_ESC	12	/* waiting for ST, got ESC */
    109  1.1  drochner #define	VT100_EMUL_STATE_CSI_DQ		13	/* got CSI<p>" */
    110  1.1  drochner #define	VT100_EMUL_STATE_DCS		14	/* got DCS (ESC P) */
    111  1.1  drochner #define	VT100_EMUL_STATE_CSI_DOLLAR	15	/* got CSI<p>$ */
    112  1.1  drochner #define	VT100_EMUL_STATE_CSI_QM_DOLLAR	16	/* got CSI?<p>$ */
    113  1.1  drochner #define	VT100_EMUL_STATE_CSI_AMP	17	/* got CSI& */
    114  1.1  drochner #define	VT100_EMUL_STATE_CSI_EM		18	/* got CSI! */
    115  1.1  drochner #define	VT100_EMUL_STATE_DCS_DOLLAR	19	/* got DCS<p>$ */
    116  1.1  drochner 
    117  1.1  drochner vt100_handler *vt100_output[] = {
    118  1.1  drochner 	wsemul_vt100_output_esc,
    119  1.1  drochner 	wsemul_vt100_output_csi,
    120  1.1  drochner 	wsemul_vt100_output_csi_qm,
    121  1.1  drochner 	wsemul_vt100_output_scs94,
    122  1.1  drochner 	wsemul_vt100_output_scs94_percent,
    123  1.1  drochner 	wsemul_vt100_output_scs96,
    124  1.1  drochner 	wsemul_vt100_output_scs96_percent,
    125  1.1  drochner 	wsemul_vt100_output_hash,
    126  1.1  drochner 	wsemul_vt100_output_esc_spc,
    127  1.1  drochner 	wsemul_vt100_output_csi_gt,
    128  1.1  drochner 	wsemul_vt100_output_string,
    129  1.1  drochner 	wsemul_vt100_output_string_esc,
    130  1.1  drochner 	wsemul_vt100_output_csi_dq,
    131  1.1  drochner 	wsemul_vt100_output_dcs,
    132  1.1  drochner 	wsemul_vt100_output_csi_dollar,
    133  1.1  drochner 	wsemul_vt100_output_csi_qm_dollar,
    134  1.1  drochner 	wsemul_vt100_output_csi_amp,
    135  1.1  drochner 	wsemul_vt100_output_csi_em,
    136  1.1  drochner 	wsemul_vt100_output_dcs_dollar,
    137  1.1  drochner };
    138  1.1  drochner 
    139  1.1  drochner static void
    140  1.1  drochner wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr)
    141  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    142  1.1  drochner 	const struct wsscreen_descr *type;
    143  1.1  drochner 	void *cookie;
    144  1.1  drochner 	int ccol, crow;
    145  1.1  drochner 	long defattr;
    146  1.1  drochner {
    147  1.1  drochner 	edp->emulops = type->textops;
    148  1.1  drochner 	edp->emulcookie = cookie;
    149  1.1  drochner 	edp->scrcapabilities = type->capabilities;
    150  1.1  drochner 	edp->nrows = type->nrows;
    151  1.1  drochner 	edp->ncols = type->ncols;
    152  1.1  drochner 	edp->crow = crow;
    153  1.1  drochner 	edp->ccol = ccol;
    154  1.1  drochner 	edp->defattr = defattr;
    155  1.1  drochner }
    156  1.1  drochner 
    157  1.1  drochner void *
    158  1.1  drochner wsemul_vt100_cnattach(type, cookie, ccol, crow, defattr)
    159  1.1  drochner 	const struct wsscreen_descr *type;
    160  1.1  drochner 	void *cookie;
    161  1.1  drochner 	int ccol, crow;
    162  1.1  drochner 	long defattr;
    163  1.1  drochner {
    164  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    165  1.1  drochner 	int res;
    166  1.1  drochner 
    167  1.1  drochner 	edp = &wsemul_vt100_console_emuldata;
    168  1.1  drochner 	wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
    169  1.1  drochner #ifdef DIAGNOSTIC
    170  1.1  drochner 	edp->console = 1;
    171  1.1  drochner #endif
    172  1.1  drochner 	edp->cbcookie = NULL;
    173  1.1  drochner 
    174  1.1  drochner #if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
    175  1.1  drochner   defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
    176  1.1  drochner #ifndef WS_KERNEL_FG
    177  1.1  drochner #define WS_KERNEL_FG WSCOL_WHITE
    178  1.1  drochner #endif
    179  1.1  drochner #ifndef WS_KERNEL_BG
    180  1.1  drochner #define WS_KERNEL_BG WSCOL_BLACK
    181  1.1  drochner #endif
    182  1.1  drochner #ifndef WS_KERNEL_COLATTR
    183  1.1  drochner #define WS_KERNEL_COLATTR 0
    184  1.1  drochner #endif
    185  1.1  drochner #ifndef WS_KERNEL_MONOATTR
    186  1.1  drochner #define WS_KERNEL_MONOATTR 0
    187  1.1  drochner #endif
    188  1.1  drochner 	if (type->capabilities & WSSCREEN_WSCOLORS)
    189  1.1  drochner 		res = (*edp->emulops->alloc_attr)(cookie,
    190  1.1  drochner 					    WS_KERNEL_FG, WS_KERNEL_BG,
    191  1.1  drochner 					    WS_KERNEL_COLATTR | WSATTR_WSCOLORS,
    192  1.1  drochner 					    &edp->kernattr);
    193  1.1  drochner 	else
    194  1.1  drochner 		res = (*edp->emulops->alloc_attr)(cookie, 0, 0,
    195  1.1  drochner 					    WS_KERNEL_MONOATTR,
    196  1.1  drochner 					    &edp->kernattr);
    197  1.1  drochner 	if (res)
    198  1.1  drochner #endif
    199  1.1  drochner 	edp->kernattr = defattr;
    200  1.1  drochner 
    201  1.1  drochner 	edp->tabs = 0;
    202  1.1  drochner 	edp->dcsarg = 0;
    203  1.1  drochner 	wsemul_vt100_reset(edp);
    204  1.1  drochner 	return (edp);
    205  1.1  drochner }
    206  1.1  drochner 
    207  1.1  drochner void *
    208  1.1  drochner wsemul_vt100_attach(console, type, cookie, ccol, crow, cbcookie, defattr)
    209  1.1  drochner 	int console;
    210  1.1  drochner 	const struct wsscreen_descr *type;
    211  1.1  drochner 	void *cookie;
    212  1.1  drochner 	int ccol, crow;
    213  1.1  drochner 	void *cbcookie;
    214  1.1  drochner 	long defattr;
    215  1.1  drochner {
    216  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    217  1.1  drochner 
    218  1.1  drochner 	if (console) {
    219  1.1  drochner 		edp = &wsemul_vt100_console_emuldata;
    220  1.1  drochner #ifdef DIAGNOSTIC
    221  1.1  drochner 		KASSERT(edp->console == 1);
    222  1.1  drochner #endif
    223  1.1  drochner 	} else {
    224  1.1  drochner 		edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
    225  1.1  drochner 		wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
    226  1.1  drochner #ifdef DIAGNOSTIC
    227  1.1  drochner 		edp->console = 0;
    228  1.1  drochner #endif
    229  1.1  drochner 	}
    230  1.1  drochner 	edp->cbcookie = cbcookie;
    231  1.1  drochner 
    232  1.1  drochner 	edp->tabs = malloc(type->ncols, M_DEVBUF, M_NOWAIT);
    233  1.1  drochner 	edp->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_NOWAIT);
    234  1.1  drochner 	wsemul_vt100_reset(edp);
    235  1.1  drochner 	return (edp);
    236  1.1  drochner }
    237  1.1  drochner 
    238  1.1  drochner void
    239  1.1  drochner wsemul_vt100_detach(cookie, crowp, ccolp)
    240  1.1  drochner 	void *cookie;
    241  1.1  drochner 	u_int *crowp, *ccolp;
    242  1.1  drochner {
    243  1.1  drochner 	struct wsemul_vt100_emuldata *edp = cookie;
    244  1.1  drochner 
    245  1.1  drochner 	*crowp = edp->crow;
    246  1.1  drochner 	*ccolp = edp->ccol;
    247  1.1  drochner 	if (edp->tabs) {
    248  1.1  drochner 		free(edp->tabs, M_DEVBUF);
    249  1.1  drochner 		edp->tabs = 0;
    250  1.1  drochner 	}
    251  1.1  drochner 	if (edp->dcsarg) {
    252  1.1  drochner 		free(edp->dcsarg, M_DEVBUF);
    253  1.1  drochner 		edp->dcsarg = 0;
    254  1.1  drochner 	}
    255  1.1  drochner 	if (edp != &wsemul_vt100_console_emuldata)
    256  1.1  drochner 		free(edp, M_DEVBUF);
    257  1.1  drochner }
    258  1.1  drochner 
    259  1.1  drochner void
    260  1.1  drochner wsemul_vt100_reset(edp)
    261  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    262  1.1  drochner {
    263  1.1  drochner 	int i;
    264  1.1  drochner 
    265  1.1  drochner 	edp->state = VT100_EMUL_STATE_NORMAL;
    266  1.1  drochner 	edp->flags = VTFL_DECAWM | VTFL_CURSORON;
    267  1.1  drochner 	edp->curattr = edp->defattr;
    268  1.1  drochner 	edp->attrflags = 0;
    269  1.1  drochner 	edp->fgcol = WSCOL_WHITE;
    270  1.1  drochner 	edp->bgcol = WSCOL_BLACK;
    271  1.1  drochner 	edp->scrreg_startrow = 0;
    272  1.1  drochner 	edp->scrreg_nrows = edp->nrows;
    273  1.1  drochner 	if (edp->tabs) {
    274  1.1  drochner 		bzero(edp->tabs, edp->ncols);
    275  1.1  drochner 		for (i = 1; i < edp->ncols; i += 8 - (i & 7))
    276  1.1  drochner 			edp->tabs[i] = 1;
    277  1.1  drochner 	}
    278  1.1  drochner 	edp->dcspos = 0;
    279  1.1  drochner 	edp->dcstype = 0;
    280  1.1  drochner }
    281  1.1  drochner 
    282  1.1  drochner /*
    283  1.1  drochner  * now all the state machine bits
    284  1.1  drochner  */
    285  1.1  drochner 
    286  1.1  drochner static u_int
    287  1.1  drochner wsemul_vt100_output_normal(edp, c, kernel)
    288  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    289  1.1  drochner 	u_char c;
    290  1.1  drochner 	int kernel;
    291  1.1  drochner {
    292  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_NORMAL;
    293  1.1  drochner 	u_int n;
    294  1.1  drochner 
    295  1.1  drochner 	switch (c) {
    296  1.1  drochner 	    case ASCII_NUL:
    297  1.1  drochner 		/* ignore */
    298  1.1  drochner 		break;
    299  1.1  drochner 	    case ASCII_BEL:
    300  1.1  drochner 		wsdisplay_emulbell(edp->cbcookie);
    301  1.1  drochner 		break;
    302  1.1  drochner 	    case ASCII_BS:
    303  1.1  drochner 		if (edp->ccol > 0) {
    304  1.1  drochner 			edp->ccol--;
    305  1.1  drochner 			edp->flags &= ~VTFL_LASTCHAR;
    306  1.1  drochner 		}
    307  1.1  drochner 		break;
    308  1.1  drochner 	    case ASCII_CR:
    309  1.1  drochner 		edp->ccol = 0;
    310  1.1  drochner 		edp->flags &= ~VTFL_LASTCHAR;
    311  1.1  drochner 		break;
    312  1.1  drochner 	    case ASCII_HT:
    313  1.1  drochner 		if (edp->tabs) {
    314  1.1  drochner 			if (edp->ccol >= edp->ncols - 1)
    315  1.1  drochner 				break;
    316  1.1  drochner 			for (n = edp->ccol + 1; n < edp->ncols - 1; n++)
    317  1.1  drochner 				if (edp->tabs[n])
    318  1.1  drochner 					break;
    319  1.1  drochner 		} else {
    320  1.1  drochner 			n = edp->ccol + min(8 - (edp->ccol & 7), COLS_LEFT);
    321  1.1  drochner 		}
    322  1.1  drochner 		(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
    323  1.1  drochner 					   edp->ccol, n - edp->ccol,
    324  1.1  drochner 				     kernel ? edp->kernattr : edp->curattr);
    325  1.1  drochner 		edp->ccol = n;
    326  1.1  drochner 		break;
    327  1.1  drochner 	    case ASCII_SI: /* LS0 */
    328  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    329  1.1  drochner 		printf("SI ignored\n");
    330  1.1  drochner #endif
    331  1.1  drochner 		break;
    332  1.1  drochner 	    case ASCII_SO: /* LS1 */
    333  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    334  1.1  drochner 		printf("SO ignored\n");
    335  1.1  drochner #endif
    336  1.1  drochner 		break;
    337  1.1  drochner 	    case ASCII_ESC:
    338  1.1  drochner #ifdef DIAGNOSTIC
    339  1.1  drochner 		if (kernel)
    340  1.1  drochner 			panic("ESC in kernel output");
    341  1.1  drochner #endif
    342  1.1  drochner 		newstate = VT100_EMUL_STATE_ESC;
    343  1.1  drochner 		break;
    344  1.1  drochner #if 0
    345  1.1  drochner 	    case CSI: /* 8-bit */
    346  1.1  drochner 		edp->nargs = 0;
    347  1.1  drochner 		bzero(edp->args, sizeof (edp->args));
    348  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI;
    349  1.1  drochner 		break;
    350  1.1  drochner 	    case DCS: /* 8-bit */
    351  1.1  drochner 		edp->nargs = 0;
    352  1.1  drochner 		bzero(edp->args, sizeof (edp->args));
    353  1.1  drochner 		newstate = VT100_EMUL_STATE_DCS;
    354  1.1  drochner 		break;
    355  1.1  drochner #endif
    356  1.1  drochner 	    default: /* normal character */
    357  1.1  drochner 		if ((edp->flags & (VTFL_LASTCHAR | VTFL_DECAWM)) ==
    358  1.1  drochner 		    (VTFL_LASTCHAR | VTFL_DECAWM)) {
    359  1.1  drochner 			if (ROWS_BELOW > 0)
    360  1.1  drochner 				edp->crow++;
    361  1.1  drochner 			else
    362  1.1  drochner 				wsemul_vt100_scrollup(edp, 1);
    363  1.1  drochner 			edp->ccol = 0;
    364  1.1  drochner 			edp->flags &= ~VTFL_LASTCHAR;
    365  1.1  drochner 		}
    366  1.1  drochner 
    367  1.1  drochner 		if ((edp->flags & VTFL_INSERTMODE) &&
    368  1.1  drochner 		    edp->ccol < edp->ncols - 1) {
    369  1.1  drochner 			(*edp->emulops->copycols)(edp->emulcookie, edp->crow,
    370  1.1  drochner 						  edp->ccol, edp->ccol + 1,
    371  1.1  drochner 						  edp->ncols - edp->ccol - 1);
    372  1.1  drochner 		}
    373  1.1  drochner 
    374  1.1  drochner 		(*edp->emulops->putstr)(edp->emulcookie, edp->crow, edp->ccol,
    375  1.1  drochner 					&c, 1,
    376  1.1  drochner 				    kernel ? edp->kernattr : edp->curattr);
    377  1.1  drochner 
    378  1.1  drochner 		if (edp->ccol < edp->ncols - 1)
    379  1.1  drochner 			edp->ccol++;
    380  1.1  drochner 		else
    381  1.1  drochner 			edp->flags |= VTFL_LASTCHAR;
    382  1.1  drochner 		break;
    383  1.1  drochner 	    case ASCII_LF:
    384  1.1  drochner 	    case ASCII_VT:
    385  1.1  drochner 	    case ASCII_FF:
    386  1.1  drochner 		if (ROWS_BELOW > 0)
    387  1.1  drochner 			edp->crow++;
    388  1.1  drochner 		else
    389  1.1  drochner 			wsemul_vt100_scrollup(edp, 1);
    390  1.1  drochner 		break;
    391  1.1  drochner 	}
    392  1.1  drochner 
    393  1.1  drochner 	return (newstate);
    394  1.1  drochner }
    395  1.1  drochner 
    396  1.1  drochner static u_int
    397  1.1  drochner wsemul_vt100_output_esc(edp, c)
    398  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    399  1.1  drochner 	u_char c;
    400  1.1  drochner {
    401  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_NORMAL;
    402  1.1  drochner 
    403  1.1  drochner 	switch (c) {
    404  1.1  drochner 	    case '[': /* CSI */
    405  1.1  drochner 		edp->nargs = 0;
    406  1.1  drochner 		bzero(edp->args, sizeof (edp->args));
    407  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI;
    408  1.1  drochner 		break;
    409  1.1  drochner 	    case '7': /* DECSC */
    410  1.1  drochner 		edp->savedcursor_row = edp->crow;
    411  1.1  drochner 		edp->savedcursor_col = edp->ccol;
    412  1.1  drochner 		/* save attributes! */
    413  1.1  drochner 		break;
    414  1.1  drochner 	    case '8': /* DECRC */
    415  1.1  drochner 		edp->crow = edp->savedcursor_row;
    416  1.1  drochner 		edp->ccol = edp->savedcursor_col;
    417  1.1  drochner 		/* restore attributes! */
    418  1.1  drochner 		break;
    419  1.1  drochner 	    case '=': /* DECKPAM application mode */
    420  1.1  drochner 		edp->flags |= VTFL_APPLKEYPAD;
    421  1.1  drochner 		break;
    422  1.1  drochner 	    case '>': /* DECKPNM numeric mode */
    423  1.1  drochner 		edp->flags &= ~VTFL_APPLKEYPAD;
    424  1.1  drochner 		break;
    425  1.1  drochner 	    case 'E': /* NEL */
    426  1.1  drochner 		edp->ccol = 0;
    427  1.1  drochner 		/* FALLTHRU */
    428  1.1  drochner 	    case 'D': /* IND */
    429  1.1  drochner 		if (ROWS_BELOW > 0) {
    430  1.1  drochner 			edp->crow++;
    431  1.1  drochner 			break;
    432  1.1  drochner 		}
    433  1.1  drochner 		wsemul_vt100_scrollup(edp, 1);
    434  1.1  drochner 		break;
    435  1.1  drochner 	    case 'H': /* HTS */
    436  1.1  drochner 		KASSERT(edp->tabs != 0);
    437  1.1  drochner 		edp->tabs[edp->ccol] = 1;
    438  1.1  drochner 		break;
    439  1.1  drochner 	    case '~': /* LS1R */
    440  1.1  drochner 	    case 'n': /* LS2 */
    441  1.1  drochner 	    case '}': /* LS2R */
    442  1.1  drochner 	    case 'o': /* LS3 */
    443  1.1  drochner 	    case '|': /* LS3R */
    444  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    445  1.1  drochner 		printf("ESC %c ignored\n", c);
    446  1.1  drochner #endif
    447  1.1  drochner 		break;
    448  1.1  drochner 	    case 'N': /* SS2 */
    449  1.1  drochner 	    case 'O': /* SS3 */
    450  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    451  1.1  drochner 		printf("ESC %c ignored\n", c);
    452  1.1  drochner #endif
    453  1.1  drochner 		break;
    454  1.1  drochner 	    case 'M': /* RI */
    455  1.1  drochner 		if (ROWS_ABOVE > 0) {
    456  1.1  drochner 			edp->crow--;
    457  1.1  drochner 			break;
    458  1.1  drochner 		}
    459  1.1  drochner 		wsemul_vt100_scrolldown(edp, 1);
    460  1.1  drochner 		break;
    461  1.1  drochner 	    case 'P': /* DCS */
    462  1.1  drochner 		edp->nargs = 0;
    463  1.1  drochner 		bzero(edp->args, sizeof (edp->args));
    464  1.1  drochner 		newstate = VT100_EMUL_STATE_DCS;
    465  1.1  drochner 		break;
    466  1.1  drochner 	    case 'c': /* RIS */
    467  1.1  drochner 		wsemul_vt100_reset(edp);
    468  1.1  drochner 		edp->ccol = edp->crow = 0;
    469  1.1  drochner 		break;
    470  1.1  drochner 	    case '(': case ')': case '*': case '+': /* SCS */
    471  1.1  drochner 		edp->designating = c;
    472  1.1  drochner 		newstate = VT100_EMUL_STATE_SCS94;
    473  1.1  drochner 		break;
    474  1.1  drochner 	    case '-': case '.': case '/': /* SCS */
    475  1.1  drochner 		edp->designating = c;
    476  1.1  drochner 		newstate = VT100_EMUL_STATE_SCS96;
    477  1.1  drochner 		break;
    478  1.1  drochner 	    case '#':
    479  1.1  drochner 		newstate = VT100_EMUL_STATE_HASH;
    480  1.1  drochner 		break;
    481  1.1  drochner 	    case ' ': /* 7/8 bit */
    482  1.1  drochner 		newstate = VT100_EMUL_STATE_ESC_SPC;
    483  1.1  drochner 		break;
    484  1.1  drochner 	    case ']': /* OSC operating system command */
    485  1.1  drochner 	    case '^': /* PM privacy message */
    486  1.1  drochner 	    case '_': /* APC application program command */
    487  1.1  drochner 		/* ignored */
    488  1.1  drochner 		newstate = VT100_EMUL_STATE_STRING;
    489  1.1  drochner 		break;
    490  1.1  drochner 	    case '<': /* exit VT52 mode - ignored */
    491  1.1  drochner 		break;
    492  1.1  drochner 	    default:
    493  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    494  1.1  drochner 		printf("ESC%c unknown\n", c);
    495  1.1  drochner #endif
    496  1.1  drochner 		break;
    497  1.1  drochner 	}
    498  1.1  drochner 
    499  1.1  drochner 	return (newstate);
    500  1.1  drochner }
    501  1.1  drochner 
    502  1.1  drochner static u_int
    503  1.1  drochner wsemul_vt100_output_csi_qm(edp, c)
    504  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    505  1.1  drochner 	u_char c;
    506  1.1  drochner {
    507  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_CSI_QM;
    508  1.1  drochner 
    509  1.1  drochner 	switch (c) {
    510  1.1  drochner 	    case '0': case '1': case '2': case '3': case '4':
    511  1.1  drochner 	    case '5': case '6': case '7': case '8': case '9':
    512  1.1  drochner 		/* argument digit */
    513  1.1  drochner 		if (edp->nargs > VT100_EMUL_NARGS - 1)
    514  1.1  drochner 			break;
    515  1.1  drochner 		edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
    516  1.1  drochner 		    (c - '0');
    517  1.1  drochner 		break;
    518  1.1  drochner 	    case ';': /* argument terminator */
    519  1.1  drochner 		edp->nargs++;
    520  1.1  drochner 		break;
    521  1.1  drochner 	    case '$': /* request mode */
    522  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_QM_DOLLAR;
    523  1.1  drochner 		break;
    524  1.1  drochner 	    default: /* end of escape sequence */
    525  1.1  drochner 		edp->nargs++;
    526  1.1  drochner 		if (edp->nargs > VT100_EMUL_NARGS) {
    527  1.1  drochner #ifdef VT100_DEBUG
    528  1.1  drochner 			printf("vt100: too many arguments\n");
    529  1.1  drochner #endif
    530  1.1  drochner 			edp->nargs = VT100_EMUL_NARGS;
    531  1.1  drochner 		}
    532  1.1  drochner 		wsemul_vt100_handle_csi_qm(edp, c);
    533  1.1  drochner 		newstate = VT100_EMUL_STATE_NORMAL;
    534  1.1  drochner 		break;
    535  1.1  drochner 	}
    536  1.1  drochner 	return (newstate);
    537  1.1  drochner }
    538  1.1  drochner 
    539  1.1  drochner static u_int
    540  1.1  drochner wsemul_vt100_output_csi_qm_dollar(edp, c)
    541  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    542  1.1  drochner 	u_char c;
    543  1.1  drochner {
    544  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_NORMAL;
    545  1.1  drochner 
    546  1.1  drochner 	switch (c) {
    547  1.1  drochner 	    case 'p': /* DECRQM request DEC private mode */
    548  1.1  drochner 		vt100_reportmode(edp, ARG(0), 1);
    549  1.1  drochner 		break;
    550  1.1  drochner 	    default:
    551  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    552  1.1  drochner 		printf("CSI?%c unknown\n", c);
    553  1.1  drochner #endif
    554  1.1  drochner 		break;
    555  1.1  drochner 	}
    556  1.1  drochner 
    557  1.1  drochner 	return (newstate);
    558  1.1  drochner }
    559  1.1  drochner 
    560  1.1  drochner static u_int
    561  1.1  drochner wsemul_vt100_output_csi_amp(edp, c)
    562  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    563  1.1  drochner 	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 'u': /* DECRQUPSS request user preferred supplemental set */
    569  1.1  drochner 		wsdisplay_emulinput(edp->emulcookie, "\033P0!u%5\033\\", 9);
    570  1.1  drochner 		break;
    571  1.1  drochner 	    default:
    572  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    573  1.1  drochner 		printf("CSI&%c unknown\n", c);
    574  1.1  drochner #endif
    575  1.1  drochner 		break;
    576  1.1  drochner 	}
    577  1.1  drochner 
    578  1.1  drochner 	return (newstate);
    579  1.1  drochner }
    580  1.1  drochner 
    581  1.1  drochner static u_int
    582  1.1  drochner wsemul_vt100_output_scs94(edp, c)
    583  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    584  1.1  drochner 	u_char c;
    585  1.1  drochner {
    586  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_NORMAL;
    587  1.1  drochner 
    588  1.1  drochner 	switch (c) {
    589  1.1  drochner 	    case '%': /* probably DEC supplemental graphic */
    590  1.1  drochner 		newstate = VT100_EMUL_STATE_SCS94_PERCENT;
    591  1.1  drochner 		break;
    592  1.1  drochner 	    case 'B': /* ASCII */
    593  1.1  drochner 	    case 'A': /* ISO-latin-1 supplemental */
    594  1.1  drochner 	    case '<': /* user preferred supplemental */
    595  1.1  drochner 	    case '0': /* DEC special graphic */
    596  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    597  1.1  drochner 		printf("ESC%c%c ignored\n", edp->designating, c);
    598  1.1  drochner #endif
    599  1.1  drochner 		break;
    600  1.1  drochner 	    default:
    601  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    602  1.1  drochner 		printf("ESC%c%c unknown\n", edp->designating, c);
    603  1.1  drochner #endif
    604  1.1  drochner 		break;
    605  1.1  drochner 	}
    606  1.1  drochner 	return (newstate);
    607  1.1  drochner }
    608  1.1  drochner 
    609  1.1  drochner static u_int
    610  1.1  drochner wsemul_vt100_output_scs94_percent(edp, c)
    611  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    612  1.1  drochner 	u_char c;
    613  1.1  drochner {
    614  1.1  drochner 	switch (c) {
    615  1.1  drochner 	    case '5': /* DEC supplemental graphic */
    616  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    617  1.1  drochner 		printf("ESC%c%%5 ignored\n", edp->designating);
    618  1.1  drochner #endif
    619  1.1  drochner 		break;
    620  1.1  drochner 	    default:
    621  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    622  1.1  drochner 		printf("ESC%c%%%c unknown\n", edp->designating, c);
    623  1.1  drochner #endif
    624  1.1  drochner 		break;
    625  1.1  drochner 	}
    626  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
    627  1.1  drochner }
    628  1.1  drochner 
    629  1.1  drochner static u_int
    630  1.1  drochner wsemul_vt100_output_scs96(edp, c)
    631  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    632  1.1  drochner 	u_char c;
    633  1.1  drochner {
    634  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_NORMAL;
    635  1.1  drochner 
    636  1.1  drochner 	switch (c) {
    637  1.1  drochner 	    case '%': /* probably portugese */
    638  1.1  drochner 		newstate = VT100_EMUL_STATE_SCS96_PERCENT;
    639  1.1  drochner 		break;
    640  1.1  drochner 	    case 'A': /* british */
    641  1.1  drochner 	    case '4': /* dutch */
    642  1.1  drochner 	    case '5': case 'C': /* finnish */
    643  1.1  drochner 	    case 'R': /* french */
    644  1.1  drochner 	    case 'Q': /* french canadian */
    645  1.1  drochner 	    case 'K': /* german */
    646  1.1  drochner 	    case 'Y': /* italian */
    647  1.1  drochner 	    case 'E': case '6': /* norwegian / danish */
    648  1.1  drochner 	    case 'Z': /* spanish */
    649  1.1  drochner 	    case '7': case 'H': /* swedish */
    650  1.1  drochner 	    case '=': /* swiss */
    651  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    652  1.1  drochner 		printf("ESC%c%c ignored\n", edp->designating, c);
    653  1.1  drochner #endif
    654  1.1  drochner 		break;
    655  1.1  drochner 	    default:
    656  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    657  1.1  drochner 		printf("ESC%c%c unknown\n", edp->designating, c);
    658  1.1  drochner #endif
    659  1.1  drochner 		break;
    660  1.1  drochner 	}
    661  1.1  drochner 	return (newstate);
    662  1.1  drochner }
    663  1.1  drochner 
    664  1.1  drochner static u_int
    665  1.1  drochner wsemul_vt100_output_scs96_percent(edp, c)
    666  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    667  1.1  drochner 	u_char c;
    668  1.1  drochner {
    669  1.1  drochner 	switch (c) {
    670  1.1  drochner 	    case '6': /* portugese */
    671  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    672  1.1  drochner 		printf("ESC%c%%6 ignored\n", edp->designating);
    673  1.1  drochner #endif
    674  1.1  drochner 		break;
    675  1.1  drochner 	    default:
    676  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    677  1.1  drochner 		printf("ESC%c%%%c unknown\n", edp->designating, c);
    678  1.1  drochner #endif
    679  1.1  drochner 		break;
    680  1.1  drochner 	}
    681  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
    682  1.1  drochner }
    683  1.1  drochner 
    684  1.1  drochner static u_int
    685  1.1  drochner wsemul_vt100_output_esc_spc(edp, c)
    686  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    687  1.1  drochner 	u_char c;
    688  1.1  drochner {
    689  1.1  drochner 	switch (c) {
    690  1.1  drochner 	    case 'F': /* 7-bit controls */
    691  1.1  drochner 	    case 'G': /* 8-bit controls */
    692  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    693  1.1  drochner 		printf("ESC<SPC>%c ignored\n", c);
    694  1.1  drochner #endif
    695  1.1  drochner 		break;
    696  1.1  drochner 	    default:
    697  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    698  1.1  drochner 		printf("ESC<SPC>%c unknown\n", c);
    699  1.1  drochner #endif
    700  1.1  drochner 		break;
    701  1.1  drochner 	}
    702  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
    703  1.1  drochner }
    704  1.1  drochner 
    705  1.1  drochner static u_int
    706  1.1  drochner wsemul_vt100_output_string(edp, c)
    707  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    708  1.1  drochner 	u_char c;
    709  1.1  drochner {
    710  1.1  drochner 	switch (c) {
    711  1.1  drochner 	    case ASCII_ESC: /* might be a string end */
    712  1.1  drochner 		return (VT100_EMUL_STATE_STRING_ESC);
    713  1.1  drochner #if 0
    714  1.1  drochner 	    case ST: /* string end 8-bit */
    715  1.1  drochner 		wsemul_vt100_handle_dcs(edp);
    716  1.1  drochner 		return (VT100_EMUL_STATE_NORMAL);
    717  1.1  drochner #endif
    718  1.1  drochner 	    default:
    719  1.1  drochner 		if (edp->dcstype && edp->dcspos < DCS_MAXLEN)
    720  1.1  drochner 			edp->dcsarg[edp->dcspos++] = c;
    721  1.1  drochner 	}
    722  1.1  drochner 	return (VT100_EMUL_STATE_STRING);
    723  1.1  drochner }
    724  1.1  drochner 
    725  1.1  drochner static u_int
    726  1.1  drochner wsemul_vt100_output_string_esc(edp, c)
    727  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    728  1.1  drochner 	u_char c;
    729  1.1  drochner {
    730  1.1  drochner 	if (c == '\\') { /* ST complete */
    731  1.1  drochner 		wsemul_vt100_handle_dcs(edp);
    732  1.1  drochner 		return (VT100_EMUL_STATE_NORMAL);
    733  1.1  drochner 	} else
    734  1.1  drochner 		return (VT100_EMUL_STATE_STRING);
    735  1.1  drochner }
    736  1.1  drochner 
    737  1.1  drochner static u_int
    738  1.1  drochner wsemul_vt100_output_csi_em(edp, c)
    739  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    740  1.1  drochner 	u_char c;
    741  1.1  drochner {
    742  1.1  drochner 	switch (c) {
    743  1.1  drochner 	    case 'p': /* DECSTR soft reset VT300 only */
    744  1.1  drochner 		wsemul_vt100_reset(edp);
    745  1.1  drochner 		break;
    746  1.1  drochner 	    default:
    747  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    748  1.1  drochner 		printf("ESC!%c unknown\n", c);
    749  1.1  drochner #endif
    750  1.1  drochner 		break;
    751  1.1  drochner 	}
    752  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
    753  1.1  drochner }
    754  1.1  drochner 
    755  1.1  drochner static u_int
    756  1.1  drochner wsemul_vt100_output_dcs(edp, c)
    757  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    758  1.1  drochner 	u_char c;
    759  1.1  drochner {
    760  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_DCS;
    761  1.1  drochner 
    762  1.1  drochner 	switch (c) {
    763  1.1  drochner 	    case '0': case '1': case '2': case '3': case '4':
    764  1.1  drochner 	    case '5': case '6': case '7': case '8': case '9':
    765  1.1  drochner 		/* argument digit */
    766  1.1  drochner 		if (edp->nargs > VT100_EMUL_NARGS - 1)
    767  1.1  drochner 			break;
    768  1.1  drochner 		edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
    769  1.1  drochner 		    (c - '0');
    770  1.1  drochner 		break;
    771  1.1  drochner 	    case ';': /* argument terminator */
    772  1.1  drochner 		edp->nargs++;
    773  1.1  drochner 		break;
    774  1.1  drochner 	    default:
    775  1.1  drochner 		edp->nargs++;
    776  1.1  drochner 		if (edp->nargs > VT100_EMUL_NARGS) {
    777  1.1  drochner #ifdef VT100_DEBUG
    778  1.1  drochner 			printf("vt100: too many arguments\n");
    779  1.1  drochner #endif
    780  1.1  drochner 			edp->nargs = VT100_EMUL_NARGS;
    781  1.1  drochner 		}
    782  1.1  drochner 		newstate = VT100_EMUL_STATE_STRING;
    783  1.1  drochner 		switch (c) {
    784  1.1  drochner 		    case '$':
    785  1.1  drochner 			newstate = VT100_EMUL_STATE_DCS_DOLLAR;
    786  1.1  drochner 			break;
    787  1.1  drochner 		    case '{': /* DECDLD soft charset */
    788  1.1  drochner 		    case '!': /* DECRQUPSS user preferred supplemental set */
    789  1.1  drochner 			/* 'u' must follow - need another state */
    790  1.1  drochner 		    case '|': /* DECUDK program F6..F20 */
    791  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    792  1.1  drochner 			printf("DCS%c ignored\n", c);
    793  1.1  drochner #endif
    794  1.1  drochner 			break;
    795  1.1  drochner 		    default:
    796  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    797  1.1  drochner 			printf("DCS%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
    798  1.1  drochner #endif
    799  1.1  drochner 			break;
    800  1.1  drochner 		}
    801  1.1  drochner 	}
    802  1.1  drochner 
    803  1.1  drochner 	return (newstate);
    804  1.1  drochner }
    805  1.1  drochner 
    806  1.1  drochner static u_int
    807  1.1  drochner wsemul_vt100_output_dcs_dollar(edp, c)
    808  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    809  1.1  drochner 	u_char c;
    810  1.1  drochner {
    811  1.1  drochner 	switch (c) {
    812  1.1  drochner 	    case 'p': /* DECRSTS terminal state restore */
    813  1.1  drochner 	    case 'q': /* DECRQSS control function request */
    814  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    815  1.1  drochner 		printf("DCS$%c ignored\n", c);
    816  1.1  drochner #endif
    817  1.1  drochner 		break;
    818  1.1  drochner 	    case 't': /* DECRSPS restore presentation state */
    819  1.1  drochner 		switch (ARG(0)) {
    820  1.1  drochner 		    case 0: /* error */
    821  1.1  drochner 			break;
    822  1.1  drochner 		    case 1: /* cursor information restore */
    823  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    824  1.1  drochner 			printf("DCS1$t ignored\n");
    825  1.1  drochner #endif
    826  1.1  drochner 			break;
    827  1.1  drochner 		    case 2: /* tab stop restore */
    828  1.1  drochner 			edp->dcspos = 0;
    829  1.1  drochner 			edp->dcstype = DCSTYPE_TABRESTORE;
    830  1.1  drochner 			break;
    831  1.1  drochner 		    default:
    832  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    833  1.1  drochner 			printf("DCS%d$t unknown\n", ARG(0));
    834  1.1  drochner #endif
    835  1.1  drochner 			break;
    836  1.1  drochner 		}
    837  1.1  drochner 		break;
    838  1.1  drochner 	    default:
    839  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    840  1.1  drochner 		printf("DCS$%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
    841  1.1  drochner #endif
    842  1.1  drochner 		break;
    843  1.1  drochner 	}
    844  1.1  drochner 	return (VT100_EMUL_STATE_STRING);
    845  1.1  drochner }
    846  1.1  drochner 
    847  1.1  drochner static u_int
    848  1.1  drochner wsemul_vt100_output_csi_gt(edp, c)
    849  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    850  1.1  drochner 	u_char c;
    851  1.1  drochner {
    852  1.1  drochner 	switch (c) {
    853  1.1  drochner 	    case 'c': /* DA secondary */
    854  1.1  drochner 		wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID2,
    855  1.1  drochner 				    sizeof(WSEMUL_VT_ID2));
    856  1.1  drochner 		break;
    857  1.1  drochner 	    default:
    858  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    859  1.1  drochner 		printf("CSI>%c unknown\n", c);
    860  1.1  drochner #endif
    861  1.1  drochner 		break;
    862  1.1  drochner 	}
    863  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
    864  1.1  drochner }
    865  1.1  drochner 
    866  1.1  drochner static u_int
    867  1.1  drochner wsemul_vt100_output_csi_dollar(edp, c)
    868  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    869  1.1  drochner 	u_char c;
    870  1.1  drochner {
    871  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_NORMAL;
    872  1.1  drochner 
    873  1.1  drochner 	switch (c) {
    874  1.1  drochner 	    case '}': /* DECSASD */
    875  1.1  drochner 		/* select active status display */
    876  1.1  drochner 		switch (ARG(0)) {
    877  1.1  drochner 		    case 0: /* main display */
    878  1.1  drochner 		    case 1: /* status line */
    879  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    880  1.1  drochner 			printf("CSI%d$} ignored\n", ARG(0));
    881  1.1  drochner #endif
    882  1.1  drochner 			break;
    883  1.1  drochner 		    default:
    884  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    885  1.1  drochner 			printf("CSI%d$} unknown\n", ARG(0));
    886  1.1  drochner #endif
    887  1.1  drochner 			break;
    888  1.1  drochner 		}
    889  1.1  drochner 		break;
    890  1.1  drochner 	    case '~': /* DECSSDD */
    891  1.1  drochner 		/* select status line type */
    892  1.1  drochner 		switch (ARG(0)) {
    893  1.1  drochner 		    case 0: /* none */
    894  1.1  drochner 		    case 1: /* indicator */
    895  1.1  drochner 		    case 2: /* host-writable */
    896  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    897  1.1  drochner 			printf("CSI%d$~ ignored\n", ARG(0));
    898  1.1  drochner #endif
    899  1.1  drochner 			break;
    900  1.1  drochner 		    default:
    901  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    902  1.1  drochner 			printf("CSI%d$~ unknown\n", ARG(0));
    903  1.1  drochner #endif
    904  1.1  drochner 			break;
    905  1.1  drochner 		}
    906  1.1  drochner 		break;
    907  1.1  drochner 	    case 'p': /* DECRQM request mode ANSI */
    908  1.1  drochner 		vt100_reportmode(edp, ARG(0), 0);
    909  1.1  drochner 		break;
    910  1.1  drochner 	    case 'u': /* DECRQTSR request terminal status report */
    911  1.1  drochner 		switch (ARG(0)) {
    912  1.1  drochner 		    case 0: /* ignored */
    913  1.1  drochner 			break;
    914  1.1  drochner 		    case 1: /* terminal state report */
    915  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    916  1.1  drochner 			printf("CSI1$u ignored\n");
    917  1.1  drochner #endif
    918  1.1  drochner 			break;
    919  1.1  drochner 		    default:
    920  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    921  1.1  drochner 			printf("CSI%d$u unknown\n", ARG(0));
    922  1.1  drochner #endif
    923  1.1  drochner 			break;
    924  1.1  drochner 		}
    925  1.1  drochner 		break;
    926  1.1  drochner 	    case 'w': /* DECRQPSR request presentation status report
    927  1.1  drochner 			 (VT300 only) */
    928  1.1  drochner 		switch (ARG(0)) {
    929  1.1  drochner 		    case 0: /* error */
    930  1.1  drochner 			break;
    931  1.1  drochner 		    case 1: /* cursor information report */
    932  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    933  1.1  drochner 			printf("CSI1$w ignored\n");
    934  1.1  drochner #endif
    935  1.1  drochner 			break;
    936  1.1  drochner 		    case 2: /* tab stop report */
    937  1.1  drochner 			{
    938  1.1  drochner 			int i, n;
    939  1.1  drochner 			char buf[20];
    940  1.1  drochner 			KASSERT(edp->tabs != 0);
    941  1.1  drochner 			wsdisplay_emulinput(edp->cbcookie, "\033P2$u", 5);
    942  1.1  drochner 			for (i = 0; i < edp->ncols; i++)
    943  1.1  drochner 				if (edp->tabs[i]) {
    944  1.1  drochner 					n = sprintf(buf, "%s%d",
    945  1.1  drochner 						    (i ? "/" : ""), i + 1);
    946  1.1  drochner 					wsdisplay_emulinput(edp->cbcookie,
    947  1.1  drochner 							    buf, n);
    948  1.1  drochner 				}
    949  1.1  drochner 			}
    950  1.1  drochner 			wsdisplay_emulinput(edp->cbcookie, "\033\\", 2);
    951  1.1  drochner 			break;
    952  1.1  drochner 		    default:
    953  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    954  1.1  drochner 			printf("CSI%d$w unknown\n", ARG(0));
    955  1.1  drochner #endif
    956  1.1  drochner 			break;
    957  1.1  drochner 		}
    958  1.1  drochner 		break;
    959  1.1  drochner 	    default:
    960  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    961  1.1  drochner 		printf("CSI$%c unknown\n", c);
    962  1.1  drochner #endif
    963  1.1  drochner 		break;
    964  1.1  drochner 	}
    965  1.1  drochner 	return (newstate);
    966  1.1  drochner }
    967  1.1  drochner 
    968  1.1  drochner static u_int
    969  1.1  drochner wsemul_vt100_output_hash(edp, c)
    970  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
    971  1.1  drochner 	u_char c;
    972  1.1  drochner {
    973  1.1  drochner 	switch (c) {
    974  1.1  drochner 	    case '5': /*  DECSWL single width, single height */
    975  1.1  drochner 		break;
    976  1.1  drochner 	    case '6': /*  DECDWL double width, single height */
    977  1.1  drochner 	    case '3': /*  DECDHL double width, double height, top half */
    978  1.1  drochner 	    case '4': /*  DECDHL double width, double height, bottom half */
    979  1.1  drochner #ifdef VT100_PRINTNOTIMPL
    980  1.1  drochner 		printf("ESC#%c ignored\n", c);
    981  1.1  drochner #endif
    982  1.1  drochner 		break;
    983  1.1  drochner 	    case '8': { /* DECALN */
    984  1.1  drochner 		int i, j;
    985  1.1  drochner 		for (i = 0; i < edp->nrows; i++)
    986  1.1  drochner 			for (j = 0; j < edp->ncols; j++)
    987  1.1  drochner 				(*edp->emulops->putstr)(edp->emulcookie, i, j,
    988  1.1  drochner 							"E", 1, edp->curattr);
    989  1.1  drochner 		}
    990  1.1  drochner 		edp->ccol = 0;
    991  1.1  drochner 		edp->crow = 0;
    992  1.1  drochner 		break;
    993  1.1  drochner 	    default:
    994  1.1  drochner #ifdef VT100_PRINTUNKNOWN
    995  1.1  drochner 		printf("ESC#%c unknown\n", c);
    996  1.1  drochner #endif
    997  1.1  drochner 		break;
    998  1.1  drochner 	}
    999  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
   1000  1.1  drochner }
   1001  1.1  drochner 
   1002  1.1  drochner static u_int
   1003  1.1  drochner wsemul_vt100_output_csi(edp, c)
   1004  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
   1005  1.1  drochner 	u_char c;
   1006  1.1  drochner {
   1007  1.1  drochner 	u_int newstate = VT100_EMUL_STATE_CSI;
   1008  1.1  drochner 
   1009  1.1  drochner 	switch (c) {
   1010  1.1  drochner 	    case '0': case '1': case '2': case '3': case '4':
   1011  1.1  drochner 	    case '5': case '6': case '7': case '8': case '9':
   1012  1.1  drochner 		/* argument digit */
   1013  1.1  drochner 		if (edp->nargs > VT100_EMUL_NARGS - 1)
   1014  1.1  drochner 			break;
   1015  1.1  drochner 		edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
   1016  1.1  drochner 		    (c - '0');
   1017  1.1  drochner 		break;
   1018  1.1  drochner 	    case ';': /* argument terminator */
   1019  1.1  drochner 		edp->nargs++;
   1020  1.1  drochner 		break;
   1021  1.1  drochner 	    case '?': /* DEC specific */
   1022  1.1  drochner 		edp->nargs = 0;
   1023  1.1  drochner 		bzero(edp->args, sizeof (edp->args));
   1024  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_QM;
   1025  1.1  drochner 		break;
   1026  1.1  drochner 	    case '>': /* DA query */
   1027  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_GT;
   1028  1.1  drochner 		break;
   1029  1.1  drochner 	    case '"':
   1030  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_DQ;
   1031  1.1  drochner 		break;
   1032  1.1  drochner 	    case '$':
   1033  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_DOLLAR;
   1034  1.1  drochner 		break;
   1035  1.1  drochner 	    case '&':
   1036  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_AMP;
   1037  1.1  drochner 		break;
   1038  1.1  drochner 	    case '!':
   1039  1.1  drochner 		newstate = VT100_EMUL_STATE_CSI_EM;
   1040  1.1  drochner 		break;
   1041  1.1  drochner 	    default: /* end of escape sequence */
   1042  1.1  drochner 		edp->nargs++;
   1043  1.1  drochner 		if (edp->nargs > VT100_EMUL_NARGS) {
   1044  1.1  drochner #ifdef VT100_DEBUG
   1045  1.1  drochner 			printf("vt100: too many arguments\n");
   1046  1.1  drochner #endif
   1047  1.1  drochner 			edp->nargs = VT100_EMUL_NARGS;
   1048  1.1  drochner 		}
   1049  1.1  drochner 		wsemul_vt100_handle_csi(edp, c);
   1050  1.1  drochner 		newstate = VT100_EMUL_STATE_NORMAL;
   1051  1.1  drochner 		break;
   1052  1.1  drochner 	}
   1053  1.1  drochner 	return (newstate);
   1054  1.1  drochner }
   1055  1.1  drochner 
   1056  1.1  drochner static u_int
   1057  1.1  drochner wsemul_vt100_output_csi_dq(edp, c)
   1058  1.1  drochner 	struct wsemul_vt100_emuldata *edp;
   1059  1.1  drochner 	u_char c;
   1060  1.1  drochner {
   1061  1.1  drochner 	switch (c) {
   1062  1.1  drochner 	    case 'p': /* DECSCL */
   1063  1.1  drochner 		switch (ARG(0)) {
   1064  1.1  drochner 		    case 61: /* VT100 mode (no further arguments!) */
   1065  1.1  drochner 			break;
   1066  1.1  drochner 		    case 62:
   1067  1.1  drochner 		    case 63: /* VT300 mode */
   1068  1.1  drochner 			break;
   1069  1.1  drochner 		    default:
   1070  1.1  drochner #ifdef VT100_PRINTUNKNOWN
   1071  1.1  drochner 			printf("CSI%d\"p unknown\n", ARG(0));
   1072  1.1  drochner #endif
   1073  1.1  drochner 			break;
   1074  1.1  drochner 		}
   1075  1.1  drochner 		switch (ARG(1)) {
   1076  1.1  drochner 		    case 0:
   1077  1.1  drochner 		    case 2: /* 8-bit controls */
   1078  1.1  drochner #ifdef VT100_PRINTNOTIMPL
   1079  1.1  drochner 			printf("CSI%d;%d\"p ignored\n", ARG(0), ARG(1));
   1080  1.1  drochner #endif
   1081  1.1  drochner 			break;
   1082  1.1  drochner 		    case 1: /* 7-bit controls */
   1083  1.1  drochner 			break;
   1084  1.1  drochner 		    default:
   1085  1.1  drochner #ifdef VT100_PRINTUNKNOWN
   1086  1.1  drochner 			printf("CSI%d;%d\"p unknown\n", ARG(0), ARG(1));
   1087  1.1  drochner #endif
   1088  1.1  drochner 			break;
   1089  1.1  drochner 		}
   1090  1.1  drochner 		break;
   1091  1.1  drochner 	    case 'q': /* DECSCA select character attribute VT300 only */
   1092  1.1  drochner 		switch (ARG(0)) {
   1093  1.1  drochner 		    case 0:
   1094  1.1  drochner 		    case 1: /* erasable */
   1095  1.1  drochner 			break;
   1096  1.1  drochner 		    case 2: /* not erasable */
   1097  1.1  drochner #ifdef VT100_PRINTNOTIMPL
   1098  1.1  drochner 			printf("CSI2\"q ignored\n");
   1099  1.1  drochner #endif
   1100  1.1  drochner 			break;
   1101  1.1  drochner 		    default:
   1102  1.1  drochner #ifdef VT100_PRINTUNKNOWN
   1103  1.1  drochner 			printf("CSI%d\"q unknown\n", ARG(0));
   1104  1.1  drochner #endif
   1105  1.1  drochner 			break;
   1106  1.1  drochner 		}
   1107  1.1  drochner 		break;
   1108  1.1  drochner 	    default:
   1109  1.1  drochner #ifdef VT100_PRINTUNKNOWN
   1110  1.1  drochner 		printf("CSI\"%c unknown (%d, %d)\n", c, ARG(0), ARG(1));
   1111  1.1  drochner #endif
   1112  1.1  drochner 		break;
   1113  1.1  drochner 	}
   1114  1.1  drochner 	return (VT100_EMUL_STATE_NORMAL);
   1115  1.1  drochner }
   1116  1.1  drochner 
   1117  1.1  drochner void
   1118  1.1  drochner wsemul_vt100_output(cookie, data, count, kernel)
   1119  1.1  drochner 	void *cookie;
   1120  1.1  drochner 	const u_char *data;
   1121  1.1  drochner 	u_int count;
   1122  1.1  drochner 	int kernel;
   1123  1.1  drochner {
   1124  1.1  drochner 	struct wsemul_vt100_emuldata *edp = cookie;
   1125  1.1  drochner 
   1126  1.1  drochner #ifdef DIAGNOSTIC
   1127  1.1  drochner 	if (kernel && !edp->console)
   1128  1.1  drochner 		panic("wsemul_vt100_output: kernel output, not console");
   1129  1.1  drochner #endif
   1130  1.1  drochner 
   1131  1.1  drochner 	/* XXX */
   1132  1.1  drochner 	(*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
   1133  1.1  drochner 	for (; count > 0; data++, count--) {
   1134  1.1  drochner 		if (edp->state == VT100_EMUL_STATE_NORMAL || kernel) {
   1135  1.1  drochner 			edp->state = wsemul_vt100_output_normal(edp, *data,
   1136  1.1  drochner 								kernel);
   1137  1.1  drochner 			continue;
   1138  1.1  drochner 		}
   1139  1.1  drochner #ifdef DIAGNOSTIC
   1140  1.1  drochner 		if (edp->state > sizeof(vt100_output) / sizeof(vt100_output[0]))
   1141  1.1  drochner 			panic("wsemul_vt100: invalid state %d\n", edp->state);
   1142  1.1  drochner #endif
   1143  1.1  drochner 		edp->state = vt100_output[edp->state - 1](edp, *data);
   1144  1.1  drochner 	}
   1145  1.1  drochner 	/* XXX */
   1146  1.1  drochner 	(*edp->emulops->cursor)(edp->emulcookie, edp->flags & VTFL_CURSORON,
   1147  1.1  drochner 				edp->crow, edp->ccol);
   1148  1.1  drochner }
   1149