Home | History | Annotate | Line # | Download | only in dev
ite_cc.c revision 1.1
      1  1.1  leo /*	$NetBSD: ite_cc.c,v 1.1 1995/03/26 07:12:14 leo Exp $	*/
      2  1.1  leo 
      3  1.1  leo /*
      4  1.1  leo  * Copyright (c) 1994 Christian E. Hopps
      5  1.1  leo  * All rights reserved.
      6  1.1  leo  *
      7  1.1  leo  * Redistribution and use in source and binary forms, with or without
      8  1.1  leo  * modification, are permitted provided that the following conditions
      9  1.1  leo  * are met:
     10  1.1  leo  * 1. Redistributions of source code must retain the above copyright
     11  1.1  leo  *    notice, this list of conditions and the following disclaimer.
     12  1.1  leo  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  leo  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  leo  *    documentation and/or other materials provided with the distribution.
     15  1.1  leo  * 3. All advertising materials mentioning features or use of this software
     16  1.1  leo  *    must display the following acknowledgement:
     17  1.1  leo  *      This product includes software developed by Christian E. Hopps.
     18  1.1  leo  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  leo  *    derived from this software without specific prior written permission
     20  1.1  leo  *
     21  1.1  leo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  leo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  leo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  leo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  leo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  leo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  leo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  leo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  leo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  leo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  leo  */
     32  1.1  leo 
     33  1.1  leo #include "grf.h"
     34  1.1  leo #if NGRF > 0
     35  1.1  leo 
     36  1.1  leo #include <sys/param.h>
     37  1.1  leo #include <sys/conf.h>
     38  1.1  leo #include <sys/proc.h>
     39  1.1  leo #include <sys/device.h>
     40  1.1  leo #include <sys/ioctl.h>
     41  1.1  leo #include <sys/tty.h>
     42  1.1  leo #include <sys/systm.h>
     43  1.1  leo #include <sys/queue.h>
     44  1.1  leo #include <sys/termios.h>
     45  1.1  leo #include <sys/malloc.h>
     46  1.1  leo #include <dev/cons.h>
     47  1.1  leo #include <machine/cpu.h>
     48  1.1  leo #include <atari/dev/itevar.h>
     49  1.1  leo #include <atari/dev/iteioctl.h>
     50  1.1  leo #include <atari/dev/grfioctl.h>
     51  1.1  leo #include <atari/dev/grfabs_reg.h>
     52  1.1  leo #include <atari/dev/grfvar.h>
     53  1.1  leo #include <atari/dev/font.h>
     54  1.1  leo #include <atari/dev/viewioctl.h>
     55  1.1  leo #include <atari/dev/viewvar.h>
     56  1.1  leo 
     57  1.1  leo /*
     58  1.1  leo  * This is what ip->priv points to;
     59  1.1  leo  * it contains local variables for custom-chip ites.
     60  1.1  leo  */
     61  1.1  leo struct ite_priv {
     62  1.1  leo 	u_char	**row_ptr;	/* array of pointers into the bitmap	*/
     63  1.1  leo 	u_long	row_bytes;
     64  1.1  leo 	u_long	cursor_opt;
     65  1.1  leo 	u_short	*column_offset;	/* array of offsets for columns		*/
     66  1.1  leo 	u_int	row_offset;	/* the row offset			*/
     67  1.1  leo 	u_short	width;		/* the bitmap width			*/
     68  1.1  leo 	u_short	underline;	/* where the underline goes		*/
     69  1.1  leo 	u_short	ft_x;		/* the font width			*/
     70  1.1  leo 	u_short	ft_y;		/* the font height			*/
     71  1.1  leo 	u_char	*font_cell[256];/* the font pointer			*/
     72  1.1  leo };
     73  1.1  leo typedef struct ite_priv ipriv_t;
     74  1.1  leo 
     75  1.1  leo /*
     76  1.1  leo  * We need the following space to get an ite-console setup before
     77  1.1  leo  * the VM-system is brought up. We setup for a 1280x960 monitor with
     78  1.1  leo  * an 8x8 font.
     79  1.1  leo  */
     80  1.1  leo extern int	atari_realconfig;
     81  1.1  leo 
     82  1.1  leo #define	CONS_MAXROW	120	/* Max. number of rows on console	*/
     83  1.1  leo #define	CONS_MAXCOL	160	/* Max. number of columns on console	*/
     84  1.1  leo static u_short	con_columns[CONS_MAXCOL];
     85  1.1  leo static u_char	*con_rows[CONS_MAXROW];
     86  1.1  leo static ipriv_t	con_ipriv;
     87  1.1  leo 
     88  1.1  leo extern font_info	font_info_8x8;
     89  1.1  leo extern font_info	font_info_8x16;
     90  1.1  leo 
     91  1.1  leo static void view_init __P((struct ite_softc *));
     92  1.1  leo static void view_deinit __P((struct ite_softc *));
     93  1.1  leo static int  ite_newsize __P((struct ite_softc *, struct itewinsize *));
     94  1.1  leo static void cursor32 __P((struct ite_softc *, int));
     95  1.1  leo static void putc8 __P((struct ite_softc *, int, int, int, int));
     96  1.1  leo static void clear8 __P((struct ite_softc *, int, int, int, int));
     97  1.1  leo static void scroll8 __P((struct ite_softc *, int, int, int, int));
     98  1.1  leo static void scrollbmap __P((bmap_t *, u_short, u_short, u_short, u_short,
     99  1.1  leo 							short, short));
    100  1.1  leo 
    101  1.1  leo /*
    102  1.1  leo  * Patchable
    103  1.1  leo  */
    104  1.1  leo int ite_default_x      = 0;	/* def leftedge offset	*/
    105  1.1  leo int ite_default_y      = 0;	/* def topedge offset	*/
    106  1.1  leo int ite_default_width  = 640;	/* def width		*/
    107  1.1  leo int ite_default_depth  = 1;	/* def depth		*/
    108  1.1  leo int ite_default_height = 400;	/* def height		*/
    109  1.1  leo 
    110  1.1  leo /*
    111  1.1  leo  * called from grf_cc to return console priority
    112  1.1  leo  */
    113  1.1  leo int
    114  1.1  leo grfcc_cnprobe()
    115  1.1  leo {
    116  1.1  leo 	return(CN_INTERNAL);
    117  1.1  leo }
    118  1.1  leo /*
    119  1.1  leo  * called from grf_cc to init ite portion of
    120  1.1  leo  * grf_softc struct
    121  1.1  leo  */
    122  1.1  leo void
    123  1.1  leo grfcc_iteinit(gp)
    124  1.1  leo struct grf_softc *gp;
    125  1.1  leo {
    126  1.1  leo 
    127  1.1  leo 	gp->g_itecursor = cursor32;
    128  1.1  leo 	gp->g_iteputc   = putc8;
    129  1.1  leo 	gp->g_iteclear  = clear8;
    130  1.1  leo 	gp->g_itescroll = scroll8;
    131  1.1  leo 	gp->g_iteinit   = view_init;
    132  1.1  leo 	gp->g_itedeinit = view_deinit;
    133  1.1  leo }
    134  1.1  leo 
    135  1.1  leo static void
    136  1.1  leo view_deinit(ip)
    137  1.1  leo struct ite_softc	*ip;
    138  1.1  leo {
    139  1.1  leo 	ip->flags &= ~ITE_INITED;
    140  1.1  leo }
    141  1.1  leo 
    142  1.1  leo static void
    143  1.1  leo view_init(ip)
    144  1.1  leo register struct ite_softc *ip;
    145  1.1  leo {
    146  1.1  leo 	struct itewinsize	wsz;
    147  1.1  leo 	ipriv_t			*cci;
    148  1.1  leo 
    149  1.1  leo 	if(cci = ip->priv)
    150  1.1  leo 		return;
    151  1.1  leo 
    152  1.1  leo #if defined(KFONT_8X8)
    153  1.1  leo 	ip->font = font_info_8x8;
    154  1.1  leo #else
    155  1.1  leo 	ip->font = font_info_8x16;
    156  1.1  leo #endif
    157  1.1  leo 
    158  1.1  leo 	/* Find the correct set of rendering routines for this font.  */
    159  1.1  leo 	if(ip->font.width != 8)
    160  1.1  leo 		panic("kernel font size not supported");
    161  1.1  leo 
    162  1.1  leo 	if(!atari_realconfig)
    163  1.1  leo 		ip->priv = cci = &con_ipriv;
    164  1.1  leo 	else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
    165  1.1  leo 	if(cci == NULL)
    166  1.1  leo 		panic("No memory for ite-view");
    167  1.1  leo 	bzero(cci, sizeof(*cci));
    168  1.1  leo 
    169  1.1  leo 	cci->cursor_opt    = 0;
    170  1.1  leo 	cci->row_ptr       = NULL;
    171  1.1  leo 	cci->column_offset = NULL;
    172  1.1  leo 
    173  1.1  leo 	wsz.x      = ite_default_x;
    174  1.1  leo 	wsz.y      = ite_default_y;
    175  1.1  leo 	wsz.width  = ite_default_width;
    176  1.1  leo 	wsz.height = ite_default_height;
    177  1.1  leo 	wsz.depth  = ite_default_depth;
    178  1.1  leo 
    179  1.1  leo 	ite_newsize (ip, &wsz);
    180  1.1  leo 
    181  1.1  leo 	/*
    182  1.1  leo 	 * Only console will be turned on by default..
    183  1.1  leo 	 */
    184  1.1  leo 	if(ip->flags & ITE_ISCONS)
    185  1.1  leo 		ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
    186  1.1  leo }
    187  1.1  leo 
    188  1.1  leo static int
    189  1.1  leo ite_newsize(ip, winsz)
    190  1.1  leo struct ite_softc	*ip;
    191  1.1  leo struct itewinsize	*winsz;
    192  1.1  leo {
    193  1.1  leo 	struct view_size		vs;
    194  1.1  leo 	ipriv_t				*cci = ip->priv;
    195  1.1  leo 	u_long				fbp, i, j;
    196  1.1  leo 	int				error = 0;
    197  1.1  leo 	view_t				*view = ip->grf->g_view;
    198  1.1  leo 
    199  1.1  leo 	vs.x      = winsz->x;
    200  1.1  leo 	vs.y      = winsz->y;
    201  1.1  leo 	vs.width  = winsz->width;
    202  1.1  leo 	vs.height = winsz->height;
    203  1.1  leo 	vs.depth  = winsz->depth;
    204  1.1  leo 	error = viewioctl(ip->grf->g_viewdev, VIOCSSIZE, &vs, 0, -1);
    205  1.1  leo 
    206  1.1  leo 	/*
    207  1.1  leo 	 * Reinitialize our structs
    208  1.1  leo 	 */
    209  1.1  leo 	ip->cols = view->display.width  / ip->font.width;
    210  1.1  leo 	ip->rows = view->display.height / ip->font.height;
    211  1.1  leo 
    212  1.1  leo 	/*
    213  1.1  leo 	 * save new values so that future opens use them
    214  1.1  leo 	 * this may not be correct when we implement Virtual Consoles
    215  1.1  leo 	 */
    216  1.1  leo 	ite_default_height = view->display.height;
    217  1.1  leo 	ite_default_width  = view->display.width;
    218  1.1  leo 	ite_default_x      = view->display.x;
    219  1.1  leo 	ite_default_y      = view->display.y;
    220  1.1  leo 	ite_default_depth  = view->bitmap->depth;
    221  1.1  leo 
    222  1.1  leo 	if(cci->row_ptr && (cci->row_ptr != con_rows)) {
    223  1.1  leo 		free(cci->row_ptr, M_DEVBUF);
    224  1.1  leo 		cci->row_ptr = NULL;
    225  1.1  leo 	}
    226  1.1  leo 	if(cci->column_offset && (cci->column_offset != con_columns)) {
    227  1.1  leo 		free(cci->column_offset, M_DEVBUF);
    228  1.1  leo 		cci->column_offset = NULL;
    229  1.1  leo 	}
    230  1.1  leo 
    231  1.1  leo 	if(!atari_realconfig) {
    232  1.1  leo 		cci->row_ptr       = con_rows;
    233  1.1  leo 		cci->column_offset = con_columns;
    234  1.1  leo 	}
    235  1.1  leo 	else {
    236  1.1  leo 	  cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,M_DEVBUF,M_WAITOK);
    237  1.1  leo 	  cci->column_offset = malloc(sizeof(u_int)*ip->cols,M_DEVBUF,M_WAITOK);
    238  1.1  leo 	}
    239  1.1  leo 
    240  1.1  leo 	if(!cci->row_ptr || !cci->column_offset)
    241  1.1  leo 		panic("No memory for ite-view");
    242  1.1  leo 
    243  1.1  leo 
    244  1.1  leo 	cci->width      = view->bitmap->bytes_per_row << 3;
    245  1.1  leo 	cci->underline  = ip->font.baseline + 1;
    246  1.1  leo 	cci->row_offset = view->bitmap->bytes_per_row;
    247  1.1  leo 	cci->ft_x       = ip->font.width;
    248  1.1  leo 	cci->ft_y       = ip->font.height;
    249  1.1  leo 	cci->row_bytes  = cci->row_offset * cci->ft_y;
    250  1.1  leo 	cci->row_ptr[0] = view->bitmap->plane;
    251  1.1  leo 	for(i = 1; i < ip->rows; i++)
    252  1.1  leo 		cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes;
    253  1.1  leo 
    254  1.1  leo 	/*
    255  1.1  leo 	 * Initialize the column offsets to point at the correct location
    256  1.1  leo 	 * in the first plane. This definitely assumes a font width of 8!
    257  1.1  leo 	 */
    258  1.1  leo 	j = view->bitmap->depth * 2;
    259  1.1  leo 	cci->column_offset[0] = 0;
    260  1.1  leo 	for(i = 1; i < ip->cols; i++)
    261  1.1  leo 		cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
    262  1.1  leo 
    263  1.1  leo 	/* initialize the font cell pointers */
    264  1.1  leo 	cci->font_cell[ip->font.font_lo] = ip->font.font_p;
    265  1.1  leo 	for(i = ip->font.font_lo+1; i <= ip->font.font_hi; i++)
    266  1.1  leo 		cci->font_cell[i] = cci->font_cell[i-1] + ip->font.height;
    267  1.1  leo 
    268  1.1  leo 	return(error);
    269  1.1  leo }
    270  1.1  leo 
    271  1.1  leo static void
    272  1.1  leo cursor32(struct ite_softc *ip, int flag)
    273  1.1  leo {
    274  1.1  leo 	int	cend;
    275  1.1  leo 	u_char	*pl;
    276  1.1  leo 	ipriv_t	*cci;
    277  1.1  leo 
    278  1.1  leo 	cci = ip->priv;
    279  1.1  leo 
    280  1.1  leo 	if(flag == END_CURSOROPT)
    281  1.1  leo 		cci->cursor_opt--;
    282  1.1  leo 	else if(flag == START_CURSOROPT) {
    283  1.1  leo 			if(!cci->cursor_opt)
    284  1.1  leo 				cursor32(ip, ERASE_CURSOR);
    285  1.1  leo 			cci->cursor_opt++;
    286  1.1  leo 			return;		  /* if we are already opted. */
    287  1.1  leo 	}
    288  1.1  leo 
    289  1.1  leo 	if(cci->cursor_opt)
    290  1.1  leo 		return;		  /* if we are still nested. */
    291  1.1  leo 				  /* else we draw the cursor. */
    292  1.1  leo 
    293  1.1  leo 	if(flag != DRAW_CURSOR && flag != END_CURSOROPT) {
    294  1.1  leo 		/*
    295  1.1  leo 		 * erase the cursor
    296  1.1  leo 		 */
    297  1.1  leo 		cend = ip->font.height-1;
    298  1.1  leo 		pl   = cci->column_offset[ip->cursorx]
    299  1.1  leo 				+ cci->row_ptr[ip->cursory];
    300  1.1  leo 		__asm__ __volatile__
    301  1.1  leo 			("1: notb  %0@ ; addaw %4,%0\n\t"
    302  1.1  leo 			 "dbra  %1,1b"
    303  1.1  leo 			 : "=a" (pl), "=d" (cend)
    304  1.1  leo 			 : "0" (pl), "1" (cend),
    305  1.1  leo 			 "d" (cci->row_offset)
    306  1.1  leo 			 );
    307  1.1  leo 	}
    308  1.1  leo 
    309  1.1  leo 	if(flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
    310  1.1  leo 		return;
    311  1.1  leo 
    312  1.1  leo 	/*
    313  1.1  leo 	 * draw the cursor
    314  1.1  leo 	 */
    315  1.1  leo 	ip->cursorx = min(ip->curx, ip->cols-1);
    316  1.1  leo 	ip->cursory = ip->cury;
    317  1.1  leo 	cend        = ip->font.height-1;
    318  1.1  leo 	pl          = cci->column_offset[ip->cursorx]
    319  1.1  leo 			+ cci->row_ptr[ip->cursory];
    320  1.1  leo 
    321  1.1  leo 	__asm__ __volatile__
    322  1.1  leo 		("1: notb  %0@ ; addaw %4,%0\n\t"
    323  1.1  leo 		 "dbra  %1,1b"
    324  1.1  leo 		 : "=a" (pl), "=d" (cend)
    325  1.1  leo 		 : "0" (pl), "1" (cend),
    326  1.1  leo 		 "d" (cci->row_offset)
    327  1.1  leo 		 );
    328  1.1  leo }
    329  1.1  leo 
    330  1.1  leo static void
    331  1.1  leo putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
    332  1.1  leo {
    333  1.1  leo     register ipriv_t	*cci = (ipriv_t *)ip->priv;
    334  1.1  leo     register u_char	*pl  = cci->column_offset[dx] + cci->row_ptr[dy];
    335  1.1  leo     register u_int	fh   = cci->ft_y;
    336  1.1  leo     register u_int	ro   = cci->row_offset;
    337  1.1  leo     register u_char	eor_mask;
    338  1.1  leo     register u_char	bl, tmp, ul;
    339  1.1  leo     register u_char	*ft;
    340  1.1  leo 
    341  1.1  leo     if(c < ip->font.font_lo || c > ip->font.font_hi)
    342  1.1  leo 		return;
    343  1.1  leo 
    344  1.1  leo 	ft = cci->font_cell[c];
    345  1.1  leo 
    346  1.1  leo 	if(!mode) {
    347  1.1  leo 		while(fh--) {
    348  1.1  leo 			*pl = *ft++; pl += ro;
    349  1.1  leo 		}
    350  1.1  leo 		return;
    351  1.1  leo 	}
    352  1.1  leo 
    353  1.1  leo 	eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
    354  1.1  leo 	bl       = (mode & ATTR_BOLD) ? 1 : 0;
    355  1.1  leo 	ul       = fh - cci->underline;
    356  1.1  leo 	while(fh--) {
    357  1.1  leo 		tmp = *ft++ ^ eor_mask;
    358  1.1  leo 		if(bl)
    359  1.1  leo 			*pl = tmp | (tmp >> 1);
    360  1.1  leo 		else *pl = tmp;
    361  1.1  leo 		if(fh == ul)
    362  1.1  leo 			*pl = 0xff;
    363  1.1  leo 		pl += ro;
    364  1.1  leo 	}
    365  1.1  leo }
    366  1.1  leo 
    367  1.1  leo static void
    368  1.1  leo clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
    369  1.1  leo {
    370  1.1  leo 	ipriv_t	*cci = (ipriv_t *) ip->priv;
    371  1.1  leo 	view_t	*v   = ip->grf->g_view;
    372  1.1  leo 	bmap_t	*bm  = v->bitmap;
    373  1.1  leo 
    374  1.1  leo 	if((sx == 0) && (w == ip->cols)) {
    375  1.1  leo 		/* common case: clearing whole lines */
    376  1.1  leo 		while (h--) {
    377  1.1  leo 			int		i;
    378  1.1  leo 			u_char	*ptr = cci->row_ptr[sy];
    379  1.1  leo 			for(i = 0; i < ip->font.height; i++) {
    380  1.1  leo 				bzero(ptr, bm->bytes_per_row);
    381  1.1  leo 				ptr += bm->bytes_per_row;
    382  1.1  leo 			}
    383  1.1  leo 			sy++;
    384  1.1  leo 		}
    385  1.1  leo 	}
    386  1.1  leo 	else {
    387  1.1  leo 		/*
    388  1.1  leo 		 * clearing only part of a line
    389  1.1  leo 		 * XXX could be optimized MUCH better, but is it worth the
    390  1.1  leo 		 * trouble?
    391  1.1  leo 		 */
    392  1.1  leo 
    393  1.1  leo 		int		i;
    394  1.1  leo 		u_char  *pls, *ple;
    395  1.1  leo 
    396  1.1  leo 		pls = cci->row_ptr[sy];
    397  1.1  leo 		ple = pls + cci->column_offset[sx + w-1];
    398  1.1  leo 		pls = pls + cci->column_offset[sx];
    399  1.1  leo 
    400  1.1  leo 		for(i = ((ip->font.height) * h)-1; i >= 0; i--) {
    401  1.1  leo 			u_char *p = pls;
    402  1.1  leo 			while(p <= ple)
    403  1.1  leo 				*p++ = 0;
    404  1.1  leo 			pls += bm->bytes_per_row;
    405  1.1  leo 			ple += bm->bytes_per_row;
    406  1.1  leo 		}
    407  1.1  leo 	}
    408  1.1  leo }
    409  1.1  leo 
    410  1.1  leo /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT.  */
    411  1.1  leo static void
    412  1.1  leo scroll8(ip, sy, sx, count, dir)
    413  1.1  leo register struct ite_softc	*ip;
    414  1.1  leo register int			sy;
    415  1.1  leo int				dir, sx, count;
    416  1.1  leo {
    417  1.1  leo 	bmap_t *bm = ip->grf->g_view->bitmap;
    418  1.1  leo 	u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
    419  1.1  leo 
    420  1.1  leo 	if(dir == SCROLL_UP) {
    421  1.1  leo 		int	dy = sy - count;
    422  1.1  leo 		int	height = ip->bottom_margin - sy + 1;
    423  1.1  leo 		int	i;
    424  1.1  leo 
    425  1.1  leo 		cursor32(ip, ERASE_CURSOR);
    426  1.1  leo 		scrollbmap(bm, 0, dy*ip->font.height, bm->bytes_per_row >> 3,
    427  1.1  leo 				(ip->bottom_margin-dy+1)*ip->font.height,
    428  1.1  leo 				0, -(count*ip->font.height));
    429  1.1  leo 	}
    430  1.1  leo 	else if(dir == SCROLL_DOWN) {
    431  1.1  leo 		int	dy = sy + count;
    432  1.1  leo 		int	height = ip->bottom_margin - dy + 1;
    433  1.1  leo 		int	i;
    434  1.1  leo 
    435  1.1  leo         cursor32(ip, ERASE_CURSOR);
    436  1.1  leo 		scrollbmap(bm, 0, sy*ip->font.height, bm->bytes_per_row >> 3,
    437  1.1  leo 				(ip->bottom_margin-sy+1)*ip->font.height,
    438  1.1  leo 				0, count*ip->font.height);
    439  1.1  leo 	}
    440  1.1  leo 	else if(dir == SCROLL_RIGHT) {
    441  1.1  leo 		int	sofs = (ip->cols - count) * ip->font.width;
    442  1.1  leo 		int	dofs = (ip->cols) * ip->font.width;
    443  1.1  leo 		int	i, j;
    444  1.1  leo 
    445  1.1  leo 		cursor32(ip, ERASE_CURSOR);
    446  1.1  leo 		for(j = ip->font.height-1; j >= 0; j--) {
    447  1.1  leo 		    int sofs2 = sofs, dofs2 = dofs;
    448  1.1  leo 		    for (i = (ip->cols - (sx + count))-1; i >= 0; i--) {
    449  1.1  leo 			int	t;
    450  1.1  leo 			sofs2 -= ip->font.width;
    451  1.1  leo 			dofs2 -= ip->font.width;
    452  1.1  leo 			asm("bfextu %1@{%2:%3},%0" : "=d" (t)
    453  1.1  leo 				: "a" (pl), "d" (sofs2), "d" (ip->font.width));
    454  1.1  leo 			asm("bfins %3,%0@{%1:%2}" :
    455  1.1  leo 				: "a" (pl), "d" (dofs2), "d" (ip->font.width),
    456  1.1  leo 				  "d" (t));
    457  1.1  leo 		    }
    458  1.1  leo 			pl += bm->bytes_per_row;
    459  1.1  leo 		}
    460  1.1  leo 	}
    461  1.1  leo 	else { /* SCROLL_LEFT */
    462  1.1  leo 		int sofs = (sx) * ip->font.width;
    463  1.1  leo 		int dofs = (sx - count) * ip->font.width;
    464  1.1  leo 		int i, j;
    465  1.1  leo 
    466  1.1  leo 		cursor32(ip, ERASE_CURSOR);
    467  1.1  leo 		for(j = ip->font.height-1; j >= 0; j--) {
    468  1.1  leo 		    int sofs2 = sofs, dofs2 = dofs;
    469  1.1  leo 		    for(i = (ip->cols - sx)-1; i >= 0; i--) {
    470  1.1  leo 			int	t;
    471  1.1  leo 
    472  1.1  leo 			asm("bfextu %1@{%2:%3},%0" : "=d" (t)
    473  1.1  leo 				: "a" (pl), "d" (sofs2), "d" (ip->font.width));
    474  1.1  leo 			asm("bfins %3,%0@{%1:%2}"
    475  1.1  leo 				: : "a" (pl), "d" (dofs2),"d" (ip->font.width),
    476  1.1  leo 				    "d" (t));
    477  1.1  leo 			sofs2 += ip->font.width;
    478  1.1  leo 			dofs2 += ip->font.width;
    479  1.1  leo 		    }
    480  1.1  leo 		    pl += bm->bytes_per_row;
    481  1.1  leo 		}
    482  1.1  leo     }
    483  1.1  leo }
    484  1.1  leo 
    485  1.1  leo static void
    486  1.1  leo scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy)
    487  1.1  leo {
    488  1.1  leo     u_short	depth = bm->depth;
    489  1.1  leo     u_short lwpr  = bm->bytes_per_row >> 2;
    490  1.1  leo 
    491  1.1  leo     if(dx) {
    492  1.1  leo     	/* FIX: */ panic ("delta x not supported in scroll bitmap yet.");
    493  1.1  leo     }
    494  1.1  leo 
    495  1.1  leo     if(dy == 0) {
    496  1.1  leo         return;
    497  1.1  leo     }
    498  1.1  leo     if(dy > 0) {
    499  1.1  leo 		u_long *pl       = (u_long *)bm->plane;
    500  1.1  leo 		u_long *src_y    = pl + (lwpr*y);
    501  1.1  leo 		u_long *dest_y   = pl + (lwpr*(y+dy));
    502  1.1  leo 		u_long count     = lwpr*(height-dy);
    503  1.1  leo 		u_long *clr_y    = src_y;
    504  1.1  leo 		u_long clr_count = dest_y - src_y;
    505  1.1  leo 		u_long bc, cbc;
    506  1.1  leo 
    507  1.1  leo 		src_y  += count - 1;
    508  1.1  leo 		dest_y += count - 1;
    509  1.1  leo 
    510  1.1  leo 		bc = count >> 4;
    511  1.1  leo 		count &= 0xf;
    512  1.1  leo 
    513  1.1  leo 		while (bc--) {
    514  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    515  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    516  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    517  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    518  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    519  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    520  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    521  1.1  leo 		    *dest_y-- = *src_y--; *dest_y-- = *src_y--;
    522  1.1  leo 		}
    523  1.1  leo 		while (count--)
    524  1.1  leo 		    *dest_y-- = *src_y--;
    525  1.1  leo 
    526  1.1  leo 		cbc = clr_count >> 4;
    527  1.1  leo 		clr_count &= 0xf;
    528  1.1  leo 
    529  1.1  leo 		while (cbc--) {
    530  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    531  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    532  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    533  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    534  1.1  leo 		}
    535  1.1  leo 		while(clr_count--)
    536  1.1  leo 		    *clr_y++ = 0;
    537  1.1  leo     }
    538  1.1  leo 	else {
    539  1.1  leo 		u_long	*pl       = (u_long *)bm->plane;
    540  1.1  leo 		u_long	*src_y    = pl + (lwpr*(y-dy));
    541  1.1  leo 		u_long	*dest_y   = pl + (lwpr*y);
    542  1.1  leo 		long	count     = lwpr*(height + dy);
    543  1.1  leo 		u_long	*clr_y    = dest_y + count;
    544  1.1  leo 		u_long	clr_count = src_y - dest_y;
    545  1.1  leo 		u_long	bc, cbc;
    546  1.1  leo 
    547  1.1  leo 		bc = count >> 4;
    548  1.1  leo 		count &= 0xf;
    549  1.1  leo 
    550  1.1  leo 		while(bc--) {
    551  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    552  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    553  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    554  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    555  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    556  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    557  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    558  1.1  leo 		    *dest_y++ = *src_y++; *dest_y++ = *src_y++;
    559  1.1  leo 		}
    560  1.1  leo 		while(count--)
    561  1.1  leo 		    *dest_y++ = *src_y++;
    562  1.1  leo 
    563  1.1  leo 		cbc = clr_count >> 4;
    564  1.1  leo 		clr_count &= 0xf;
    565  1.1  leo 
    566  1.1  leo 		while (cbc--) {
    567  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    568  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    569  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    570  1.1  leo 		    *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
    571  1.1  leo 		}
    572  1.1  leo 		while (clr_count--)
    573  1.1  leo 		    *clr_y++ = 0;
    574  1.1  leo     }
    575  1.1  leo }
    576  1.1  leo #else
    577  1.1  leo #error Must be defined
    578  1.1  leo #endif /* NGRF */
    579