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