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