xref: /original-bsd/sys/hp300/stand/ite.c (revision b7ac173c)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: ite.c 1.24 93/06/25$
13  *
14  *	@(#)ite.c	8.1 (Berkeley) 07/08/93
15  */
16 
17 /*
18  * Standalone Internal Terminal Emulator (CRT and keyboard)
19  */
20 #include <hp300/stand/samachdep.h>
21 
22 #ifdef ITECONSOLE
23 
24 #include <sys/param.h>
25 #include <hp/dev/cons.h>
26 #include <hp/dev/device.h>
27 #include <hp/dev/itevar.h>
28 #include <hp/dev/grfreg.h>
29 
30 extern int nodev();
31 extern u_char ite_readbyte();
32 extern int ite_writeglyph();
33 
34 extern int topcat_init(), topcat_putc();
35 extern int topcat_clear(), topcat_cursor(), topcat_scroll();
36 extern int gbox_init(), gbox_clear();
37 extern int gbox_putc(), gbox_cursor(), gbox_scroll();
38 extern int rbox_init(), rbox_clear();
39 extern int rbox_putc(), rbox_cursor(), rbox_scroll();
40 extern int dvbox_init(), dvbox_clear();
41 extern int dvbox_putc(), dvbox_cursor(), dvbox_scroll();
42 extern int hyper_init(), hyper_clear();
43 extern int hyper_putc(), hyper_cursor(), hyper_scroll();
44 
45 struct itesw itesw[] = {
46 	GID_TOPCAT,
47 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
48 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
49 	GID_GATORBOX,
50 	gbox_init,	nodev,		gbox_clear,	gbox_putc,
51 	gbox_cursor,	gbox_scroll,	ite_readbyte,	ite_writeglyph,
52 	GID_RENAISSANCE,
53 	rbox_init,	nodev,		rbox_clear,	rbox_putc,
54 	rbox_cursor,	rbox_scroll,	ite_readbyte,	ite_writeglyph,
55 	GID_LRCATSEYE,
56 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
57 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
58 	GID_HRCCATSEYE,
59 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
60 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
61 	GID_HRMCATSEYE,
62 	topcat_init,	nodev,		topcat_clear,	topcat_putc,
63 	topcat_cursor,	topcat_scroll,	ite_readbyte,	ite_writeglyph,
64 	GID_DAVINCI,
65       	dvbox_init,	nodev,		dvbox_clear,	dvbox_putc,
66 	dvbox_cursor,	dvbox_scroll,	ite_readbyte,	ite_writeglyph,
67 	GID_HYPERION,
68 	hyper_init,	nodev,		hyper_clear,	hyper_putc,
69 	hyper_cursor,	hyper_scroll,	ite_readbyte,	ite_writeglyph,
70 };
71 int	nitesw = sizeof(itesw) / sizeof(itesw[0]);
72 
73 /* these guys need to be in initialized data */
74 int itecons = -1;
75 struct  ite_softc ite_softc[NITE] = { 0 };
76 
77 /*
78  * Locate all bitmapped displays
79  */
80 iteconfig()
81 {
82 	extern struct hp_hw sc_table[];
83 	int dtype, fboff, i;
84 	struct hp_hw *hw;
85 	struct grfreg *gr;
86 	struct ite_softc *ip;
87 
88 	i = 0;
89 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) {
90 	        if (!HW_ISDEV(hw, D_BITMAP))
91 			continue;
92 		gr = (struct grfreg *) hw->hw_kva;
93 		/* XXX: redundent but safe */
94 		if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
95 			continue;
96 		for (dtype = 0; dtype < nitesw; dtype++)
97 			if (itesw[dtype].ite_hwid == gr->gr_id2)
98 				break;
99 		if (dtype == nitesw)
100 			continue;
101 		if (i >= NITE)
102 			break;
103 		ip = &ite_softc[i];
104 		ip->isw = &itesw[dtype];
105 		ip->regbase = (caddr_t) gr;
106 		fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
107 		ip->fbbase = (caddr_t) (*((u_char *)ip->regbase+fboff) << 16);
108 		/* DIO II: FB offset is relative to select code space */
109 		if (ip->regbase >= (caddr_t)DIOIIBASE)
110 			ip->fbbase += (int)ip->regbase;
111 		ip->fbwidth  = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l;
112 		ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l;
113 		ip->dwidth   = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l;
114 		ip->dheight  = gr->gr_dheight_h << 8 | gr->gr_dheight_l;
115 		/*
116 		 * XXX some displays (e.g. the davinci) appear
117 		 * to return a display height greater than the
118 		 * returned FB height.  Guess we should go back
119 		 * to getting the display dimensions from the
120 		 * fontrom...
121 		 */
122 		if (ip->dwidth > ip->fbwidth)
123 			ip->dwidth = ip->fbwidth;
124 		if (ip->dheight > ip->fbheight)
125 			ip->dheight = ip->fbheight;
126 		ip->flags = ITE_ALIVE|ITE_CONSOLE;
127 		i++;
128 	}
129 }
130 
131 #ifdef CONSDEBUG
132 /*
133  * Allows us to cycle through all possible consoles (NITE ites and serial port)
134  * by using SHIFT-RESET on the keyboard.
135  */
136 int	whichconsole = -1;
137 #endif
138 
139 iteprobe(cp)
140 	struct consdev *cp;
141 {
142 	register int ite;
143 	register struct ite_softc *ip;
144 	int unit, pri;
145 
146 #ifdef CONSDEBUG
147 	whichconsole = ++whichconsole % (NITE+1);
148 #endif
149 
150 	if (itecons != -1)
151 		return(1);
152 
153 	iteconfig();
154 	unit = -1;
155 	pri = CN_DEAD;
156 	for (ite = 0; ite < NITE; ite++) {
157 #ifdef CONSDEBUG
158 		if (ite < whichconsole)
159 			continue;
160 #endif
161 		ip = &ite_softc[ite];
162 		if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
163 		    != (ITE_ALIVE|ITE_CONSOLE))
164 			continue;
165 		if ((int)ip->regbase == GRFIADDR) {
166 			pri = CN_INTERNAL;
167 			unit = ite;
168 		} else if (unit < 0) {
169 			pri = CN_NORMAL;
170 			unit = ite;
171 		}
172 	}
173 	cp->cn_dev = unit;
174 	cp->cn_pri = pri;
175 }
176 
177 iteinit(cp)
178 	struct consdev *cp;
179 {
180 	int ite = cp->cn_dev;
181 	struct ite_softc *ip;
182 
183 	if (itecons != -1)
184 		return(1);
185 
186 	ip = &ite_softc[ite];
187 
188 	ip->curx = 0;
189 	ip->cury = 0;
190 	ip->cursorx = 0;
191 	ip->cursory = 0;
192 
193 	(*ip->isw->ite_init)(ip);
194 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
195 
196 	itecons = ite;
197 	kbdinit();
198 }
199 
200 iteputchar(c)
201 	register int c;
202 {
203 	register struct ite_softc *ip = &ite_softc[itecons];
204 	register struct itesw *sp = ip->isw;
205 
206 	c &= 0x7F;
207 	switch (c) {
208 
209 	case '\n':
210 		if (++ip->cury == ip->rows) {
211 			ip->cury--;
212 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
213 			ite_clrtoeol(ip, sp, ip->cury, 0);
214 		}
215 		else
216 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
217 		break;
218 
219 	case '\r':
220 		ip->curx = 0;
221 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
222 		break;
223 
224 	case '\b':
225 		if (--ip->curx < 0)
226 			ip->curx = 0;
227 		else
228 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
229 		break;
230 
231 	default:
232 		if (c < ' ' || c == 0177)
233 			break;
234 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
235 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
236 		itecheckwrap(ip, sp);
237 		break;
238 	}
239 }
240 
241 itecheckwrap(ip, sp)
242      register struct ite_softc *ip;
243      register struct itesw *sp;
244 {
245 	if (++ip->curx == ip->cols) {
246 		ip->curx = 0;
247 		if (++ip->cury == ip->rows) {
248 			--ip->cury;
249 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
250 			ite_clrtoeol(ip, sp, ip->cury, 0);
251 			return;
252 		}
253 	}
254 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
255 }
256 
257 ite_clrtoeol(ip, sp, y, x)
258      register struct ite_softc *ip;
259      register struct itesw *sp;
260      register int y, x;
261 {
262 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
263 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
264 }
265 
266 itegetchar()
267 {
268 #ifdef SMALL
269 	return (0);
270 #else
271 	return (kbdgetc());
272 #endif
273 }
274 #endif
275