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