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