ite.c revision 1.15 1 /* $NetBSD: ite.c,v 1.15 2011/02/10 13:04:32 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 int nitesw = sizeof(itesw) / sizeof(itesw[0]);
101
102 /* these guys need to be in initialized data */
103 int itecons = -1;
104 struct ite_data ite_data[NITE] = { { 0 } };
105 int ite_scode[NITE] = { 0 };
106
107 /*
108 * Locate all bitmapped displays
109 */
110 static void
111 iteconfig(void)
112 {
113 int dtype, fboff, i;
114 struct hp_hw *hw;
115 struct grfreg *gr;
116 struct ite_data *ip;
117
118 i = 0;
119 for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
120 if (!HW_ISDEV(hw, D_BITMAP))
121 continue;
122 gr = (struct grfreg *) hw->hw_kva;
123 /* XXX: redundent but safe */
124 if (badaddr((void *)gr) || gr->gr_id != GRFHWID)
125 continue;
126 for (dtype = 0; dtype < nitesw; dtype++)
127 if (itesw[dtype].ite_hwid == gr->gr_id2)
128 break;
129 if (dtype == nitesw)
130 continue;
131 if (i >= NITE)
132 break;
133 ite_scode[i] = hw->hw_sc;
134 ip = &ite_data[i];
135 ip->isw = &itesw[dtype];
136 ip->regbase = (void *) gr;
137 fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
138 ip->fbbase = (void *)(*((u_char *)ip->regbase + fboff) << 16);
139 /* DIO II: FB offset is relative to select code space */
140 if (ip->regbase >= (void *)DIOIIBASE)
141 ip->fbbase = (char*)ip->fbbase + (int)ip->regbase;
142 ip->fbwidth = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
143 ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
144 ip->dwidth = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
145 ip->dheight = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
146 /*
147 * XXX some displays (e.g. the davinci) appear
148 * to return a display height greater than the
149 * returned FB height. Guess we should go back
150 * to getting the display dimensions from the
151 * fontrom...
152 */
153 if (ip->dwidth > ip->fbwidth)
154 ip->dwidth = ip->fbwidth;
155 if (ip->dheight > ip->fbheight)
156 ip->dheight = ip->fbheight;
157 ip->alive = 1;
158 i++;
159 }
160 }
161
162 #ifdef CONSDEBUG
163 /*
164 * Allows us to cycle through all possible consoles (NITE ites and serial port)
165 * by using SHIFT-RESET on the keyboard.
166 */
167 int whichconsole = -1;
168 #endif
169
170 void
171 iteprobe(struct consdev *cp)
172 {
173 int ite;
174 struct ite_data *ip;
175 int unit, pri;
176
177 #ifdef CONSDEBUG
178 whichconsole = ++whichconsole % (NITE+1);
179 #endif
180
181 if (itecons != -1)
182 return;
183
184 iteconfig();
185 unit = -1;
186 pri = CN_DEAD;
187 for (ite = 0; ite < NITE; ite++) {
188 #ifdef CONSDEBUG
189 if (ite < whichconsole)
190 continue;
191 #endif
192 ip = &ite_data[ite];
193 if (ip->alive == 0)
194 continue;
195 if ((int)ip->regbase == INTIOBASE + FB_BASE) {
196 pri = CN_INTERNAL;
197 unit = ite;
198 } else if (unit < 0) {
199 pri = CN_NORMAL;
200 unit = ite;
201 }
202 }
203 curcons_scode = ite_scode[unit];
204 cp->cn_dev = unit;
205 cp->cn_pri = pri;
206 }
207
208 void
209 iteinit(struct consdev *cp)
210 {
211 int ite = cp->cn_dev;
212 struct ite_data *ip;
213
214 if (itecons != -1)
215 return;
216
217 ip = &ite_data[ite];
218
219 ip->curx = 0;
220 ip->cury = 0;
221 ip->cursorx = 0;
222 ip->cursory = 0;
223
224 (*ip->isw->ite_init)(ip);
225 (*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
226
227 itecons = ite;
228 kbdinit();
229 }
230
231 /* ARGSUSED */
232 void
233 iteputchar(dev_t dev, int c)
234 {
235 struct ite_data *ip = &ite_data[itecons];
236 struct itesw *sp = ip->isw;
237
238 c &= 0x7F;
239 switch (c) {
240
241 case '\n':
242 if (++ip->cury == ip->rows) {
243 ip->cury--;
244 (*sp->ite_scroll)(ip);
245 ite_clrtoeol(ip, sp, ip->cury, 0);
246 }
247 else
248 (*sp->ite_cursor)(ip, MOVE_CURSOR);
249 break;
250
251 case '\r':
252 ip->curx = 0;
253 (*sp->ite_cursor)(ip, MOVE_CURSOR);
254 break;
255
256 case '\b':
257 if (--ip->curx < 0)
258 ip->curx = 0;
259 else
260 (*sp->ite_cursor)(ip, MOVE_CURSOR);
261 break;
262
263 default:
264 if (c < ' ' || c == 0177)
265 break;
266 (*sp->ite_putc)(ip, c, ip->cury, ip->curx);
267 (*sp->ite_cursor)(ip, DRAW_CURSOR);
268 itecheckwrap(ip, sp);
269 break;
270 }
271 }
272
273 static void
274 itecheckwrap(struct ite_data *ip, struct itesw *sp)
275 {
276 if (++ip->curx == ip->cols) {
277 ip->curx = 0;
278 if (++ip->cury == ip->rows) {
279 --ip->cury;
280 (*sp->ite_scroll)(ip);
281 ite_clrtoeol(ip, sp, ip->cury, 0);
282 return;
283 }
284 }
285 (*sp->ite_cursor)(ip, MOVE_CURSOR);
286 }
287
288 static void
289 ite_clrtoeol(struct ite_data *ip, struct itesw *sp, int y, int x)
290 {
291
292 (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
293 (*sp->ite_cursor)(ip, DRAW_CURSOR);
294 }
295
296 /* ARGSUSED */
297 int
298 itegetchar(dev_t dev)
299 {
300
301 #ifdef SMALL
302 return 0;
303 #else
304 return kbdgetc();
305 #endif
306 }
307 #endif
308