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