ite.c revision 1.2 1 1.2 agc /* $NetBSD: ite.c,v 1.2 2003/08/07 16:27:41 agc Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1990, 1993
5 1.1 thorpej * The Regents of the University of California. All rights reserved.
6 1.2 agc *
7 1.2 agc * This code is derived from software contributed to Berkeley by
8 1.2 agc * the Systems Programming Group of the University of Utah Computer
9 1.2 agc * Science Department.
10 1.2 agc *
11 1.2 agc * Redistribution and use in source and binary forms, with or without
12 1.2 agc * modification, are permitted provided that the following conditions
13 1.2 agc * are met:
14 1.2 agc * 1. Redistributions of source code must retain the above copyright
15 1.2 agc * notice, this list of conditions and the following disclaimer.
16 1.2 agc * 2. Redistributions in binary form must reproduce the above copyright
17 1.2 agc * notice, this list of conditions and the following disclaimer in the
18 1.2 agc * documentation and/or other materials provided with the distribution.
19 1.2 agc * 3. Neither the name of the University nor the names of its contributors
20 1.2 agc * may be used to endorse or promote products derived from this software
21 1.2 agc * without specific prior written permission.
22 1.2 agc *
23 1.2 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.2 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.2 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.2 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.2 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.2 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.2 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.2 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.2 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.2 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.2 agc * SUCH DAMAGE.
34 1.2 agc *
35 1.2 agc * from: Utah $Hdr: ite.c 1.24 93/06/25$
36 1.2 agc *
37 1.2 agc * @(#)ite.c 8.1 (Berkeley) 7/8/93
38 1.2 agc */
39 1.2 agc /*
40 1.2 agc * Copyright (c) 1988 University of Utah.
41 1.1 thorpej *
42 1.1 thorpej * This code is derived from software contributed to Berkeley by
43 1.1 thorpej * the Systems Programming Group of the University of Utah Computer
44 1.1 thorpej * Science Department.
45 1.1 thorpej *
46 1.1 thorpej * Redistribution and use in source and binary forms, with or without
47 1.1 thorpej * modification, are permitted provided that the following conditions
48 1.1 thorpej * are met:
49 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
50 1.1 thorpej * notice, this list of conditions and the following disclaimer.
51 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
52 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
53 1.1 thorpej * documentation and/or other materials provided with the distribution.
54 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
55 1.1 thorpej * must display the following acknowledgement:
56 1.1 thorpej * This product includes software developed by the University of
57 1.1 thorpej * California, Berkeley and its contributors.
58 1.1 thorpej * 4. Neither the name of the University nor the names of its contributors
59 1.1 thorpej * may be used to endorse or promote products derived from this software
60 1.1 thorpej * without specific prior written permission.
61 1.1 thorpej *
62 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.1 thorpej * SUCH DAMAGE.
73 1.1 thorpej *
74 1.1 thorpej * from: Utah $Hdr: ite.c 1.24 93/06/25$
75 1.1 thorpej *
76 1.1 thorpej * @(#)ite.c 8.1 (Berkeley) 7/8/93
77 1.1 thorpej */
78 1.1 thorpej
79 1.1 thorpej /*
80 1.1 thorpej * Standalone Internal Terminal Emulator (CRT and keyboard)
81 1.1 thorpej */
82 1.1 thorpej
83 1.1 thorpej #ifdef ITECONSOLE
84 1.1 thorpej
85 1.1 thorpej #include <sys/param.h>
86 1.1 thorpej #include <dev/cons.h>
87 1.1 thorpej
88 1.1 thorpej #include <hp300/dev/grfreg.h>
89 1.1 thorpej
90 1.1 thorpej #include <hp300/stand/common/device.h>
91 1.1 thorpej #include <hp300/stand/common/itevar.h>
92 1.1 thorpej #include <hp300/stand/common/consdefs.h>
93 1.1 thorpej #include <hp300/stand/common/samachdep.h>
94 1.1 thorpej
95 1.1 thorpej void ite_deinit_noop __P((struct ite_data *));
96 1.1 thorpej
97 1.1 thorpej struct itesw itesw[] = {
98 1.1 thorpej { GID_TOPCAT,
99 1.1 thorpej topcat_init, ite_deinit_noop, topcat_clear, topcat_putc,
100 1.1 thorpej topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph },
101 1.1 thorpej
102 1.1 thorpej { GID_GATORBOX,
103 1.1 thorpej gbox_init, ite_deinit_noop, gbox_clear, gbox_putc,
104 1.1 thorpej gbox_cursor, gbox_scroll, ite_readbyte, ite_writeglyph },
105 1.1 thorpej
106 1.1 thorpej { GID_RENAISSANCE,
107 1.1 thorpej rbox_init, ite_deinit_noop, rbox_clear, rbox_putc,
108 1.1 thorpej rbox_cursor, rbox_scroll, ite_readbyte, ite_writeglyph },
109 1.1 thorpej
110 1.1 thorpej { GID_LRCATSEYE,
111 1.1 thorpej topcat_init, ite_deinit_noop, topcat_clear, topcat_putc,
112 1.1 thorpej topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph },
113 1.1 thorpej
114 1.1 thorpej { GID_HRCCATSEYE,
115 1.1 thorpej topcat_init, ite_deinit_noop, topcat_clear, topcat_putc,
116 1.1 thorpej topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph },
117 1.1 thorpej
118 1.1 thorpej { GID_HRMCATSEYE,
119 1.1 thorpej topcat_init, ite_deinit_noop, topcat_clear, topcat_putc,
120 1.1 thorpej topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph },
121 1.1 thorpej
122 1.1 thorpej { GID_DAVINCI,
123 1.1 thorpej dvbox_init, ite_deinit_noop, dvbox_clear, dvbox_putc,
124 1.1 thorpej dvbox_cursor, dvbox_scroll, ite_readbyte, ite_writeglyph },
125 1.1 thorpej
126 1.1 thorpej { GID_HYPERION,
127 1.1 thorpej hyper_init, ite_deinit_noop, hyper_clear, hyper_putc,
128 1.1 thorpej hyper_cursor, hyper_scroll, ite_readbyte, ite_writeglyph },
129 1.1 thorpej };
130 1.1 thorpej int nitesw = sizeof(itesw) / sizeof(itesw[0]);
131 1.1 thorpej
132 1.1 thorpej /* these guys need to be in initialized data */
133 1.1 thorpej int itecons = -1;
134 1.1 thorpej struct ite_data ite_data[NITE] = { 0 };
135 1.1 thorpej int ite_scode[NITE] = { 0 };
136 1.1 thorpej
137 1.1 thorpej /*
138 1.1 thorpej * Locate all bitmapped displays
139 1.1 thorpej */
140 1.1 thorpej iteconfig()
141 1.1 thorpej {
142 1.1 thorpej extern struct hp_hw sc_table[];
143 1.1 thorpej int dtype, fboff, i;
144 1.1 thorpej struct hp_hw *hw;
145 1.1 thorpej struct grfreg *gr;
146 1.1 thorpej struct ite_data *ip;
147 1.1 thorpej
148 1.1 thorpej i = 0;
149 1.1 thorpej for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
150 1.1 thorpej if (!HW_ISDEV(hw, D_BITMAP))
151 1.1 thorpej continue;
152 1.1 thorpej gr = (struct grfreg *) hw->hw_kva;
153 1.1 thorpej /* XXX: redundent but safe */
154 1.1 thorpej if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
155 1.1 thorpej continue;
156 1.1 thorpej for (dtype = 0; dtype < nitesw; dtype++)
157 1.1 thorpej if (itesw[dtype].ite_hwid == gr->gr_id2)
158 1.1 thorpej break;
159 1.1 thorpej if (dtype == nitesw)
160 1.1 thorpej continue;
161 1.1 thorpej if (i >= NITE)
162 1.1 thorpej break;
163 1.1 thorpej ite_scode[i] = hw->hw_sc;
164 1.1 thorpej ip = &ite_data[i];
165 1.1 thorpej ip->isw = &itesw[dtype];
166 1.1 thorpej ip->regbase = (caddr_t) gr;
167 1.1 thorpej fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
168 1.1 thorpej ip->fbbase = (caddr_t) (*((u_char *)ip->regbase+fboff) << 16);
169 1.1 thorpej /* DIO II: FB offset is relative to select code space */
170 1.1 thorpej if (ip->regbase >= (caddr_t)DIOIIBASE)
171 1.1 thorpej ip->fbbase += (int)ip->regbase;
172 1.1 thorpej ip->fbwidth = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
173 1.1 thorpej ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
174 1.1 thorpej ip->dwidth = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
175 1.1 thorpej ip->dheight = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
176 1.1 thorpej /*
177 1.1 thorpej * XXX some displays (e.g. the davinci) appear
178 1.1 thorpej * to return a display height greater than the
179 1.1 thorpej * returned FB height. Guess we should go back
180 1.1 thorpej * to getting the display dimensions from the
181 1.1 thorpej * fontrom...
182 1.1 thorpej */
183 1.1 thorpej if (ip->dwidth > ip->fbwidth)
184 1.1 thorpej ip->dwidth = ip->fbwidth;
185 1.1 thorpej if (ip->dheight > ip->fbheight)
186 1.1 thorpej ip->dheight = ip->fbheight;
187 1.1 thorpej ip->flags = ITE_ALIVE|ITE_CONSOLE;
188 1.1 thorpej i++;
189 1.1 thorpej }
190 1.1 thorpej }
191 1.1 thorpej
192 1.1 thorpej #ifdef CONSDEBUG
193 1.1 thorpej /*
194 1.1 thorpej * Allows us to cycle through all possible consoles (NITE ites and serial port)
195 1.1 thorpej * by using SHIFT-RESET on the keyboard.
196 1.1 thorpej */
197 1.1 thorpej int whichconsole = -1;
198 1.1 thorpej #endif
199 1.1 thorpej
200 1.1 thorpej void
201 1.1 thorpej iteprobe(cp)
202 1.1 thorpej struct consdev *cp;
203 1.1 thorpej {
204 1.1 thorpej register int ite;
205 1.1 thorpej register struct ite_data *ip;
206 1.1 thorpej int unit, pri;
207 1.1 thorpej
208 1.1 thorpej #ifdef CONSDEBUG
209 1.1 thorpej whichconsole = ++whichconsole % (NITE+1);
210 1.1 thorpej #endif
211 1.1 thorpej
212 1.1 thorpej if (itecons != -1)
213 1.1 thorpej return;
214 1.1 thorpej
215 1.1 thorpej iteconfig();
216 1.1 thorpej unit = -1;
217 1.1 thorpej pri = CN_DEAD;
218 1.1 thorpej for (ite = 0; ite < NITE; ite++) {
219 1.1 thorpej #ifdef CONSDEBUG
220 1.1 thorpej if (ite < whichconsole)
221 1.1 thorpej continue;
222 1.1 thorpej #endif
223 1.1 thorpej ip = &ite_data[ite];
224 1.1 thorpej if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
225 1.1 thorpej != (ITE_ALIVE|ITE_CONSOLE))
226 1.1 thorpej continue;
227 1.1 thorpej if ((int)ip->regbase == GRFIADDR) {
228 1.1 thorpej pri = CN_INTERNAL;
229 1.1 thorpej unit = ite;
230 1.1 thorpej } else if (unit < 0) {
231 1.1 thorpej pri = CN_NORMAL;
232 1.1 thorpej unit = ite;
233 1.1 thorpej }
234 1.1 thorpej }
235 1.1 thorpej curcons_scode = ite_scode[unit];
236 1.1 thorpej cp->cn_dev = unit;
237 1.1 thorpej cp->cn_pri = pri;
238 1.1 thorpej }
239 1.1 thorpej
240 1.1 thorpej void
241 1.1 thorpej iteinit(cp)
242 1.1 thorpej struct consdev *cp;
243 1.1 thorpej {
244 1.1 thorpej int ite = cp->cn_dev;
245 1.1 thorpej struct ite_data *ip;
246 1.1 thorpej
247 1.1 thorpej if (itecons != -1)
248 1.1 thorpej return;
249 1.1 thorpej
250 1.1 thorpej ip = &ite_data[ite];
251 1.1 thorpej
252 1.1 thorpej ip->curx = 0;
253 1.1 thorpej ip->cury = 0;
254 1.1 thorpej ip->cursorx = 0;
255 1.1 thorpej ip->cursory = 0;
256 1.1 thorpej
257 1.1 thorpej (*ip->isw->ite_init)(ip);
258 1.1 thorpej (*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
259 1.1 thorpej
260 1.1 thorpej itecons = ite;
261 1.1 thorpej kbdinit();
262 1.1 thorpej }
263 1.1 thorpej
264 1.1 thorpej /* ARGSUSED */
265 1.1 thorpej void
266 1.1 thorpej iteputchar(dev, c)
267 1.1 thorpej dev_t dev;
268 1.1 thorpej register int c;
269 1.1 thorpej {
270 1.1 thorpej register struct ite_data *ip = &ite_data[itecons];
271 1.1 thorpej register struct itesw *sp = ip->isw;
272 1.1 thorpej
273 1.1 thorpej c &= 0x7F;
274 1.1 thorpej switch (c) {
275 1.1 thorpej
276 1.1 thorpej case '\n':
277 1.1 thorpej if (++ip->cury == ip->rows) {
278 1.1 thorpej ip->cury--;
279 1.1 thorpej (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
280 1.1 thorpej ite_clrtoeol(ip, sp, ip->cury, 0);
281 1.1 thorpej }
282 1.1 thorpej else
283 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
284 1.1 thorpej break;
285 1.1 thorpej
286 1.1 thorpej case '\r':
287 1.1 thorpej ip->curx = 0;
288 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
289 1.1 thorpej break;
290 1.1 thorpej
291 1.1 thorpej case '\b':
292 1.1 thorpej if (--ip->curx < 0)
293 1.1 thorpej ip->curx = 0;
294 1.1 thorpej else
295 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
296 1.1 thorpej break;
297 1.1 thorpej
298 1.1 thorpej default:
299 1.1 thorpej if (c < ' ' || c == 0177)
300 1.1 thorpej break;
301 1.1 thorpej (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
302 1.1 thorpej (*sp->ite_cursor)(ip, DRAW_CURSOR);
303 1.1 thorpej itecheckwrap(ip, sp);
304 1.1 thorpej break;
305 1.1 thorpej }
306 1.1 thorpej }
307 1.1 thorpej
308 1.1 thorpej itecheckwrap(ip, sp)
309 1.1 thorpej register struct ite_data *ip;
310 1.1 thorpej register struct itesw *sp;
311 1.1 thorpej {
312 1.1 thorpej if (++ip->curx == ip->cols) {
313 1.1 thorpej ip->curx = 0;
314 1.1 thorpej if (++ip->cury == ip->rows) {
315 1.1 thorpej --ip->cury;
316 1.1 thorpej (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
317 1.1 thorpej ite_clrtoeol(ip, sp, ip->cury, 0);
318 1.1 thorpej return;
319 1.1 thorpej }
320 1.1 thorpej }
321 1.1 thorpej (*sp->ite_cursor)(ip, MOVE_CURSOR);
322 1.1 thorpej }
323 1.1 thorpej
324 1.1 thorpej ite_clrtoeol(ip, sp, y, x)
325 1.1 thorpej register struct ite_data *ip;
326 1.1 thorpej register struct itesw *sp;
327 1.1 thorpej register int y, x;
328 1.1 thorpej {
329 1.1 thorpej (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
330 1.1 thorpej (*sp->ite_cursor)(ip, DRAW_CURSOR);
331 1.1 thorpej }
332 1.1 thorpej
333 1.1 thorpej /* ARGSUSED */
334 1.1 thorpej int
335 1.1 thorpej itegetchar(dev)
336 1.1 thorpej dev_t dev;
337 1.1 thorpej {
338 1.1 thorpej #ifdef SMALL
339 1.1 thorpej return (0);
340 1.1 thorpej #else
341 1.1 thorpej return (kbdgetc());
342 1.1 thorpej #endif
343 1.1 thorpej }
344 1.1 thorpej #endif
345 1.1 thorpej
346 1.1 thorpej /* ARGSUSED */
347 1.1 thorpej void
348 1.1 thorpej ite_deinit_noop(ip)
349 1.1 thorpej struct ite_data *ip;
350 1.1 thorpej {
351 1.1 thorpej }
352