xref: /original-bsd/sys/hp300/dev/ite_tc.c (revision c8876cb1)
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.22 89/04/11$
13  *
14  *	@(#)ite_tc.c	7.2 (Berkeley) 12/16/90
15  */
16 
17 #include "ite.h"
18 #if NITE > 0
19 
20 #include "sys/param.h"
21 #include "sys/conf.h"
22 #include "sys/user.h"
23 #include "sys/proc.h"
24 #include "sys/ioctl.h"
25 #include "sys/tty.h"
26 #include "sys/systm.h"
27 #include "sys/uio.h"
28 
29 #include "grf_tcreg.h"
30 #include "itereg.h"
31 #include "itevar.h"
32 
33 #include "../include/cpu.h"
34 
35 #define REGBASE	    	((struct tcboxfb *)(ip->regbase))
36 #define WINDOWMOVER 	topcat_windowmove
37 
38 /* XXX */
39 #include "grfioctl.h"
40 #include "grfvar.h"
41 
42 topcat_init(ip)
43 	register struct ite_softc *ip;
44 {
45 	/* XXX */
46 	if (ip->regbase == NULL) {
47 		struct grfinfo *gi = &grf_softc[ip - ite_softc].g_display;
48 		ip->regbase = IOV(gi->gd_regaddr);
49 		ip->fbbase = IOV(gi->gd_fbaddr);
50 	}
51 
52 	/*
53 	 * Determine the number of planes by writing to the first frame
54 	 * buffer display location, then reading it back.
55 	 */
56 	REGBASE->wen = ~0;
57 	REGBASE->fben = ~0;
58 	REGBASE->prr = RR_COPY;
59 	*FBBASE = 0xFF;
60 	ip->planemask = *FBBASE;
61 
62 	/*
63 	 * Enable reading/writing of all the planes.
64 	 */
65 	REGBASE->fben = ip->planemask;
66 	REGBASE->wen  = ip->planemask;
67 	REGBASE->ren  = ip->planemask;
68 	REGBASE->prr  = RR_COPY;
69 
70 	ite_devinfo(ip);
71 
72 	/*
73 	 * Clear the framebuffer on all planes.
74 	 */
75 	topcat_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
76 	tc_waitbusy(REGADDR, ip->planemask);
77 
78 	ite_fontinit(ip);
79 
80 	/*
81 	 * Initialize color map for color displays
82 	 */
83 	if (ip->planemask != 1) {
84 	  	tc_waitbusy(REGADDR, ip->planemask);
85 		REGBASE->nblank = 0x01;
86 
87 		tccm_waitbusy(REGADDR);
88 		REGBASE->rdata  = 0x0;
89 		REGBASE->gdata  = 0x0;
90 		REGBASE->bdata  = 0x0;
91 		REGBASE->cindex = 0xFF;
92 		REGBASE->strobe = 0xFF;
93 
94 		DELAY(100);
95 		tccm_waitbusy(REGADDR);
96 		REGBASE->rdata  = 0x0;
97 		REGBASE->gdata  = 0x0;
98 		REGBASE->bdata  = 0x0;
99 		REGBASE->cindex = 0x0;
100 
101 		DELAY(100);
102 		tccm_waitbusy(REGADDR);
103 		REGBASE->rdata  = 0xFF;
104 		REGBASE->gdata  = 0xFF;
105 		REGBASE->bdata  = 0xFF;
106 		REGBASE->cindex = 0xFE;
107 		REGBASE->strobe = 0xFF;
108 
109 		DELAY(100);
110 		tccm_waitbusy(REGADDR);
111 		REGBASE->rdata  = 0x0;
112 		REGBASE->gdata  = 0x0;
113 		REGBASE->bdata  = 0x0;
114 		REGBASE->cindex = 0x0;
115 	}
116 
117 	/*
118 	 * Stash the inverted cursor.
119 	 */
120 	topcat_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
121 			  ip->cblanky, ip->cblankx, ip->ftheight,
122 			  ip->ftwidth, RR_COPYINVERTED);
123 }
124 
125 topcat_deinit(ip)
126 	register struct ite_softc *ip;
127 {
128 	topcat_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
129 	tc_waitbusy(REGADDR, ip->planemask);
130 
131 	REGBASE->nblank = ~0;
132    	ip->flags &= ~ITE_INITED;
133 }
134 
135 topcat_putc(ip, c, dy, dx, mode)
136 	register struct ite_softc *ip;
137 	int c, dy, dx, mode;
138 {
139         int wmrr = ((mode == ATTR_INV) ? RR_COPYINVERTED : RR_COPY);
140 
141 	topcat_windowmove(ip, charY(ip, c), charX(ip, c),
142 			  dy * ip->ftheight, dx * ip->ftwidth,
143 			  ip->ftheight, ip->ftwidth, wmrr);
144 }
145 
146 topcat_cursor(ip, flag)
147 	register struct ite_softc *ip;
148 	register int flag;
149 {
150 	if (flag == DRAW_CURSOR)
151 		draw_cursor(ip)
152 	else if (flag == MOVE_CURSOR) {
153 		erase_cursor(ip)
154 		draw_cursor(ip)
155 	}
156 	else
157 		erase_cursor(ip)
158 }
159 
160 topcat_clear(ip, sy, sx, h, w)
161 	register struct ite_softc *ip;
162 	register int sy, sx, h, w;
163 {
164 	topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
165 			  sy * ip->ftheight, sx * ip->ftwidth,
166 			  h  * ip->ftheight, w  * ip->ftwidth,
167 			  RR_CLEAR);
168 }
169 
170 topcat_scroll(ip, sy, sx, count, dir)
171         register struct ite_softc *ip;
172         register int sy, count;
173         int dir, sx;
174 {
175 	register int dy;
176 	register int dx = sx;
177 	register int height = 1;
178 	register int width = ip->cols;
179 
180 	topcat_cursor(ip, ERASE_CURSOR);
181 
182 	if (dir == SCROLL_UP) {
183 		dy = sy - count;
184 		height = ip->rows - sy;
185 	}
186 	else if (dir == SCROLL_DOWN) {
187 		dy = sy + count;
188 		height = ip->rows - dy - 1;
189 	}
190 	else if (dir == SCROLL_RIGHT) {
191 		dy = sy;
192 		dx = sx + count;
193 		width = ip->cols - dx;
194 	}
195 	else {
196 		dy = sy;
197 		dx = sx - count;
198 		width = ip->cols - sx;
199 	}
200 
201 	topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
202 			  dy * ip->ftheight, dx * ip->ftwidth,
203 			  height * ip->ftheight,
204 			  width  * ip->ftwidth, RR_COPY);
205 }
206 
207 topcat_windowmove(ip, sy, sx, dy, dx, h, w, func)
208 	struct ite_softc *ip;
209 	int sy, sx, dy, dx, h, w, func;
210 {
211   	register struct tcboxfb *rp = REGBASE;
212 
213 	if (h == 0 || w == 0)
214 		return;
215 	tc_waitbusy(REGADDR, ip->planemask);
216 	rp->wmrr     = func;
217 	rp->source_y = sy;
218 	rp->source_x = sx;
219 	rp->dest_y   = dy;
220 	rp->dest_x   = dx;
221 	rp->wheight  = h;
222 	rp->wwidth   = w;
223 	rp->wmove    = ip->planemask;
224 }
225 #endif
226