xref: /original-bsd/sys/hp300/dev/ite_dv.c (revision bd226a66)
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_dv.c 1.7 91/01/21$
13  *
14  *	@(#)ite_dv.c	7.5 (Berkeley) 05/07/91
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 "itevar.h"
28 #include "itereg.h"
29 #include "grf_dvreg.h"
30 
31 #include "machine/cpu.h"
32 
33 /* XXX */
34 #include "grfioctl.h"
35 #include "grfvar.h"
36 
37 #define REGBASE		((struct dvboxfb *)(ip->regbase))
38 #define WINDOWMOVER	dvbox_windowmove
39 
40 dvbox_init(ip)
41 	struct ite_softc *ip;
42 {
43 	int i;
44 
45 	/* XXX */
46 	if (ip->regbase == 0) {
47 		struct grf_softc *gp = &grf_softc[ip - ite_softc];
48 		ip->regbase = gp->g_regkva;
49 		ip->fbbase = gp->g_fbkva;
50 	}
51 
52 	dv_reset(REGADDR);
53 
54 	/*
55 	 * Turn on frame buffer, turn on overlay planes, set replacement
56 	 * rule, enable top overlay plane writes for ite, disable all frame
57 	 * buffer planes, set byte per pixel, and display frame buffer 0.
58 	 * Lastly, turn on the box.
59 	 */
60 	REGBASE->interrupt = 0x04;
61 	REGBASE->drive     = 0x10;
62  	REGBASE->rep_rule  = RR_COPY << 4 | RR_COPY;
63 	REGBASE->opwen     = 0x01;
64 	REGBASE->fbwen     = 0x0;
65 	REGBASE->fold      = 0x01;
66 	REGBASE->vdrive    = 0x0;
67 	REGBASE->dispen    = 0x01;
68 
69 	/*
70 	 * Video enable top overlay plane.
71 	 */
72 	REGBASE->opvenp = 0x01;
73 	REGBASE->opvens = 0x01;
74 
75 	/*
76 	 * Make sure that overlay planes override frame buffer planes.
77 	 */
78 	REGBASE->ovly0p  = 0x0;
79 	REGBASE->ovly0s  = 0x0;
80 	REGBASE->ovly1p  = 0x0;
81 	REGBASE->ovly1s  = 0x0;
82 	REGBASE->fv_trig = 0x1;
83 	DELAY(100);
84 
85 	/*
86 	 * Setup the overlay colormaps. Need to set the 0,1 (black/white)
87 	 * color for both banks.
88 	 */
89 
90 	for (i = 0; i <= 1; i++) {
91 		REGBASE->cmapbank = i;
92 		REGBASE->rgb[0].red   = 0x00;
93 		REGBASE->rgb[0].green = 0x00;
94 		REGBASE->rgb[0].blue  = 0x00;
95 		REGBASE->rgb[1].red   = 0xFF;
96 		REGBASE->rgb[1].green = 0xFF;
97 		REGBASE->rgb[1].blue  = 0xFF;
98 	}
99 	REGBASE->cmapbank = 0;
100 
101 	db_waitbusy(REGADDR);
102 
103 	ite_devinfo(ip);
104 	ite_fontinit(ip);
105 
106 	/*
107 	 * Clear the (visible) framebuffer.
108 	 */
109 	dvbox_windowmove(ip, 0, 0, 0, 0, ip->dheight, ip->dwidth, RR_CLEAR);
110 	db_waitbusy(REGADDR);
111 
112 	/*
113 	 * Stash the inverted cursor.
114 	 */
115 	dvbox_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
116 			 ip->cblanky, ip->cblankx, ip->ftheight,
117 			 ip->ftwidth, RR_COPYINVERTED);
118 }
119 
120 dvbox_deinit(ip)
121 	struct ite_softc *ip;
122 {
123 	dvbox_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
124 	db_waitbusy(REGADDR);
125 
126    	ip->flags &= ~ITE_INITED;
127 }
128 
129 dvbox_putc(ip, c, dy, dx, mode)
130 	register struct ite_softc *ip;
131         register int dy, dx;
132 	int c, mode;
133 {
134         register int wrr = ((mode == ATTR_INV) ? RR_COPYINVERTED : RR_COPY);
135 
136 	dvbox_windowmove(ip, charY(ip, c), charX(ip, c),
137 			 dy * ip->ftheight, dx * ip->ftwidth,
138 			 ip->ftheight, ip->ftwidth, wrr);
139 }
140 
141 dvbox_cursor(ip, flag)
142 	register struct ite_softc *ip;
143         register int flag;
144 {
145 	if (flag == DRAW_CURSOR)
146 		draw_cursor(ip)
147 	else if (flag == MOVE_CURSOR) {
148 		erase_cursor(ip)
149 		draw_cursor(ip)
150 	}
151 	else
152 		erase_cursor(ip)
153 }
154 
155 dvbox_clear(ip, sy, sx, h, w)
156 	struct ite_softc *ip;
157 	register int sy, sx, h, w;
158 {
159 	dvbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
160 			 sy * ip->ftheight, sx * ip->ftwidth,
161 			 h  * ip->ftheight, w  * ip->ftwidth,
162 			 RR_CLEAR);
163 }
164 
165 dvbox_scroll(ip, sy, sx, count, dir)
166         register struct ite_softc *ip;
167         register int sy, count;
168         int dir, sx;
169 {
170 	register int dy;
171 	register int dx = sx;
172 	register int height = 1;
173 	register int width = ip->cols;
174 
175 	dvbox_cursor(ip, ERASE_CURSOR);
176 
177 	if (dir == SCROLL_UP) {
178 		dy = sy - count;
179 		height = ip->rows - sy;
180 	}
181 	else if (dir == SCROLL_DOWN) {
182 		dy = sy + count;
183 		height = ip->rows - dy - 1;
184 	}
185 	else if (dir == SCROLL_RIGHT) {
186 		dy = sy;
187 		dx = sx + count;
188 		width = ip->cols - dx;
189 	}
190 	else {
191 		dy = sy;
192 		dx = sx - count;
193 		width = ip->cols - sx;
194 	}
195 
196 	dvbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
197 			 dy * ip->ftheight, dx * ip->ftwidth,
198 			 height * ip->ftheight,
199 			 width  * ip->ftwidth, RR_COPY);
200 }
201 
202 dvbox_windowmove(ip, sy, sx, dy, dx, h, w, func)
203 	struct ite_softc *ip;
204 	int sy, sx, dy, dx, h, w, func;
205 {
206 	register struct dvboxfb *dp = REGBASE;
207 	if (h == 0 || w == 0)
208 		return;
209 
210 	db_waitbusy(REGADDR);
211 	dp->rep_rule = func << 4 | func;
212 	dp->source_y = sy;
213 	dp->source_x = sx;
214 	dp->dest_y   = dy;
215 	dp->dest_x   = dx;
216 	dp->wheight  = h;
217 	dp->wwidth   = w;
218 	dp->wmove    = 1;
219 }
220 #endif
221