xref: /original-bsd/sys/hp300/dev/ite_tc.c (revision bacd16ee)
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_tc.c 1.27 92/12/20$
13  *
14  *	@(#)ite_tc.c	8.1 (Berkeley) 06/10/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 <hp300/dev/grf_tcreg.h>
28 #include <hp/dev/grfreg.h>
29 #include <hp/dev/itereg.h>
30 #include <hp/dev/itevar.h>
31 
32 #include <machine/cpu.h>
33 
34 /* XXX */
35 #include <hp/dev/grfioctl.h>
36 #include <hp/dev/grfvar.h>
37 
38 #define REGBASE	    	((struct tcboxfb *)(ip->regbase))
39 #define WINDOWMOVER 	topcat_windowmove
40 
41 topcat_init(ip)
42 	register struct ite_softc *ip;
43 {
44 	/* XXX */
45 	if (ip->regbase == NULL) {
46 		struct grf_softc *gp = ip->grf;
47 
48 		ip->regbase = gp->g_regkva;
49 		ip->fbbase = gp->g_fbkva;
50 		ip->fbwidth = gp->g_display.gd_fbwidth;
51 		ip->fbheight = gp->g_display.gd_fbheight;
52 		ip->dwidth = gp->g_display.gd_dwidth;
53 		ip->dheight = gp->g_display.gd_dheight;
54 	}
55 
56 	/*
57 	 * Catseye looks a lot like a topcat, but not completely.
58 	 * So, we set some bits to make it work.
59 	 */
60 	if (REGBASE->fbid != GID_TOPCAT) {
61 		while ((REGBASE->catseye_status & 1))
62 			;
63 		REGBASE->catseye_status = 0x0;
64 		REGBASE->vb_select      = 0x0;
65 		REGBASE->tcntrl         = 0x0;
66 		REGBASE->acntrl         = 0x0;
67 		REGBASE->pncntrl        = 0x0;
68 		REGBASE->rug_cmdstat    = 0x90;
69 	}
70 
71 	/*
72 	 * Determine the number of planes by writing to the first frame
73 	 * buffer display location, then reading it back.
74 	 */
75 	REGBASE->wen = ~0;
76 	REGBASE->fben = ~0;
77 	REGBASE->prr = RR_COPY;
78 	*FBBASE = 0xFF;
79 	ip->planemask = *FBBASE;
80 
81 	/*
82 	 * Enable reading/writing of all the planes.
83 	 */
84 	REGBASE->fben = ip->planemask;
85 	REGBASE->wen  = ip->planemask;
86 	REGBASE->ren  = ip->planemask;
87 	REGBASE->prr  = RR_COPY;
88 
89 	ite_fontinfo(ip);
90 
91 	/*
92 	 * Clear the framebuffer on all planes.
93 	 */
94 	topcat_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
95 	tc_waitbusy(ip->regbase, ip->planemask);
96 
97 	ite_fontinit(ip);
98 
99 	/*
100 	 * Initialize color map for color displays
101 	 */
102 	if (ip->planemask != 1) {
103 	  	tc_waitbusy(ip->regbase, ip->planemask);
104 		REGBASE->nblank = 0x01;
105 
106 		tccm_waitbusy(ip->regbase);
107 		REGBASE->rdata  = 0x0;
108 		REGBASE->gdata  = 0x0;
109 		REGBASE->bdata  = 0x0;
110 		REGBASE->cindex = 0xFF;
111 		REGBASE->strobe = 0xFF;
112 
113 		DELAY(100);
114 		tccm_waitbusy(ip->regbase);
115 		REGBASE->rdata  = 0x0;
116 		REGBASE->gdata  = 0x0;
117 		REGBASE->bdata  = 0x0;
118 		REGBASE->cindex = 0x0;
119 
120 		DELAY(100);
121 		tccm_waitbusy(ip->regbase);
122 		REGBASE->rdata  = 0xFF;
123 		REGBASE->gdata  = 0xFF;
124 		REGBASE->bdata  = 0xFF;
125 		REGBASE->cindex = 0xFE;
126 		REGBASE->strobe = 0xFF;
127 
128 		DELAY(100);
129 		tccm_waitbusy(ip->regbase);
130 		REGBASE->rdata  = 0x0;
131 		REGBASE->gdata  = 0x0;
132 		REGBASE->bdata  = 0x0;
133 		REGBASE->cindex = 0x0;
134 	}
135 
136 	/*
137 	 * Stash the inverted cursor.
138 	 */
139 	topcat_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
140 			  ip->cblanky, ip->cblankx, ip->ftheight,
141 			  ip->ftwidth, RR_COPYINVERTED);
142 }
143 
144 topcat_deinit(ip)
145 	register struct ite_softc *ip;
146 {
147 	topcat_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
148 	tc_waitbusy(ip->regbase, ip->planemask);
149 
150 	REGBASE->nblank = ~0;
151    	ip->flags &= ~ITE_INITED;
152 }
153 
154 topcat_putc(ip, c, dy, dx, mode)
155 	register struct ite_softc *ip;
156 	int c, dy, dx, mode;
157 {
158         int wmrr = ((mode == ATTR_INV) ? RR_COPYINVERTED : RR_COPY);
159 
160 	topcat_windowmove(ip, charY(ip, c), charX(ip, c),
161 			  dy * ip->ftheight, dx * ip->ftwidth,
162 			  ip->ftheight, ip->ftwidth, wmrr);
163 }
164 
165 topcat_cursor(ip, flag)
166 	register struct ite_softc *ip;
167 	register int flag;
168 {
169 	if (flag == DRAW_CURSOR)
170 		draw_cursor(ip)
171 	else if (flag == MOVE_CURSOR) {
172 		erase_cursor(ip)
173 		draw_cursor(ip)
174 	}
175 	else
176 		erase_cursor(ip)
177 }
178 
179 topcat_clear(ip, sy, sx, h, w)
180 	register struct ite_softc *ip;
181 	register int sy, sx, h, w;
182 {
183 	topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
184 			  sy * ip->ftheight, sx * ip->ftwidth,
185 			  h  * ip->ftheight, w  * ip->ftwidth,
186 			  RR_CLEAR);
187 }
188 
189 topcat_scroll(ip, sy, sx, count, dir)
190         register struct ite_softc *ip;
191         register int sy, count;
192         int dir, sx;
193 {
194 	register int dy;
195 	register int dx = sx;
196 	register int height = 1;
197 	register int width = ip->cols;
198 
199 	if (dir == SCROLL_UP) {
200 		dy = sy - count;
201 		height = ip->rows - sy;
202 	}
203 	else if (dir == SCROLL_DOWN) {
204 		dy = sy + count;
205 		height = ip->rows - dy - 1;
206 	}
207 	else if (dir == SCROLL_RIGHT) {
208 		dy = sy;
209 		dx = sx + count;
210 		width = ip->cols - dx;
211 	}
212 	else {
213 		dy = sy;
214 		dx = sx - count;
215 		width = ip->cols - sx;
216 	}
217 
218 	topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
219 			  dy * ip->ftheight, dx * ip->ftwidth,
220 			  height * ip->ftheight,
221 			  width  * ip->ftwidth, RR_COPY);
222 }
223 
224 topcat_windowmove(ip, sy, sx, dy, dx, h, w, func)
225 	struct ite_softc *ip;
226 	int sy, sx, dy, dx, h, w, func;
227 {
228   	register struct tcboxfb *rp = REGBASE;
229 
230 	if (h == 0 || w == 0)
231 		return;
232 	tc_waitbusy(ip->regbase, ip->planemask);
233 	rp->wmrr     = func;
234 	rp->source_y = sy;
235 	rp->source_x = sx;
236 	rp->dest_y   = dy;
237 	rp->dest_x   = dx;
238 	rp->wheight  = h;
239 	rp->wwidth   = w;
240 	rp->wmove    = ip->planemask;
241 }
242 #endif
243