Home | History | Annotate | Line # | Download | only in wscons
wsemul_vt100var.h revision 1.13
      1 /* $NetBSD: wsemul_vt100var.h,v 1.13 2006/10/09 11:03:43 peter Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1998
      5  *	Matthias Drochner.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  */
     28 
     29 #define	VT100_EMUL_NARGS	10	/* max # of args to a command */
     30 
     31 struct wsemul_vt100_emuldata {
     32 	const struct wsdisplay_emulops *emulops;
     33 	void *emulcookie;
     34 	int scrcapabilities;
     35 	u_int nrows, ncols, crow, ccol;
     36 	struct wsdisplay_msgattrs msgattrs;
     37 	long defattr;			/* default attribute */
     38 
     39 	long kernattr;			/* attribute for kernel output */
     40 	void *cbcookie;
     41 	int console;			/* used for DIAGNOSTIC */
     42 
     43 	u_int state;			/* processing state */
     44 	int flags;
     45 #define VTFL_LASTCHAR	0x001	/* printed last char on line (below cursor) */
     46 #define VTFL_INSERTMODE	0x002
     47 #define VTFL_APPLKEYPAD	0x004
     48 #define VTFL_APPLCURSOR	0x008
     49 #define VTFL_DECOM	0x010	/* origin mode */
     50 #define VTFL_DECAWM	0x020	/* auto wrap */
     51 #define VTFL_CURSORON	0x040
     52 #define VTFL_NATCHARSET	0x080	/* national replacement charset mode */
     53 #define VTFL_SAVEDCURS	0x100	/* we have a saved cursor state */
     54 	long curattr, bkgdattr;		/* currently used attribute */
     55 	int attrflags, fgcol, bgcol;	/* properties of curattr */
     56 	u_int scrreg_startrow;
     57 	u_int scrreg_nrows;
     58 	char *tabs;
     59 	char *dblwid;
     60 	int dw;
     61 
     62 	int chartab0, chartab1;
     63 	u_int *chartab_G[4];
     64 	u_int *isolatin1tab, *decgraphtab, *dectechtab;
     65 	u_int *nrctab;
     66 	int sschartab; /* single shift */
     67 
     68 	int nargs;
     69 	u_int args[VT100_EMUL_NARGS]; /* numeric command args (CSI/DCS) */
     70 
     71 	char modif1;	/* {>?} in VT100_EMUL_STATE_CSI */
     72 	char modif2;	/* {!"$&} in VT100_EMUL_STATE_CSI */
     73 
     74 	int designating;	/* substate in VT100_EMUL_STATE_SCS* */
     75 
     76 	int dcstype;		/* substate in VT100_EMUL_STATE_STRING */
     77 	char *dcsarg;
     78 	int dcspos;
     79 #define DCS_MAXLEN 256 /* ??? */
     80 #define DCSTYPE_TABRESTORE 1 /* DCS2$t */
     81 
     82 	u_int savedcursor_row, savedcursor_col;
     83 	long savedattr, savedbkgdattr;
     84 	int savedattrflags, savedfgcol, savedbgcol;
     85 	int savedchartab0, savedchartab1;
     86 	u_int *savedchartab_G[4];
     87 };
     88 
     89 /* some useful utility macros */
     90 #define	ARG(n)			(edp->args[(n)])
     91 #define	DEF1_ARG(n)		(ARG(n) ? ARG(n) : 1)
     92 #define	DEFx_ARG(n, x)		(ARG(n) ? ARG(n) : (x))
     93 /* the following two can be negative if we are outside the scrolling region */
     94 #define ROWS_ABOVE	((int)edp->crow - (int)edp->scrreg_startrow)
     95 #define ROWS_BELOW	((int)(edp->scrreg_startrow + edp->scrreg_nrows) \
     96 					- (int)edp->crow - 1)
     97 #define CHECK_DW do { \
     98 	if (edp->dblwid && edp->dblwid[edp->crow]) { \
     99 		edp->dw = 1; \
    100 		if (edp->ccol > (edp->ncols >> 1) - 1) \
    101 			edp->ccol = (edp->ncols >> 1) - 1; \
    102 	} else \
    103 		edp->dw = 0; \
    104 } while (0)
    105 #define NCOLS		(edp->ncols >> edp->dw)
    106 #define	COLS_LEFT	(NCOLS - edp->ccol - 1)
    107 #define COPYCOLS(f, t, n) (*edp->emulops->copycols)(edp->emulcookie, \
    108 	edp->crow, (f) << edp->dw, (t) << edp->dw, (n) << edp->dw)
    109 #define ERASECOLS(f, n, a) (*edp->emulops->erasecols)(edp->emulcookie, \
    110 	edp->crow, (f) << edp->dw, (n) << edp->dw, a)
    111 
    112 /*
    113  * response to primary DA request
    114  * operating level: 61 = VT100, 62 = VT200, 63 = VT300
    115  * extensions: 1 = 132 cols, 2 = printer port, 6 = selective erase,
    116  *	7 = soft charset, 8 = UDKs, 9 = NRC sets
    117  * VT100 = "033[?1;2c"
    118  */
    119 #define WSEMUL_VT_ID1 "\033[?62;6c"
    120 /*
    121  * response to secondary DA request
    122  * ident code: 24 = VT320
    123  * firmware version
    124  * hardware options: 0 = no options
    125  */
    126 #define WSEMUL_VT_ID2 "\033[>24;20;0c"
    127 
    128 void wsemul_vt100_reset(struct wsemul_vt100_emuldata *);
    129 void wsemul_vt100_scrollup(struct wsemul_vt100_emuldata *, int);
    130 void wsemul_vt100_scrolldown(struct wsemul_vt100_emuldata *, int);
    131 void wsemul_vt100_ed(struct wsemul_vt100_emuldata *, int);
    132 void wsemul_vt100_el(struct wsemul_vt100_emuldata *, int);
    133 void wsemul_vt100_handle_csi(struct wsemul_vt100_emuldata *, u_char);
    134 void wsemul_vt100_handle_dcs(struct wsemul_vt100_emuldata *);
    135 
    136 int wsemul_vt100_translate(void *, keysym_t, const char **);
    137 
    138 void vt100_initchartables(struct wsemul_vt100_emuldata *);
    139 void vt100_setnrc(struct wsemul_vt100_emuldata *, int);
    140