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