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