xref: /original-bsd/sys/hp300/stand/ite.c (revision cf2124ff)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990 The Regents of the University of California.
4  * 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.23 92/02/28$
13  *
14  *	@(#)ite.c	7.5 (Berkeley) 10/11/92
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 		ip->flags = ITE_ALIVE|ITE_CONSOLE;
116 		i++;
117 	}
118 }
119 
120 #ifdef CONSDEBUG
121 /*
122  * Allows us to cycle through all possible consoles (NITE ites and serial port)
123  * by using SHIFT-RESET on the keyboard.
124  */
125 int	whichconsole = -1;
126 #endif
127 
128 iteprobe(cp)
129 	struct consdev *cp;
130 {
131 	register int ite;
132 	register struct ite_softc *ip;
133 	int unit, pri;
134 
135 #ifdef CONSDEBUG
136 	whichconsole = ++whichconsole % (NITE+1);
137 #endif
138 
139 	if (itecons != -1)
140 		return(1);
141 
142 	iteconfig();
143 	unit = -1;
144 	pri = CN_DEAD;
145 	for (ite = 0; ite < NITE; ite++) {
146 #ifdef CONSDEBUG
147 		if (ite < whichconsole)
148 			continue;
149 #endif
150 		ip = &ite_softc[ite];
151 		if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
152 		    != (ITE_ALIVE|ITE_CONSOLE))
153 			continue;
154 		if ((int)ip->regbase == GRFIADDR) {
155 			pri = CN_INTERNAL;
156 			unit = ite;
157 		} else if (unit < 0) {
158 			pri = CN_NORMAL;
159 			unit = ite;
160 		}
161 	}
162 	cp->cn_dev = unit;
163 	cp->cn_pri = pri;
164 }
165 
166 iteinit(cp)
167 	struct consdev *cp;
168 {
169 	int ite = cp->cn_dev;
170 	struct ite_softc *ip;
171 
172 	if (itecons != -1)
173 		return(1);
174 
175 	ip = &ite_softc[ite];
176 
177 	ip->curx = 0;
178 	ip->cury = 0;
179 	ip->cursorx = 0;
180 	ip->cursory = 0;
181 
182 	(*ip->isw->ite_init)(ip);
183 	(*ip->isw->ite_cursor)(ip, DRAW_CURSOR);
184 
185 	itecons = ite;
186 	kbdinit();
187 }
188 
189 iteputchar(c)
190 	register int c;
191 {
192 	register struct ite_softc *ip = &ite_softc[itecons];
193 	register struct itesw *sp = ip->isw;
194 
195 	c &= 0x7F;
196 	switch (c) {
197 
198 	case '\n':
199 		if (++ip->cury == ip->rows) {
200 			ip->cury--;
201 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
202 			ite_clrtoeol(ip, sp, ip->cury, 0);
203 		}
204 		else
205 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
206 		break;
207 
208 	case '\r':
209 		ip->curx = 0;
210 		(*sp->ite_cursor)(ip, MOVE_CURSOR);
211 		break;
212 
213 	case '\b':
214 		if (--ip->curx < 0)
215 			ip->curx = 0;
216 		else
217 			(*sp->ite_cursor)(ip, MOVE_CURSOR);
218 		break;
219 
220 	default:
221 		if (c < ' ' || c == 0177)
222 			break;
223 		(*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
224 		(*sp->ite_cursor)(ip, DRAW_CURSOR);
225 		itecheckwrap(ip, sp);
226 		break;
227 	}
228 }
229 
230 itecheckwrap(ip, sp)
231      register struct ite_softc *ip;
232      register struct itesw *sp;
233 {
234 	if (++ip->curx == ip->cols) {
235 		ip->curx = 0;
236 		if (++ip->cury == ip->rows) {
237 			--ip->cury;
238 			(*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
239 			ite_clrtoeol(ip, sp, ip->cury, 0);
240 			return;
241 		}
242 	}
243 	(*sp->ite_cursor)(ip, MOVE_CURSOR);
244 }
245 
246 ite_clrtoeol(ip, sp, y, x)
247      register struct ite_softc *ip;
248      register struct itesw *sp;
249      register int y, x;
250 {
251 	(*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
252 	(*sp->ite_cursor)(ip, DRAW_CURSOR);
253 }
254 
255 itegetchar()
256 {
257 #ifdef SMALL
258 	return (0);
259 #else
260 	return (kbdgetc());
261 #endif
262 }
263 #endif
264