xref: /netbsd/sys/arch/hp300/stand/common/ite_hy.c (revision bf9ec67e)
1 /*	$NetBSD: ite_hy.c,v 1.1 1997/02/04 03:52:33 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1990, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department and Mark Davies of the Department of Computer
11  * Science, Victoria University of Wellington, New Zealand.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgement:
23  *	This product includes software developed by the University of
24  *	California, Berkeley and its contributors.
25  * 4. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  * from: Utah $Hdr: ite_hy.c 1.1 92/01/22$
42  *
43  *	@(#)ite_hy.c	8.1 (Berkeley) 6/10/93
44  */
45 
46 #ifdef ITECONSOLE
47 
48 #include <sys/param.h>
49 
50 #include <hp300/dev/itereg.h>
51 #include <hp300/dev/grf_hyreg.h>
52 
53 #include <hp300/stand/common/samachdep.h>
54 #include <hp300/stand/common/itevar.h>
55 
56 #define REGBASE	    	((struct hyboxfb *)(ip->regbase))
57 #define WINDOWMOVER     hyper_windowmove
58 
59 #undef charX
60 #define	charX(ip,c)	\
61 	(((c) % (ip)->cpl) * ((((ip)->ftwidth + 7) / 8) * 8) + (ip)->fontx)
62 
63 void	hyper_ite_fontinit __P((struct ite_data *));
64 void	hyper_windowmove __P((struct ite_data *, int, int, int, int,
65 	    int, int, int));
66 
67 void
68 hyper_init(ip)
69 	register struct ite_data *ip;
70 {
71 	int width;
72 
73 	ite_fontinfo(ip);
74 	width = ((ip->ftwidth + 7) / 8) * 8;
75 	ip->cpl      = (ip->fbwidth - ip->dwidth) / width;
76 	ip->cblanky  = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight;
77 
78 	REGBASE->nblank = 0x05;
79 
80 	/*
81 	 * Clear the framebuffer on all planes.
82 	 */
83 	hyper_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
84 
85 	hyper_ite_fontinit(ip);
86 
87 	/*
88 	 * Stash the inverted cursor.
89 	 */
90 	hyper_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
91 			 ip->cblanky, ip->cblankx, ip->ftheight,
92 			 ip->ftwidth, RR_COPYINVERTED);
93 }
94 
95 void
96 hyper_ite_fontinit(ip)
97 	register struct ite_data *ip;
98 {
99 	register u_char *fbmem, *dp;
100 	int c, l, b;
101 	int stride, width;
102 
103 	dp = (u_char *)(getword(ip, getword(ip, FONTROM) + FONTADDR) +
104 	    ip->regbase) + FONTDATA;
105 	stride = ip->fbwidth >> 3;
106 	width = (ip->ftwidth + 7) / 8;
107 
108 	for (c = 0; c < 128; c++) {
109 		fbmem = (u_char *) FBBASE +
110 			(ip->fonty + (c / ip->cpl) * ip->ftheight) *
111 			stride;
112 		fbmem += (ip->fontx >> 3) + (c % ip->cpl) * width;
113 		for (l = 0; l < ip->ftheight; l++) {
114 			for (b = 0; b < width; b++) {
115 				*fbmem++ = *dp;
116 				dp += 2;
117 			}
118 			fbmem -= width;
119 			fbmem += stride;
120 		}
121 	}
122 }
123 
124 void
125 hyper_putc(ip, c, dy, dx, mode)
126 	register struct ite_data *ip;
127         register int dy, dx;
128 	int c, mode;
129 {
130 	hyper_windowmove(ip, charY(ip, c), charX(ip, c),
131 			 dy * ip->ftheight, dx * ip->ftwidth,
132 			 ip->ftheight, ip->ftwidth, RR_COPY);
133 }
134 
135 void
136 hyper_cursor(ip, flag)
137 	register struct ite_data *ip;
138         int flag;
139 {
140 	switch (flag) {
141 	case MOVE_CURSOR:
142 		erase_cursor(ip);
143 		/* fall through ... */
144 	case DRAW_CURSOR:
145 		draw_cursor(ip);
146 		break;
147 	default:
148 		erase_cursor(ip);
149 		break;
150 	}
151 }
152 
153 void
154 hyper_clear(ip, sy, sx, h, w)
155 	struct ite_data *ip;
156 	register int sy, sx, h, w;
157 {
158 	hyper_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
159 			 sy * ip->ftheight, sx * ip->ftwidth,
160 			 h  * ip->ftheight, w  * ip->ftwidth,
161 			 RR_CLEAR);
162 }
163 
164 void
165 hyper_scroll(ip, sy, sx, count, dir)
166         register struct ite_data *ip;
167         register int sy, count;
168         int dir, sx;
169 {
170 	register int dy = sy - count;
171 	register int height = ip->rows - sy;
172 
173 	hyper_cursor(ip, ERASE_CURSOR);
174 
175 	hyper_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
176 			 dy * ip->ftheight, sx * ip->ftwidth,
177 			 height * ip->ftheight,
178 			 ip->cols  * ip->ftwidth, RR_COPY);
179 }
180 
181 #include <hp300/dev/maskbits.h>
182 
183 /* NOTE:
184  * the first element in starttab could be 0xffffffff.  making it 0
185  * lets us deal with a full first word in the middle loop, rather
186  * than having to do the multiple reads and masks that we'd
187  * have to do if we thought it was partial.
188  */
189 int starttab[32] =
190     {
191 	0x00000000,
192 	0x7FFFFFFF,
193 	0x3FFFFFFF,
194 	0x1FFFFFFF,
195 	0x0FFFFFFF,
196 	0x07FFFFFF,
197 	0x03FFFFFF,
198 	0x01FFFFFF,
199 	0x00FFFFFF,
200 	0x007FFFFF,
201 	0x003FFFFF,
202 	0x001FFFFF,
203 	0x000FFFFF,
204 	0x0007FFFF,
205 	0x0003FFFF,
206 	0x0001FFFF,
207 	0x0000FFFF,
208 	0x00007FFF,
209 	0x00003FFF,
210 	0x00001FFF,
211 	0x00000FFF,
212 	0x000007FF,
213 	0x000003FF,
214 	0x000001FF,
215 	0x000000FF,
216 	0x0000007F,
217 	0x0000003F,
218 	0x0000001F,
219 	0x0000000F,
220 	0x00000007,
221 	0x00000003,
222 	0x00000001
223     };
224 
225 int endtab[32] =
226     {
227 	0x00000000,
228 	0x80000000,
229 	0xC0000000,
230 	0xE0000000,
231 	0xF0000000,
232 	0xF8000000,
233 	0xFC000000,
234 	0xFE000000,
235 	0xFF000000,
236 	0xFF800000,
237 	0xFFC00000,
238 	0xFFE00000,
239 	0xFFF00000,
240 	0xFFF80000,
241 	0xFFFC0000,
242 	0xFFFE0000,
243 	0xFFFF0000,
244 	0xFFFF8000,
245 	0xFFFFC000,
246 	0xFFFFE000,
247 	0xFFFFF000,
248 	0xFFFFF800,
249 	0xFFFFFC00,
250 	0xFFFFFE00,
251 	0xFFFFFF00,
252 	0xFFFFFF80,
253 	0xFFFFFFC0,
254 	0xFFFFFFE0,
255 	0xFFFFFFF0,
256 	0xFFFFFFF8,
257 	0xFFFFFFFC,
258 	0xFFFFFFFE
259     };
260 
261 void
262 hyper_windowmove(ip, sy, sx, dy, dx, h, w, func)
263 	struct ite_data *ip;
264 	int sy, sx, dy, dx, h, w, func;
265 {
266 	unsigned int *psrcBase, *pdstBase;
267 				/* start of src and dst bitmaps */
268 	int width;		/* add to get to same position in next line */
269 
270 	unsigned int *psrcLine, *pdstLine;
271                                 /* pointers to line with current src and dst */
272 	register unsigned int *psrc;  /* pointer to current src longword */
273 	register unsigned int *pdst;  /* pointer to current dst longword */
274 
275                                 /* following used for looping through a line */
276 	unsigned int startmask, endmask;  /* masks for writing ends of dst */
277 	int nlMiddle;		/* whole longwords in dst */
278 	register int nl;	/* temp copy of nlMiddle */
279 	register unsigned int tmpSrc;
280                                 /* place to store full source word */
281 	register int xoffSrc;	/* offset (>= 0, < 32) from which to
282                                    fetch whole longwords fetched
283                                    in src */
284 	int nstart;		/* number of ragged bits at start of dst */
285 	int nend;		/* number of ragged bits at end of dst */
286 	int srcStartOver;	/* pulling nstart bits from src
287                                    overflows into the next word? */
288 
289 	if (h == 0 || w == 0)
290 		return;
291 
292 	width = ip->fbwidth >> 5;
293 	psrcLine = ((unsigned int *) ip->fbbase) + (sy * width);
294 	pdstLine = ((unsigned int *) ip->fbbase) + (dy * width);
295 
296 	/* x direction doesn't matter for < 1 longword */
297 	if (w <= 32)
298 	{
299 	    int srcBit, dstBit;     /* bit offset of src and dst */
300 
301 	    pdstLine += (dx >> 5);
302 	    psrcLine += (sx >> 5);
303 	    psrc = psrcLine;
304 	    pdst = pdstLine;
305 
306 	    srcBit = sx & 0x1f;
307 	    dstBit = dx & 0x1f;
308 
309 	    while(h--)
310 	    {
311                 getandputrop(psrc, srcBit, dstBit, w, pdst, func)
312 	        pdst += width;
313 		psrc += width;
314 	    }
315 	}
316 	else
317         {
318 	    maskbits(dx, w, startmask, endmask, nlMiddle)
319 	    if (startmask)
320 	      nstart = 32 - (dx & 0x1f);
321 	    else
322 	      nstart = 0;
323 	    if (endmask)
324 	      nend = (dx + w) & 0x1f;
325 	    else
326 	      nend = 0;
327 
328 	    xoffSrc = ((sx & 0x1f) + nstart) & 0x1f;
329 	    srcStartOver = ((sx & 0x1f) + nstart) > 31;
330 
331 	    pdstLine += (dx >> 5);
332 	    psrcLine += (sx >> 5);
333 
334 	    while (h--)
335 	    {
336 	        psrc = psrcLine;
337 		pdst = pdstLine;
338 
339 		if (startmask)
340 		{
341 		    getandputrop(psrc, (sx & 0x1f),
342 				 (dx & 0x1f), nstart, pdst, func)
343 		    pdst++;
344 		    if (srcStartOver)
345 		        psrc++;
346 		}
347 
348 		/* special case for aligned operations */
349 		if (xoffSrc == 0)
350 		{
351 		    nl = nlMiddle;
352 		    while (nl--)
353 		    {
354 		        DoRop (*pdst, func, *psrc++, *pdst);
355 			pdst++;
356 		    }
357 		}
358 		else
359 		{
360 		    nl = nlMiddle + 1;
361 		    while (--nl)
362 		    {
363 		        getunalignedword (psrc, xoffSrc, tmpSrc)
364 			DoRop (*pdst, func, tmpSrc, *pdst);
365 			pdst++;
366 			psrc++;
367 		    }
368 		}
369 
370 		if (endmask)
371 		{
372 		    getandputrop0(psrc, xoffSrc, nend, pdst, func);
373 		}
374 
375 		pdstLine += width;
376 		psrcLine += width;
377 	    }
378 	}
379 }
380 #endif
381