Home | History | Annotate | Line # | Download | only in wscons
wsemul_sun.c revision 1.19
      1 /* $NetBSD: wsemul_sun.c,v 1.19 2004/08/03 11:16:30 he Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Christopher G. Demetriou
     17  *	for the NetBSD Project.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /* XXX DESCRIPTION/SOURCE OF INFORMATION */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: wsemul_sun.c,v 1.19 2004/08/03 11:16:30 he Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/time.h>
     41 #include <sys/malloc.h>
     42 #include <sys/fcntl.h>
     43 
     44 #include <dev/wscons/wsconsio.h>
     45 #include <dev/wscons/wsdisplayvar.h>
     46 #include <dev/wscons/wsemulvar.h>
     47 #include <dev/wscons/wsksymdef.h>
     48 #include <dev/wscons/ascii.h>
     49 
     50 void	*wsemul_sun_cnattach(const struct wsscreen_descr *, void *,
     51 				  int, int, long);
     52 void	*wsemul_sun_attach(int console, const struct wsscreen_descr *,
     53 				void *, int, int, void *, long);
     54 void	wsemul_sun_output(void *cookie, const u_char *data, u_int count,
     55 			       int);
     56 int	wsemul_sun_translate(void *cookie, keysym_t, char **);
     57 void	wsemul_sun_detach(void *cookie, u_int *crowp, u_int *ccolp);
     58 void	wsemul_sun_resetop(void *, enum wsemul_resetops);
     59 
     60 const struct wsemul_ops wsemul_sun_ops = {
     61 	"sun",
     62 	wsemul_sun_cnattach,
     63 	wsemul_sun_attach,
     64 	wsemul_sun_output,
     65 	wsemul_sun_translate,
     66 	wsemul_sun_detach,
     67 	wsemul_sun_resetop
     68 };
     69 
     70 #define	SUN_EMUL_STATE_NORMAL	0	/* normal processing */
     71 #define	SUN_EMUL_STATE_HAVEESC	1	/* seen start of ctl seq */
     72 #define	SUN_EMUL_STATE_CONTROL	2	/* processing ctl seq */
     73 
     74 #define	SUN_EMUL_NARGS	2		/* max # of args to a command */
     75 
     76 struct wsemul_sun_emuldata {
     77 	const struct wsdisplay_emulops *emulops;
     78 	void *emulcookie;
     79 	void *cbcookie;
     80 	int scrcapabilities;
     81 	u_int nrows, ncols, crow, ccol;
     82 
     83 	u_int state;			/* processing state */
     84 	u_int args[SUN_EMUL_NARGS];	/* command args, if CONTROL */
     85 	u_int scrolldist;		/* distance to scroll */
     86 	long defattr;			/* default attribute (rendition) */
     87 	long bowattr;			/* attribute for reversed mode */
     88 	int rendflags;
     89 #define REND_BOW 1
     90 #define REND_SO 2
     91 	long curattr;			/* currently used attribute */
     92 	long kernattr;			/* attribute for kernel output */
     93 #ifdef DIAGNOSTIC
     94 	int console;
     95 #endif
     96 };
     97 
     98 static u_int	wsemul_sun_output_normal(struct wsemul_sun_emuldata *,
     99 		    u_char, int);
    100 static u_int	wsemul_sun_output_haveesc(struct wsemul_sun_emuldata *, u_char);
    101 static u_int	wsemul_sun_output_control(struct wsemul_sun_emuldata *, u_char);
    102 static void	wsemul_sun_control(struct wsemul_sun_emuldata *, u_char);
    103 
    104 struct wsemul_sun_emuldata wsemul_sun_console_emuldata;
    105 
    106 /* some useful utility macros */
    107 #define	ARG(n)			(edp->args[(n)])
    108 #define	NORMALIZE_ARG(n)	(ARG(n) ? ARG(n) : 1)
    109 #define	COLS_LEFT		(edp->ncols - edp->ccol - 1)
    110 #define	ROWS_LEFT		(edp->nrows - edp->crow - 1)
    111 
    112 void *
    113 wsemul_sun_cnattach(const struct wsscreen_descr *type, void *cookie,
    114 	int ccol, int crow, long defattr)
    115 {
    116 	struct wsemul_sun_emuldata *edp;
    117 	int res;
    118 
    119 	edp = &wsemul_sun_console_emuldata;
    120 
    121 	edp->emulops = type->textops;
    122 	edp->emulcookie = cookie;
    123 	edp->scrcapabilities = type->capabilities;
    124 	edp->nrows = type->nrows;
    125 	edp->ncols = type->ncols;
    126 	edp->crow = crow;
    127 	edp->ccol = ccol;
    128 	edp->curattr = edp->defattr = defattr;
    129 #if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
    130   defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
    131 #ifndef WS_KERNEL_FG
    132 #define WS_KERNEL_FG WSCOL_WHITE
    133 #endif
    134 #ifndef WS_KERNEL_BG
    135 #define WS_KERNEL_BG WSCOL_BLACK
    136 #endif
    137 #ifndef WS_KERNEL_COLATTR
    138 #define WS_KERNEL_COLATTR 0
    139 #endif
    140 #ifndef WS_KERNEL_MONOATTR
    141 #define WS_KERNEL_MONOATTR 0
    142 #endif
    143 	if (type->capabilities & WSSCREEN_WSCOLORS)
    144 		res = (*edp->emulops->allocattr)(cookie,
    145 					    WS_KERNEL_FG, WS_KERNEL_BG,
    146 					    WS_KERNEL_COLATTR | WSATTR_WSCOLORS,
    147 					    &edp->kernattr);
    148 	else
    149 		res = (*edp->emulops->allocattr)(cookie, 0, 0,
    150 					    WS_KERNEL_MONOATTR,
    151 					    &edp->kernattr);
    152 	if (res)
    153 #else
    154 	res = 0; /* XXX gcc */
    155 #endif
    156 	edp->kernattr = defattr;
    157 
    158 	edp->cbcookie = NULL;
    159 
    160 	edp->state = SUN_EMUL_STATE_NORMAL;
    161 	edp->scrolldist = 1;
    162 #ifdef DIAGNOSTIC
    163 	edp->console = 1;
    164 #endif
    165 	return (edp);
    166 }
    167 
    168 void *
    169 wsemul_sun_attach(int console, const struct wsscreen_descr *type,
    170 	void *cookie, int ccol, int crow, void *cbcookie, long defattr)
    171 {
    172 	struct wsemul_sun_emuldata *edp;
    173 
    174 	if (console) {
    175 		edp = &wsemul_sun_console_emuldata;
    176 #ifdef DIAGNOSTIC
    177 		KASSERT(edp->console == 1);
    178 #endif
    179 	} else {
    180 		edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
    181 
    182 		edp->emulops = type->textops;
    183 		edp->emulcookie = cookie;
    184 		edp->scrcapabilities = type->capabilities;
    185 		edp->nrows = type->nrows;
    186 		edp->ncols = type->ncols;
    187 		edp->crow = crow;
    188 		edp->ccol = ccol;
    189 		edp->defattr = defattr;
    190 
    191 		edp->state = SUN_EMUL_STATE_NORMAL;
    192 		edp->scrolldist = 1;
    193 #ifdef DIAGNOSTIC
    194 		edp->console = 0;
    195 #endif
    196 	}
    197 
    198 	edp->cbcookie = cbcookie;
    199 
    200 	/* XXX This assumes that the default attribute is wob. */
    201 	if ((!(edp->scrcapabilities & WSSCREEN_WSCOLORS) ||
    202 		(*edp->emulops->allocattr)(edp->emulcookie,
    203 					   WSCOL_BLACK, WSCOL_WHITE,
    204 					   WSATTR_WSCOLORS,
    205 					   &edp->bowattr)) &&
    206 	    (!(edp->scrcapabilities & WSSCREEN_REVERSE) ||
    207 		(*edp->emulops->allocattr)(edp->emulcookie, 0, 0,
    208 					   WSATTR_REVERSE,
    209 					   &edp->bowattr)))
    210 		edp->bowattr = edp->defattr;
    211 
    212 	edp->curattr = edp->defattr;
    213 	edp->rendflags = 0;
    214 
    215 	return (edp);
    216 }
    217 
    218 static inline u_int
    219 wsemul_sun_output_normal(struct wsemul_sun_emuldata *edp, u_char c, int kernel)
    220 {
    221 	u_int newstate = SUN_EMUL_STATE_NORMAL;
    222 	u_int n;
    223 
    224 	switch (c) {
    225 	case ASCII_BEL:		/* "Bell (BEL)" */
    226 		wsdisplay_emulbell(edp->cbcookie);
    227 		break;
    228 
    229 	case ASCII_BS:		/* "Backspace (BS)" */
    230 		if (edp->ccol > 0)
    231 			edp->ccol--;
    232 		break;
    233 
    234 	case ASCII_CR:		/* "Return (CR)" */
    235 		edp->ccol = 0;
    236 		break;
    237 
    238 	case ASCII_HT:		/* "Tab (TAB)" */
    239 		n = min(8 - (edp->ccol & 7), COLS_LEFT);
    240 		(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
    241 				edp->ccol, n,
    242 				kernel ? edp->kernattr : edp->curattr);
    243 		edp->ccol += n;
    244 		break;
    245 
    246 	case ASCII_FF:		/* "Form Feed (FF)" */
    247 		(*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
    248 				kernel ? edp->kernattr : edp->curattr);
    249 				/* XXX possible in kernel output? */
    250 		edp->ccol = 0;
    251 		edp->crow = 0;
    252 		break;
    253 
    254 	case ASCII_VT:		/* "Reverse Line Feed" */
    255 		if (edp->crow > 0)
    256 			edp->crow--;
    257 		break;
    258 
    259 	case ASCII_ESC:		/* "Escape (ESC)" */
    260 		if (kernel) {
    261 			printf("wsemul_sun_output_normal: ESC in kernel output ignored\n");
    262 			break;	/* ignore the ESC */
    263 		}
    264 
    265 		if (edp->state == SUN_EMUL_STATE_NORMAL) {
    266 			newstate = SUN_EMUL_STATE_HAVEESC;
    267 			break;
    268 		}
    269 		/* special case: fall through, we're printing one out */
    270 		/* FALLTHRU */
    271 
    272 	default:		/* normal character */
    273 		(*edp->emulops->putchar)(edp->emulcookie, edp->crow, edp->ccol,
    274 		    c, kernel ? edp->kernattr : edp->curattr);
    275 		edp->ccol++;
    276 
    277 		/* if cur col is still on cur line, done. */
    278 		if (edp->ccol < edp->ncols)
    279 			break;
    280 
    281 		/* wrap the column around. */
    282 		edp->ccol = 0;
    283 
    284                	/* FALLTHRU */
    285 
    286 	case ASCII_LF:		/* "Line Feed (LF)" */
    287                 /* if the cur line isn't the last, incr and leave. */
    288 		if (edp->crow < edp->nrows - 1) {
    289 			edp->crow++;
    290 			break;
    291 		}
    292 
    293 		/*
    294 		 * if we're in wrap-around mode, go to the first
    295 		 * line and clear it.
    296 		 */
    297 		if (edp->scrolldist == 0) {
    298 			edp->crow = 0;
    299 			(*edp->emulops->eraserows)(edp->emulcookie, 0, 1,
    300 						   edp->curattr);
    301 			break;
    302 		}
    303 
    304 		/* scroll by the scrolling distance. */
    305 		(*edp->emulops->copyrows)(edp->emulcookie, edp->scrolldist, 0,
    306 		    edp->nrows - edp->scrolldist);
    307 		(*edp->emulops->eraserows)(edp->emulcookie,
    308 		    edp->nrows - edp->scrolldist, edp->scrolldist,
    309 					   edp->curattr);
    310 		edp->crow -= edp->scrolldist - 1;
    311 		break;
    312 	}
    313 
    314 	return (newstate);
    315 }
    316 
    317 static inline u_int
    318 wsemul_sun_output_haveesc(struct wsemul_sun_emuldata *edp, u_char c)
    319 {
    320 	u_int newstate;
    321 
    322 	switch (c) {
    323 	case '[':		/* continuation of multi-char sequence */
    324 		memset(edp->args, 0, sizeof (edp->args));
    325 		newstate = SUN_EMUL_STATE_CONTROL;
    326 		break;
    327 
    328 	default:
    329 		/* spit out the escape char (???), then the new character */
    330 		wsemul_sun_output_normal(edp, ASCII_ESC, 0);	/* ??? */
    331 		newstate = wsemul_sun_output_normal(edp, c, 0);
    332 		break;
    333 	}
    334 
    335 	return (newstate);
    336 }
    337 
    338 static inline void
    339 wsemul_sun_control(struct wsemul_sun_emuldata *edp, u_char c)
    340 {
    341 	u_int n, src, dst;
    342 
    343 	switch (c) {
    344 	case '@':		/* "Insert Character (ICH)" */
    345 		n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
    346 		src = edp->ccol;
    347 		dst = edp->ccol + n;
    348 		if (dst < edp->ncols) {
    349 			(*edp->emulops->copycols)(edp->emulcookie, edp->crow,
    350 			    src, dst, edp->ncols - dst);
    351 		}
    352 		(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
    353 		    src, dst - src, edp->curattr);
    354 		break;
    355 
    356 	case 'A':		/* "Cursor Up (CUU)" */
    357 		edp->crow -= min(NORMALIZE_ARG(0), edp->crow);
    358 		break;
    359 
    360 	case 'E':		/* "Cursor Next Line (CNL)" */
    361 		edp->ccol = 0;
    362 		/* FALLTHRU */
    363 	case 'B':		/* "Cursor Down (CUD)" */
    364 		edp->crow += min(NORMALIZE_ARG(0), ROWS_LEFT);
    365 		break;
    366 
    367 	case 'C':		/* "Cursor Forward (CUF)" */
    368 		edp->ccol += min(NORMALIZE_ARG(0), COLS_LEFT);
    369 		break;
    370 
    371 	case 'D':		/* "Cursor Backward (CUB)" */
    372 		edp->ccol -= min(NORMALIZE_ARG(0), edp->ccol);
    373 		break;
    374 
    375 	case 'f':		/* "Horizontal And Vertical Position (HVP)" */
    376 	case 'H':		/* "Cursor Position (CUP)" */
    377 		edp->crow = min(NORMALIZE_ARG(1), edp->nrows) - 1;
    378 		edp->ccol = min(NORMALIZE_ARG(0), edp->ncols) - 1;
    379 		break;
    380 
    381 	case 'J':		/* "Erase in Display (ED)" */
    382 		if (ROWS_LEFT > 0) {
    383 			(*edp->emulops->eraserows)(edp->emulcookie,
    384 			     edp->crow + 1, ROWS_LEFT, edp->curattr);
    385 		}
    386 		/* FALLTHRU */
    387 	case 'K':		/* "Erase in Line (EL)" */
    388 		(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
    389 		    edp->ccol, COLS_LEFT + 1, edp->curattr);
    390 		break;
    391 
    392 	case 'L':		/* "Insert Line (IL)" */
    393 		n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
    394 		src = edp->crow;
    395 		dst = edp->crow + n;
    396 		if (dst < edp->nrows) {
    397 			(*edp->emulops->copyrows)(edp->emulcookie,
    398 			    src, dst, edp->nrows - dst);
    399 		}
    400 		(*edp->emulops->eraserows)(edp->emulcookie,
    401 		    src, dst - src, edp->curattr);
    402 		break;
    403 
    404 	case 'M':		/* "Delete Line (DL)" */
    405 		n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
    406 		src = edp->crow + n;
    407 		dst = edp->crow;
    408 		if (src < edp->nrows) {
    409 			(*edp->emulops->copyrows)(edp->emulcookie,
    410 			    src, dst, edp->nrows - src);
    411 		}
    412 		(*edp->emulops->eraserows)(edp->emulcookie,
    413 		    dst + edp->nrows - src, src - dst, edp->curattr);
    414 		break;
    415 
    416 	case 'P':		/* "Delete Character (DCH)" */
    417 		n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
    418 		src = edp->ccol + n;
    419 		dst = edp->ccol;
    420 		if (src < edp->ncols) {
    421 			(*edp->emulops->copycols)(edp->emulcookie, edp->crow,
    422 			    src, dst, edp->ncols - src);
    423 		}
    424 		(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
    425 		    dst + edp->ncols - src, src - dst, edp->curattr);
    426 		break;
    427 
    428 	case 'm':		/* "Select Graphic Rendition (SGR)" */
    429 		if (ARG(0))
    430 			edp->rendflags |= REND_SO;
    431 		else
    432 			edp->rendflags &= ~REND_SO;
    433 		goto setattr;
    434 
    435 	case 'p':		/* "Black On White (SUNBOW)" */
    436 		edp->rendflags |= REND_BOW;
    437 		goto setattr;
    438 
    439 	case 'q':		/* "White On Black (SUNWOB)" */
    440 		edp->rendflags &= ~REND_BOW;
    441 		goto setattr;
    442 
    443 	case 'r':		/* "Set Scrolling (SUNSCRL)" */
    444 		edp->scrolldist = min(ARG(0), edp->nrows);
    445 		break;
    446 
    447 	case 's':		/* "Reset Terminal Emulator (SUNRESET)" */
    448 		edp->scrolldist = 1;
    449 		edp->rendflags = 0;
    450 setattr:
    451 		if (((edp->rendflags & REND_BOW) != 0) ^
    452 		    ((edp->rendflags & REND_SO) != 0))
    453 			edp->curattr = edp->bowattr;
    454 		else
    455 			edp->curattr = edp->defattr;
    456 		break;
    457 	}
    458 }
    459 
    460 static inline u_int
    461 wsemul_sun_output_control(struct wsemul_sun_emuldata *edp, u_char c)
    462 {
    463 	u_int newstate = SUN_EMUL_STATE_CONTROL;
    464 	u_int i;
    465 
    466 	switch (c) {
    467 	case '0': case '1': case '2': case '3': case '4': /* argument digit */
    468 	case '5': case '6': case '7': case '8': case '9':
    469 		edp->args[0] = (edp->args[0] * 10) + (c - '0');
    470                 break;
    471 
    472 	case ';':		/* argument terminator */
    473 		for (i = 1; i < SUN_EMUL_NARGS; i++)
    474 			edp->args[i] = edp->args[i - 1];
    475 		edp->args[0] = 0;
    476 		break;
    477 
    478 	default:		/* end of escape sequence */
    479 		wsemul_sun_control(edp, c);
    480 		newstate = SUN_EMUL_STATE_NORMAL;
    481 		break;
    482 	}
    483 	return (newstate);
    484 }
    485 
    486 void
    487 wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
    488 {
    489 	struct wsemul_sun_emuldata *edp = cookie;
    490 	u_int newstate;
    491 
    492 #ifdef DIAGNOSTIC
    493 	if (kernel && !edp->console)
    494 		panic("wsemul_sun_output: kernel output, not console");
    495 #endif
    496 
    497 	/* XXX */
    498 	(*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
    499 	for (; count > 0; data++, count--) {
    500 		if (kernel) {
    501 			wsemul_sun_output_normal(edp, *data, 1);
    502 			continue;
    503 		}
    504 		switch (edp->state) {
    505 		case SUN_EMUL_STATE_NORMAL:
    506 			/* XXX SCAN INPUT FOR NEWLINES, DO PRESCROLLING */
    507 			newstate = wsemul_sun_output_normal(edp, *data, 0);
    508 			break;
    509 		case SUN_EMUL_STATE_HAVEESC:
    510 			newstate = wsemul_sun_output_haveesc(edp, *data);
    511 			break;
    512 		case SUN_EMUL_STATE_CONTROL:
    513 			newstate = wsemul_sun_output_control(edp, *data);
    514 			break;
    515 		default:
    516 #ifdef DIAGNOSTIC
    517 			panic("wsemul_sun: invalid state %d", edp->state);
    518 #endif
    519                         /* try to recover, if things get screwed up... */
    520 			newstate = wsemul_sun_output_normal(edp, *data, 0);
    521                         break;
    522 		}
    523 		edp->state = newstate;
    524 	}
    525 	/* XXX */
    526 	(*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol);
    527 }
    528 
    529 static char *sun_fkeys[] = {
    530 	"\033[224z",	/* F1 */
    531 	"\033[225z",
    532 	"\033[226z",
    533 	"\033[227z",
    534 	"\033[228z",
    535 	"\033[229z",
    536 	"\033[230z",
    537 	"\033[231z",
    538 	"\033[232z",
    539 	"\033[233z",	/* F10 */
    540 };
    541 
    542 int
    543 wsemul_sun_translate(void *cookie, keysym_t in, char **out)
    544 {
    545 	static char c;
    546 
    547 	if (KS_GROUP(in) == KS_GROUP_Keypad && (in & 0x80) == 0) {
    548 		c = in & 0xff; /* turn into ASCII */
    549 		*out = &c;
    550 		return (1);
    551 	}
    552 
    553 	if (in >= KS_f1 && in <= KS_f10) {
    554 		*out = sun_fkeys[in - KS_f1];
    555 		return (6);
    556 	}
    557 	if (in >= KS_F1 && in <= KS_F10) {
    558 		*out = sun_fkeys[in - KS_F1];
    559 		return (6);
    560 	}
    561 	if (in >= KS_KP_F1 && in <= KS_KP_F4) {
    562 		*out = sun_fkeys[in - KS_KP_F1];
    563 		return (6);
    564 	}
    565 
    566 	switch (in) {
    567 	case KS_Home:
    568 	case KS_KP_Home:
    569 	case KS_KP_Begin:
    570 		*out = "\033[214z";
    571 		return (6);
    572 	case KS_Prior:
    573 	case KS_KP_Prior:
    574 		*out = "\033[216z";
    575 		return (6);
    576 	case KS_Next:
    577 	case KS_KP_Next:
    578 		*out = "\033[222z";
    579 		return (6);
    580 	case KS_Up:
    581 	case KS_KP_Up:
    582 		*out = "\033[A";
    583 		return (3);
    584 	case KS_Down:
    585 	case KS_KP_Down:
    586 		*out = "\033[B";
    587 		return (3);
    588 	case KS_Left:
    589 	case KS_KP_Left:
    590 		*out = "\033[D";
    591 		return (3);
    592 	case KS_Right:
    593 	case KS_KP_Right:
    594 		*out = "\033[C";
    595 		return (3);
    596 	case KS_KP_Delete:
    597 		*out = "\177";
    598 		return (1);
    599 	}
    600 	return (0);
    601 }
    602 
    603 void
    604 wsemul_sun_detach(void *cookie, u_int *crowp, u_int *ccolp)
    605 {
    606 	struct wsemul_sun_emuldata *edp = cookie;
    607 
    608 	*crowp = edp->crow;
    609 	*ccolp = edp->ccol;
    610 	if (edp != &wsemul_sun_console_emuldata)
    611 		free(edp, M_DEVBUF);
    612 }
    613 
    614 void
    615 wsemul_sun_resetop(void *cookie, enum wsemul_resetops op)
    616 {
    617 	struct wsemul_sun_emuldata *edp = cookie;
    618 
    619 	switch (op) {
    620 	case WSEMUL_RESET:
    621 		edp->state = SUN_EMUL_STATE_NORMAL;
    622 		edp->scrolldist = 1;
    623 		edp->rendflags = 0;
    624 		edp->curattr = edp->defattr;
    625 		break;
    626 	case WSEMUL_CLEARSCREEN:
    627 		(*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
    628 					   edp->defattr);
    629 		edp->ccol = edp->crow = 0;
    630 		(*edp->emulops->cursor)(edp->emulcookie, 1, 0, 0);
    631 		break;
    632 	default:
    633 		break;
    634 	}
    635 }
    636