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