Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/wscons Allow big parts of the vt100 emulation code (...



details:   https://anonhg.NetBSD.org/src/rev/ff1a7a50a82c
branches:  trunk
changeset: 751985:ff1a7a50a82c
user:      drochner <drochner%NetBSD.org@localhost>
date:      Wed Feb 10 19:39:39 2010 +0000

description:
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.

diffstat:

 sys/dev/wscons/vt100_base.h         |  116 +++++++++
 sys/dev/wscons/wsemul_vt100.c       |  449 ++++++++++++++++++-----------------
 sys/dev/wscons/wsemul_vt100_chars.c |   16 +-
 sys/dev/wscons/wsemul_vt100_keys.c  |   15 +-
 sys/dev/wscons/wsemul_vt100_subr.c  |  176 +++++++------
 sys/dev/wscons/wsemul_vt100var.h    |   86 +------
 6 files changed, 461 insertions(+), 397 deletions(-)

diffs (truncated from 1772 to 300 lines):

diff -r 12e9d373fe79 -r ff1a7a50a82c sys/dev/wscons/vt100_base.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/wscons/vt100_base.h       Wed Feb 10 19:39:39 2010 +0000
@@ -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 *);
diff -r 12e9d373fe79 -r ff1a7a50a82c sys/dev/wscons/wsemul_vt100.c
--- a/sys/dev/wscons/wsemul_vt100.c     Wed Feb 10 17:00:45 2010 +0000
+++ b/sys/dev/wscons/wsemul_vt100.c     Wed Feb 10 19:39:39 2010 +0000
@@ -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 @@



Home | Main Index | Thread Index | Old Index