Home | History | Annotate | Line # | Download | only in dev
ite_cc.c revision 1.25.6.1
      1 /*	$NetBSD: ite_cc.c,v 1.25.6.1 2006/04/22 11:37:20 simonb Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Leo Weppelman
      5  * Copyright (c) 1994 Christian E. Hopps
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by Christian E. Hopps.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: ite_cc.c,v 1.25.6.1 2006/04/22 11:37:20 simonb Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/conf.h>
     39 #include <sys/proc.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/tty.h>
     42 #include <sys/systm.h>
     43 #include <sys/queue.h>
     44 #include <sys/termios.h>
     45 #include <sys/malloc.h>
     46 #include <sys/device.h>
     47 #include <dev/cons.h>
     48 #include <machine/cpu.h>
     49 #include <atari/atari/device.h>
     50 #include <atari/dev/itevar.h>
     51 #include <atari/dev/iteioctl.h>
     52 #include <atari/dev/grfioctl.h>
     53 #include <atari/dev/grfabs_reg.h>
     54 #include <atari/dev/grfvar.h>
     55 #include <atari/dev/font.h>
     56 #include <atari/dev/viewioctl.h>
     57 #include <atari/dev/viewvar.h>
     58 
     59 #include "grfcc.h"
     60 
     61 /*
     62  * This is what ip->priv points to;
     63  * it contains local variables for custom-chip ites.
     64  */
     65 struct ite_priv {
     66 	u_char	**row_ptr;	/* array of pointers into the bitmap	*/
     67 	u_long	row_bytes;
     68 	u_long	cursor_opt;
     69 	u_short	*column_offset;	/* array of offsets for columns		*/
     70 	u_int	row_offset;	/* the row offset			*/
     71 	u_short	width;		/* the bitmap width			*/
     72 	u_short	underline;	/* where the underline goes		*/
     73 	u_short	ft_x;		/* the font width			*/
     74 	u_short	ft_y;		/* the font height			*/
     75 	u_char	*font_cell[256];/* the font pointer			*/
     76 };
     77 typedef struct ite_priv ipriv_t;
     78 
     79 /*
     80  * We need the following space to get an ite-console setup before
     81  * the VM-system is brought up. We setup for a 1280x960 monitor with
     82  * an 8x8 font.
     83  */
     84 #define	CONS_MAXROW	120	/* Max. number of rows on console	*/
     85 #define	CONS_MAXCOL	160	/* Max. number of columns on console	*/
     86 static u_short	con_columns[CONS_MAXCOL];
     87 static u_char	*con_rows[CONS_MAXROW];
     88 static ipriv_t	con_ipriv;
     89 
     90 extern font_info	font_info_8x8;
     91 extern font_info	font_info_8x16;
     92 
     93 static void view_init __P((struct ite_softc *));
     94 static void view_deinit __P((struct ite_softc *));
     95 static int  itecc_ioctl __P((struct ite_softc *, u_long, caddr_t, int,
     96 							struct lwp *));
     97 static int  ite_newsize __P((struct ite_softc *, struct itewinsize *));
     98 static void cursor32 __P((struct ite_softc *, int));
     99 static void putc8 __P((struct ite_softc *, int, int, int, int));
    100 static void clear8 __P((struct ite_softc *, int, int, int, int));
    101 static void scroll8 __P((struct ite_softc *, int, int, int, int));
    102 static void scrollbmap __P((bmap_t *, u_short, u_short, u_short, u_short,
    103 							short, short));
    104 
    105 /*
    106  * grfcc config stuff
    107  */
    108 void grfccattach __P((struct device *, struct device *, void *));
    109 int  grfccmatch __P((struct device *, struct cfdata *, void *));
    110 int  grfccprint __P((void *, const char *));
    111 
    112 CFATTACH_DECL(grfcc, sizeof(struct grf_softc),
    113     grfccmatch, grfccattach, NULL, NULL);
    114 
    115 /*
    116  * only used in console init.
    117  */
    118 static struct cfdata *cfdata_grf   = NULL;
    119 
    120 /*
    121  * Probe functions we can use:
    122  */
    123 #ifdef TT_VIDEO
    124 void	tt_probe_video __P((MODES *));
    125 #endif /* TT_VIDEO */
    126 #ifdef FALCON_VIDEO
    127 void	falcon_probe_video __P((MODES *));
    128 #endif /* FALCON_VIDEO */
    129 
    130 int
    131 grfccmatch(pdp, cfp, auxp)
    132 struct device	*pdp;
    133 struct cfdata	*cfp;
    134 void		*auxp;
    135 {
    136 	static int	did_consinit = 0;
    137 	static int	must_probe = 1;
    138 	grf_auxp_t	*grf_auxp = auxp;
    139 	extern const struct cdevsw view_cdevsw;
    140 
    141 	if (must_probe) {
    142 		/*
    143 		 * Check if the layers we depend on exist
    144 		 */
    145 		if (!(machineid & (ATARI_TT|ATARI_FALCON)))
    146 			return (0);
    147 #ifdef TT_VIDEO
    148 		if ((machineid & ATARI_TT) && !grfabs_probe(&tt_probe_video))
    149 			return (0);
    150 #endif /* TT_VIDEO */
    151 #ifdef FALCON_VIDEO
    152 		if ((machineid & ATARI_FALCON)
    153 		    && !grfabs_probe(&falcon_probe_video))
    154 			return (0);
    155 #endif /* FALCON_VIDEO */
    156 
    157 		viewprobe();
    158 		must_probe = 0;
    159 	}
    160 
    161 	if (atari_realconfig == 0) {
    162 		/*
    163 		 * Early console init. Only match first unit.
    164 		 */
    165 		if (did_consinit)
    166 			return(0);
    167 		if ((*view_cdevsw.d_open)(cfp->cf_unit, 0, 0, NULL))
    168 			return(0);
    169 		cfdata_grf = cfp;
    170 		did_consinit = 1;
    171 		return (1);
    172 	}
    173 
    174 	/*
    175 	 * Normal config. When we are called directly from the grfbus,
    176 	 * we only match the first unit. The attach function will call us for
    177 	 * the other configured units.
    178 	 */
    179 	if (grf_auxp->from_bus_match && (did_consinit > 1))
    180 		return (0);
    181 
    182 	if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
    183 		return (0);
    184 
    185 	/*
    186 	 * Final constraint: each grf needs a view....
    187 	 */
    188 	if((cfdata_grf == NULL) || (did_consinit > 1)) {
    189 	    if((*view_cdevsw.d_open)(cfp->cf_unit, 0, 0, NULL))
    190 		return(0);
    191 	}
    192 	did_consinit = 2;
    193 	return(1);
    194 }
    195 
    196 /*
    197  * attach: initialize the grf-structure and try to attach an ite to us.
    198  * note  : dp is NULL during early console init.
    199  */
    200 void
    201 grfccattach(pdp, dp, auxp)
    202 struct device	*pdp, *dp;
    203 void		*auxp;
    204 {
    205 	static struct grf_softc		congrf;
    206 	static int			first_attach = 1;
    207 	       grf_auxp_t		*grf_bus_auxp = auxp;
    208 	       grf_auxp_t		grf_auxp;
    209 	       struct grf_softc		*gp;
    210 	       int			maj;
    211 	extern const struct cdevsw grf_cdevsw;
    212 
    213 	/*
    214 	 * find our major device number
    215 	 */
    216 	maj = cdevsw_lookup_major(&grf_cdevsw);
    217 
    218 	/*
    219 	 * Handle exeption case: early console init
    220 	 */
    221 	if(dp == NULL) {
    222 		congrf.g_unit    = cfdata_grf->cf_unit;
    223 		congrf.g_grfdev  = makedev(maj, congrf.g_unit);
    224 		congrf.g_itedev  = (dev_t)-1;
    225 		congrf.g_flags   = GF_ALIVE;
    226 		congrf.g_mode    = grf_mode;
    227 		congrf.g_conpri  = grfcc_cnprobe();
    228 		congrf.g_viewdev = congrf.g_unit;
    229 		grfcc_iteinit(&congrf);
    230 		grf_viewsync(&congrf);
    231 
    232 		/* Attach console ite */
    233 		atari_config_found(cfdata_grf, NULL, &congrf, grfccprint);
    234 		return;
    235 	}
    236 
    237 	gp = (struct grf_softc *)dp;
    238 	gp->g_unit = device_unit(&gp->g_device);
    239 	grfsp[gp->g_unit] = gp;
    240 
    241 	if((cfdata_grf != NULL) && (gp->g_unit == congrf.g_unit)) {
    242 		/*
    243 		 * We inited earlier just copy the info, take care
    244 		 * not to copy the device struct though.
    245 		 */
    246 		bcopy(&congrf.g_display, &gp->g_display,
    247 			(char *)&gp[1] - (char *)&gp->g_display);
    248 	}
    249 	else {
    250 		gp->g_grfdev  = makedev(maj, gp->g_unit);
    251 		gp->g_itedev  = (dev_t)-1;
    252 		gp->g_flags   = GF_ALIVE;
    253 		gp->g_mode    = grf_mode;
    254 		gp->g_conpri  = 0;
    255 		gp->g_viewdev = gp->g_unit;
    256 		grfcc_iteinit(gp);
    257 		grf_viewsync(gp);
    258 	}
    259 
    260 	printf(": width %d height %d", gp->g_display.gd_dwidth,
    261 		    gp->g_display.gd_dheight);
    262 	if(gp->g_display.gd_colors == 2)
    263 		printf(" monochrome\n");
    264 	else printf(" colors %d\n", gp->g_display.gd_colors);
    265 
    266 	/*
    267 	 * try and attach an ite
    268 	 */
    269 	config_found(dp, gp, grfccprint);
    270 
    271 	/*
    272 	 * If attaching the first unit, go ahead and 'find' the rest of us
    273 	 */
    274 	if (first_attach) {
    275 		first_attach = 0;
    276 		grf_auxp.from_bus_match = 0;
    277 		for (grf_auxp.unit=1; grf_auxp.unit < NGRFCC; grf_auxp.unit++) {
    278 		    config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
    279 		}
    280 	}
    281 }
    282 
    283 int
    284 grfccprint(auxp, pnp)
    285 void		*auxp;
    286 const char	*pnp;
    287 {
    288 	if(pnp)
    289 		aprint_normal("ite at %s", pnp);
    290 	return(UNCONF);
    291 }
    292 
    293 /*
    294  * called from grf_cc to return console priority
    295  */
    296 int
    297 grfcc_cnprobe()
    298 {
    299 	return(CN_INTERNAL);
    300 }
    301 /*
    302  * called from grf_cc to init ite portion of
    303  * grf_softc struct
    304  */
    305 void
    306 grfcc_iteinit(gp)
    307 struct grf_softc *gp;
    308 {
    309 
    310 	gp->g_itecursor = cursor32;
    311 	gp->g_iteputc   = putc8;
    312 	gp->g_iteclear  = clear8;
    313 	gp->g_itescroll = scroll8;
    314 	gp->g_iteinit   = view_init;
    315 	gp->g_itedeinit = view_deinit;
    316 }
    317 
    318 static void
    319 view_deinit(ip)
    320 struct ite_softc	*ip;
    321 {
    322 	ip->flags &= ~ITE_INITED;
    323 }
    324 
    325 static void
    326 view_init(ip)
    327 register struct ite_softc *ip;
    328 {
    329 	struct itewinsize	wsz;
    330 	ipriv_t			*cci;
    331 
    332 	if((cci = ip->priv) != NULL)
    333 		return;
    334 
    335 	ip->itexx_ioctl = itecc_ioctl;
    336 
    337 #if defined(KFONT_8X8)
    338 	ip->font = font_info_8x8;
    339 #else
    340 	ip->font = font_info_8x16;
    341 #endif
    342 
    343 	/* Find the correct set of rendering routines for this font.  */
    344 	if(ip->font.width != 8)
    345 		panic("kernel font size not supported");
    346 
    347 	if(!atari_realconfig)
    348 		ip->priv = cci = &con_ipriv;
    349 	else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
    350 	if(cci == NULL)
    351 		panic("No memory for ite-view");
    352 	bzero(cci, sizeof(*cci));
    353 
    354 	cci->cursor_opt    = 0;
    355 	cci->row_ptr       = NULL;
    356 	cci->column_offset = NULL;
    357 
    358 	wsz.x      = ite_default_x;
    359 	wsz.y      = ite_default_y;
    360 	wsz.width  = ite_default_width;
    361 	wsz.height = ite_default_height;
    362 	wsz.depth  = ite_default_depth;
    363 
    364 	ite_newsize (ip, &wsz);
    365 
    366 	/*
    367 	 * Only console will be turned on by default..
    368 	 */
    369 	if(ip->flags & ITE_ISCONS)
    370 		ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
    371 }
    372 
    373 static int
    374 ite_newsize(ip, winsz)
    375 struct ite_softc	*ip;
    376 struct itewinsize	*winsz;
    377 {
    378 	struct view_size	vs;
    379 	ipriv_t			*cci = ip->priv;
    380 	u_long			i, j;
    381 	int			error = 0;
    382 	view_t			*view;
    383 	extern const struct cdevsw view_cdevsw;
    384 
    385 	vs.x      = winsz->x;
    386 	vs.y      = winsz->y;
    387 	vs.width  = winsz->width;
    388 	vs.height = winsz->height;
    389 	vs.depth  = winsz->depth;
    390 
    391 	error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, VIOCSSIZE,
    392 				       (caddr_t)&vs, 0, NOLWP);
    393 	view  = viewview(ip->grf->g_viewdev);
    394 
    395 	/*
    396 	 * Reinitialize our structs
    397 	 */
    398 	ip->cols = view->display.width  / ip->font.width;
    399 	ip->rows = view->display.height / ip->font.height;
    400 
    401 	/*
    402 	 * save new values so that future opens use them
    403 	 * this may not be correct when we implement Virtual Consoles
    404 	 */
    405 	ite_default_height = view->display.height;
    406 	ite_default_width  = view->display.width;
    407 	ite_default_x      = view->display.x;
    408 	ite_default_y      = view->display.y;
    409 	ite_default_depth  = view->bitmap->depth;
    410 
    411 	if(cci->row_ptr && (cci->row_ptr != con_rows)) {
    412 		free(cci->row_ptr, M_DEVBUF);
    413 		cci->row_ptr = NULL;
    414 	}
    415 	if(cci->column_offset && (cci->column_offset != con_columns)) {
    416 		free(cci->column_offset, M_DEVBUF);
    417 		cci->column_offset = NULL;
    418 	}
    419 
    420 	if(!atari_realconfig) {
    421 		cci->row_ptr       = con_rows;
    422 		cci->column_offset = con_columns;
    423 	}
    424 	else {
    425 	  cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,M_DEVBUF,M_NOWAIT);
    426 	  cci->column_offset = malloc(sizeof(u_int)*ip->cols,M_DEVBUF,M_NOWAIT);
    427 	}
    428 
    429 	if(!cci->row_ptr || !cci->column_offset)
    430 		panic("No memory for ite-view");
    431 
    432 	cci->width      = view->bitmap->bytes_per_row << 3;
    433 	cci->underline  = ip->font.baseline + 1;
    434 	cci->row_offset = view->bitmap->bytes_per_row;
    435 	cci->ft_x       = ip->font.width;
    436 	cci->ft_y       = ip->font.height;
    437 	cci->row_bytes  = cci->row_offset * cci->ft_y;
    438 	cci->row_ptr[0] = view->bitmap->plane;
    439 	for(i = 1; i < ip->rows; i++)
    440 		cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes;
    441 
    442 	/*
    443 	 * Initialize the column offsets to point at the correct location
    444 	 * in the first plane. This definitely assumes a font width of 8!
    445 	 */
    446 	j = view->bitmap->depth * 2;
    447 	cci->column_offset[0] = 0;
    448 	for(i = 1; i < ip->cols; i++)
    449 		cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
    450 
    451 	/* initialize the font cell pointers */
    452 	cci->font_cell[ip->font.font_lo] = ip->font.font_p;
    453 	for(i = ip->font.font_lo+1; i <= ip->font.font_hi; i++)
    454 		cci->font_cell[i] = cci->font_cell[i-1] + ip->font.height;
    455 
    456 	return(error);
    457 }
    458 
    459 int
    460 itecc_ioctl(ip, cmd, addr, flag, l)
    461 struct ite_softc	*ip;
    462 u_long			cmd;
    463 caddr_t			addr;
    464 int			flag;
    465 struct lwp		*l;
    466 {
    467 	struct winsize		ws;
    468 	struct itewinsize	*is;
    469 	int			error = 0;
    470 	view_t			*view = viewview(ip->grf->g_viewdev);
    471 	extern const struct cdevsw ite_cdevsw;
    472 	extern const struct cdevsw view_cdevsw;
    473 
    474 	switch (cmd) {
    475 	case ITEIOCSWINSZ:
    476 		is = (struct itewinsize *)addr;
    477 
    478 		if(ite_newsize(ip, is))
    479 			error = ENOMEM;
    480 		else {
    481 			view         = viewview(ip->grf->g_viewdev);
    482 			ws.ws_row    = ip->rows;
    483 			ws.ws_col    = ip->cols;
    484 			ws.ws_xpixel = view->display.width;
    485 			ws.ws_ypixel = view->display.height;
    486 			ite_reset(ip);
    487 			/*
    488 			 * XXX tell tty about the change
    489 			 * XXX this is messy, but works
    490 			 */
    491 			(*ite_cdevsw.d_ioctl)(ip->grf->g_itedev, TIOCSWINSZ,
    492 					      (caddr_t)&ws, 0, l);
    493 		}
    494 		break;
    495 	case VIOCSCMAP:
    496 	case VIOCGCMAP:
    497 		/*
    498 		 * XXX watchout for that NOLWP. its not really the kernel
    499 		 * XXX talking these two commands don't use the proc pointer
    500 		 * XXX though.
    501 		 */
    502 		error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, cmd, addr,
    503 					       flag, NOLWP);
    504 		break;
    505 	default:
    506 		error = EPASSTHROUGH;
    507 		break;
    508 	}
    509 	return (error);
    510 }
    511 
    512 static void
    513 cursor32(struct ite_softc *ip, int flag)
    514 {
    515 	int	cend;
    516 	u_char	*pl;
    517 	ipriv_t	*cci;
    518 
    519 	cci = ip->priv;
    520 
    521 	if(flag == END_CURSOROPT)
    522 		cci->cursor_opt--;
    523 	else if(flag == START_CURSOROPT) {
    524 			if(!cci->cursor_opt)
    525 				cursor32(ip, ERASE_CURSOR);
    526 			cci->cursor_opt++;
    527 			return;		  /* if we are already opted. */
    528 	}
    529 
    530 	if(cci->cursor_opt)
    531 		return;		  /* if we are still nested. */
    532 				  /* else we draw the cursor. */
    533 
    534 	if(flag != DRAW_CURSOR && flag != END_CURSOROPT) {
    535 		/*
    536 		 * erase the cursor
    537 		 */
    538 		cend = ip->font.height-1;
    539 		pl   = cci->column_offset[ip->cursorx]
    540 				+ cci->row_ptr[ip->cursory];
    541 		__asm volatile
    542 			("1: notb  %0@ ; addaw %4,%0\n\t"
    543 			 "dbra  %1,1b"
    544 			 : "=a" (pl), "=d" (cend)
    545 			 : "0" (pl), "1" (cend),
    546 			 "d" (cci->row_offset)
    547 			 );
    548 	}
    549 
    550 	if(flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
    551 		return;
    552 
    553 	/*
    554 	 * draw the cursor
    555 	 */
    556 	cend = min(ip->curx, ip->cols-1);
    557 	if (flag == DRAW_CURSOR
    558 		&& ip->cursorx == cend && ip->cursory == ip->cury)
    559 		return;
    560 	ip->cursorx = cend;
    561 	ip->cursory = ip->cury;
    562 	cend        = ip->font.height-1;
    563 	pl          = cci->column_offset[ip->cursorx]
    564 			+ cci->row_ptr[ip->cursory];
    565 
    566 	__asm volatile
    567 		("1: notb  %0@ ; addaw %4,%0\n\t"
    568 		 "dbra  %1,1b"
    569 		 : "=a" (pl), "=d" (cend)
    570 		 : "0" (pl), "1" (cend),
    571 		 "d" (cci->row_offset)
    572 		 );
    573 }
    574 
    575 static void
    576 putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
    577 {
    578     register ipriv_t	*cci = (ipriv_t *)ip->priv;
    579     register u_char	*pl  = cci->column_offset[dx] + cci->row_ptr[dy];
    580     register u_int	fh   = cci->ft_y;
    581     register u_int	ro   = cci->row_offset;
    582     register u_char	eor_mask;
    583     register u_char	bl, tmp, ul;
    584     register u_char	*ft;
    585 
    586     if(c < ip->font.font_lo || c > ip->font.font_hi)
    587 		return;
    588 
    589 	ft = cci->font_cell[c];
    590 
    591 	if(!mode) {
    592 		while(fh--) {
    593 			*pl = *ft++; pl += ro;
    594 		}
    595 		return;
    596 	}
    597 
    598 	eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
    599 	bl       = (mode & ATTR_BOLD) ? 1 : 0;
    600 	ul       = (mode & ATTR_UL) ? fh - cci->underline : fh;
    601 	for(; fh--; pl += ro) {
    602 		if(fh != ul) {
    603 			tmp = *ft++;
    604 			if(bl)
    605 				tmp |= (tmp >> 1);
    606 			*pl = tmp ^ eor_mask;
    607 		}
    608 		else {
    609 			*pl = 0xff ^ eor_mask;
    610 			ft++;
    611 		}
    612 	}
    613 }
    614 
    615 static void
    616 clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
    617 {
    618 	ipriv_t	*cci = (ipriv_t *) ip->priv;
    619 	view_t	*v   = viewview(ip->grf->g_viewdev);
    620 	bmap_t	*bm  = v->bitmap;
    621 
    622 	if((sx == 0) && (w == ip->cols)) {
    623 		/* common case: clearing whole lines */
    624 		while (h--) {
    625 			int		i;
    626 			u_char	*ptr = cci->row_ptr[sy];
    627 			for(i = 0; i < ip->font.height; i++) {
    628 				bzero(ptr, bm->bytes_per_row);
    629 				ptr += bm->bytes_per_row;
    630 			}
    631 			sy++;
    632 		}
    633 	}
    634 	else {
    635 		/*
    636 		 * clearing only part of a line
    637 		 * XXX could be optimized MUCH better, but is it worth the
    638 		 * trouble?
    639 		 */
    640 
    641 		int		i;
    642 		u_char  *pls, *ple;
    643 
    644 		pls = cci->row_ptr[sy];
    645 		ple = pls + cci->column_offset[sx + w-1];
    646 		pls = pls + cci->column_offset[sx];
    647 
    648 		for(i = ((ip->font.height) * h)-1; i >= 0; i--) {
    649 			u_char *p = pls;
    650 			while(p <= ple)
    651 				*p++ = 0;
    652 			pls += bm->bytes_per_row;
    653 			ple += bm->bytes_per_row;
    654 		}
    655 	}
    656 }
    657 
    658 /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT.  */
    659 static void
    660 scroll8(ip, sy, sx, count, dir)
    661 register struct ite_softc	*ip;
    662 register int			sy;
    663 int				dir, sx, count;
    664 {
    665 	bmap_t *bm = viewview(ip->grf->g_viewdev)->bitmap;
    666 	u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
    667 
    668 	if(dir == SCROLL_UP) {
    669 		int	dy = sy - count;
    670 
    671 		cursor32(ip, ERASE_CURSOR);
    672 		scrollbmap(bm, 0, dy*ip->font.height, bm->bytes_per_row >> 3,
    673 				(ip->bottom_margin-dy+1)*ip->font.height,
    674 				0, -(count*ip->font.height));
    675 	}
    676 	else if(dir == SCROLL_DOWN) {
    677         	cursor32(ip, ERASE_CURSOR);
    678 		scrollbmap(bm, 0, sy*ip->font.height, bm->bytes_per_row >> 3,
    679 				(ip->bottom_margin-sy+1)*ip->font.height,
    680 				0, count*ip->font.height);
    681 	}
    682 	else if(dir == SCROLL_RIGHT) {
    683 		int	sofs = (ip->cols - count) * ip->font.width;
    684 		int	dofs = (ip->cols) * ip->font.width;
    685 		int	i, j;
    686 
    687 		cursor32(ip, ERASE_CURSOR);
    688 		for(j = ip->font.height-1; j >= 0; j--) {
    689 		    int sofs2 = sofs, dofs2 = dofs;
    690 		    for (i = (ip->cols - (sx + count))-1; i >= 0; i--) {
    691 			int	t;
    692 			sofs2 -= ip->font.width;
    693 			dofs2 -= ip->font.width;
    694 			__asm("bfextu %1@{%2:%3},%0" : "=d" (t)
    695 				: "a" (pl), "d" (sofs2), "d" (ip->font.width));
    696 			__asm("bfins %3,%0@{%1:%2}" :
    697 				: "a" (pl), "d" (dofs2), "d" (ip->font.width),
    698 				  "d" (t));
    699 		    }
    700 			pl += bm->bytes_per_row;
    701 		}
    702 	}
    703 	else { /* SCROLL_LEFT */
    704 		int sofs = (sx) * ip->font.width;
    705 		int dofs = (sx - count) * ip->font.width;
    706 		int i, j;
    707 
    708 		cursor32(ip, ERASE_CURSOR);
    709 		for(j = ip->font.height-1; j >= 0; j--) {
    710 		    int sofs2 = sofs, dofs2 = dofs;
    711 		    for(i = (ip->cols - sx)-1; i >= 0; i--) {
    712 			int	t;
    713 
    714 			__asm("bfextu %1@{%2:%3},%0" : "=d" (t)
    715 				: "a" (pl), "d" (sofs2), "d" (ip->font.width));
    716 			__asm("bfins %3,%0@{%1:%2}"
    717 				: : "a" (pl), "d" (dofs2),"d" (ip->font.width),
    718 				    "d" (t));
    719 			sofs2 += ip->font.width;
    720 			dofs2 += ip->font.width;
    721 		    }
    722 		    pl += bm->bytes_per_row;
    723 		}
    724     }
    725 }
    726 
    727 static void
    728 scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy)
    729 {
    730     u_short lwpr  = bm->bytes_per_row >> 2;
    731 
    732     if(dx) {
    733     	/* FIX: */ panic ("delta x not supported in scroll bitmap yet.");
    734     }
    735 
    736     if(dy == 0) {
    737         return;
    738     }
    739     if(dy > 0) {
    740 		u_long *pl       = (u_long *)bm->plane;
    741 		u_long *src_y    = pl + (lwpr*y);
    742 		u_long *dest_y   = pl + (lwpr*(y+dy));
    743 		u_long count     = lwpr*(height-dy);
    744 		u_long *clr_y    = src_y;
    745 		u_long clr_count = dest_y - src_y;
    746 		u_long bc, cbc;
    747 
    748 		src_y  += count - 1;
    749 		dest_y += count - 1;
    750 
    751 		bc = count >> 4;
    752 		count &= 0xf;
    753 
    754 		while (bc--) {
    755 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    756 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    757 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    758 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    759 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    760 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    761 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    762 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    763 		}
    764 		while (count--)
    765 		    *dest_y-- = *src_y--;
    766 
    767 		cbc = clr_count >> 4;
    768 		clr_count &= 0xf;
    769 
    770 		while (cbc--) {
    771 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    772 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    773 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    774 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    775 		}
    776 		while(clr_count--)
    777 		    *clr_y++ = 0;
    778     }
    779 	else {
    780 		u_long	*pl       = (u_long *)bm->plane;
    781 		u_long	*src_y    = pl + (lwpr*(y-dy));
    782 		u_long	*dest_y   = pl + (lwpr*y);
    783 		long	count     = lwpr*(height + dy);
    784 		u_long	*clr_y    = dest_y + count;
    785 		u_long	clr_count = src_y - dest_y;
    786 		u_long	bc, cbc;
    787 
    788 		bc = count >> 4;
    789 		count &= 0xf;
    790 
    791 		while(bc--) {
    792 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    793 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    794 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    795 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    796 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    797 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    798 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    799 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    800 		}
    801 		while(count--)
    802 		    *dest_y++ = *src_y++;
    803 
    804 		cbc = clr_count >> 4;
    805 		clr_count &= 0xf;
    806 
    807 		while (cbc--) {
    808 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    809 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    810 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    811 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    812 		}
    813 		while (clr_count--)
    814 		    *clr_y++ = 0;
    815     }
    816 }
    817