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