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