xref: /netbsd-src/sys/arch/hp300/stand/common/ite.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: ite.c,v 1.3 2003/11/14 16:52:40 tsutsui Exp $	*/
2 
3 /*
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  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: ite.c 1.24 93/06/25$
36  *
37  *	@(#)ite.c	8.1 (Berkeley) 7/8/93
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: ite.c 1.24 93/06/25$
75  *
76  *	@(#)ite.c	8.1 (Berkeley) 7/8/93
77  */
78 
79 /*
80  * Standalone Internal Terminal Emulator (CRT and keyboard)
81  */
82 
83 #ifdef ITECONSOLE
84 
85 #include <sys/param.h>
86 #include <dev/cons.h>
87 
88 #include <hp300/dev/grfreg.h>
89 
90 #include <hp300/stand/common/device.h>
91 #include <hp300/stand/common/itevar.h>
92 #include <hp300/stand/common/kbdvar.h>
93 #include <hp300/stand/common/consdefs.h>
94 #include <hp300/stand/common/samachdep.h>
95 
96 static void iteconfig(void);
97 static void ite_deinit_noop(struct ite_data *);
98 static void ite_clrtoeol(struct ite_data *, struct itesw *, int, int);
99 static void itecheckwrap(struct ite_data *, struct itesw *);
100 
101 struct itesw itesw[] = {
102 	{ GID_TOPCAT,
103 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
104 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
105 
106 	{ GID_GATORBOX,
107 	gbox_init,	ite_deinit_noop, gbox_clear,	gbox_putc,
108 	gbox_cursor,	gbox_scroll,	ite_readbyte,	ite_writeglyph },
109 
110 	{ GID_RENAISSANCE,
111 	rbox_init,	ite_deinit_noop, rbox_clear,	rbox_putc,
112 	rbox_cursor,	rbox_scroll,	ite_readbyte,	ite_writeglyph },
113 
114 	{ GID_LRCATSEYE,
115 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
116 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
117 
118 	{ GID_HRCCATSEYE,
119 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
120 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
121 
122 	{ GID_HRMCATSEYE,
123 	topcat_init,	ite_deinit_noop, topcat_clear,	topcat_putc,
124 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph },
125 
126 	{ GID_DAVINCI,
127       	dvbox_init,	ite_deinit_noop, dvbox_clear,	dvbox_putc,
128 	dvbox_cursor,	dvbox_scroll,	ite_readbyte,	ite_writeglyph },
129 
130 	{ GID_HYPERION,
131 	hyper_init,	ite_deinit_noop, hyper_clear,	hyper_putc,
132 	hyper_cursor,	hyper_scroll,	ite_readbyte,	ite_writeglyph },
133 };
134 int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
135 
136 /* these guys need to be in initialized data */
137 int itecons = -1;
138 struct  ite_data ite_data[NITE] = { { 0 } };
139 int	ite_scode[NITE] = { 0 };
140 
141 /*
142  * Locate all bitmapped displays
143  */
144 static void
145 iteconfig()
146 {
147 	extern struct hp_hw sc_table[];
148 	int dtype, fboff, i;
149 	struct hp_hw *hw;
150 	struct grfreg *gr;
151 	struct ite_data *ip;
152 
153 	i = 0;
154 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
155 	        if (!HW_ISDEV(hw, D_BITMAP))
156 			continue;
157 		gr = (struct grfreg *) hw->hw_kva;
158 		/* XXX: redundent but safe */
159 		if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
160 			continue;
161 		for (dtype = 0; dtype < nitesw; dtype++)
162 			if (itesw[dtype].ite_hwid == gr->gr_id2)
163 				break;
164 		if (dtype == nitesw)
165 			continue;
166 		if (i >= NITE)
167 			break;
168 		ite_scode[i] = hw->hw_sc;
169 		ip = &ite_data[i];
170 		ip->isw = &itesw[dtype];
171 		ip->regbase = (caddr_t) gr;
172 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
173 		ip->fbbase = (caddr_t)(*((u_char *)ip->regbase + fboff) << 16);
174 		/* DIO II: FB offset is relative to select code space */
175 		if (ip->regbase >= (caddr_t)DIOIIBASE)
176 			ip->fbbase += (int)ip->regbase;
177 		ip->fbwidth  = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
178 		ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
179 		ip->dwidth   = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
180 		ip->dheight  = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
181 		/*
182 		 * XXX some displays (e.g. the davinci) appear
183 		 * to return a display height greater than the
184 		 * returned FB height.  Guess we should go back
185 		 * to getting the display dimensions from the
186 		 * fontrom...
187 		 */
188 		if (ip->dwidth > ip->fbwidth)
189 			ip->dwidth = ip->fbwidth;
190 		if (ip->dheight > ip->fbheight)
191 			ip->dheight = ip->fbheight;
192 		ip->flags = ITE_ALIVE|ITE_CONSOLE;
193 		i++;
194 	}
195 }
196 
197 #ifdef CONSDEBUG
198 /*
199  * Allows us to cycle through all possible consoles (NITE ites and serial port)
200  * by using SHIFT-RESET on the keyboard.
201  */
202 int	whichconsole = -1;
203 #endif
204 
205 void
206 iteprobe(cp)
207 	struct consdev *cp;
208 {
209 	int ite;
210 	struct ite_data *ip;
211 	int unit, pri;
212 
213 #ifdef CONSDEBUG
214 	whichconsole = ++whichconsole % (NITE+1);
215 #endif
216 
217 	if (itecons != -1)
218 		return;
219 
220 	iteconfig();
221 	unit = -1;
222 	pri = CN_DEAD;
223 	for (ite = 0; ite < NITE; ite++) {
224 #ifdef CONSDEBUG
225 		if (ite < whichconsole)
226 			continue;
227 #endif
228 		ip = &ite_data[ite];
229 		if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
230 		    != (ITE_ALIVE|ITE_CONSOLE))
231 			continue;
232 		if ((int)ip->regbase == GRFIADDR) {
233 			pri = CN_INTERNAL;
234 			unit = ite;
235 		} else if (unit < 0) {
236 			pri = CN_NORMAL;
237 			unit = ite;
238 		}
239 	}
240 	curcons_scode = ite_scode[unit];
241 	cp->cn_dev = unit;
242 	cp->cn_pri = pri;
243 }
244 
245 void
246 iteinit(cp)
247 	struct consdev *cp;
248 {
249 	int ite = cp->cn_dev;
250 	struct ite_data *ip;
251 
252 	if (itecons != -1)
253 		return;
254 
255 	ip = &ite_data[ite];
256 
257 	ip->curx = 0;
258 	ip->cury = 0;
259 	ip->cursorx = 0;
260 	ip->cursory = 0;
261 
262 	(*ip->isw->ite_init)(ip);
263 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
264 
265 	itecons = ite;
266 	kbdinit();
267 }
268 
269 /* ARGSUSED */
270 void
271 iteputchar(dev, c)
272 	dev_t dev;
273 	int c;
274 {
275 	struct ite_data *ip = &ite_data[itecons];
276 	struct itesw *sp = ip->isw;
277 
278 	c &= 0x7F;
279 	switch (c) {
280 
281 	case '\n':
282 		if (++ip->cury == ip->rows) {
283 			ip->cury--;
284 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
285 			ite_clrtoeol(ip, sp, ip->cury, 0);
286 		}
287 		else
288 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
289 		break;
290 
291 	case '\r':
292 		ip->curx = 0;
293 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
294 		break;
295 
296 	case '\b':
297 		if (--ip->curx < 0)
298 			ip->curx = 0;
299 		else
300 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
301 		break;
302 
303 	default:
304 		if (c < ' ' || c == 0177)
305 			break;
306 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
307 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
308 		itecheckwrap(ip, sp);
309 		break;
310 	}
311 }
312 
313 static void
314 itecheckwrap(ip, sp)
315 	struct ite_data *ip;
316 	struct itesw *sp;
317 {
318 	if (++ip->curx == ip->cols) {
319 		ip->curx = 0;
320 		if (++ip->cury == ip->rows) {
321 			--ip->cury;
322 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
323 			ite_clrtoeol(ip, sp, ip->cury, 0);
324 			return;
325 		}
326 	}
327 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
328 }
329 
330 static void
331 ite_clrtoeol(ip, sp, y, x)
332 	struct ite_data *ip;
333 	struct itesw *sp;
334 	int y, x;
335 {
336 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
337 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
338 }
339 
340 /* ARGSUSED */
341 int
342 itegetchar(dev)
343 	dev_t dev;
344 {
345 
346 #ifdef SMALL
347 	return 0;
348 #else
349 	return kbdgetc();
350 #endif
351 }
352 #endif
353 
354 /* ARGSUSED */
355 static void
356 ite_deinit_noop(ip)
357 	struct ite_data *ip;
358 {
359 }
360