1999-01-17 18:44:57 +03:00
|
|
|
/* $NetBSD: wsemul_sun.c,v 1.10 1999/01/17 15:44:57 drochner Exp $ */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Christopher G. Demetriou
|
|
|
|
* for the NetBSD Project.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char _copyright[] __attribute__ ((unused)) =
|
|
|
|
"Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.";
|
|
|
|
static const char _rcsid[] __attribute__ ((unused)) =
|
1999-01-17 18:44:57 +03:00
|
|
|
"$NetBSD: wsemul_sun.c,v 1.10 1999/01/17 15:44:57 drochner Exp $";
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/* XXX DESCRIPTION/SOURCE OF INFORMATION */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wsdisplayvar.h>
|
|
|
|
#include <dev/wscons/wsemulvar.h>
|
1998-06-15 21:48:32 +04:00
|
|
|
#include <dev/wscons/wsksymdef.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
#include <dev/wscons/ascii.h>
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
#include "opt_wskernattr.h"
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
void *wsemul_sun_cnattach __P((const struct wsscreen_descr *, void *,
|
1998-05-15 00:49:55 +04:00
|
|
|
int, int, long));
|
1998-03-22 17:24:02 +03:00
|
|
|
void *wsemul_sun_attach __P((int console, const struct wsscreen_descr *,
|
1998-05-15 00:49:55 +04:00
|
|
|
void *, int, int, void *, long));
|
|
|
|
void wsemul_sun_output __P((void *cookie, const u_char *data, u_int count,
|
|
|
|
int));
|
1998-06-15 21:48:32 +04:00
|
|
|
int wsemul_sun_translate __P((void *cookie, keysym_t, char **));
|
1998-03-22 17:24:02 +03:00
|
|
|
void wsemul_sun_detach __P((void *cookie, u_int *crowp, u_int *ccolp));
|
1999-01-17 18:44:57 +03:00
|
|
|
void wsemul_sun_resetop __P((void *, enum wsemul_resetops));
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
const struct wsemul_ops wsemul_sun_ops = {
|
|
|
|
"sun",
|
|
|
|
wsemul_sun_cnattach,
|
|
|
|
wsemul_sun_attach,
|
|
|
|
wsemul_sun_output,
|
1998-06-15 21:48:32 +04:00
|
|
|
wsemul_sun_translate,
|
1998-03-22 17:24:02 +03:00
|
|
|
wsemul_sun_detach,
|
1999-01-17 18:44:57 +03:00
|
|
|
wsemul_sun_resetop
|
1998-03-22 17:24:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SUN_EMUL_STATE_NORMAL 0 /* normal processing */
|
|
|
|
#define SUN_EMUL_STATE_HAVEESC 1 /* seen start of ctl seq */
|
|
|
|
#define SUN_EMUL_STATE_CONTROL 2 /* processing ctl seq */
|
|
|
|
|
|
|
|
#define SUN_EMUL_NARGS 2 /* max # of args to a command */
|
|
|
|
|
|
|
|
struct wsemul_sun_emuldata {
|
|
|
|
const struct wsdisplay_emulops *emulops;
|
|
|
|
void *emulcookie;
|
|
|
|
void *cbcookie;
|
1998-05-15 00:49:55 +04:00
|
|
|
int scrcapabilities;
|
1998-03-22 17:24:02 +03:00
|
|
|
u_int nrows, ncols, crow, ccol;
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
u_int state; /* processing state */
|
|
|
|
u_int args[SUN_EMUL_NARGS]; /* command args, if CONTROL */
|
|
|
|
u_int scrolldist; /* distance to scroll */
|
|
|
|
long defattr; /* default attribute (rendition) */
|
|
|
|
long bowattr; /* attribute for reversed mode */
|
|
|
|
int rendflags;
|
|
|
|
#define REND_BOW 1
|
|
|
|
#define REND_SO 2
|
|
|
|
long curattr; /* currently used attribute */
|
|
|
|
long kernattr; /* attribute for kernel output */
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
int console;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static u_int wsemul_sun_output_normal __P((struct wsemul_sun_emuldata *,
|
1998-05-15 00:49:55 +04:00
|
|
|
u_char, int));
|
1998-03-22 17:24:02 +03:00
|
|
|
static u_int wsemul_sun_output_haveesc __P((struct wsemul_sun_emuldata *,
|
|
|
|
u_char));
|
|
|
|
static u_int wsemul_sun_output_control __P((struct wsemul_sun_emuldata *,
|
|
|
|
u_char));
|
|
|
|
static void wsemul_sun_control __P((struct wsemul_sun_emuldata *, u_char));
|
|
|
|
|
|
|
|
struct wsemul_sun_emuldata wsemul_sun_console_emuldata;
|
|
|
|
|
|
|
|
/* some useful utility macros */
|
|
|
|
#define ARG(n) (edp->args[(n)])
|
|
|
|
#define NORMALIZE_ARG(n) (ARG(n) ? ARG(n) : 1)
|
|
|
|
#define COLS_LEFT (edp->ncols - edp->ccol - 1)
|
|
|
|
#define ROWS_LEFT (edp->nrows - edp->crow - 1)
|
|
|
|
|
|
|
|
void *
|
1998-05-15 00:49:55 +04:00
|
|
|
wsemul_sun_cnattach(type, cookie, ccol, crow, defattr)
|
1998-03-22 17:24:02 +03:00
|
|
|
const struct wsscreen_descr *type;
|
|
|
|
void *cookie;
|
|
|
|
int ccol, crow;
|
1998-05-15 00:49:55 +04:00
|
|
|
long defattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
struct wsemul_sun_emuldata *edp;
|
1998-05-15 00:49:55 +04:00
|
|
|
int res;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
edp = &wsemul_sun_console_emuldata;
|
|
|
|
|
|
|
|
edp->emulops = type->textops;
|
|
|
|
edp->emulcookie = cookie;
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->scrcapabilities = type->capabilities;
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->nrows = type->nrows;
|
|
|
|
edp->ncols = type->ncols;
|
|
|
|
edp->crow = crow;
|
|
|
|
edp->ccol = ccol;
|
1998-05-19 22:47:13 +04:00
|
|
|
edp->curattr = edp->defattr = defattr;
|
1998-05-15 00:49:55 +04:00
|
|
|
#if defined(WS_KERNEL_FG) || defined(WS_KERNEL_BG) || \
|
|
|
|
defined(WS_KERNEL_COLATTR) || defined(WS_KERNEL_MONOATTR)
|
|
|
|
#ifndef WS_KERNEL_FG
|
|
|
|
#define WS_KERNEL_FG WSCOL_WHITE
|
|
|
|
#endif
|
|
|
|
#ifndef WS_KERNEL_BG
|
|
|
|
#define WS_KERNEL_BG WSCOL_BLACK
|
|
|
|
#endif
|
|
|
|
#ifndef WS_KERNEL_COLATTR
|
|
|
|
#define WS_KERNEL_COLATTR 0
|
|
|
|
#endif
|
|
|
|
#ifndef WS_KERNEL_MONOATTR
|
|
|
|
#define WS_KERNEL_MONOATTR 0
|
|
|
|
#endif
|
|
|
|
if (type->capabilities & WSSCREEN_WSCOLORS)
|
|
|
|
res = (*edp->emulops->alloc_attr)(cookie,
|
|
|
|
WS_KERNEL_FG, WS_KERNEL_BG,
|
|
|
|
WS_KERNEL_COLATTR | WSATTR_WSCOLORS,
|
|
|
|
&edp->kernattr);
|
|
|
|
else
|
|
|
|
res = (*edp->emulops->alloc_attr)(cookie, 0, 0,
|
|
|
|
WS_KERNEL_MONOATTR,
|
|
|
|
&edp->kernattr);
|
|
|
|
if (res)
|
|
|
|
#else
|
|
|
|
res = 0; /* XXX gcc */
|
|
|
|
#endif
|
|
|
|
edp->kernattr = defattr;
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->cbcookie = NULL;
|
|
|
|
|
|
|
|
edp->state = SUN_EMUL_STATE_NORMAL;
|
|
|
|
edp->scrolldist = 1;
|
1998-05-15 00:49:55 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
edp->console = 1;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
return (edp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
1998-05-15 00:49:55 +04:00
|
|
|
wsemul_sun_attach(console, type, cookie, ccol, crow, cbcookie, defattr)
|
1998-03-22 17:24:02 +03:00
|
|
|
int console;
|
|
|
|
const struct wsscreen_descr *type;
|
|
|
|
void *cookie;
|
|
|
|
int ccol, crow;
|
|
|
|
void *cbcookie;
|
1998-05-15 00:49:55 +04:00
|
|
|
long defattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
struct wsemul_sun_emuldata *edp;
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
if (console) {
|
1998-03-22 17:24:02 +03:00
|
|
|
edp = &wsemul_sun_console_emuldata;
|
1998-05-15 00:49:55 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
KASSERT(edp->console == 1);
|
|
|
|
#endif
|
|
|
|
} else {
|
1998-03-22 17:24:02 +03:00
|
|
|
edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
|
|
|
|
|
|
|
|
edp->emulops = type->textops;
|
|
|
|
edp->emulcookie = cookie;
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->scrcapabilities = type->capabilities;
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->nrows = type->nrows;
|
|
|
|
edp->ncols = type->ncols;
|
|
|
|
edp->crow = crow;
|
|
|
|
edp->ccol = ccol;
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->defattr = defattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
edp->state = SUN_EMUL_STATE_NORMAL;
|
|
|
|
edp->scrolldist = 1;
|
1998-05-15 00:49:55 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
edp->console = 0;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
edp->cbcookie = cbcookie;
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
/* XXX This assumes that the default attribute is wob. */
|
|
|
|
if ((!(edp->scrcapabilities & WSSCREEN_WSCOLORS) ||
|
|
|
|
(*edp->emulops->alloc_attr)(edp->emulcookie,
|
|
|
|
WSCOL_BLACK, WSCOL_WHITE,
|
|
|
|
WSATTR_WSCOLORS,
|
|
|
|
&edp->bowattr)) &&
|
|
|
|
(!(edp->scrcapabilities & WSSCREEN_REVERSE) ||
|
|
|
|
(*edp->emulops->alloc_attr)(edp->emulcookie, 0, 0,
|
|
|
|
WSATTR_REVERSE,
|
|
|
|
&edp->bowattr)))
|
|
|
|
edp->bowattr = edp->defattr;
|
|
|
|
|
|
|
|
edp->curattr = edp->defattr;
|
|
|
|
edp->rendflags = 0;
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
return (edp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u_int
|
1998-05-15 00:49:55 +04:00
|
|
|
wsemul_sun_output_normal(edp, c, kernel)
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wsemul_sun_emuldata *edp;
|
|
|
|
u_char c;
|
1998-05-15 00:49:55 +04:00
|
|
|
int kernel;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
u_int newstate = SUN_EMUL_STATE_NORMAL;
|
|
|
|
u_int n;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case ASCII_BEL: /* "Bell (BEL)" */
|
|
|
|
wsdisplay_emulbell(edp->cbcookie);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASCII_BS: /* "Backspace (BS)" */
|
|
|
|
if (edp->ccol > 0)
|
|
|
|
edp->ccol--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASCII_CR: /* "Return (CR)" */
|
|
|
|
edp->ccol = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASCII_HT: /* "Tab (TAB)" */
|
1998-03-27 21:22:36 +03:00
|
|
|
n = min(8 - (edp->ccol & 7), COLS_LEFT);
|
1998-03-22 17:24:02 +03:00
|
|
|
(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->ccol, n,
|
|
|
|
kernel ? edp->kernattr : edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->ccol += n;
|
|
|
|
break;
|
|
|
|
|
1998-06-20 23:11:04 +04:00
|
|
|
case ASCII_FF: /* "Form Feed (FF)" */
|
1998-05-15 00:49:55 +04:00
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
|
|
|
|
kernel ? edp->kernattr : edp->curattr);
|
|
|
|
/* XXX possible in kernel output? */
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->ccol = 0;
|
|
|
|
edp->crow = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASCII_VT: /* "Reverse Line Feed" */
|
|
|
|
if (edp->crow > 0)
|
|
|
|
edp->crow--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASCII_ESC: /* "Escape (ESC)" */
|
1998-05-15 00:49:55 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (kernel)
|
|
|
|
panic("ESC in kernel output");
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
if (edp->state == SUN_EMUL_STATE_NORMAL) {
|
|
|
|
newstate = SUN_EMUL_STATE_HAVEESC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* special case: fall through, we're printing one out */
|
|
|
|
/* FALLTHRU */
|
|
|
|
|
|
|
|
default: /* normal character */
|
1998-06-21 01:52:49 +04:00
|
|
|
(*edp->emulops->putchar)(edp->emulcookie, edp->crow, edp->ccol,
|
|
|
|
c, kernel ? edp->kernattr : edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->ccol++;
|
|
|
|
|
|
|
|
/* if cur col is still on cur line, done. */
|
|
|
|
if (edp->ccol < edp->ncols)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* wrap the column around. */
|
|
|
|
edp->ccol = 0;
|
|
|
|
|
|
|
|
/* FALLTHRU */
|
|
|
|
|
|
|
|
case ASCII_LF: /* "Line Feed (LF)" */
|
|
|
|
/* if the cur line isn't the last, incr and leave. */
|
|
|
|
if (edp->crow < edp->nrows - 1) {
|
|
|
|
edp->crow++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we're in wrap-around mode, go to the first
|
|
|
|
* line and clear it.
|
|
|
|
*/
|
|
|
|
if (edp->scrolldist == 0) {
|
|
|
|
edp->crow = 0;
|
1998-05-15 00:49:55 +04:00
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie, 0, 1,
|
|
|
|
edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scroll by the scrolling distance. */
|
|
|
|
(*edp->emulops->copyrows)(edp->emulcookie, edp->scrolldist, 0,
|
|
|
|
edp->nrows - edp->scrolldist);
|
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie,
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->nrows - edp->scrolldist, edp->scrolldist,
|
|
|
|
edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
edp->crow -= edp->scrolldist - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (newstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u_int
|
|
|
|
wsemul_sun_output_haveesc(edp, c)
|
|
|
|
struct wsemul_sun_emuldata *edp;
|
|
|
|
u_char c;
|
|
|
|
{
|
|
|
|
u_int newstate;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '[': /* continuation of multi-char sequence */
|
1999-01-10 03:28:21 +03:00
|
|
|
memset(edp->args, 0, sizeof (edp->args));
|
1998-03-22 17:24:02 +03:00
|
|
|
newstate = SUN_EMUL_STATE_CONTROL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* spit out the escape char (???), then the new character */
|
1998-05-15 00:49:55 +04:00
|
|
|
wsemul_sun_output_normal(edp, ASCII_ESC, 0); /* ??? */
|
|
|
|
newstate = wsemul_sun_output_normal(edp, c, 0);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (newstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
wsemul_sun_control(edp, c)
|
|
|
|
struct wsemul_sun_emuldata *edp;
|
|
|
|
u_char c;
|
|
|
|
{
|
|
|
|
u_int n, src, dst;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '@': /* "Insert Character (ICH)" */
|
|
|
|
n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
|
|
|
|
src = edp->ccol;
|
|
|
|
dst = edp->ccol + n;
|
|
|
|
if (dst < edp->ncols) {
|
|
|
|
(*edp->emulops->copycols)(edp->emulcookie, edp->crow,
|
|
|
|
src, dst, edp->ncols - dst);
|
|
|
|
}
|
|
|
|
(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
|
1998-05-15 00:49:55 +04:00
|
|
|
src, dst - src, edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A': /* "Cursor Up (CUU)" */
|
|
|
|
edp->crow -= min(NORMALIZE_ARG(0), edp->crow);
|
|
|
|
break;
|
|
|
|
|
1998-05-24 14:56:16 +04:00
|
|
|
case 'E': /* "Cursor Next Line (CNL)" */
|
|
|
|
edp->ccol = 0;
|
|
|
|
/* FALLTHRU */
|
1998-03-22 17:24:02 +03:00
|
|
|
case 'B': /* "Cursor Down (CUD)" */
|
|
|
|
edp->crow += min(NORMALIZE_ARG(0), ROWS_LEFT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': /* "Cursor Forward (CUF)" */
|
|
|
|
edp->ccol += min(NORMALIZE_ARG(0), COLS_LEFT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D': /* "Cursor Backward (CUB)" */
|
|
|
|
edp->ccol -= min(NORMALIZE_ARG(0), edp->ccol);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': /* "Horizontal And Vertical Position (HVP)" */
|
|
|
|
case 'H': /* "Cursor Position (CUP)" */
|
|
|
|
edp->crow = min(NORMALIZE_ARG(1), edp->nrows) - 1;
|
|
|
|
edp->ccol = min(NORMALIZE_ARG(0), edp->ncols) - 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'J': /* "Erase in Display (ED)" */
|
|
|
|
if (ROWS_LEFT > 0) {
|
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie,
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->crow + 1, ROWS_LEFT, edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
/* FALLTHRU */
|
|
|
|
case 'K': /* "Erase in Line (EL)" */
|
|
|
|
(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->ccol, COLS_LEFT + 1, edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L': /* "Insert Line (IL)" */
|
|
|
|
n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
|
|
|
|
src = edp->crow;
|
|
|
|
dst = edp->crow + n;
|
|
|
|
if (dst < edp->nrows) {
|
|
|
|
(*edp->emulops->copyrows)(edp->emulcookie,
|
|
|
|
src, dst, edp->nrows - dst);
|
|
|
|
}
|
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie,
|
1998-05-15 00:49:55 +04:00
|
|
|
src, dst - src, edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M': /* "Delete Line (DL)" */
|
|
|
|
n = min(NORMALIZE_ARG(0), ROWS_LEFT + 1);
|
|
|
|
src = edp->crow + n;
|
|
|
|
dst = edp->crow;
|
|
|
|
if (src < edp->nrows) {
|
|
|
|
(*edp->emulops->copyrows)(edp->emulcookie,
|
|
|
|
src, dst, edp->nrows - src);
|
|
|
|
}
|
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie,
|
1998-05-15 00:49:55 +04:00
|
|
|
dst + edp->nrows - src, src - dst, edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P': /* "Delete Character (DCH)" */
|
|
|
|
n = min(NORMALIZE_ARG(0), COLS_LEFT + 1);
|
|
|
|
src = edp->ccol + n;
|
|
|
|
dst = edp->ccol;
|
|
|
|
if (src < edp->ncols) {
|
|
|
|
(*edp->emulops->copycols)(edp->emulcookie, edp->crow,
|
|
|
|
src, dst, edp->ncols - src);
|
|
|
|
}
|
|
|
|
(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
|
1998-05-15 00:49:55 +04:00
|
|
|
dst + edp->ncols - src, src - dst, edp->curattr);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm': /* "Select Graphic Rendition (SGR)" */
|
1998-05-15 00:49:55 +04:00
|
|
|
if (ARG(0))
|
|
|
|
edp->rendflags |= REND_SO;
|
|
|
|
else
|
|
|
|
edp->rendflags &= ~REND_SO;
|
|
|
|
goto setattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
case 'p': /* "Black On White (SUNBOW)" */
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->rendflags |= REND_BOW;
|
|
|
|
goto setattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
case 'q': /* "White On Black (SUNWOB)" */
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->rendflags &= ~REND_BOW;
|
|
|
|
goto setattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
case 'r': /* "Set Scrolling (SUNSCRL)" */
|
1998-03-27 21:22:36 +03:00
|
|
|
edp->scrolldist = min(ARG(0), edp->nrows);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* "Reset Terminal Emulator (SUNRESET)" */
|
|
|
|
edp->scrolldist = 1;
|
1998-05-15 00:49:55 +04:00
|
|
|
edp->rendflags = 0;
|
|
|
|
setattr:
|
|
|
|
if (((edp->rendflags & REND_BOW) != 0) ^
|
|
|
|
((edp->rendflags & REND_SO) != 0))
|
|
|
|
edp->curattr = edp->bowattr;
|
|
|
|
else
|
|
|
|
edp->curattr = edp->defattr;
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u_int
|
|
|
|
wsemul_sun_output_control(edp, c)
|
|
|
|
struct wsemul_sun_emuldata *edp;
|
|
|
|
u_char c;
|
|
|
|
{
|
|
|
|
u_int newstate = SUN_EMUL_STATE_CONTROL;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '0': case '1': case '2': case '3': case '4': /* argument digit */
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
edp->args[0] = (edp->args[0] * 10) + (c - '0');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ';': /* argument terminator */
|
|
|
|
for (i = 1; i < SUN_EMUL_NARGS; i++)
|
|
|
|
edp->args[i] = edp->args[i - 1];
|
|
|
|
edp->args[0] = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* end of escape sequence */
|
|
|
|
wsemul_sun_control(edp, c);
|
|
|
|
newstate = SUN_EMUL_STATE_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (newstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-15 00:49:55 +04:00
|
|
|
wsemul_sun_output(cookie, data, count, kernel)
|
1998-03-22 17:24:02 +03:00
|
|
|
void *cookie;
|
|
|
|
const u_char *data;
|
|
|
|
u_int count;
|
1998-05-15 00:49:55 +04:00
|
|
|
int kernel;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
struct wsemul_sun_emuldata *edp = cookie;
|
|
|
|
u_int newstate;
|
|
|
|
|
1998-05-15 00:49:55 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (kernel && !edp->console)
|
|
|
|
panic("wsemul_sun_output: kernel output, not console");
|
|
|
|
#endif
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/* XXX */
|
|
|
|
(*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
|
|
|
|
for (; count > 0; data++, count--) {
|
1998-05-15 00:49:55 +04:00
|
|
|
if (kernel) {
|
|
|
|
wsemul_sun_output_normal(edp, *data, 1);
|
|
|
|
continue;
|
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
switch (edp->state) {
|
|
|
|
case SUN_EMUL_STATE_NORMAL:
|
|
|
|
/* XXX SCAN INPUT FOR NEWLINES, DO PRESCROLLING */
|
1998-05-15 00:49:55 +04:00
|
|
|
newstate = wsemul_sun_output_normal(edp, *data, 0);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
case SUN_EMUL_STATE_HAVEESC:
|
|
|
|
newstate = wsemul_sun_output_haveesc(edp, *data);
|
|
|
|
break;
|
|
|
|
case SUN_EMUL_STATE_CONTROL:
|
|
|
|
newstate = wsemul_sun_output_control(edp, *data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("wsemul_sun: invalid state %d\n", edp->state);
|
|
|
|
#endif
|
|
|
|
/* try to recover, if things get screwed up... */
|
1998-05-15 00:49:55 +04:00
|
|
|
newstate = wsemul_sun_output_normal(edp, *data, 0);
|
1998-03-22 17:24:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
edp->state = newstate;
|
|
|
|
}
|
|
|
|
/* XXX */
|
|
|
|
(*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol);
|
|
|
|
}
|
|
|
|
|
1998-06-15 21:48:32 +04:00
|
|
|
static char *sun_fkeys[] = {
|
|
|
|
"\033[224z", /* F1 */
|
|
|
|
"\033[225z",
|
|
|
|
"\033[226z",
|
|
|
|
"\033[227z",
|
|
|
|
"\033[228z",
|
|
|
|
"\033[229z",
|
|
|
|
"\033[230z",
|
|
|
|
"\033[231z",
|
|
|
|
"\033[232z",
|
|
|
|
"\033[233z", /* F10 */
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
wsemul_sun_translate(cookie, in, out)
|
|
|
|
void *cookie;
|
|
|
|
keysym_t in;
|
|
|
|
char **out;
|
|
|
|
{
|
|
|
|
static char c;
|
|
|
|
|
|
|
|
if (KS_GROUP(in) == KS_GROUP_Keypad && (in & 0x80) == 0) {
|
|
|
|
c = in & 0xff; /* turn into ASCII */
|
|
|
|
*out = &c;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in >= KS_f1 && in <= KS_f10) {
|
|
|
|
*out = sun_fkeys[in - KS_f1];
|
|
|
|
return (6);
|
|
|
|
}
|
|
|
|
if (in >= KS_F1 && in <= KS_F10) {
|
|
|
|
*out = sun_fkeys[in - KS_F1];
|
|
|
|
return (6);
|
|
|
|
}
|
|
|
|
if (in >= KS_KP_F1 && in <= KS_KP_F4) {
|
|
|
|
*out = sun_fkeys[in - KS_KP_F1];
|
|
|
|
return (6);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (in) {
|
|
|
|
case KS_Home:
|
|
|
|
case KS_KP_Home:
|
|
|
|
case KS_KP_Begin:
|
|
|
|
*out = "\033[214z";
|
|
|
|
return (6);
|
|
|
|
case KS_Prior:
|
|
|
|
case KS_KP_Prior:
|
|
|
|
*out = "\033[216z";
|
|
|
|
return (6);
|
|
|
|
case KS_Next:
|
|
|
|
case KS_KP_Next:
|
|
|
|
*out = "\033[222z";
|
|
|
|
return (6);
|
|
|
|
case KS_Up:
|
|
|
|
case KS_KP_Up:
|
|
|
|
*out = "\033[A";
|
|
|
|
return (3);
|
|
|
|
case KS_Down:
|
|
|
|
case KS_KP_Down:
|
|
|
|
*out = "\033[B";
|
|
|
|
return (3);
|
|
|
|
case KS_Left:
|
|
|
|
case KS_KP_Left:
|
|
|
|
*out = "\033[D";
|
|
|
|
return (3);
|
|
|
|
case KS_Right:
|
|
|
|
case KS_KP_Right:
|
|
|
|
*out = "\033[C";
|
|
|
|
return (3);
|
|
|
|
case KS_KP_Delete:
|
|
|
|
*out = "\177";
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
void
|
|
|
|
wsemul_sun_detach(cookie, crowp, ccolp)
|
|
|
|
void *cookie;
|
|
|
|
u_int *crowp, *ccolp;
|
|
|
|
{
|
|
|
|
struct wsemul_sun_emuldata *edp = cookie;
|
|
|
|
|
|
|
|
*crowp = edp->crow;
|
|
|
|
*ccolp = edp->ccol;
|
|
|
|
if (edp != &wsemul_sun_console_emuldata)
|
|
|
|
free(edp, M_DEVBUF);
|
|
|
|
}
|
1999-01-17 18:44:57 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
wsemul_sun_resetop(cookie, op)
|
|
|
|
void *cookie;
|
|
|
|
enum wsemul_resetops op;
|
|
|
|
{
|
|
|
|
struct wsemul_sun_emuldata *edp = cookie;
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case WSEMUL_RESET:
|
|
|
|
edp->state = SUN_EMUL_STATE_NORMAL;
|
|
|
|
edp->scrolldist = 1;
|
|
|
|
edp->rendflags = 0;
|
|
|
|
edp->curattr = edp->defattr;
|
|
|
|
break;
|
|
|
|
case WSEMUL_CLEARSCREEN:
|
|
|
|
(*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
|
|
|
|
edp->defattr);
|
|
|
|
edp->ccol = edp->crow = 0;
|
|
|
|
(*edp->emulops->cursor)(edp->emulcookie, 1, 0, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|