xref: /netbsd-src/sys/arch/x68k/dev/itevar.h (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: itevar.h,v 1.13 2007/10/17 19:58:02 garbled Exp $	*/
2 
3 /*
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * from: Utah $Hdr: itevar.h 1.1 90/07/09$
36  *
37  *	@(#)itevar.h	7.2 (Berkeley) 11/4/90
38  */
39 /*
40  * Copyright (c) 1988 University of Utah.
41  *
42  * This code is derived from software contributed to Berkeley by
43  * the Systems Programming Group of the University of Utah Computer
44  * Science Department.
45  *
46  * Redistribution and use in source and binary forms, with or without
47  * modification, are permitted provided that the following conditions
48  * are met:
49  * 1. Redistributions of source code must retain the above copyright
50  *    notice, this list of conditions and the following disclaimer.
51  * 2. Redistributions in binary form must reproduce the above copyright
52  *    notice, this list of conditions and the following disclaimer in the
53  *    documentation and/or other materials provided with the distribution.
54  * 3. All advertising materials mentioning features or use of this software
55  *    must display the following acknowledgement:
56  *	This product includes software developed by the University of
57  *	California, Berkeley and its contributors.
58  * 4. Neither the name of the University nor the names of its contributors
59  *    may be used to endorse or promote products derived from this software
60  *    without specific prior written permission.
61  *
62  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72  * SUCH DAMAGE.
73  *
74  * from: Utah $Hdr: itevar.h 1.1 90/07/09$
75  *
76  *	@(#)itevar.h	7.2 (Berkeley) 11/4/90
77  */
78 
79 #define UNIT(dev)       minor(dev)
80 
81 struct ite_softc;
82 
83 struct itesw {
84 	int	(*ite_cnprobe)(int minor);
85 	void	(*ite_init)(struct ite_softc *);
86 	void	(*ite_deinit)(struct ite_softc *);
87 	void	(*ite_clear)(struct ite_softc *, int, int, int, int);
88 	void	(*ite_putc)(struct ite_softc *, int, int, int, int);
89 	void	(*ite_cursor)(struct ite_softc *, int);
90 	void	(*ite_scroll)(struct ite_softc *, int, int, int, int);
91 };
92 
93 enum ite_arraymaxs {
94 	MAX_ARGSIZE = 256,
95 	MAX_TABS = 256,
96 };
97 
98 /* maximum number of argument characters (<CSI>33;34;3m for example) */
99 #define ARGBUF_SIZE 256
100 
101 struct ite_softc {
102 	struct	device device;
103 	struct grf_softc *grf;
104 	struct	itesw *isw;
105 	int	flags;
106 	int	type;
107 	int	open_cnt;
108 	void	*priv;
109 	short	curx, cury;
110 	short   cursorx, cursory;
111 	u_char	*font;
112 	u_char	*cursor;
113 	u_char	font_lo, font_hi;
114 	short	rows, cols;
115 	short   cpl;
116 	short	ftheight, ftwidth, ftbaseline, ftboldsmear;
117 	short   attribute;
118 	u_char	*attrbuf;
119 	short	planemask;
120 	short	pos;
121 	char	imode, fpd, hold;
122 	u_char  escape, cursor_opt, key_repeat;
123 	char	*GL, *GR, *save_GL;
124 	char	G0, G1, G2, G3;
125 	char	fgcolor, bgcolor;
126 	char	linefeed_newline, auto_wrap;
127 	char	cursor_appmode, keypad_appmode;
128 	char	argbuf[ARGBUF_SIZE], *ap, *tabs;
129 	char	emul_level, eightbit_C1;
130 	int	top_margin, bottom_margin;
131 	char	inside_margins, sc_om;
132 	short	save_curx, save_cury, save_attribute, save_char;
133 	char	sc_G0, sc_G1, sc_G2, sc_G3;
134 	char	*sc_GL, *sc_GR;
135 };
136 
137 enum emul_level {
138 	EMUL_VT100 = 1,
139 	EMUL_VT300_8,
140 	EMUL_VT300_7
141 };
142 
143 /* Flags */
144 #define ITE_ALIVE	0x01	/* hardware exists */
145 #define ITE_INITED	0x02	/* device has been initialized */
146 #define ITE_CONSOLE	0x04	/* device can be console */
147 #define ITE_ISCONS	0x08	/* device is console */
148 #define ITE_ACTIVE	0x10	/* device is being used as ITE */
149 #define ITE_INGRF	0x20	/* device in use as non-ITE */
150 
151 #ifdef DO_WEIRD_ATTRIBUTES
152 #define attrloc(ip, y, x) \
153 	(ip->attrbuf + ((y) * ip->cols) + (x))
154 
155 #define attrclr(ip, sy, sx, h, w) \
156 	memset(ip->attrbuf + ((sy) * ip->cols) + (sx), 0, (h) * (w))
157 
158 #define attrmov(ip, sy, sx, dy, dx, h, w) \
159 	memcpy(ip->attrbuf + ((dy) * ip->cols) + (dx), \
160 	      ip->attrbuf + ((sy) * ip->cols) + (sx), \
161 	      (h) * (w))
162 
163 #define attrtest(ip, attr) \
164 	((* (u_char *) attrloc(ip, ip->cury, ip->curx)) & attr)
165 
166 #define attrset(ip, attr) \
167 	((* (u_char *) attrloc(ip, ip->cury, ip->curx)) = attr)
168 #else
169 #define attrloc(ip, y, x) 0
170 #define attrclr(ip, sy, sx, h, w)
171 #define attrmov(ip, sy, sx, dy, dx, h, w)
172 #define attrtest(ip, attr) 0
173 #define attrset(ip, attr)
174 #endif
175 
176 
177 /*
178  * X and Y location of character 'c' in the framebuffer, in pixels.
179  */
180 #define	charX(ip,c)	\
181 	(((c) % (ip)->cpl) * (ip)->ftwidth + (ip)->fontx)
182 
183 #define	charY(ip,c)	\
184 	(((c) / (ip)->cpl) * (ip)->ftheight + (ip)->fonty)
185 
186 /* Character attributes */
187 #define ATTR_NOR        0x0             /* normal */
188 #define	ATTR_INV	0x1		/* inverse */
189 #define	ATTR_UL		0x2		/* underline */
190 #define ATTR_BOLD	0x4		/* bold */
191 #define ATTR_BLINK	0x8		/* blink */
192 #define ATTR_ALL	(ATTR_INV | ATTR_UL|ATTR_BOLD|ATTR_BLINK)
193 
194 /* Keyboard attributes */
195 #define ATTR_KPAD	0x80		/* keypad transmit */
196 
197 /* Replacement Rules */
198 #define RR_CLEAR		0x0
199 #define RR_COPY			0x3
200 #define RR_XOR			0x6
201 #define RR_COPYINVERTED  	0xc
202 
203 #define SCROLL_UP	0x01
204 #define SCROLL_DOWN	0x02
205 #define SCROLL_LEFT	0x03
206 #define SCROLL_RIGHT	0x04
207 #define DRAW_CURSOR	0x05
208 #define ERASE_CURSOR    0x06
209 #define MOVE_CURSOR	0x07
210 #define START_CURSOROPT	0x08	/* at start of output. May disable cursor */
211 #define END_CURSOROPT	0x09	/* at end, make sure cursor state is ok */
212 
213 /* special key codes */
214 #define KBD_LEFT_SHIFT	0x70
215 #define KBD_RIGHT_SHIFT	0x70
216 #define KBD_CAPS_LOCK	0x5d
217 #define KBD_CTRL	0x71
218 #define KBD_LEFT_ALT	0x55
219 #define KBD_RIGHT_ALT	0x58
220 #define KBD_LEFT_META	0x56
221 #define KBD_RIGHT_META	0x57
222 #define KBD_OPT1	0x72
223 #define KBD_OPT2	0x73
224 #define KBD_RECONNECT	0x7f
225 
226 /* modifier map for use in itefilter() */
227 #define KBD_MOD_LSHIFT	(1<<0)
228 #define KBD_MOD_RSHIFT	(1<<1)
229 #define KBD_MOD_SHIFT	(KBD_MOD_LSHIFT | KBD_MOD_RSHIFT)
230 #define KBD_MOD_CTRL	(1<<2)
231 #define KBD_MOD_LALT	(1<<3)
232 #define KBD_MOD_RALT	(1<<4)
233 #define KBD_MOD_ALT	(KBD_MOD_LALT | KBD_MOD_RALT)
234 #define KBD_MOD_LMETA	(1<<5)
235 #define KBD_MOD_RMETA	(1<<6)
236 #define KBD_MOD_META	(KBD_MOD_LMETA | KBD_MOD_RMETA)
237 #define KBD_MOD_CAPS	(1<<7)
238 #define KBD_MOD_OPT1	(1<<8)
239 #define KBD_MOD_OPT2	(1<<9)
240 
241 /* type for the second argument to itefilter(). Note that the
242    driver doesn't support key-repeat for console-mode, since it can't use
243    timeout() for polled I/O. */
244 
245 enum tab_size { TABSIZE = 8 };
246 #define TABEND(u) (ite_tty[u]->t_windsize.ws_col - TABSIZE) /* XXX */
247 
248 #define set_attr(ip, attr)	((ip)->attribute |= (attr))
249 #define clr_attr(ip, attr)	((ip)->attribute &= ~(attr))
250 #define attrloc(ip, y, x) 0
251 #define attrclr(ip, sy, sx, h, w)
252 #define attrmov(ip, sy, sx, dy, dx, h, w)
253 #define attrtest(ip, attr) 0
254 #define attrset(ip, attr)
255 
256 /* character set */
257 #define CSET_MULTI	0x80 /* multibytes flag */
258 #define CSET_ASCII	0 /* ascii */
259 #define CSET_JISROMA	1 /* iso2022jp romaji */
260 #define CSET_JISKANA	2 /* iso2022jp kana */
261 #define CSET_JIS1978	(3|CSET_MULTI) /* iso2022jp old jis kanji */
262 #define CSET_JIS1983	(4|CSET_MULTI) /* iso2022jp new jis kanji */
263 #define CSET_JIS1990	(5|CSET_MULTI) /* iso2022jp hojo kanji */
264 
265 struct consdev;
266 
267 /* console related function */
268 void	itecnprobe(struct consdev *);
269 void	itecninit(struct consdev *);
270 int	itecngetc(dev_t);
271 void	itecnputc(dev_t, int);
272 void	itecnfinish(struct ite_softc *);
273 
274 /* standard ite device entry points. */
275 void	iteinit(dev_t);
276 void	itestart(struct tty *);
277 
278 /* ite functions */
279 int	iteon(dev_t, int);
280 void	iteoff(dev_t, int);
281 void	ite_reinit(dev_t);
282 void	ite_reset(struct ite_softc *);
283 int	ite_cnfilter(u_char);
284 void	ite_filter(u_char);
285 
286 /* lower layer functions */
287 void	tv_init(struct ite_softc *);
288 void	tv_deinit(struct ite_softc *);
289 
290 #ifdef _KERNEL
291 extern unsigned char kern_font[];
292 
293 /* keyboard LED status variable */
294 extern unsigned char kbdled;
295 void ite_set_glyph(void);
296 void kbd_setLED(void);
297 #endif
298