xref: /original-bsd/sys/hp300/dev/ite_gb.c (revision c0290416)
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_gb.c 1.19 92/01/21$
13  *
14  *	@(#)ite_gb.c	7.6 (Berkeley) 06/05/92
15  */
16 
17 #include "ite.h"
18 #if NITE > 0
19 
20 #include "param.h"
21 #include "conf.h"
22 #include "proc.h"
23 #include "ioctl.h"
24 #include "tty.h"
25 #include "systm.h"
26 
27 #include "hp/dev/itevar.h"
28 #include "hp/dev/itereg.h"
29 #include "grf_gbreg.h"
30 
31 #include "machine/cpu.h"
32 
33 /* XXX */
34 #include "hp/dev/grfioctl.h"
35 #include "hp/dev/grfvar.h"
36 
37 #define REGBASE     	((struct gboxfb *)(ip->regbase))
38 #define WINDOWMOVER 	gbox_windowmove
39 
40 gbox_init(ip)
41 	register struct ite_softc *ip;
42 {
43 	/* XXX */
44 	if (ip->regbase == 0) {
45 		struct grf_softc *gp = ip->grf;
46 
47 		ip->regbase = gp->g_regkva;
48 		ip->fbbase = gp->g_fbkva;
49 		ip->fbwidth = gp->g_display.gd_fbwidth;
50 		ip->fbheight = gp->g_display.gd_fbheight;
51 		ip->dwidth = gp->g_display.gd_dwidth;
52 		ip->dheight = gp->g_display.gd_dheight;
53 	}
54 
55 	REGBASE->write_protect = 0x0;
56 	REGBASE->interrupt = 0x4;
57 	REGBASE->rep_rule = RR_COPY;
58 	REGBASE->blink1 = 0xff;
59 	REGBASE->blink2 = 0xff;
60 	gb_microcode(ip->regbase);
61 	REGBASE->sec_interrupt = 0x01;
62 
63 	/*
64 	 * Set up the color map entries. We use three entries in the
65 	 * color map. The first, is for black, the second is for
66 	 * white, and the very last entry is for the inverted cursor.
67 	 */
68 	REGBASE->creg_select = 0x00;
69 	REGBASE->cmap_red    = 0x00;
70 	REGBASE->cmap_grn    = 0x00;
71 	REGBASE->cmap_blu    = 0x00;
72 	REGBASE->cmap_write  = 0x00;
73 	gbcm_waitbusy(ip->regbase);
74 
75 	REGBASE->creg_select = 0x01;
76 	REGBASE->cmap_red    = 0xFF;
77 	REGBASE->cmap_grn    = 0xFF;
78 	REGBASE->cmap_blu    = 0xFF;
79 	REGBASE->cmap_write  = 0x01;
80 	gbcm_waitbusy(ip->regbase);
81 
82 	REGBASE->creg_select = 0xFF;
83 	REGBASE->cmap_red    = 0xFF;
84 	REGBASE->cmap_grn    = 0xFF;
85 	REGBASE->cmap_blu    = 0xFF;
86 	REGBASE->cmap_write  = 0x01;
87 	gbcm_waitbusy(ip->regbase);
88 
89 	ite_fontinfo(ip);
90 	ite_fontinit(ip);
91 
92 	/*
93 	 * Clear the display. This used to be before the font unpacking
94 	 * but it crashes. Figure it out later.
95 	 */
96 	gbox_windowmove(ip, 0, 0, 0, 0, ip->dheight, ip->dwidth, RR_CLEAR);
97 	tile_mover_waitbusy(ip->regbase);
98 
99 	/*
100 	 * Stash the inverted cursor.
101 	 */
102 	gbox_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
103 			ip->cblanky, ip->cblankx, ip->ftheight,
104 			ip->ftwidth, RR_COPYINVERTED);
105 }
106 
107 gbox_deinit(ip)
108 	struct ite_softc *ip;
109 {
110 	gbox_windowmove(ip, 0, 0, 0, 0, ip->dheight, ip->dwidth, RR_CLEAR);
111 	tile_mover_waitbusy(ip->regbase);
112 
113    	ip->flags &= ~ITE_INITED;
114 }
115 
116 gbox_putc(ip, c, dy, dx, mode)
117 	register struct ite_softc *ip;
118         register int dy, dx;
119 	int c, mode;
120 {
121         register int wrr = ((mode == ATTR_INV) ? RR_COPYINVERTED : RR_COPY);
122 
123 	gbox_windowmove(ip, charY(ip, c), charX(ip, c),
124 			    dy * ip->ftheight, dx * ip->ftwidth,
125 			    ip->ftheight, ip->ftwidth, wrr);
126 }
127 
128 gbox_cursor(ip, flag)
129 	register struct ite_softc *ip;
130         register int flag;
131 {
132 	if (flag == DRAW_CURSOR)
133 		draw_cursor(ip)
134 	else if (flag == MOVE_CURSOR) {
135 		erase_cursor(ip)
136 		draw_cursor(ip)
137 	}
138 	else
139 		erase_cursor(ip)
140 }
141 
142 gbox_clear(ip, sy, sx, h, w)
143 	struct ite_softc *ip;
144 	register int sy, sx, h, w;
145 {
146 	gbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
147 			sy * ip->ftheight, sx * ip->ftwidth,
148 			h  * ip->ftheight, w  * ip->ftwidth,
149 			RR_CLEAR);
150 }
151 #define	gbox_blockmove(ip, sy, sx, dy, dx, h, w) \
152 	gbox_windowmove((ip), \
153 			(sy) * ip->ftheight, \
154 			(sx) * ip->ftwidth, \
155 			(dy) * ip->ftheight, \
156 			(dx) * ip->ftwidth, \
157 			(h)  * ip->ftheight, \
158 			(w)  * ip->ftwidth, \
159 			RR_COPY)
160 
161 gbox_scroll(ip, sy, sx, count, dir)
162         register struct ite_softc *ip;
163         register int sy;
164         int dir, sx, count;
165 {
166 	register int height, dy, i;
167 
168 	tile_mover_waitbusy(ip->regbase);
169 	REGBASE->write_protect = 0x0;
170 
171 	gbox_cursor(ip, ERASE_CURSOR);
172 
173 	if (dir == SCROLL_UP) {
174 		dy = sy - count;
175 		height = ip->rows - sy;
176 		for (i = 0; i < height; i++)
177 			gbox_blockmove(ip, sy + i, sx, dy + i, 0, 1, ip->cols);
178 	}
179 	else if (dir == SCROLL_DOWN) {
180 		dy = sy + count;
181 		height = ip->rows - dy;
182 		for (i = (height - 1); i >= 0; i--)
183 			gbox_blockmove(ip, sy + i, sx, dy + i, 0, 1, ip->cols);
184 	}
185 	else if (dir == SCROLL_RIGHT) {
186 		gbox_blockmove(ip, sy, sx, sy, sx + count,
187 			       1, ip->cols - (sx + count));
188 	}
189 	else {
190 		gbox_blockmove(ip, sy, sx, sy, sx - count,
191 			       1, ip->cols - sx);
192 	}
193 }
194 
195 gbox_windowmove(ip, sy, sx, dy, dx, h, w, mask)
196      register struct ite_softc *ip;
197      int sy, sx, dy, dx, mask;
198      register int h, w;
199 {
200 	register int src, dest;
201 
202 	src  = (sy * 1024) + sx;	/* upper left corner in pixels */
203 	dest = (dy * 1024) + dx;
204 
205 	tile_mover_waitbusy(ip->regbase);
206 	REGBASE->width = -(w / 4);
207 	REGBASE->height = -(h / 4);
208 	if (src < dest)
209 		REGBASE->rep_rule = MOVE_DOWN_RIGHT|mask;
210 	else {
211 		REGBASE->rep_rule = MOVE_UP_LEFT|mask;
212 		/*
213 		 * Adjust to top of lower right tile of the block.
214 		 */
215 		src = src + ((h - 4) * 1024) + (w - 4);
216 		dest= dest + ((h - 4) * 1024) + (w - 4);
217 	}
218 	FBBASE[dest] = FBBASE[src];
219 }
220 #endif
221