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