Home | History | Annotate | Line # | Download | only in common
ite_hy.c revision 1.8
      1 /*	$NetBSD: ite_hy.c,v 1.8 2007/03/07 09:10:21 he 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 WINDOWMOVER     hyper_windowmove
     93 
     94 #undef charX
     95 #define	charX(ip,c)	\
     96 	(((c) % (ip)->cpl) * ((((ip)->ftwidth + 7) / 8) * 8) + (ip)->fontx)
     97 
     98 void hyper_ite_fontinit(struct ite_data *);
     99 void hyper_windowmove(struct ite_data *, int, int, int, int, int, int, int);
    100 
    101 void
    102 hyper_init(struct ite_data *ip)
    103 {
    104 	struct hyboxfb *regbase = (void *)ip->regbase;
    105 	int width;
    106 
    107 	ite_fontinfo(ip);
    108 	width = ((ip->ftwidth + 7) / 8) * 8;
    109 	ip->cpl      = (ip->fbwidth - ip->dwidth) / width;
    110 	ip->cblanky  = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight;
    111 
    112 	regbase->nblank = 0x05;
    113 
    114 	/*
    115 	 * Clear the framebuffer on all planes.
    116 	 */
    117 	hyper_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
    118 
    119 	hyper_ite_fontinit(ip);
    120 
    121 	/*
    122 	 * Stash the inverted cursor.
    123 	 */
    124 	hyper_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
    125 			 ip->cblanky, ip->cblankx, ip->ftheight,
    126 			 ip->ftwidth, RR_COPYINVERTED);
    127 }
    128 
    129 void
    130 hyper_ite_fontinit(struct ite_data *ip)
    131 {
    132 	u_char *fbmem, *dp;
    133 	int c, l, b;
    134 	int stride, width;
    135 
    136 	dp = (u_char *)(getword(ip, getword(ip, FONTROM) + FONTADDR) +
    137 	    (char *)ip->regbase) + FONTDATA;
    138 	stride = ip->fbwidth >> 3;
    139 	width = (ip->ftwidth + 7) / 8;
    140 
    141 	for (c = 0; c < 128; c++) {
    142 		fbmem = (u_char *) FBBASE +
    143 			(ip->fonty + (c / ip->cpl) * ip->ftheight) *
    144 			stride;
    145 		fbmem += (ip->fontx >> 3) + (c % ip->cpl) * width;
    146 		for (l = 0; l < ip->ftheight; l++) {
    147 			for (b = 0; b < width; b++) {
    148 				*fbmem++ = *dp;
    149 				dp += 2;
    150 			}
    151 			fbmem -= width;
    152 			fbmem += stride;
    153 		}
    154 	}
    155 }
    156 
    157 void
    158 hyper_putc(struct ite_data *ip, int c, int dy, int dx, int mode)
    159 {
    160 
    161 	hyper_windowmove(ip, charY(ip, c), charX(ip, c),
    162 			 dy * ip->ftheight, dx * ip->ftwidth,
    163 			 ip->ftheight, ip->ftwidth, RR_COPY);
    164 }
    165 
    166 void
    167 hyper_cursor(struct ite_data *ip, int flag)
    168 {
    169 
    170 	switch (flag) {
    171 	case MOVE_CURSOR:
    172 		erase_cursor(ip);
    173 		/* fall through ... */
    174 	case DRAW_CURSOR:
    175 		draw_cursor(ip);
    176 		break;
    177 	default:
    178 		erase_cursor(ip);
    179 		break;
    180 	}
    181 }
    182 
    183 void
    184 hyper_clear(struct ite_data *ip, int sy, int sx, int h, int w)
    185 {
    186 
    187 	hyper_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
    188 			 sy * ip->ftheight, sx * ip->ftwidth,
    189 			 h  * ip->ftheight, w  * ip->ftwidth,
    190 			 RR_CLEAR);
    191 }
    192 
    193 void
    194 hyper_scroll(struct ite_data *ip, int sy, int sx, int count, int dir)
    195 {
    196 	int dy = sy - count;
    197 	int height = ip->rows - sy;
    198 
    199 	hyper_cursor(ip, ERASE_CURSOR);
    200 
    201 	hyper_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
    202 			 dy * ip->ftheight, sx * ip->ftwidth,
    203 			 height * ip->ftheight,
    204 			 ip->cols  * ip->ftwidth, RR_COPY);
    205 }
    206 
    207 #include <hp300/dev/maskbits.h>
    208 
    209 /* NOTE:
    210  * the first element in starttab could be 0xffffffff.  making it 0
    211  * lets us deal with a full first word in the middle loop, rather
    212  * than having to do the multiple reads and masks that we'd
    213  * have to do if we thought it was partial.
    214  */
    215 int starttab[32] = {
    216 	0x00000000,
    217 	0x7FFFFFFF,
    218 	0x3FFFFFFF,
    219 	0x1FFFFFFF,
    220 	0x0FFFFFFF,
    221 	0x07FFFFFF,
    222 	0x03FFFFFF,
    223 	0x01FFFFFF,
    224 	0x00FFFFFF,
    225 	0x007FFFFF,
    226 	0x003FFFFF,
    227 	0x001FFFFF,
    228 	0x000FFFFF,
    229 	0x0007FFFF,
    230 	0x0003FFFF,
    231 	0x0001FFFF,
    232 	0x0000FFFF,
    233 	0x00007FFF,
    234 	0x00003FFF,
    235 	0x00001FFF,
    236 	0x00000FFF,
    237 	0x000007FF,
    238 	0x000003FF,
    239 	0x000001FF,
    240 	0x000000FF,
    241 	0x0000007F,
    242 	0x0000003F,
    243 	0x0000001F,
    244 	0x0000000F,
    245 	0x00000007,
    246 	0x00000003,
    247 	0x00000001
    248 };
    249 
    250 int endtab[32] = {
    251 	0x00000000,
    252 	0x80000000,
    253 	0xC0000000,
    254 	0xE0000000,
    255 	0xF0000000,
    256 	0xF8000000,
    257 	0xFC000000,
    258 	0xFE000000,
    259 	0xFF000000,
    260 	0xFF800000,
    261 	0xFFC00000,
    262 	0xFFE00000,
    263 	0xFFF00000,
    264 	0xFFF80000,
    265 	0xFFFC0000,
    266 	0xFFFE0000,
    267 	0xFFFF0000,
    268 	0xFFFF8000,
    269 	0xFFFFC000,
    270 	0xFFFFE000,
    271 	0xFFFFF000,
    272 	0xFFFFF800,
    273 	0xFFFFFC00,
    274 	0xFFFFFE00,
    275 	0xFFFFFF00,
    276 	0xFFFFFF80,
    277 	0xFFFFFFC0,
    278 	0xFFFFFFE0,
    279 	0xFFFFFFF0,
    280 	0xFFFFFFF8,
    281 	0xFFFFFFFC,
    282 	0xFFFFFFFE
    283 };
    284 
    285 void
    286 hyper_windowmove(struct ite_data *ip, int sy, int sx, int dy, int dx,
    287     int h, int w, int func)
    288 {
    289 	int width;		/* add to get to same position in next line */
    290 
    291 	unsigned int *psrcLine, *pdstLine;
    292 				/* pointers to line with current src and dst */
    293 	unsigned int *psrc;	/* pointer to current src longword */
    294 	unsigned int *pdst;	/* pointer to current dst longword */
    295 
    296 				/* following used for looping through a line */
    297 	unsigned int startmask, endmask;  /* masks for writing ends of dst */
    298 	int nlMiddle;		/* whole longwords in dst */
    299 	int nl;			/* temp copy of nlMiddle */
    300 	unsigned int tmpSrc;
    301 				/* place to store full source word */
    302 	int xoffSrc;		/* offset (>= 0, < 32) from which to
    303 				   fetch whole longwords fetched
    304 				   in src */
    305 	int nstart;		/* number of ragged bits at start of dst */
    306 	int nend;		/* number of ragged bits at end of dst */
    307 	int srcStartOver;	/* pulling nstart bits from src
    308 				   overflows into the next word? */
    309 
    310 	if (h == 0 || w == 0)
    311 		return;
    312 
    313 	width = ip->fbwidth >> 5;
    314 	psrcLine = ((unsigned int *) ip->fbbase) + (sy * width);
    315 	pdstLine = ((unsigned int *) ip->fbbase) + (dy * width);
    316 
    317 	/* x direction doesn't matter for < 1 longword */
    318 	if (w <= 32) {
    319 		int srcBit, dstBit;     /* bit offset of src and dst */
    320 
    321 		pdstLine += (dx >> 5);
    322 		psrcLine += (sx >> 5);
    323 		psrc = psrcLine;
    324 		pdst = pdstLine;
    325 
    326 		srcBit = sx & 0x1f;
    327 		dstBit = dx & 0x1f;
    328 
    329 		while (h--) {
    330 			getandputrop(psrc, srcBit, dstBit, w, pdst, func);
    331 		        pdst += width;
    332 			psrc += width;
    333 		}
    334 	} else {
    335 		maskbits(dx, w, startmask, endmask, nlMiddle);
    336 		if (startmask)
    337 			nstart = 32 - (dx & 0x1f);
    338 		else
    339 			nstart = 0;
    340 		if (endmask)
    341 			nend = (dx + w) & 0x1f;
    342 		else
    343 			nend = 0;
    344 
    345 		xoffSrc = ((sx & 0x1f) + nstart) & 0x1f;
    346 		srcStartOver = ((sx & 0x1f) + nstart) > 31;
    347 
    348 		pdstLine += (dx >> 5);
    349 		psrcLine += (sx >> 5);
    350 
    351 		while (h--) {
    352 		        psrc = psrcLine;
    353 			pdst = pdstLine;
    354 
    355 			if (startmask) {
    356 				getandputrop(psrc, (sx & 0x1f),
    357 				    (dx & 0x1f), nstart, pdst, func);
    358 				pdst++;
    359 				if (srcStartOver)
    360 					psrc++;
    361 			}
    362 
    363 			/* special case for aligned operations */
    364 			if (xoffSrc == 0) {
    365 				nl = nlMiddle;
    366 				while (nl--) {
    367 					DoRop (*pdst, func, *psrc++, *pdst);
    368 					pdst++;
    369 		    		}
    370 			} else {
    371 				nl = nlMiddle + 1;
    372 				while (--nl) {
    373 					getunalignedword(psrc, xoffSrc, tmpSrc);
    374 					DoRop(*pdst, func, tmpSrc, *pdst);
    375 					pdst++;
    376 					psrc++;
    377 				}
    378 			}
    379 
    380 			if (endmask) {
    381 				getandputrop0(psrc, xoffSrc, nend, pdst, func);
    382 			}
    383 
    384 			pdstLine += width;
    385 			psrcLine += width;
    386 		}
    387 	}
    388 }
    389 #endif
    390