xref: /original-bsd/sys/hp300/stand/ite_hy.c (revision 13deef58)
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 and Mark Davies of the Department of Computer
9  * Science, Victoria University of Wellington, New Zealand.
10  *
11  * %sccs.include.redist.c%
12  *
13  * from: Utah $Hdr: ite_hy.c 1.1 92/01/22$
14  *
15  *	@(#)ite_hy.c	7.2 (Berkeley) 06/23/92
16  */
17 
18 #include "samachdep.h"
19 
20 #ifdef ITECONSOLE
21 #include "sys/param.h"
22 
23 #include "hp/dev/itevar.h"
24 #include "hp/dev/itereg.h"
25 #include "../dev/grf_hyreg.h"
26 
27 #define REGBASE	    	((struct hyboxfb *)(ip->regbase))
28 #define WINDOWMOVER     hyper_windowmove
29 
30 #undef charX
31 #define	charX(ip,c)	\
32 	(((c) % (ip)->cpl) * ((((ip)->ftwidth + 7) / 8) * 8) + (ip)->fontx)
33 
34 hyper_init(ip)
35 	register struct ite_softc *ip;
36 {
37 	int width;
38 
39 	ite_fontinfo(ip);
40 	width = ((ip->ftwidth + 7) / 8) * 8;
41 	ip->cpl      = (ip->fbwidth - ip->dwidth) / width;
42 	ip->cblanky  = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight;
43 
44 	REGBASE->nblank = 0x05;
45 
46 	/*
47 	 * Clear the framebuffer on all planes.
48 	 */
49 	hyper_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
50 
51 	hyper_ite_fontinit(ip);
52 
53 	/*
54 	 * Stash the inverted cursor.
55 	 */
56 	hyper_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
57 			 ip->cblanky, ip->cblankx, ip->ftheight,
58 			 ip->ftwidth, RR_COPYINVERTED);
59 }
60 
61 hyper_ite_fontinit(ip)
62 	register struct ite_softc *ip;
63 {
64 	register u_char *fbmem, *dp;
65 	int c, l, b;
66 	int stride, width;
67 
68 	dp = (u_char *)getword(ip, getword(ip, FONTROM) + FONTADDR) + FONTDATA;
69 	stride = ip->fbwidth >> 3;
70 	width = (ip->ftwidth + 7) / 8;
71 
72 	for (c = 0; c < 128; c++) {
73 		fbmem = (u_char *) FBBASE +
74 			(ip->fonty + (c / ip->cpl) * ip->ftheight) *
75 			stride;
76 		fbmem += (ip->fontx >> 3) + (c % ip->cpl) * width;
77 		for (l = 0; l < ip->ftheight; l++) {
78 			for (b = 0; b < width; b++) {
79 				*fbmem++ = *dp;
80 				dp += 2;
81 			}
82 			fbmem -= width;
83 			fbmem += stride;
84 		}
85 	}
86 }
87 
88 hyper_putc(ip, c, dy, dx, mode)
89 	register struct ite_softc *ip;
90         register int dy, dx;
91 	int c, mode;
92 {
93 	hyper_windowmove(ip, charY(ip, c), charX(ip, c),
94 			 dy * ip->ftheight, dx * ip->ftwidth,
95 			 ip->ftheight, ip->ftwidth, RR_COPY);
96 }
97 
98 hyper_cursor(ip, flag)
99 	register struct ite_softc *ip;
100         int flag;
101 {
102 	switch (flag) {
103 	case MOVE_CURSOR:
104 		erase_cursor(ip);
105 		/* fall through ... */
106 	case DRAW_CURSOR:
107 		draw_cursor(ip);
108 		break;
109 	default:
110 		erase_cursor(ip);
111 		break;
112 	}
113 }
114 
115 hyper_clear(ip, sy, sx, h, w)
116 	struct ite_softc *ip;
117 	register int sy, sx, h, w;
118 {
119 	hyper_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
120 			 sy * ip->ftheight, sx * ip->ftwidth,
121 			 h  * ip->ftheight, w  * ip->ftwidth,
122 			 RR_CLEAR);
123 }
124 
125 hyper_scroll(ip, sy, sx, count, dir)
126         register struct ite_softc *ip;
127         register int sy, count;
128         int dir, sx;
129 {
130 	register int dy = sy - count;
131 	register int height = ip->rows - sy;
132 
133 	hyper_cursor(ip, ERASE_CURSOR);
134 
135 	hyper_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
136 			 dy * ip->ftheight, sx * ip->ftwidth,
137 			 height * ip->ftheight,
138 			 ip->cols  * ip->ftwidth, RR_COPY);
139 }
140 
141 #include "../dev/maskbits.h"
142 
143 /* NOTE:
144  * the first element in starttab could be 0xffffffff.  making it 0
145  * lets us deal with a full first word in the middle loop, rather
146  * than having to do the multiple reads and masks that we'd
147  * have to do if we thought it was partial.
148  */
149 int starttab[32] =
150     {
151 	0x00000000,
152 	0x7FFFFFFF,
153 	0x3FFFFFFF,
154 	0x1FFFFFFF,
155 	0x0FFFFFFF,
156 	0x07FFFFFF,
157 	0x03FFFFFF,
158 	0x01FFFFFF,
159 	0x00FFFFFF,
160 	0x007FFFFF,
161 	0x003FFFFF,
162 	0x001FFFFF,
163 	0x000FFFFF,
164 	0x0007FFFF,
165 	0x0003FFFF,
166 	0x0001FFFF,
167 	0x0000FFFF,
168 	0x00007FFF,
169 	0x00003FFF,
170 	0x00001FFF,
171 	0x00000FFF,
172 	0x000007FF,
173 	0x000003FF,
174 	0x000001FF,
175 	0x000000FF,
176 	0x0000007F,
177 	0x0000003F,
178 	0x0000001F,
179 	0x0000000F,
180 	0x00000007,
181 	0x00000003,
182 	0x00000001
183     };
184 
185 int endtab[32] =
186     {
187 	0x00000000,
188 	0x80000000,
189 	0xC0000000,
190 	0xE0000000,
191 	0xF0000000,
192 	0xF8000000,
193 	0xFC000000,
194 	0xFE000000,
195 	0xFF000000,
196 	0xFF800000,
197 	0xFFC00000,
198 	0xFFE00000,
199 	0xFFF00000,
200 	0xFFF80000,
201 	0xFFFC0000,
202 	0xFFFE0000,
203 	0xFFFF0000,
204 	0xFFFF8000,
205 	0xFFFFC000,
206 	0xFFFFE000,
207 	0xFFFFF000,
208 	0xFFFFF800,
209 	0xFFFFFC00,
210 	0xFFFFFE00,
211 	0xFFFFFF00,
212 	0xFFFFFF80,
213 	0xFFFFFFC0,
214 	0xFFFFFFE0,
215 	0xFFFFFFF0,
216 	0xFFFFFFF8,
217 	0xFFFFFFFC,
218 	0xFFFFFFFE
219     };
220 
221 hyper_windowmove(ip, sy, sx, dy, dx, h, w, func)
222 	struct ite_softc *ip;
223 	int sy, sx, dy, dx, h, w, func;
224 {
225 	unsigned int *psrcBase, *pdstBase;
226 				/* start of src and dst bitmaps */
227 	int width;		/* add to get to same position in next line */
228 
229 	unsigned int *psrcLine, *pdstLine;
230                                 /* pointers to line with current src and dst */
231 	register unsigned int *psrc;  /* pointer to current src longword */
232 	register unsigned int *pdst;  /* pointer to current dst longword */
233 
234                                 /* following used for looping through a line */
235 	unsigned int startmask, endmask;  /* masks for writing ends of dst */
236 	int nlMiddle;		/* whole longwords in dst */
237 	register int nl;	/* temp copy of nlMiddle */
238 	register unsigned int tmpSrc;
239                                 /* place to store full source word */
240 	register int xoffSrc;	/* offset (>= 0, < 32) from which to
241                                    fetch whole longwords fetched
242                                    in src */
243 	int nstart;		/* number of ragged bits at start of dst */
244 	int nend;		/* number of ragged bits at end of dst */
245 	int srcStartOver;	/* pulling nstart bits from src
246                                    overflows into the next word? */
247 
248 	if (h == 0 || w == 0)
249 		return;
250 
251 	width = ip->fbwidth >> 5;
252 	psrcLine = ((unsigned int *) ip->fbbase) + (sy * width);
253 	pdstLine = ((unsigned int *) ip->fbbase) + (dy * width);
254 
255 	/* x direction doesn't matter for < 1 longword */
256 	if (w <= 32)
257 	{
258 	    int srcBit, dstBit;     /* bit offset of src and dst */
259 
260 	    pdstLine += (dx >> 5);
261 	    psrcLine += (sx >> 5);
262 	    psrc = psrcLine;
263 	    pdst = pdstLine;
264 
265 	    srcBit = sx & 0x1f;
266 	    dstBit = dx & 0x1f;
267 
268 	    while(h--)
269 	    {
270                 getandputrop(psrc, srcBit, dstBit, w, pdst, func)
271 	        pdst += width;
272 		psrc += width;
273 	    }
274 	}
275 	else
276         {
277 	    maskbits(dx, w, startmask, endmask, nlMiddle)
278 	    if (startmask)
279 	      nstart = 32 - (dx & 0x1f);
280 	    else
281 	      nstart = 0;
282 	    if (endmask)
283 	      nend = (dx + w) & 0x1f;
284 	    else
285 	      nend = 0;
286 
287 	    xoffSrc = ((sx & 0x1f) + nstart) & 0x1f;
288 	    srcStartOver = ((sx & 0x1f) + nstart) > 31;
289 
290 	    pdstLine += (dx >> 5);
291 	    psrcLine += (sx >> 5);
292 
293 	    while (h--)
294 	    {
295 	        psrc = psrcLine;
296 		pdst = pdstLine;
297 
298 		if (startmask)
299 		{
300 		    getandputrop(psrc, (sx & 0x1f),
301 				 (dx & 0x1f), nstart, pdst, func)
302 		    pdst++;
303 		    if (srcStartOver)
304 		        psrc++;
305 		}
306 
307 		/* special case for aligned operations */
308 		if (xoffSrc == 0)
309 		{
310 		    nl = nlMiddle;
311 		    while (nl--)
312 		    {
313 		        DoRop (*pdst, func, *psrc++, *pdst);
314 			pdst++;
315 		    }
316 		}
317 		else
318 		{
319 		    nl = nlMiddle + 1;
320 		    while (--nl)
321 		    {
322 		        getunalignedword (psrc, xoffSrc, tmpSrc)
323 			DoRop (*pdst, func, tmpSrc, *pdst);
324 			pdst++;
325 			psrc++;
326 		    }
327 		}
328 
329 		if (endmask)
330 		{
331 		    getandputrop0(psrc, xoffSrc, nend, pdst, func);
332 		}
333 
334 		pdstLine += width;
335 		psrcLine += width;
336 	    }
337 	}
338 }
339 #endif
340