ite.c revision 1.6 1 /* $NetBSD: ite.c,v 1.6 2006/07/02 11:10:28 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(void)
146 {
147 int dtype, fboff, i;
148 struct hp_hw *hw;
149 struct grfreg *gr;
150 struct ite_data *ip;
151
152 i = 0;
153 for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
154 if (!HW_ISDEV(hw, D_BITMAP))
155 continue;
156 gr = (struct grfreg *) hw->hw_kva;
157 /* XXX: redundent but safe */
158 if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
159 continue;
160 for (dtype = 0; dtype < nitesw; dtype++)
161 if (itesw[dtype].ite_hwid == gr->gr_id2)
162 break;
163 if (dtype == nitesw)
164 continue;
165 if (i >= NITE)
166 break;
167 ite_scode[i] = hw->hw_sc;
168 ip = &ite_data[i];
169 ip->isw = &itesw[dtype];
170 ip->regbase = (caddr_t) gr;
171 fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
172 ip->fbbase = (caddr_t)(*((u_char *)ip->regbase + fboff) << 16);
173 /* DIO II: FB offset is relative to select code space */
174 if (ip->regbase >= (caddr_t)DIOIIBASE)
175 ip->fbbase += (int)ip->regbase;
176 ip->fbwidth = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
177 ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
178 ip->dwidth = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
179 ip->dheight = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
180 /*
181 * XXX some displays (e.g. the davinci) appear
182 * to return a display height greater than the
183 * returned FB height. Guess we should go back
184 * to getting the display dimensions from the
185 * fontrom...
186 */
187 if (ip->dwidth > ip->fbwidth)
188 ip->dwidth = ip->fbwidth;
189 if (ip->dheight > ip->fbheight)
190 ip->dheight = ip->fbheight;
191 ip->flags = ITE_ALIVE|ITE_CONSOLE;
192 i++;
193 }
194 }
195
196 #ifdef CONSDEBUG
197 /*
198 * Allows us to cycle through all possible consoles (NITE ites and serial port)
199 * by using SHIFT-RESET on the keyboard.
200 */
201 int whichconsole = -1;
202 #endif
203
204 void
205 iteprobe(struct consdev *cp)
206 {
207 int ite;
208 struct ite_data *ip;
209 int unit, pri;
210
211 #ifdef CONSDEBUG
212 whichconsole = ++whichconsole % (NITE+1);
213 #endif
214
215 if (itecons != -1)
216 return;
217
218 iteconfig();
219 unit = -1;
220 pri = CN_DEAD;
221 for (ite = 0; ite < NITE; ite++) {
222 #ifdef CONSDEBUG
223 if (ite < whichconsole)
224 continue;
225 #endif
226 ip = &ite_data[ite];
227 if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
228 != (ITE_ALIVE|ITE_CONSOLE))
229 continue;
230 if ((int)ip->regbase == GRFIADDR) {
231 pri = CN_INTERNAL;
232 unit = ite;
233 } else if (unit < 0) {
234 pri = CN_NORMAL;
235 unit = ite;
236 }
237 }
238 curcons_scode = ite_scode[unit];
239 cp->cn_dev = unit;
240 cp->cn_pri = pri;
241 }
242
243 void
244 iteinit(struct consdev *cp)
245 {
246 int ite = cp->cn_dev;
247 struct ite_data *ip;
248
249 if (itecons != -1)
250 return;
251
252 ip = &ite_data[ite];
253
254 ip->curx = 0;
255 ip->cury = 0;
256 ip->cursorx = 0;
257 ip->cursory = 0;
258
259 (*ip->isw->ite_init)(ip);
260 (*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
261
262 itecons = ite;
263 kbdinit();
264 }
265
266 /* ARGSUSED */
267 void
268 iteputchar(dev_t dev, int c)
269 {
270 struct ite_data *ip = &ite_data[itecons];
271 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 static void
309 itecheckwrap(struct ite_data *ip, struct itesw *sp)
310 {
311 if (++ip->curx == ip->cols) {
312 ip->curx = 0;
313 if (++ip->cury == ip->rows) {
314 --ip->cury;
315 (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
316 ite_clrtoeol(ip, sp, ip->cury, 0);
317 return;
318 }
319 }
320 (*sp->ite_cursor)(ip, MOVE_CURSOR);
321 }
322
323 static void
324 ite_clrtoeol(struct ite_data *ip, struct itesw *sp, int y, int x)
325 {
326
327 (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
328 (*sp->ite_cursor)(ip, DRAW_CURSOR);
329 }
330
331 /* ARGSUSED */
332 int
333 itegetchar(dev_t dev)
334 {
335
336 #ifdef SMALL
337 return 0;
338 #else
339 return kbdgetc();
340 #endif
341 }
342 #endif
343
344 /* ARGSUSED */
345 static void
346 ite_deinit_noop(struct ite_data *ip)
347 {
348 }
349