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