xref: /original-bsd/sys/hp300/dev/ite_tc.c (revision 63b2a11c)
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_tc.c 1.26 92/01/21$
13  *
14  *	@(#)ite_tc.c	7.5 (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 "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 	topcat_cursor(ip, ERASE_CURSOR);
200 
201 	if (dir == SCROLL_UP) {
202 		dy = sy - count;
203 		height = ip->rows - sy;
204 	}
205 	else if (dir == SCROLL_DOWN) {
206 		dy = sy + count;
207 		height = ip->rows - dy - 1;
208 	}
209 	else if (dir == SCROLL_RIGHT) {
210 		dy = sy;
211 		dx = sx + count;
212 		width = ip->cols - dx;
213 	}
214 	else {
215 		dy = sy;
216 		dx = sx - count;
217 		width = ip->cols - sx;
218 	}
219 
220 	topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
221 			  dy * ip->ftheight, dx * ip->ftwidth,
222 			  height * ip->ftheight,
223 			  width  * ip->ftwidth, RR_COPY);
224 }
225 
226 topcat_windowmove(ip, sy, sx, dy, dx, h, w, func)
227 	struct ite_softc *ip;
228 	int sy, sx, dy, dx, h, w, func;
229 {
230   	register struct tcboxfb *rp = REGBASE;
231 
232 	if (h == 0 || w == 0)
233 		return;
234 	tc_waitbusy(ip->regbase, ip->planemask);
235 	rp->wmrr     = func;
236 	rp->source_y = sy;
237 	rp->source_x = sx;
238 	rp->dest_y   = dy;
239 	rp->dest_x   = dx;
240 	rp->wheight  = h;
241 	rp->wwidth   = w;
242 	rp->wmove    = ip->planemask;
243 }
244 #endif
245