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