xref: /netbsd-src/sys/arch/hp300/stand/common/ite.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: ite.c,v 1.16 2011/02/12 05:08:40 tsutsui Exp $	*/
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1990, 1993
6  *	The Regents of the University of California.  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: ite.c 1.24 93/06/25$
37  *
38  *	@(#)ite.c	8.1 (Berkeley) 7/8/93
39  */
40 
41 /*
42  * Standalone Internal Terminal Emulator (CRT and keyboard)
43  */
44 
45 #ifdef ITECONSOLE
46 
47 #include <sys/param.h>
48 #include <dev/cons.h>
49 
50 #include <hp300/stand/common/grfreg.h>
51 #include <hp300/dev/intioreg.h>
52 
53 #include <hp300/stand/common/device.h>
54 #include <hp300/stand/common/itevar.h>
55 #include <hp300/stand/common/kbdvar.h>
56 #include <hp300/stand/common/consdefs.h>
57 #include <hp300/stand/common/samachdep.h>
58 
59 static void iteconfig(void);
60 static void ite_clrtoeol(struct ite_data *, struct itesw *, int, int);
61 static void itecheckwrap(struct ite_data *, struct itesw *);
62 
63 struct itesw itesw[] = {
64 	{ GID_TOPCAT,
65 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
66 	ite_dio_cursor,	ite_dio_scroll },
67 
68 	{ GID_GATORBOX,
69 	gbox_init,	ite_dio_clear,	ite_dio_putc8bpp,
70 	ite_dio_cursor,	gbox_scroll },
71 
72 	{ GID_RENAISSANCE,
73 	rbox_init,	ite_dio_clear,	ite_dio_putc8bpp,
74 	ite_dio_cursor,	ite_dio_scroll },
75 
76 	{ GID_LRCATSEYE,
77 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
78 	ite_dio_cursor,	ite_dio_scroll },
79 
80 	{ GID_HRCCATSEYE,
81 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
82 	ite_dio_cursor,	ite_dio_scroll },
83 
84 	{ GID_HRMCATSEYE,
85 	topcat_init,	ite_dio_clear,	ite_dio_putc8bpp,
86 	ite_dio_cursor,	ite_dio_scroll },
87 
88 	{ GID_DAVINCI,
89       	dvbox_init,	ite_dio_clear,	ite_dio_putc8bpp,
90 	ite_dio_cursor,	ite_dio_scroll },
91 
92 	{ GID_HYPERION,
93 	hyper_init,	ite_dio_clear,	ite_dio_putc1bpp,
94 	ite_dio_cursor,	ite_dio_scroll },
95 
96 	{ GID_TIGER,
97 	tvrx_init,	ite_dio_clear,	ite_dio_putc1bpp,
98 	ite_dio_cursor,	ite_dio_scroll },
99 
100 	{ GID_A1474MID,
101 	dumb_init,	dumb_clear,	dumb_putc,
102 	dumb_cursor,	dumb_scroll },
103 
104 	{ GID_A147xVGA,
105 	dumb_init,	dumb_clear,	dumb_putc,
106 	dumb_cursor,	dumb_scroll },
107 };
108 int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
109 
110 /* these guys need to be in initialized data */
111 int itecons = -1;
112 struct  ite_data ite_data[NITE] = { { 0 } };
113 int	ite_scode[NITE] = { 0 };
114 
115 /*
116  * Locate all bitmapped displays
117  */
118 static void
119 iteconfig(void)
120 {
121 	int dtype, fboff, i;
122 	struct hp_hw *hw;
123 	struct grfreg *gr;
124 	struct ite_data *ip;
125 
126 	i = 0;
127 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
128 	        if (!HW_ISDEV(hw, D_BITMAP))
129 			continue;
130 		gr = (struct grfreg *) hw->hw_kva;
131 		/* XXX: redundent but safe */
132 		if (badaddr((void *)gr) || gr->gr_id != GRFHWID)
133 			continue;
134 		for (dtype = 0; dtype < nitesw; dtype++)
135 			if (itesw[dtype].ite_hwid == gr->gr_id2)
136 				break;
137 		if (dtype == nitesw)
138 			continue;
139 		if (i >= NITE)
140 			break;
141 		ite_scode[i] = hw->hw_sc;
142 		ip = &ite_data[i];
143 		ip->isw = &itesw[dtype];
144 		ip->regbase = (void *) gr;
145 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
146 		ip->fbbase = (void *)(*((u_char *)ip->regbase + fboff) << 16);
147 		/* DIO II: FB offset is relative to select code space */
148 		if (ip->regbase >= (void *)DIOIIBASE)
149 			ip->fbbase = (char*)ip->fbbase + (int)ip->regbase;
150 		ip->fbwidth  = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
151 		ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
152 		ip->dwidth   = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
153 		ip->dheight  = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
154 		/*
155 		 * XXX some displays (e.g. the davinci) appear
156 		 * to return a display height greater than the
157 		 * returned FB height.  Guess we should go back
158 		 * to getting the display dimensions from the
159 		 * fontrom...
160 		 */
161 		if (ip->dwidth > ip->fbwidth)
162 			ip->dwidth = ip->fbwidth;
163 		if (ip->dheight > ip->fbheight)
164 			ip->dheight = ip->fbheight;
165 		ip->alive = 1;
166 		i++;
167 	}
168 }
169 
170 #ifdef CONSDEBUG
171 /*
172  * Allows us to cycle through all possible consoles (NITE ites and serial port)
173  * by using SHIFT-RESET on the keyboard.
174  */
175 int	whichconsole = -1;
176 #endif
177 
178 void
179 iteprobe(struct consdev *cp)
180 {
181 	int ite;
182 	struct ite_data *ip;
183 	int unit, pri;
184 
185 #ifdef CONSDEBUG
186 	whichconsole = ++whichconsole % (NITE+1);
187 #endif
188 
189 	if (itecons != -1)
190 		return;
191 
192 	iteconfig();
193 	unit = -1;
194 	pri = CN_DEAD;
195 	for (ite = 0; ite < NITE; ite++) {
196 #ifdef CONSDEBUG
197 		if (ite < whichconsole)
198 			continue;
199 #endif
200 		ip = &ite_data[ite];
201 		if (ip->alive == 0)
202 			continue;
203 		if ((int)ip->regbase == INTIOBASE + FB_BASE) {
204 			pri = CN_INTERNAL;
205 			unit = ite;
206 		} else if (unit < 0) {
207 			pri = CN_NORMAL;
208 			unit = ite;
209 		}
210 	}
211 	curcons_scode = ite_scode[unit];
212 	cp->cn_dev = unit;
213 	cp->cn_pri = pri;
214 }
215 
216 void
217 iteinit(struct consdev *cp)
218 {
219 	int ite = cp->cn_dev;
220 	struct ite_data *ip;
221 
222 	if (itecons != -1)
223 		return;
224 
225 	ip = &ite_data[ite];
226 
227 	ip->curx = 0;
228 	ip->cury = 0;
229 	ip->cursorx = 0;
230 	ip->cursory = 0;
231 
232 	(*ip->isw->ite_init)(ip);
233 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
234 
235 	itecons = ite;
236 	kbdinit();
237 }
238 
239 /* ARGSUSED */
240 void
241 iteputchar(dev_t dev, int c)
242 {
243 	struct ite_data *ip = &ite_data[itecons];
244 	struct itesw *sp = ip->isw;
245 
246 	c &= 0x7F;
247 	switch (c) {
248 
249 	case '\n':
250 		if (++ip->cury == ip->rows) {
251 			ip->cury--;
252 			(*sp->ite_scroll)(ip);
253 			ite_clrtoeol(ip, sp, ip->cury, 0);
254 		}
255 		else
256 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
257 		break;
258 
259 	case '\r':
260 		ip->curx = 0;
261 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
262 		break;
263 
264 	case '\b':
265 		if (--ip->curx < 0)
266 			ip->curx = 0;
267 		else
268 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
269 		break;
270 
271 	default:
272 		if (c < ' ' || c == 0177)
273 			break;
274 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx);
275 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
276 		itecheckwrap(ip, sp);
277 		break;
278 	}
279 }
280 
281 static void
282 itecheckwrap(struct ite_data *ip, struct itesw *sp)
283 {
284 	if (++ip->curx == ip->cols) {
285 		ip->curx = 0;
286 		if (++ip->cury == ip->rows) {
287 			--ip->cury;
288 			(*sp->ite_scroll)(ip);
289 			ite_clrtoeol(ip, sp, ip->cury, 0);
290 			return;
291 		}
292 	}
293 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
294 }
295 
296 static void
297 ite_clrtoeol(struct ite_data *ip, struct itesw *sp, int y, int x)
298 {
299 
300 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
301 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
302 }
303 
304 /* ARGSUSED */
305 int
306 itegetchar(dev_t dev)
307 {
308 
309 #ifdef SMALL
310 	return 0;
311 #else
312 	return kbdgetc();
313 #endif
314 }
315 #endif
316