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