Module Name:    src
Committed By:   drochner
Date:           Wed Feb 10 19:39:39 UTC 2010

Modified Files:
        src/sys/dev/wscons: wsemul_vt100.c wsemul_vt100_chars.c
            wsemul_vt100_keys.c wsemul_vt100_subr.c wsemul_vt100var.h
Added Files:
        src/sys/dev/wscons: vt100_base.h

Log Message:
Allow big parts of the vt100 emulation code (what is in
wsemul_vt100_subr.c) to be used by alternative terminal emulators
(which are not in-tree yet but can be loaded as LKMs).
For this, split out that part of the state structure which is used
by the sharable code and include that in the original vt100 state.
This is only a query-replace and sed(1) job for now, it makes sense
to rearrange things a bit so that even more code can be changed --
will do so later.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/wscons/vt100_base.h
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/wscons/wsemul_vt100.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/wscons/wsemul_vt100_chars.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/wscons/wsemul_vt100_keys.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/wscons/wsemul_vt100_subr.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/wscons/wsemul_vt100var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/wscons/wsemul_vt100.c
diff -u src/sys/dev/wscons/wsemul_vt100.c:1.31 src/sys/dev/wscons/wsemul_vt100.c:1.32
--- src/sys/dev/wscons/wsemul_vt100.c:1.31	Wed Feb 18 04:17:44 2009
+++ src/sys/dev/wscons/wsemul_vt100.c	Wed Feb 10 19:39:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wsemul_vt100.c,v 1.31 2009/02/18 04:17:44 snj Exp $ */
+/* $NetBSD: wsemul_vt100.c,v 1.32 2010/02/10 19:39:39 drochner Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.31 2009/02/18 04:17:44 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.32 2010/02/10 19:39:39 drochner Exp $");
 
 #include "opt_wsmsgattrs.h"
 
@@ -134,15 +134,16 @@
 	const struct wsscreen_descr *type, void *cookie, int ccol, int crow,
 	long defattr)
 {
+	struct vt100base_data *vd = &edp->bd;
 	int error;
 
-	edp->emulops = type->textops;
-	edp->emulcookie = cookie;
-	edp->scrcapabilities = type->capabilities;
-	edp->nrows = type->nrows;
-	edp->ncols = type->ncols;
-	edp->crow = crow;
-	edp->ccol = ccol;
+	vd->emulops = type->textops;
+	vd->emulcookie = cookie;
+	vd->scrcapabilities = type->capabilities;
+	vd->nrows = type->nrows;
+	vd->ncols = type->ncols;
+	vd->crow = crow;
+	vd->ccol = ccol;
 
 	/* The underlying driver has already allocated a default and simple
 	 * attribute for us, which is stored in defattr.  We try to set the
@@ -150,41 +151,41 @@
 	 * failure we fallback to the value given by the driver. */
 
 	if (type->capabilities & WSSCREEN_WSCOLORS) {
-		edp->msgattrs.default_attrs = WS_DEFAULT_COLATTR |
+		vd->msgattrs.default_attrs = WS_DEFAULT_COLATTR |
 		    WSATTR_WSCOLORS;
-		edp->msgattrs.default_bg = WS_DEFAULT_BG;
-		edp->msgattrs.default_fg = WS_DEFAULT_FG;
+		vd->msgattrs.default_bg = WS_DEFAULT_BG;
+		vd->msgattrs.default_fg = WS_DEFAULT_FG;
 
-		edp->msgattrs.kernel_attrs = WS_KERNEL_COLATTR |
+		vd->msgattrs.kernel_attrs = WS_KERNEL_COLATTR |
 		    WSATTR_WSCOLORS;
-		edp->msgattrs.kernel_bg = WS_KERNEL_BG;
-		edp->msgattrs.kernel_fg = WS_KERNEL_FG;
+		vd->msgattrs.kernel_bg = WS_KERNEL_BG;
+		vd->msgattrs.kernel_fg = WS_KERNEL_FG;
 	} else {
-		edp->msgattrs.default_attrs = WS_DEFAULT_MONOATTR;
-		edp->msgattrs.default_bg = edp->msgattrs.default_fg = 0;
+		vd->msgattrs.default_attrs = WS_DEFAULT_MONOATTR;
+		vd->msgattrs.default_bg = vd->msgattrs.default_fg = 0;
 
-		edp->msgattrs.kernel_attrs = WS_KERNEL_MONOATTR;
-		edp->msgattrs.kernel_bg = edp->msgattrs.kernel_fg = 0;
+		vd->msgattrs.kernel_attrs = WS_KERNEL_MONOATTR;
+		vd->msgattrs.kernel_bg = vd->msgattrs.kernel_fg = 0;
 	}
 
-	error = (*edp->emulops->allocattr)(cookie,
-					   edp->msgattrs.default_fg,
-					   edp->msgattrs.default_bg,
-					   edp->msgattrs.default_attrs,
-					   &edp->defattr);
+	error = (*vd->emulops->allocattr)(cookie,
+					   vd->msgattrs.default_fg,
+					   vd->msgattrs.default_bg,
+					   vd->msgattrs.default_attrs,
+					   &vd->defattr);
 	if (error) {
-		edp->defattr = defattr;
+		vd->defattr = defattr;
 		/* XXX This assumes the driver has allocated white on black
 		 * XXX as the default attribute, which is not always true.
 		 * XXX Maybe we need an emulop that, given an attribute,
 		 * XXX (defattr) returns its flags and colors? */
-		edp->msgattrs.default_attrs = 0;
-		edp->msgattrs.default_bg = WSCOL_BLACK;
-		edp->msgattrs.default_fg = WSCOL_WHITE;
+		vd->msgattrs.default_attrs = 0;
+		vd->msgattrs.default_bg = WSCOL_BLACK;
+		vd->msgattrs.default_fg = WSCOL_WHITE;
 	} else {
-		if (edp->emulops->replaceattr != NULL)
-			(*edp->emulops->replaceattr)(cookie, defattr,
-			                             edp->defattr);
+		if (vd->emulops->replaceattr != NULL)
+			(*vd->emulops->replaceattr)(cookie, defattr,
+			                             vd->defattr);
 	}
 
 #if defined(WS_KERNEL_CUSTOMIZED)
@@ -193,14 +194,14 @@
 	 * In case of failure, we use console colors too; we can assume
 	 * they are good as they have been previously allocated and
 	 * verified. */
-	error = (*edp->emulops->allocattr)(cookie,
-					   edp->msgattrs.kernel_fg,
-					   edp->msgattrs.kernel_bg,
-					   edp->msgattrs.kernel_attrs,
+	error = (*vd->emulops->allocattr)(cookie,
+					   vd->msgattrs.kernel_fg,
+					   vd->msgattrs.kernel_bg,
+					   vd->msgattrs.kernel_attrs,
 					   &edp->kernattr);
 	if (error)
 #endif
-	edp->kernattr = edp->defattr;
+	edp->kernattr = vd->defattr;
 }
 
 void *
@@ -208,18 +209,20 @@
 	int ccol, int crow, long defattr)
 {
 	struct wsemul_vt100_emuldata *edp;
+	struct vt100base_data *vd;
 
 	edp = &wsemul_vt100_console_emuldata;
+	vd = &edp->bd;
 	wsemul_vt100_init(edp, type, cookie, ccol, crow, defattr);
 #ifdef DIAGNOSTIC
 	edp->console = 1;
 #endif
-	edp->cbcookie = NULL;
+	vd->cbcookie = NULL;
 
-	edp->tabs = 0;
-	edp->dblwid = 0;
-	edp->dw = 0;
-	edp->dcsarg = 0;
+	vd->tabs = 0;
+	vd->dblwid = 0;
+	vd->dw = 0;
+	vd->dcsarg = 0;
 	edp->isolatin1tab = edp->decgraphtab = edp->dectechtab = 0;
 	edp->nrctab = 0;
 	wsemul_vt100_reset(edp);
@@ -231,6 +234,7 @@
 	void *cookie, int ccol, int crow, void *cbcookie, long defattr)
 {
 	struct wsemul_vt100_emuldata *edp;
+	struct vt100base_data *vd;
 
 	if (console) {
 		edp = &wsemul_vt100_console_emuldata;
@@ -244,12 +248,13 @@
 		edp->console = 0;
 #endif
 	}
-	edp->cbcookie = cbcookie;
+	vd = &edp->bd;
+	vd->cbcookie = cbcookie;
 
-	edp->tabs = malloc(edp->ncols, M_DEVBUF, M_NOWAIT);
-	edp->dblwid = malloc(edp->nrows, M_DEVBUF, M_NOWAIT|M_ZERO);
-	edp->dw = 0;
-	edp->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_NOWAIT);
+	vd->tabs = malloc(vd->ncols, M_DEVBUF, M_NOWAIT);
+	vd->dblwid = malloc(vd->nrows, M_DEVBUF, M_NOWAIT|M_ZERO);
+	vd->dw = 0;
+	vd->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_NOWAIT);
 	edp->isolatin1tab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
 	edp->decgraphtab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
 	edp->dectechtab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
@@ -263,13 +268,14 @@
 wsemul_vt100_detach(void *cookie, u_int *crowp, u_int *ccolp)
 {
 	struct wsemul_vt100_emuldata *edp = cookie;
+	struct vt100base_data *vd = &edp->bd;
 
-	*crowp = edp->crow;
-	*ccolp = edp->ccol;
+	*crowp = vd->crow;
+	*ccolp = vd->ccol;
 #define f(ptr) if (ptr) {free(ptr, M_DEVBUF); ptr = 0;}
-	f(edp->tabs)
-	f(edp->dblwid)
-	f(edp->dcsarg)
+	f(vd->tabs)
+	f(vd->dblwid)
+	f(vd->dcsarg)
 	f(edp->isolatin1tab)
 	f(edp->decgraphtab)
 	f(edp->dectechtab)
@@ -283,6 +289,7 @@
 wsemul_vt100_resetop(void *cookie, enum wsemul_resetops op)
 {
 	struct wsemul_vt100_emuldata *edp = cookie;
+	struct vt100base_data *vd = &edp->bd;
 
 	switch (op) {
 	case WSEMUL_RESET:
@@ -292,10 +299,10 @@
 		vt100_initchartables(edp);
 		break;
 	case WSEMUL_CLEARSCREEN:
-		wsemul_vt100_ed(edp, 2);
-		edp->ccol = edp->crow = 0;
-		(*edp->emulops->cursor)(edp->emulcookie,
-					edp->flags & VTFL_CURSORON, 0, 0);
+		wsemul_vt100_ed(vd, 2);
+		vd->ccol = vd->crow = 0;
+		(*vd->emulops->cursor)(vd->emulcookie,
+					vd->flags & VTFL_CURSORON, 0, 0);
 		break;
 	default:
 		break;
@@ -305,23 +312,24 @@
 void
 wsemul_vt100_reset(struct wsemul_vt100_emuldata *edp)
 {
+	struct vt100base_data *vd = &edp->bd;
 	int i;
 
 	edp->state = VT100_EMUL_STATE_NORMAL;
-	edp->flags = VTFL_DECAWM | VTFL_CURSORON;
-	edp->bkgdattr = edp->curattr = edp->defattr;
-	edp->attrflags = edp->msgattrs.default_attrs;
-	edp->fgcol = edp->msgattrs.default_fg;
-	edp->bgcol = edp->msgattrs.default_bg;
-	edp->scrreg_startrow = 0;
-	edp->scrreg_nrows = edp->nrows;
-	if (edp->tabs) {
-		memset(edp->tabs, 0, edp->ncols);
-		for (i = 8; i < edp->ncols; i += 8)
-			edp->tabs[i] = 1;
+	vd->flags = VTFL_DECAWM | VTFL_CURSORON;
+	vd->bkgdattr = vd->curattr = vd->defattr;
+	vd->attrflags = vd->msgattrs.default_attrs;
+	vd->fgcol = vd->msgattrs.default_fg;
+	vd->bgcol = vd->msgattrs.default_bg;
+	vd->scrreg_startrow = 0;
+	vd->scrreg_nrows = vd->nrows;
+	if (vd->tabs) {
+		memset(vd->tabs, 0, vd->ncols);
+		for (i = 8; i < vd->ncols; i += 8)
+			vd->tabs[i] = 1;
 	}
-	edp->dcspos = 0;
-	edp->dcstype = 0;
+	vd->dcspos = 0;
+	vd->dcstype = 0;
 	edp->chartab_G[0] = 0;
 	edp->chartab_G[1] = edp->nrctab; /* ??? */
 	edp->chartab_G[2] = edp->isolatin1tab;
@@ -343,14 +351,16 @@
 static void
 wsemul_vt100_nextline(struct wsemul_vt100_emuldata *edp)
 {
-	if (ROWS_BELOW == 0) {
+	struct vt100base_data *vd = &edp->bd;
+
+	if (ROWS_BELOW(vd) == 0) {
 		/* Bottom of the scroll region. */
-	  	wsemul_vt100_scrollup(edp, 1);
+	  	wsemul_vt100_scrollup(vd, 1);
 	} else {
-		if ((edp->crow+1) < edp->nrows)
+		if ((vd->crow+1) < vd->nrows)
 			/* Cursor not at the bottom of the screen. */
-			edp->crow++;
-		CHECK_DW;
+			vd->crow++;
+		CHECK_DW(vd);
 	}
 }
 
@@ -358,13 +368,14 @@
 wsemul_vt100_output_normal(struct wsemul_vt100_emuldata *edp, u_char c,
 	int kernel)
 {
+	struct vt100base_data *vd = &edp->bd;
 	u_int *ct, dc;
 
-	if ((edp->flags & (VTFL_LASTCHAR | VTFL_DECAWM)) ==
+	if ((vd->flags & (VTFL_LASTCHAR | VTFL_DECAWM)) ==
 	    (VTFL_LASTCHAR | VTFL_DECAWM)) {
 		wsemul_vt100_nextline(edp);
-		edp->ccol = 0;
-		edp->flags &= ~VTFL_LASTCHAR;
+		vd->ccol = 0;
+		vd->flags &= ~VTFL_LASTCHAR;
 	}
 
 	if (c & 0x80) {
@@ -379,23 +390,24 @@
 	}
 	dc = (ct ? ct[c] : c);
 
-	if ((edp->flags & VTFL_INSERTMODE) && COLS_LEFT)
-		COPYCOLS(edp->ccol, edp->ccol + 1, COLS_LEFT);
+	if ((vd->flags & VTFL_INSERTMODE) && COLS_LEFT(vd))
+		COPYCOLS(vd, vd->ccol, vd->ccol + 1, COLS_LEFT(vd));
 
-	(*edp->emulops->putchar)(edp->emulcookie, edp->crow,
-				 edp->ccol << edp->dw, dc,
-				 kernel ? edp->kernattr : edp->curattr);
+	(*vd->emulops->putchar)(vd->emulcookie, vd->crow,
+				 vd->ccol << vd->dw, dc,
+				 kernel ? edp->kernattr : vd->curattr);
 
-	if (COLS_LEFT)
-		edp->ccol++;
+	if (COLS_LEFT(vd))
+		vd->ccol++;
 	else
-		edp->flags |= VTFL_LASTCHAR;
+		vd->flags |= VTFL_LASTCHAR;
 }
 
 static void
 wsemul_vt100_output_c0c1(struct wsemul_vt100_emuldata *edp, u_char c,
 	int kernel)
 {
+	struct vt100base_data *vd = &edp->bd;
 	u_int n;
 
 	switch (c) {
@@ -404,29 +416,29 @@
 		/* ignore */
 		break;
 	case ASCII_BEL:
-		wsdisplay_emulbell(edp->cbcookie);
+		wsdisplay_emulbell(vd->cbcookie);
 		break;
 	case ASCII_BS:
-		if (edp->ccol > 0) {
-			edp->ccol--;
-			edp->flags &= ~VTFL_LASTCHAR;
+		if (vd->ccol > 0) {
+			vd->ccol--;
+			vd->flags &= ~VTFL_LASTCHAR;
 		}
 		break;
 	case ASCII_CR:
-		edp->ccol = 0;
-		edp->flags &= ~VTFL_LASTCHAR;
+		vd->ccol = 0;
+		vd->flags &= ~VTFL_LASTCHAR;
 		break;
 	case ASCII_HT:
-		if (edp->tabs) {
-			if (!COLS_LEFT)
+		if (vd->tabs) {
+			if (!COLS_LEFT(vd))
 				break;
-			for (n = edp->ccol + 1; n < NCOLS - 1; n++)
-				if (edp->tabs[n])
+			for (n = vd->ccol + 1; n < NCOLS(vd) - 1; n++)
+				if (vd->tabs[n])
 					break;
 		} else {
-			n = edp->ccol + min(8 - (edp->ccol & 7), COLS_LEFT);
+			n = vd->ccol + min(8 - (vd->ccol & 7), COLS_LEFT(vd));
 		}
-		edp->ccol = n;
+		vd->ccol = n;
 		break;
 	case ASCII_SO: /* LS1 */
 		edp->chartab0 = 1;
@@ -478,60 +490,61 @@
 static u_int
 wsemul_vt100_output_esc(struct wsemul_vt100_emuldata *edp, u_char c)
 {
+	struct vt100base_data *vd = &edp->bd;
 	u_int newstate = VT100_EMUL_STATE_NORMAL;
 	int i;
 
 	switch (c) {
 	case '[': /* CSI */
-		edp->nargs = 0;
-		memset(edp->args, 0, sizeof (edp->args));
-		edp->modif1 = edp->modif2 = '\0';
+		vd->nargs = 0;
+		memset(vd->args, 0, sizeof (vd->args));
+		vd->modif1 = vd->modif2 = '\0';
 		newstate = VT100_EMUL_STATE_CSI;
 		break;
 	case '7': /* DECSC */
-		edp->flags |= VTFL_SAVEDCURS;
-		edp->savedcursor_row = edp->crow;
-		edp->savedcursor_col = edp->ccol;
-		edp->savedattr = edp->curattr;
-		edp->savedbkgdattr = edp->bkgdattr;
-		edp->savedattrflags = edp->attrflags;
-		edp->savedfgcol = edp->fgcol;
-		edp->savedbgcol = edp->bgcol;
+		vd->flags |= VTFL_SAVEDCURS;
+		edp->savedcursor_row = vd->crow;
+		edp->savedcursor_col = vd->ccol;
+		edp->savedattr = vd->curattr;
+		edp->savedbkgdattr = vd->bkgdattr;
+		edp->savedattrflags = vd->attrflags;
+		edp->savedfgcol = vd->fgcol;
+		edp->savedbgcol = vd->bgcol;
 		for (i = 0; i < 4; i++)
 			edp->savedchartab_G[i] = edp->chartab_G[i];
 		edp->savedchartab0 = edp->chartab0;
 		edp->savedchartab1 = edp->chartab1;
 		break;
 	case '8': /* DECRC */
-		if ((edp->flags & VTFL_SAVEDCURS) == 0)
+		if ((vd->flags & VTFL_SAVEDCURS) == 0)
 			break;
-		edp->crow = edp->savedcursor_row;
-		edp->ccol = edp->savedcursor_col;
-		edp->curattr = edp->savedattr;
-		edp->bkgdattr = edp->savedbkgdattr;
-		edp->attrflags = edp->savedattrflags;
-		edp->fgcol = edp->savedfgcol;
-		edp->bgcol = edp->savedbgcol;
+		vd->crow = edp->savedcursor_row;
+		vd->ccol = edp->savedcursor_col;
+		vd->curattr = edp->savedattr;
+		vd->bkgdattr = edp->savedbkgdattr;
+		vd->attrflags = edp->savedattrflags;
+		vd->fgcol = edp->savedfgcol;
+		vd->bgcol = edp->savedbgcol;
 		for (i = 0; i < 4; i++)
 			edp->chartab_G[i] = edp->savedchartab_G[i];
 		edp->chartab0 = edp->savedchartab0;
 		edp->chartab1 = edp->savedchartab1;
 		break;
 	case '=': /* DECKPAM application mode */
-		edp->flags |= VTFL_APPLKEYPAD;
+		vd->flags |= VTFL_APPLKEYPAD;
 		break;
 	case '>': /* DECKPNM numeric mode */
-		edp->flags &= ~VTFL_APPLKEYPAD;
+		vd->flags &= ~VTFL_APPLKEYPAD;
 		break;
 	case 'E': /* NEL */
-		edp->ccol = 0;
+		vd->ccol = 0;
 		/* FALLTHRU */
 	case 'D': /* IND */
 		wsemul_vt100_nextline(edp);
 		break;
 	case 'H': /* HTS */
-		KASSERT(edp->tabs != 0);
-		edp->tabs[edp->ccol] = 1;
+		KASSERT(vd->tabs != 0);
+		vd->tabs[vd->ccol] = 1;
 		break;
 	case '~': /* LS1R */
 		edp->chartab1 = 1;
@@ -555,22 +568,22 @@
 		edp->sschartab = 3;
 		break;
 	case 'M': /* RI */
-		if (ROWS_ABOVE > 0) {
-			edp->crow--;
-			CHECK_DW;
+		if (ROWS_ABOVE(vd) > 0) {
+			vd->crow--;
+			CHECK_DW(vd);
 			break;
 		}
-		wsemul_vt100_scrolldown(edp, 1);
+		wsemul_vt100_scrolldown(vd, 1);
 		break;
 	case 'P': /* DCS */
-		edp->nargs = 0;
-		memset(edp->args, 0, sizeof (edp->args));
+		vd->nargs = 0;
+		memset(vd->args, 0, sizeof (vd->args));
 		newstate = VT100_EMUL_STATE_DCS;
 		break;
 	case 'c': /* RIS */
 		wsemul_vt100_reset(edp);
-		wsemul_vt100_ed(edp, 2);
-		edp->ccol = edp->crow = 0;
+		wsemul_vt100_ed(vd, 2);
+		vd->ccol = vd->crow = 0;
 		break;
 	case '(': case ')': case '*': case '+': /* SCS */
 		edp->designating = c - '(';
@@ -748,16 +761,20 @@
 static u_int
 wsemul_vt100_output_string(struct wsemul_vt100_emuldata *edp, u_char c)
 {
-	if (edp->dcstype && edp->dcspos < DCS_MAXLEN)
-		edp->dcsarg[edp->dcspos++] = c;
+	struct vt100base_data *vd = &edp->bd;
+
+	if (vd->dcstype && vd->dcspos < DCS_MAXLEN)
+		vd->dcsarg[vd->dcspos++] = c;
 	return (VT100_EMUL_STATE_STRING);
 }
 
 static u_int
 wsemul_vt100_output_string_esc(struct wsemul_vt100_emuldata *edp, u_char c)
 {
+	struct vt100base_data *vd = &edp->bd;
+
 	if (c == '\\') { /* ST complete */
-		wsemul_vt100_handle_dcs(edp);
+		wsemul_vt100_handle_dcs(vd);
 		return (VT100_EMUL_STATE_NORMAL);
 	} else
 		return (VT100_EMUL_STATE_STRING);
@@ -766,27 +783,28 @@
 static u_int
 wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, u_char c)
 {
+	struct vt100base_data *vd = &edp->bd;
 	u_int newstate = VT100_EMUL_STATE_DCS;
 
 	switch (c) {
 	case '0': case '1': case '2': case '3': case '4':
 	case '5': case '6': case '7': case '8': case '9':
 		/* argument digit */
-		if (edp->nargs > VT100_EMUL_NARGS - 1)
+		if (vd->nargs > VT100_EMUL_NARGS - 1)
 			break;
-		edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
+		vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
 		    (c - '0');
 		break;
 	case ';': /* argument terminator */
-		edp->nargs++;
+		vd->nargs++;
 		break;
 	default:
-		edp->nargs++;
-		if (edp->nargs > VT100_EMUL_NARGS) {
+		vd->nargs++;
+		if (vd->nargs > VT100_EMUL_NARGS) {
 #ifdef VT100_DEBUG
 			printf("vt100: too many arguments\n");
 #endif
-			edp->nargs = VT100_EMUL_NARGS;
+			vd->nargs = VT100_EMUL_NARGS;
 		}
 		newstate = VT100_EMUL_STATE_STRING;
 		switch (c) {
@@ -803,7 +821,7 @@
 			break;
 		default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("DCS%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
+			printf("DCS%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1));
 #endif
 			break;
 		}
@@ -815,6 +833,8 @@
 static u_int
 wsemul_vt100_output_dcs_dollar(struct wsemul_vt100_emuldata *edp, u_char c)
 {
+	struct vt100base_data *vd = &edp->bd;
+
 	switch (c) {
 	case 'p': /* DECRSTS terminal state restore */
 	case 'q': /* DECRQSS control function request */
@@ -823,7 +843,7 @@
 #endif
 		break;
 	case 't': /* DECRSPS restore presentation state */
-		switch (ARG(0)) {
+		switch (ARG(vd, 0)) {
 		case 0: /* error */
 			break;
 		case 1: /* cursor information restore */
@@ -832,19 +852,19 @@
 #endif
 			break;
 		case 2: /* tab stop restore */
-			edp->dcspos = 0;
-			edp->dcstype = DCSTYPE_TABRESTORE;
+			vd->dcspos = 0;
+			vd->dcstype = DCSTYPE_TABRESTORE;
 			break;
 		default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("DCS%d$t unknown\n", ARG(0));
+			printf("DCS%d$t unknown\n", ARG(vd, 0));
 #endif
 			break;
 		}
 		break;
 	default:
 #ifdef VT100_PRINTUNKNOWN
-		printf("DCS$%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
+		printf("DCS$%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1));
 #endif
 		break;
 	}
@@ -854,48 +874,49 @@
 static u_int
 wsemul_vt100_output_esc_hash(struct wsemul_vt100_emuldata *edp, u_char c)
 {
+	struct vt100base_data *vd = &edp->bd;
 	int i, j;
 
 	switch (c) {
 	case '5': /*  DECSWL single width, single height */
-		if (edp->dw) {
-			for (i = 0; i < edp->ncols / 2; i++)
-				(*edp->emulops->copycols)(edp->emulcookie,
-							  edp->crow,
+		if (vd->dw) {
+			for (i = 0; i < vd->ncols / 2; i++)
+				(*vd->emulops->copycols)(vd->emulcookie,
+							  vd->crow,
 							  2 * i, i, 1);
-			(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
-						   i, edp->ncols - i,
-						   edp->bkgdattr);
-			edp->dblwid[edp->crow] = 0;
-			edp->dw = 0;
+			(*vd->emulops->erasecols)(vd->emulcookie, vd->crow,
+						   i, vd->ncols - i,
+						   vd->bkgdattr);
+			vd->dblwid[vd->crow] = 0;
+			vd->dw = 0;
 		}
 		break;
 	case '6': /*  DECDWL double width, single height */
 	case '3': /*  DECDHL double width, double height, top half */
 	case '4': /*  DECDHL double width, double height, bottom half */
-		if (!edp->dw) {
-			for (i = edp->ncols / 2 - 1; i >= 0; i--)
-				(*edp->emulops->copycols)(edp->emulcookie,
-							  edp->crow,
+		if (!vd->dw) {
+			for (i = vd->ncols / 2 - 1; i >= 0; i--)
+				(*vd->emulops->copycols)(vd->emulcookie,
+							  vd->crow,
 							  i, 2 * i, 1);
-			for (i = 0; i < edp->ncols / 2; i++)
-				(*edp->emulops->erasecols)(edp->emulcookie,
-							   edp->crow,
+			for (i = 0; i < vd->ncols / 2; i++)
+				(*vd->emulops->erasecols)(vd->emulcookie,
+							   vd->crow,
 							   2 * i + 1, 1,
-							   edp->bkgdattr);
-			edp->dblwid[edp->crow] = 1;
-			edp->dw = 1;
-			if (edp->ccol > (edp->ncols >> 1) - 1)
-				edp->ccol = (edp->ncols >> 1) - 1;
+							   vd->bkgdattr);
+			vd->dblwid[vd->crow] = 1;
+			vd->dw = 1;
+			if (vd->ccol > (vd->ncols >> 1) - 1)
+				vd->ccol = (vd->ncols >> 1) - 1;
 		}
 		break;
 	case '8': /* DECALN */
-		for (i = 0; i < edp->nrows; i++)
-			for (j = 0; j < edp->ncols; j++)
-				(*edp->emulops->putchar)(edp->emulcookie, i, j,
-							 'E', edp->curattr);
-		edp->ccol = 0;
-		edp->crow = 0;
+		for (i = 0; i < vd->nrows; i++)
+			for (j = 0; j < vd->ncols; j++)
+				(*vd->emulops->putchar)(vd->emulcookie, i, j,
+							 'E', vd->curattr);
+		vd->ccol = 0;
+		vd->crow = 0;
 		break;
 	default:
 #ifdef VT100_PRINTUNKNOWN
@@ -909,39 +930,40 @@
 static u_int
 wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, u_char c)
 {
+	struct vt100base_data *vd = &edp->bd;
 	u_int newstate = VT100_EMUL_STATE_CSI;
 
 	switch (c) {
 	case '0': case '1': case '2': case '3': case '4':
 	case '5': case '6': case '7': case '8': case '9':
 		/* argument digit */
-		if (edp->nargs > VT100_EMUL_NARGS - 1)
+		if (vd->nargs > VT100_EMUL_NARGS - 1)
 			break;
-		edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
+		vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
 		    (c - '0');
 		break;
 	case ';': /* argument terminator */
-		edp->nargs++;
+		vd->nargs++;
 		break;
 	case '?': /* DEC specific */
 	case '>': /* DA query */
-		edp->modif1 = c;
+		vd->modif1 = c;
 		break;
 	case '!':
 	case '"':
 	case '$':
 	case '&':
-		edp->modif2 = c;
+		vd->modif2 = c;
 		break;
 	default: /* end of escape sequence */
-		edp->nargs++;
-		if (edp->nargs > VT100_EMUL_NARGS) {
+		vd->nargs++;
+		if (vd->nargs > VT100_EMUL_NARGS) {
 #ifdef VT100_DEBUG
 			printf("vt100: too many arguments\n");
 #endif
-			edp->nargs = VT100_EMUL_NARGS;
+			vd->nargs = VT100_EMUL_NARGS;
 		}
-		wsemul_vt100_handle_csi(edp, c);
+		wsemul_vt100_handle_csi(vd, c);
 		newstate = VT100_EMUL_STATE_NORMAL;
 		break;
 	}
@@ -952,15 +974,16 @@
 wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
 {
 	struct wsemul_vt100_emuldata *edp = cookie;
+	struct vt100base_data *vd = &edp->bd;
 
 #ifdef DIAGNOSTIC
 	if (kernel && !edp->console)
 		panic("wsemul_vt100_output: kernel output, not console");
 #endif
 
-	if (edp->flags & VTFL_CURSORON)
-		(*edp->emulops->cursor)(edp->emulcookie, 0,
-					edp->crow, edp->ccol << edp->dw);
+	if (vd->flags & VTFL_CURSORON)
+		(*vd->emulops->cursor)(vd->emulcookie, 0,
+					vd->crow, vd->ccol << vd->dw);
 	for (; count > 0; data++, count--) {
 		if ((*data & 0x7f) < 0x20) {
 			wsemul_vt100_output_c0c1(edp, *data, kernel);
@@ -976,9 +999,9 @@
 #endif
 		edp->state = vt100_output[edp->state - 1](edp, *data);
 	}
-	if (edp->flags & VTFL_CURSORON)
-		(*edp->emulops->cursor)(edp->emulcookie, 1,
-					edp->crow, edp->ccol << edp->dw);
+	if (vd->flags & VTFL_CURSORON)
+		(*vd->emulops->cursor)(vd->emulcookie, 1,
+					vd->crow, vd->ccol << vd->dw);
 }
 
 #ifdef WSDISPLAY_CUSTOM_OUTPUT
@@ -987,7 +1010,7 @@
 {
 	struct wsemul_vt100_emuldata *edp = cookie;
 
-	*ma = edp->msgattrs;
+	*ma = vd->msgattrs;
 }
 
 static void
@@ -998,19 +1021,19 @@
 	long tmp;
 	struct wsemul_vt100_emuldata *edp = cookie;
 
-	edp->msgattrs = *ma;
+	vd->msgattrs = *ma;
 	if (type->capabilities & WSSCREEN_WSCOLORS) {
-		edp->msgattrs.default_attrs |= WSATTR_WSCOLORS;
-		edp->msgattrs.kernel_attrs |= WSATTR_WSCOLORS;
+		vd->msgattrs.default_attrs |= WSATTR_WSCOLORS;
+		vd->msgattrs.kernel_attrs |= WSATTR_WSCOLORS;
 	} else {
-		edp->msgattrs.default_bg = edp->msgattrs.kernel_bg = 0;
-		edp->msgattrs.default_fg = edp->msgattrs.kernel_fg = 0;
+		vd->msgattrs.default_bg = vd->msgattrs.kernel_bg = 0;
+		vd->msgattrs.default_fg = vd->msgattrs.kernel_fg = 0;
 	}
 
-	error = (*edp->emulops->allocattr)(edp->emulcookie,
-	                                   edp->msgattrs.default_fg,
-					   edp->msgattrs.default_bg,
-	                                   edp->msgattrs.default_attrs,
+	error = (*vd->emulops->allocattr)(vd->emulcookie,
+	                                   vd->msgattrs.default_fg,
+					   vd->msgattrs.default_bg,
+	                                   vd->msgattrs.default_attrs,
 	                                   &tmp);
 #ifdef VT100_DEBUG
 	if (error)
@@ -1019,27 +1042,27 @@
 	else
 #endif
 	{
-		if (edp->curattr == edp->defattr) {
-			edp->bkgdattr = edp->curattr = tmp;
-			edp->attrflags = edp->msgattrs.default_attrs;
-			edp->bgcol = edp->msgattrs.default_bg;
-			edp->fgcol = edp->msgattrs.default_fg;
+		if (vd->curattr == vd->defattr) {
+			vd->bkgdattr = vd->curattr = tmp;
+			vd->attrflags = vd->msgattrs.default_attrs;
+			vd->bgcol = vd->msgattrs.default_bg;
+			vd->fgcol = vd->msgattrs.default_fg;
 		} else {
 			edp->savedbkgdattr = edp->savedattr = tmp;
-			edp->savedattrflags = edp->msgattrs.default_attrs;
-			edp->savedbgcol = edp->msgattrs.default_bg;
-			edp->savedfgcol = edp->msgattrs.default_fg;
+			edp->savedattrflags = vd->msgattrs.default_attrs;
+			edp->savedbgcol = vd->msgattrs.default_bg;
+			edp->savedfgcol = vd->msgattrs.default_fg;
 		}
-		if (edp->emulops->replaceattr != NULL)
-			(*edp->emulops->replaceattr)(edp->emulcookie,
-			                             edp->defattr, tmp);
-		edp->defattr = tmp;
+		if (vd->emulops->replaceattr != NULL)
+			(*vd->emulops->replaceattr)(vd->emulcookie,
+			                             vd->defattr, tmp);
+		vd->defattr = tmp;
 	}
 
-	error = (*edp->emulops->allocattr)(edp->emulcookie,
-	                                   edp->msgattrs.kernel_fg,
-					   edp->msgattrs.kernel_bg,
-	                                   edp->msgattrs.kernel_attrs,
+	error = (*vd->emulops->allocattr)(vd->emulcookie,
+	                                   vd->msgattrs.kernel_fg,
+					   vd->msgattrs.kernel_bg,
+	                                   vd->msgattrs.kernel_attrs,
 	                                   &tmp);
 #ifdef VT100_DEBUG
 	if (error)
@@ -1048,8 +1071,8 @@
 	else
 #endif
 	{
-		if (edp->emulops->replaceattr != NULL)
-			(*edp->emulops->replaceattr)(edp->emulcookie,
+		if (vd->emulops->replaceattr != NULL)
+			(*vd->emulops->replaceattr)(vd->emulcookie,
 			                             edp->kernattr, tmp);
 		edp->kernattr = tmp;
 	}

Index: src/sys/dev/wscons/wsemul_vt100_chars.c
diff -u src/sys/dev/wscons/wsemul_vt100_chars.c:1.12 src/sys/dev/wscons/wsemul_vt100_chars.c:1.13
--- src/sys/dev/wscons/wsemul_vt100_chars.c:1.12	Wed Feb 18 04:17:44 2009
+++ src/sys/dev/wscons/wsemul_vt100_chars.c	Wed Feb 10 19:39:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wsemul_vt100_chars.c,v 1.12 2009/02/18 04:17:44 snj Exp $ */
+/* $NetBSD: wsemul_vt100_chars.c,v 1.13 2010/02/10 19:39:39 drochner Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_chars.c,v 1.12 2009/02/18 04:17:44 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_chars.c,v 1.13 2010/02/10 19:39:39 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -80,15 +80,16 @@
 vt100_initchartables(struct wsemul_vt100_emuldata *edp)
 {
 	int i;
+	struct vt100base_data *vd = &edp->bd;
 
 	for (i = 0; i < 128; i++)
-		(*edp->emulops->mapchar)(edp->emulcookie, 128 + i,
+		(*vd->emulops->mapchar)(vd->emulcookie, 128 + i,
 					 &edp->isolatin1tab[i]);
 	for (i = 0; i < 128; i++)
-		(*edp->emulops->mapchar)(edp->emulcookie, decspcgr2uni[i],
+		(*vd->emulops->mapchar)(vd->emulcookie, decspcgr2uni[i],
 					 &edp->decgraphtab[i]);
 	for (i = 0; i < 128; i++)
-		(*edp->emulops->mapchar)(edp->emulcookie, dectech2uni[i],
+		(*vd->emulops->mapchar)(vd->emulcookie, dectech2uni[i],
 					 &edp->dectechtab[i]);
 	vt100_setnrc(edp, 0);
 }
@@ -142,12 +143,13 @@
 vt100_setnrc(struct wsemul_vt100_emuldata *edp, int nrc)
 {
 	int i;
+	struct vt100base_data *vd = &edp->bd;
 
 	KASSERT(nrc < sizeof(nrctable) / sizeof(nrctable[0]));
 
 	for (i = 0; i < 128; i++)
-		(*edp->emulops->mapchar)(edp->emulcookie, i, &edp->nrctab[i]);
+		(*vd->emulops->mapchar)(vd->emulcookie, i, &edp->nrctab[i]);
 	for (i = 0; i < 12; i++)
-		(*edp->emulops->mapchar)(edp->emulcookie, nrctable[nrc].c[i],
+		(*vd->emulops->mapchar)(vd->emulcookie, nrctable[nrc].c[i],
 					 &edp->nrctab[nrcovlpos[i]]);
 }

Index: src/sys/dev/wscons/wsemul_vt100_keys.c
diff -u src/sys/dev/wscons/wsemul_vt100_keys.c:1.10 src/sys/dev/wscons/wsemul_vt100_keys.c:1.11
--- src/sys/dev/wscons/wsemul_vt100_keys.c:1.10	Thu Jan 28 22:36:19 2010
+++ src/sys/dev/wscons/wsemul_vt100_keys.c	Wed Feb 10 19:39:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wsemul_vt100_keys.c,v 1.10 2010/01/28 22:36:19 drochner Exp $ */
+/* $NetBSD: wsemul_vt100_keys.c,v 1.11 2010/02/10 19:39:39 drochner Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_keys.c,v 1.10 2010/01/28 22:36:19 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_keys.c,v 1.11 2010/02/10 19:39:39 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -85,6 +85,7 @@
 wsemul_vt100_translate(void *cookie, keysym_t in, const char **out)
 {
 	struct wsemul_vt100_emuldata *edp = cookie;
+	struct vt100base_data *vd = &edp->bd;
 	static char c;
 
 	if (KS_GROUP(in) == KS_GROUP_Plain) {
@@ -105,7 +106,7 @@
 		*out = vt100_pfkeys[in - KS_KP_F1];
 		return (3);
 	}
-	if (edp->flags & VTFL_APPLKEYPAD) {
+	if (vd->flags & VTFL_APPLKEYPAD) {
 		if (in >= KS_KP_0 && in <= KS_KP_9) {
 			*out = vt100_numpad[in - KS_KP_0];
 			return (3);
@@ -181,28 +182,28 @@
 		return (4);
 	    case KS_Up:
 	    case KS_KP_Up:
-		if (edp->flags & VTFL_APPLCURSOR)
+		if (vd->flags & VTFL_APPLCURSOR)
 			*out = "\033OA";
 		else
 			*out = "\033[A";
 		return (3);
 	    case KS_Down:
 	    case KS_KP_Down:
-		if (edp->flags & VTFL_APPLCURSOR)
+		if (vd->flags & VTFL_APPLCURSOR)
 			*out = "\033OB";
 		else
 			*out = "\033[B";
 		return (3);
 	    case KS_Left:
 	    case KS_KP_Left:
-		if (edp->flags & VTFL_APPLCURSOR)
+		if (vd->flags & VTFL_APPLCURSOR)
 			*out = "\033OD";
 		else
 			*out = "\033[D";
 		return (3);
 	    case KS_Right:
 	    case KS_KP_Right:
-		if (edp->flags & VTFL_APPLCURSOR)
+		if (vd->flags & VTFL_APPLCURSOR)
 			*out = "\033OC";
 		else
 			*out = "\033[C";

Index: src/sys/dev/wscons/wsemul_vt100_subr.c
diff -u src/sys/dev/wscons/wsemul_vt100_subr.c:1.19 src/sys/dev/wscons/wsemul_vt100_subr.c:1.20
--- src/sys/dev/wscons/wsemul_vt100_subr.c:1.19	Sun Dec 11 12:24:12 2005
+++ src/sys/dev/wscons/wsemul_vt100_subr.c	Wed Feb 10 19:39:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wsemul_vt100_subr.c,v 1.19 2005/12/11 12:24:12 christos Exp $ */
+/* $NetBSD: wsemul_vt100_subr.c,v 1.20 2010/02/10 19:39:39 drochner Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_subr.c,v 1.19 2005/12/11 12:24:12 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_subr.c,v 1.20 2010/02/10 19:39:39 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -36,14 +36,14 @@
 #include <dev/wscons/wsksymvar.h>
 #include <dev/wscons/wsdisplayvar.h>
 #include <dev/wscons/wsemulvar.h>
-#include <dev/wscons/wsemul_vt100var.h>
+#include <dev/wscons/vt100_base.h>
 
 #include "opt_wsemul.h"
 
-static int vt100_selectattribute(struct wsemul_vt100_emuldata *,
+static int vt100_selectattribute(struct vt100base_data *,
 				      int, int, int, long *, long *);
-static int vt100_ansimode(struct wsemul_vt100_emuldata *, int, int);
-static int vt100_decmode(struct wsemul_vt100_emuldata *, int, int);
+static int vt100_ansimode(struct vt100base_data *, int, int);
+static int vt100_decmode(struct vt100base_data *, int, int);
 #define VTMODE_SET 33
 #define VTMODE_RESET 44
 #define VTMODE_REPORT 55
@@ -52,7 +52,7 @@
  * scroll up within scrolling region
  */
 void
-wsemul_vt100_scrollup(struct wsemul_vt100_emuldata *edp, int n)
+wsemul_vt100_scrollup(struct vt100base_data *edp, int n)
 {
 	int help;
 
@@ -75,14 +75,14 @@
 				   edp->bkgdattr);
 	if (edp->dblwid)
 		memset(&edp->dblwid[edp->scrreg_startrow + help], 0, n);
-	CHECK_DW;
+	CHECK_DW(edp);
 }
 
 /*
  * scroll down within scrolling region
  */
 void
-wsemul_vt100_scrolldown(struct wsemul_vt100_emuldata *edp, int n)
+wsemul_vt100_scrolldown(struct vt100base_data *edp, int n)
 {
 	int help;
 
@@ -105,20 +105,20 @@
 				   edp->bkgdattr);
 	if (edp->dblwid)
 		memset(&edp->dblwid[edp->scrreg_startrow], 0, n);
-	CHECK_DW;
+	CHECK_DW(edp);
 }
 
 /*
  * erase in display
  */
 void
-wsemul_vt100_ed(struct wsemul_vt100_emuldata *edp, int arg)
+wsemul_vt100_ed(struct vt100base_data *edp, int arg)
 {
 	int n;
 
 	switch (arg) {
 	    case 0: /* cursor to end */
-		ERASECOLS(edp->ccol, COLS_LEFT + 1, edp->bkgdattr);
+		ERASECOLS(edp, edp->ccol, COLS_LEFT(edp) + 1, edp->bkgdattr);
 		n = edp->nrows - edp->crow - 1;
 		if (n > 0) {
 			(*edp->emulops->eraserows)(edp->emulcookie,
@@ -136,7 +136,7 @@
 			if (edp->dblwid)
 				memset(&edp->dblwid[0], 0, edp->crow);
 		}
-		ERASECOLS(0, edp->ccol + 1, edp->bkgdattr);
+		ERASECOLS(edp, 0, edp->ccol + 1, edp->bkgdattr);
 		break;
 	    case 2: /* complete display */
 		(*edp->emulops->eraserows)(edp->emulcookie,
@@ -151,21 +151,21 @@
 #endif
 		break;
 	}
-	CHECK_DW;
+	CHECK_DW(edp);
 }
 
 /*
  * erase in line
  */
 void
-wsemul_vt100_el(struct wsemul_vt100_emuldata *edp, int arg)
+wsemul_vt100_el(struct vt100base_data *edp, int arg)
 {
 	switch (arg) {
 	    case 0: /* cursor to end */
-		ERASECOLS(edp->ccol, COLS_LEFT + 1, edp->bkgdattr);
+		ERASECOLS(edp, edp->ccol, COLS_LEFT(edp) + 1, edp->bkgdattr);
 		break;
 	    case 1: /* beginning to cursor */
-		ERASECOLS(0, edp->ccol + 1, edp->bkgdattr);
+		ERASECOLS(edp, 0, edp->ccol + 1, edp->bkgdattr);
 		break;
 	    case 2: /* complete line */
 		(*edp->emulops->erasecols)(edp->emulcookie, edp->crow,
@@ -184,7 +184,7 @@
  * handle commands after CSI (ESC[)
  */
 void
-wsemul_vt100_handle_csi(struct wsemul_vt100_emuldata *edp, u_char c)
+wsemul_vt100_handle_csi(struct vt100base_data *edp, u_char c)
 {
 	int n, help, flags, fgcol, bgcol;
 	long attr, bkgdattr;
@@ -198,60 +198,62 @@
 
 	    case A3('\0', '\0', 'J'): /* ED selective erase in display */
 	    case A3('?', '\0', 'J'): /* DECSED selective erase in display */
-		wsemul_vt100_ed(edp, ARG(0));
+		wsemul_vt100_ed(edp, ARG(edp, 0));
 		break;
 	    case A3('\0', '\0', 'K'): /* EL selective erase in line */
 	    case A3('?', '\0', 'K'): /* DECSEL selective erase in line */
-		wsemul_vt100_el(edp, ARG(0));
+		wsemul_vt100_el(edp, ARG(edp, 0));
 		break;
 	    case A3('\0', '\0', 'h'): /* SM */
 		for (n = 0; n < edp->nargs; n++)
-			vt100_ansimode(edp, ARG(n), VTMODE_SET);
+			vt100_ansimode(edp, ARG(edp, n), VTMODE_SET);
 		break;
 	    case A3('?', '\0', 'h'): /* DECSM */
 		for (n = 0; n < edp->nargs; n++)
-			vt100_decmode(edp, ARG(n), VTMODE_SET);
+			vt100_decmode(edp, ARG(edp, n), VTMODE_SET);
 		break;
 	    case A3('\0', '\0', 'l'): /* RM */
 		for (n = 0; n < edp->nargs; n++)
-			vt100_ansimode(edp, ARG(n), VTMODE_RESET);
+			vt100_ansimode(edp, ARG(edp, n), VTMODE_RESET);
 		break;
 	    case A3('?', '\0', 'l'): /* DECRM */
 		for (n = 0; n < edp->nargs; n++)
-			vt100_decmode(edp, ARG(n), VTMODE_RESET);
+			vt100_decmode(edp, ARG(edp, n), VTMODE_RESET);
 		break;
 	    case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */
-		vt100_ansimode(edp, ARG(0), VTMODE_REPORT);
+		vt100_ansimode(edp, ARG(edp, 0), VTMODE_REPORT);
 		break;
 	    case A3('?', '$', 'p'): /* DECRQM request mode DEC */
-		vt100_decmode(edp, ARG(0), VTMODE_REPORT);
+		vt100_decmode(edp, ARG(edp, 0), VTMODE_REPORT);
 		break;
 	    case A3('\0', '\0', 'i'): /* MC printer controller mode */
 	    case A3('?', '\0', 'i'): /* MC printer controller mode */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0: /* print screen */
 		    case 1: /* print cursor line */
 		    case 4: /* off */
 		    case 5: /* on */
 #ifdef VT100_PRINTNOTIMPL
-			printf("CSI%di ignored\n", ARG(0));
+			printf("CSI%di ignored\n", ARG(edp, 0));
 #endif
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%di unknown\n", ARG(0));
+			printf("CSI%di unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 
 #define A2(a, b) (((a) << 8) | (b))
+#if 0 /* XXX */
 	    case A2('!', 'p'): /* DECSTR soft reset VT300 only */
 		wsemul_vt100_reset(edp);
 		break;
+#endif
 
 	    case A2('"', 'p'): /* DECSCL */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 61: /* VT100 mode (no further arguments!) */
 			break;
 		    case 62:
@@ -259,28 +261,28 @@
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d\"p unknown\n", ARG(0));
+			printf("CSI%d\"p unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
-		switch (ARG(1)) {
+		switch (ARG(edp, 1)) {
 		    case 0:
 		    case 2: /* 8-bit controls */
 #ifdef VT100_PRINTNOTIMPL
-			printf("CSI%d;%d\"p ignored\n", ARG(0), ARG(1));
+			printf("CSI%d;%d\"p ignored\n", ARG(edp, 0), ARG(edp, 1));
 #endif
 			break;
 		    case 1: /* 7-bit controls */
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d;%d\"p unknown\n", ARG(0), ARG(1));
+			printf("CSI%d;%d\"p unknown\n", ARG(edp, 0), ARG(edp, 1));
 #endif
 			break;
 		}
 		break;
 	    case A2('"', 'q'): /* DECSCA select character attribute VT300 */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0:
 		    case 1: /* erasable */
 			break;
@@ -291,14 +293,14 @@
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d\"q unknown\n", ARG(0));
+			printf("CSI%d\"q unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 
 	    case A2('$', 'u'): /* DECRQTSR request terminal status report */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0: /* ignored */
 			break;
 		    case 1: /* terminal state report */
@@ -308,14 +310,14 @@
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d$u unknown\n", ARG(0));
+			printf("CSI%d$u unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 	    case A2('$', 'w'): /* DECRQPSR request presentation status report
 				(VT300 only) */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0: /* error */
 			break;
 		    case 1: /* cursor information report */
@@ -342,38 +344,38 @@
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d$w unknown\n", ARG(0));
+			printf("CSI%d$w unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 	    case A2('$', '}'): /* DECSASD select active status display */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0: /* main display */
 		    case 1: /* status line */
 #ifdef VT100_PRINTNOTIMPL
-			printf("CSI%d$} ignored\n", ARG(0));
+			printf("CSI%d$} ignored\n", ARG(edp, 0));
 #endif
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d$} unknown\n", ARG(0));
+			printf("CSI%d$} unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 	    case A2('$', '~'): /* DECSSDD select status line type */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0: /* none */
 		    case 1: /* indicator */
 		    case 2: /* host-writable */
 #ifdef VT100_PRINTNOTIMPL
-			printf("CSI%d$~ ignored\n", ARG(0));
+			printf("CSI%d$~ ignored\n", ARG(edp, 0));
 #endif
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%d$~ unknown\n", ARG(0));
+			printf("CSI%d$~ unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
@@ -385,46 +387,46 @@
 		break;
 
 	    case '@': /* ICH insert character VT300 only */
-		n = min(DEF1_ARG(0), COLS_LEFT + 1);
-		help = NCOLS - (edp->ccol + n);
+		n = min(DEF1_ARG(edp, 0), COLS_LEFT(edp) + 1);
+		help = NCOLS(edp) - (edp->ccol + n);
 		if (help > 0)
-			COPYCOLS(edp->ccol, edp->ccol + n, help);
-		ERASECOLS(edp->ccol, n, edp->bkgdattr);
+			COPYCOLS(edp, edp->ccol, edp->ccol + n, help);
+		ERASECOLS(edp, edp->ccol, n, edp->bkgdattr);
 		break;
 	    case 'A': /* CUU */
-		edp->crow -= min(DEF1_ARG(0), ROWS_ABOVE);
-		CHECK_DW;
+		edp->crow -= min(DEF1_ARG(edp, 0), ROWS_ABOVE(edp));
+		CHECK_DW(edp);
 		break;
 	    case 'B': /* CUD */
-		edp->crow += min(DEF1_ARG(0), ROWS_BELOW);
-		CHECK_DW;
+		edp->crow += min(DEF1_ARG(edp, 0), ROWS_BELOW(edp));
+		CHECK_DW(edp);
 		break;
 	    case 'C': /* CUF */
-		edp->ccol += min(DEF1_ARG(0), COLS_LEFT);
+		edp->ccol += min(DEF1_ARG(edp, 0), COLS_LEFT(edp));
 		break;
 	    case 'D': /* CUB */
-		edp->ccol -= min(DEF1_ARG(0), edp->ccol);
+		edp->ccol -= min(DEF1_ARG(edp, 0), edp->ccol);
 		edp->flags &= ~VTFL_LASTCHAR;
 		break;
 	    case 'H': /* CUP */
 	    case 'f': /* HVP */
 		if (edp->flags & VTFL_DECOM)
 			edp->crow = edp->scrreg_startrow +
-			    min(DEF1_ARG(0), edp->scrreg_nrows) - 1;
+			    min(DEF1_ARG(edp, 0), edp->scrreg_nrows) - 1;
 		else
-			edp->crow = min(DEF1_ARG(0), edp->nrows) - 1;
-		CHECK_DW;
-		edp->ccol = min(DEF1_ARG(1), NCOLS) - 1;
+			edp->crow = min(DEF1_ARG(edp, 0), edp->nrows) - 1;
+		CHECK_DW(edp);
+		edp->ccol = min(DEF1_ARG(edp, 1), NCOLS(edp)) - 1;
 		edp->flags &= ~VTFL_LASTCHAR;
 		break;
 	    case 'L': /* IL insert line */
 	    case 'M': /* DL delete line */
-		n = min(DEF1_ARG(0), ROWS_BELOW + 1);
+		n = min(DEF1_ARG(edp, 0), ROWS_BELOW(edp) + 1);
 		{
 		int savscrstartrow, savscrnrows;
 		savscrstartrow = edp->scrreg_startrow;
 		savscrnrows = edp->scrreg_nrows;
-		edp->scrreg_nrows -= ROWS_ABOVE;
+		edp->scrreg_nrows -= ROWS_ABOVE(edp);
 		edp->scrreg_startrow = edp->crow;
 		if (c == 'L')
 			wsemul_vt100_scrolldown(edp, n);
@@ -435,24 +437,24 @@
 		}
 		break;
 	    case 'P': /* DCH delete character */
-		n = min(DEF1_ARG(0), COLS_LEFT + 1);
-		help = NCOLS - (edp->ccol + n);
+		n = min(DEF1_ARG(edp, 0), COLS_LEFT(edp) + 1);
+		help = NCOLS(edp) - (edp->ccol + n);
 		if (help > 0)
-			COPYCOLS(edp->ccol + n, edp->ccol, help);
-		ERASECOLS(NCOLS - n, n, edp->bkgdattr);
+			COPYCOLS(edp, edp->ccol + n, edp->ccol, help);
+		ERASECOLS(edp, NCOLS(edp) - n, n, edp->bkgdattr);
 		break;
 	    case 'X': /* ECH erase character */
-		n = min(DEF1_ARG(0), COLS_LEFT + 1);
-		ERASECOLS(edp->ccol, n, edp->bkgdattr);
+		n = min(DEF1_ARG(edp, 0), COLS_LEFT(edp) + 1);
+		ERASECOLS(edp, edp->ccol, n, edp->bkgdattr);
 		break;
 	    case 'c': /* DA primary */
-		if (ARG(0) == 0)
+		if (ARG(edp, 0) == 0)
 			wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID1,
 					    sizeof(WSEMUL_VT_ID1));
 		break;
 	    case 'g': /* TBC */
 		KASSERT(edp->tabs != 0);
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 0:
 			edp->tabs[edp->ccol] = 0;
 			break;
@@ -461,7 +463,7 @@
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%dg unknown\n", ARG(0));
+			printf("CSI%dg unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
@@ -471,7 +473,7 @@
 		fgcol = edp->fgcol;
 		bgcol = edp->bgcol;
 		for (n = 0; n < edp->nargs; n++) {
-			switch (ARG(n)) {
+			switch (ARG(edp, n)) {
 			    case 0: /* reset */
 				if (n == edp->nargs - 1) {
 					edp->bkgdattr = edp->curattr = edp->defattr;
@@ -512,17 +514,17 @@
 			    case 34: case 35: case 36: case 37:
 				/* fg color */
 				flags |= WSATTR_WSCOLORS;
-				fgcol = ARG(n) - 30;
+				fgcol = ARG(edp, n) - 30;
 				break;
 			    case 40: case 41: case 42: case 43:
 			    case 44: case 45: case 46: case 47:
 				/* bg color */
 				flags |= WSATTR_WSCOLORS;
-				bgcol = ARG(n) - 40;
+				bgcol = ARG(edp, n) - 40;
 				break;
 			    default:
 #ifdef VT100_PRINTUNKNOWN
-				printf("CSI%dm unknown\n", ARG(n));
+				printf("CSI%dm unknown\n", ARG(edp, n));
 #endif
 				break;
 			}
@@ -542,7 +544,7 @@
 		}
 		break;
 	    case 'n': /* reports */
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 5: /* DSR operating status */
 			/* 0 = OK, 3 = malfunction */
 			wsdisplay_emulinput(edp->cbcookie, "\033[0n", 4);
@@ -551,7 +553,7 @@
 			char buf[20];
 			int row;
 			if (edp->flags & VTFL_DECOM)
-				row = ROWS_ABOVE;
+				row = ROWS_ABOVE(edp);
 			else
 				row = edp->crow;
 			n = snprintf(buf, sizeof(buf), "\033[%d;%dR",
@@ -573,14 +575,14 @@
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%dn unknown\n", ARG(0));
+			printf("CSI%dn unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 	    case 'r': /* DECSTBM set top/bottom margins */
-		help = min(DEF1_ARG(0), edp->nrows) - 1;
-		n = min(DEFx_ARG(1, edp->nrows), edp->nrows) - help;
+		help = min(DEF1_ARG(edp, 0), edp->nrows) - 1;
+		n = min(DEFx_ARG(edp, 1, edp->nrows), edp->nrows) - help;
 		if (n < 2) {
 			/* minimal scrolling region has 2 lines */
 			return;
@@ -593,20 +595,20 @@
 		edp->ccol = 0;
 		break;
 	    case 'y':
-		switch (ARG(0)) {
+		switch (ARG(edp, 0)) {
 		    case 4: /* DECTST invoke confidence test */
 			/* ignore */
 			break;
 		    default:
 #ifdef VT100_PRINTUNKNOWN
-			printf("CSI%dy unknown\n", ARG(0));
+			printf("CSI%dy unknown\n", ARG(edp, 0));
 #endif
 			break;
 		}
 		break;
 	    default:
 #ifdef VT100_PRINTUNKNOWN
-		printf("CSI%c (%d, %d) unknown\n", c, ARG(0), ARG(1));
+		printf("CSI%c (%d, %d) unknown\n", c, ARG(edp, 0), ARG(edp, 1));
 #endif
 		break;
 	}
@@ -618,7 +620,7 @@
  * is not supported
  */
 static int
-vt100_selectattribute(struct wsemul_vt100_emuldata *edp,
+vt100_selectattribute(struct vt100base_data *edp,
 	int flags, int fgcol, int bgcol, long *attr, long *bkgdattr)
 {
 	int error;
@@ -708,7 +710,7 @@
  * told so by setting edp->dcstype to a nonzero value
  */
 void
-wsemul_vt100_handle_dcs(struct wsemul_vt100_emuldata *edp)
+wsemul_vt100_handle_dcs(struct vt100base_data *edp)
 {
 	int i, pos;
 
@@ -748,7 +750,7 @@
 }
 
 static int
-vt100_ansimode(struct wsemul_vt100_emuldata *edp, int nr, int op)
+vt100_ansimode(struct vt100base_data *edp, int nr, int op)
 {
 	int res = 0; /* default: unknown */
 
@@ -782,7 +784,7 @@
 }
 
 static int
-vt100_decmode(struct wsemul_vt100_emuldata *edp, int nr, int op)
+vt100_decmode(struct vt100base_data *edp, int nr, int op)
 {
 	int res = 0; /* default: unknown */
 	int flags;

Index: src/sys/dev/wscons/wsemul_vt100var.h
diff -u src/sys/dev/wscons/wsemul_vt100var.h:1.13 src/sys/dev/wscons/wsemul_vt100var.h:1.14
--- src/sys/dev/wscons/wsemul_vt100var.h:1.13	Mon Oct  9 11:03:43 2006
+++ src/sys/dev/wscons/wsemul_vt100var.h	Wed Feb 10 19:39:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wsemul_vt100var.h,v 1.13 2006/10/09 11:03:43 peter Exp $ */
+/* $NetBSD: wsemul_vt100var.h,v 1.14 2010/02/10 19:39:39 drochner Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -26,38 +26,15 @@
  *
  */
 
-#define	VT100_EMUL_NARGS	10	/* max # of args to a command */
+#include <dev/wscons/vt100_base.h>
 
 struct wsemul_vt100_emuldata {
-	const struct wsdisplay_emulops *emulops;
-	void *emulcookie;
-	int scrcapabilities;
-	u_int nrows, ncols, crow, ccol;
-	struct wsdisplay_msgattrs msgattrs;
-	long defattr;			/* default attribute */
+	struct vt100base_data bd;
 
 	long kernattr;			/* attribute for kernel output */
-	void *cbcookie;
 	int console;			/* used for DIAGNOSTIC */
 
 	u_int state;			/* processing state */
-	int flags;
-#define VTFL_LASTCHAR	0x001	/* printed last char on line (below cursor) */
-#define VTFL_INSERTMODE	0x002
-#define VTFL_APPLKEYPAD	0x004
-#define VTFL_APPLCURSOR	0x008
-#define VTFL_DECOM	0x010	/* origin mode */
-#define VTFL_DECAWM	0x020	/* auto wrap */
-#define VTFL_CURSORON	0x040
-#define VTFL_NATCHARSET	0x080	/* national replacement charset mode */
-#define VTFL_SAVEDCURS	0x100	/* we have a saved cursor state */
-	long curattr, bkgdattr;		/* currently used attribute */
-	int attrflags, fgcol, bgcol;	/* properties of curattr */
-	u_int scrreg_startrow;
-	u_int scrreg_nrows;
-	char *tabs;
-	char *dblwid;
-	int dw;
 
 	int chartab0, chartab1;
 	u_int *chartab_G[4];
@@ -65,20 +42,8 @@
 	u_int *nrctab;
 	int sschartab; /* single shift */
 
-	int nargs;
-	u_int args[VT100_EMUL_NARGS]; /* numeric command args (CSI/DCS) */
-
-	char modif1;	/* {>?} in VT100_EMUL_STATE_CSI */
-	char modif2;	/* {!"$&} in VT100_EMUL_STATE_CSI */
-
 	int designating;	/* substate in VT100_EMUL_STATE_SCS* */
 
-	int dcstype;		/* substate in VT100_EMUL_STATE_STRING */
-	char *dcsarg;
-	int dcspos;
-#define DCS_MAXLEN 256 /* ??? */
-#define DCSTYPE_TABRESTORE 1 /* DCS2$t */
-
 	u_int savedcursor_row, savedcursor_col;
 	long savedattr, savedbkgdattr;
 	int savedattrflags, savedfgcol, savedbgcol;
@@ -86,52 +51,7 @@
 	u_int *savedchartab_G[4];
 };
 
-/* some useful utility macros */
-#define	ARG(n)			(edp->args[(n)])
-#define	DEF1_ARG(n)		(ARG(n) ? ARG(n) : 1)
-#define	DEFx_ARG(n, x)		(ARG(n) ? ARG(n) : (x))
-/* the following two can be negative if we are outside the scrolling region */
-#define ROWS_ABOVE	((int)edp->crow - (int)edp->scrreg_startrow)
-#define ROWS_BELOW	((int)(edp->scrreg_startrow + edp->scrreg_nrows) \
-					- (int)edp->crow - 1)
-#define CHECK_DW do { \
-	if (edp->dblwid && edp->dblwid[edp->crow]) { \
-		edp->dw = 1; \
-		if (edp->ccol > (edp->ncols >> 1) - 1) \
-			edp->ccol = (edp->ncols >> 1) - 1; \
-	} else \
-		edp->dw = 0; \
-} while (0)
-#define NCOLS		(edp->ncols >> edp->dw)
-#define	COLS_LEFT	(NCOLS - edp->ccol - 1)
-#define COPYCOLS(f, t, n) (*edp->emulops->copycols)(edp->emulcookie, \
-	edp->crow, (f) << edp->dw, (t) << edp->dw, (n) << edp->dw)
-#define ERASECOLS(f, n, a) (*edp->emulops->erasecols)(edp->emulcookie, \
-	edp->crow, (f) << edp->dw, (n) << edp->dw, a)
-
-/*
- * response to primary DA request
- * operating level: 61 = VT100, 62 = VT200, 63 = VT300
- * extensions: 1 = 132 cols, 2 = printer port, 6 = selective erase,
- *	7 = soft charset, 8 = UDKs, 9 = NRC sets
- * VT100 = "033[?1;2c"
- */
-#define WSEMUL_VT_ID1 "\033[?62;6c"
-/*
- * response to secondary DA request
- * ident code: 24 = VT320
- * firmware version
- * hardware options: 0 = no options
- */
-#define WSEMUL_VT_ID2 "\033[>24;20;0c"
-
 void wsemul_vt100_reset(struct wsemul_vt100_emuldata *);
-void wsemul_vt100_scrollup(struct wsemul_vt100_emuldata *, int);
-void wsemul_vt100_scrolldown(struct wsemul_vt100_emuldata *, int);
-void wsemul_vt100_ed(struct wsemul_vt100_emuldata *, int);
-void wsemul_vt100_el(struct wsemul_vt100_emuldata *, int);
-void wsemul_vt100_handle_csi(struct wsemul_vt100_emuldata *, u_char);
-void wsemul_vt100_handle_dcs(struct wsemul_vt100_emuldata *);
 
 int wsemul_vt100_translate(void *, keysym_t, const char **);
 

Added files:

Index: src/sys/dev/wscons/vt100_base.h
diff -u /dev/null src/sys/dev/wscons/vt100_base.h:1.1
--- /dev/null	Wed Feb 10 19:39:39 2010
+++ src/sys/dev/wscons/vt100_base.h	Wed Feb 10 19:39:39 2010
@@ -0,0 +1,116 @@
+/* $NetBSD: vt100_base.h,v 1.1 2010/02/10 19:39:39 drochner Exp $ */
+
+/*
+ * Copyright (c) 1998
+ *	Matthias Drochner.  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.
+ *
+ * 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.
+ *
+ */
+
+#define	VT100_EMUL_NARGS	10	/* max # of args to a command */
+
+struct vt100base_data {
+	const struct wsdisplay_emulops *emulops;
+	void *emulcookie;
+	int scrcapabilities;
+	u_int nrows, ncols, crow, ccol;
+	struct wsdisplay_msgattrs msgattrs;
+	long defattr;			/* default attribute */
+
+	void *cbcookie;
+
+	int flags;
+#define VTFL_LASTCHAR	0x001	/* printed last char on line (below cursor) */
+#define VTFL_INSERTMODE	0x002
+#define VTFL_APPLKEYPAD	0x004
+#define VTFL_APPLCURSOR	0x008
+#define VTFL_DECOM	0x010	/* origin mode */
+#define VTFL_DECAWM	0x020	/* auto wrap */
+#define VTFL_CURSORON	0x040
+#define VTFL_NATCHARSET	0x080	/* national replacement charset mode */
+#define VTFL_SAVEDCURS	0x100	/* we have a saved cursor state */
+	long curattr, bkgdattr;		/* currently used attribute */
+	int attrflags, fgcol, bgcol;	/* properties of curattr */
+	u_int scrreg_startrow;
+	u_int scrreg_nrows;
+	char *tabs;
+	char *dblwid;
+	int dw;
+
+	int nargs;
+	u_int args[VT100_EMUL_NARGS]; /* numeric command args (CSI/DCS) */
+
+	char modif1;	/* {>?} in VT100_EMUL_STATE_CSI */
+	char modif2;	/* {!"$&} in VT100_EMUL_STATE_CSI */
+
+	int dcstype;		/* substate in VT100_EMUL_STATE_STRING */
+	char *dcsarg;
+	int dcspos;
+#define DCS_MAXLEN 256 /* ??? */
+#define DCSTYPE_TABRESTORE 1 /* DCS2$t */
+};
+
+/* some useful utility macros */
+#define	ARG(d, n)			((d)->args[(n)])
+#define	DEF1_ARG(d, n)		(ARG(d, n) ? ARG(d, n) : 1)
+#define	DEFx_ARG(d, n, x)		(ARG(d, n) ? ARG(d, n) : (x))
+/* the following two can be negative if we are outside the scrolling region */
+#define ROWS_ABOVE(d)	((int)(d)->crow - (int)(d)->scrreg_startrow)
+#define ROWS_BELOW(d)	((int)((d)->scrreg_startrow + (d)->scrreg_nrows) \
+					- (int)(d)->crow - 1)
+#define CHECK_DW(d) do { \
+	if ((d)->dblwid && (d)->dblwid[(d)->crow]) { \
+		(d)->dw = 1; \
+		if ((d)->ccol > ((d)->ncols >> 1) - 1) \
+			(d)->ccol = ((d)->ncols >> 1) - 1; \
+	} else \
+		(d)->dw = 0; \
+} while (0)
+#define NCOLS(d)	((d)->ncols >> (d)->dw)
+#define	COLS_LEFT(d)	(NCOLS(d) - (d)->ccol - 1)
+#define COPYCOLS(d, f, t, n) (*(d)->emulops->copycols)((d)->emulcookie, \
+	(d)->crow, (f) << (d)->dw, (t) << (d)->dw, (n) << (d)->dw)
+#define ERASECOLS(d, f, n, a) (*(d)->emulops->erasecols)((d)->emulcookie, \
+	(d)->crow, (f) << (d)->dw, (n) << (d)->dw, a)
+
+/*
+ * response to primary DA request
+ * operating level: 61 = VT100, 62 = VT200, 63 = VT300
+ * extensions: 1 = 132 cols, 2 = printer port, 6 = selective erase,
+ *	7 = soft charset, 8 = UDKs, 9 = NRC sets
+ * VT100 = "033[?1;2c"
+ */
+#define WSEMUL_VT_ID1 "\033[?62;6c"
+/*
+ * response to secondary DA request
+ * ident code: 24 = VT320
+ * firmware version
+ * hardware options: 0 = no options
+ */
+#define WSEMUL_VT_ID2 "\033[>24;20;0c"
+
+void wsemul_vt100_scrollup(struct vt100base_data *, int);
+void wsemul_vt100_scrolldown(struct vt100base_data *, int);
+void wsemul_vt100_ed(struct vt100base_data *, int);
+void wsemul_vt100_el(struct vt100base_data *, int);
+void wsemul_vt100_handle_csi(struct vt100base_data *, u_char);
+void wsemul_vt100_handle_dcs(struct vt100base_data *);

Reply via email to