Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.4
      1  1.4  christos /*	$NetBSD: ite_et.c,v 1.4 1996/10/13 04:11:02 christos Exp $	*/
      2  1.1       leo 
      3  1.1       leo /*
      4  1.1       leo  * Copyright (c) 1996 Leo Weppelman.
      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 Leo Weppelman.
     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 #include <sys/param.h>
     33  1.1       leo #include <sys/systm.h>
     34  1.1       leo #include <sys/conf.h>
     35  1.1       leo #include <sys/ioctl.h>
     36  1.1       leo #include <sys/malloc.h>
     37  1.1       leo #include <sys/device.h>
     38  1.1       leo #include <dev/cons.h>
     39  1.1       leo 
     40  1.1       leo #include <machine/cpu.h>
     41  1.1       leo 
     42  1.1       leo #include <atari/atari/device.h>
     43  1.1       leo 
     44  1.1       leo #include <atari/dev/itevar.h>
     45  1.1       leo #include <atari/dev/iteioctl.h>
     46  1.1       leo #include <atari/dev/grfioctl.h>
     47  1.3       leo #include <atari/dev/grf_etreg.h>
     48  1.1       leo #include <atari/dev/grfabs_reg.h>
     49  1.3       leo #include <atari/dev/grfabs_et.h>
     50  1.1       leo #include <atari/dev/grfvar.h>
     51  1.1       leo #include <atari/dev/font.h>
     52  1.1       leo #include <atari/dev/viewioctl.h>
     53  1.1       leo #include <atari/dev/viewvar.h>
     54  1.1       leo 
     55  1.1       leo #include "grfet.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 	volatile u_char	*regkva;
     63  1.1       leo };
     64  1.1       leo 
     65  1.1       leo typedef struct ite_priv ipriv_t;
     66  1.1       leo 
     67  1.1       leo static ipriv_t	con_ipriv;
     68  1.1       leo 
     69  1.1       leo /* Console colors */
     70  1.1       leo static u_char etconscolors[3][3] = {	/* background, foreground, hilite */
     71  1.1       leo 	{0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f,  0x3f,  0x3f}
     72  1.1       leo };
     73  1.1       leo 
     74  1.1       leo /* XXX: Shouldn't these be in font.h???? */
     75  1.1       leo extern font_info	font_info_8x8;
     76  1.1       leo extern font_info	font_info_8x16;
     77  1.1       leo 
     78  1.1       leo static void grfet_iteinit __P((struct grf_softc *));
     79  1.1       leo static void view_init __P((struct ite_softc *));
     80  1.1       leo static void view_deinit __P((struct ite_softc *));
     81  1.3       leo static int  iteet_ioctl __P((struct ite_softc *, u_long, caddr_t, int,
     82  1.3       leo 							struct proc *));
     83  1.1       leo static int  ite_newsize __P((struct ite_softc *, struct itewinsize *));
     84  1.3       leo static void et_inittextmode __P((struct ite_softc *, et_sv_reg_t *, int));
     85  1.1       leo void et_cursor __P((struct ite_softc *ip, int flag));
     86  1.1       leo void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
     87  1.1       leo void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
     88  1.1       leo void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
     89  1.1       leo     int dir));
     90  1.1       leo 
     91  1.1       leo /* XXX: move to ite.c */
     92  1.1       leo extern int ite_default_x;
     93  1.1       leo extern int ite_default_y;
     94  1.1       leo extern int ite_default_width;
     95  1.1       leo extern int ite_default_depth;
     96  1.1       leo extern int ite_default_height;
     97  1.1       leo 
     98  1.1       leo /*
     99  1.1       leo  * grfet config stuff
    100  1.1       leo  */
    101  1.1       leo void grfetattach __P((struct device *, struct device *, void *));
    102  1.1       leo int  grfetmatch __P((struct device *, void *, void *));
    103  1.1       leo int  grfetprint __P((void *, const char *));
    104  1.1       leo 
    105  1.1       leo struct cfattach grfet_ca = {
    106  1.1       leo 	sizeof(struct grf_softc), grfetmatch, grfetattach
    107  1.1       leo };
    108  1.1       leo 
    109  1.1       leo struct cfdriver grfet_cd = {
    110  1.1       leo 	NULL, "grfet", DV_DULL
    111  1.1       leo };
    112  1.1       leo 
    113  1.1       leo /*
    114  1.1       leo  * only used in console init.
    115  1.1       leo  */
    116  1.1       leo static struct cfdata *cfdata_grf   = NULL;
    117  1.1       leo 
    118  1.1       leo int
    119  1.1       leo grfetmatch(pdp, match, auxp)
    120  1.1       leo struct device	*pdp;
    121  1.1       leo void	*match, *auxp;
    122  1.1       leo {
    123  1.1       leo 	static int	must_probe = 1;
    124  1.1       leo 	grf_auxp_t	*grf_auxp = auxp;
    125  1.1       leo 	struct cfdata	*cfp = match;
    126  1.1       leo 
    127  1.1       leo 	if (must_probe) {
    128  1.1       leo 		if(!(machineid & ATARI_HADES))
    129  1.1       leo 			return 0;
    130  1.1       leo 		/*
    131  1.1       leo 		 * Check if the layers we depend on exist
    132  1.1       leo 		 */
    133  1.1       leo 		if (grfabs_probe(&et_probe_video) == 0)
    134  1.1       leo 			return 0;
    135  1.1       leo 		viewprobe();
    136  1.1       leo 		must_probe = 0;
    137  1.1       leo 	}
    138  1.1       leo 
    139  1.1       leo 	if (atari_realconfig == 0) {
    140  1.1       leo 		/*
    141  1.1       leo 		 * Early console init. Only match unit 0.
    142  1.1       leo 		 */
    143  1.1       leo 		if (cfp->cf_unit != 0)
    144  1.1       leo 			return 0;
    145  1.1       leo 		if (!et_probe_card())
    146  1.1       leo 			return 0;
    147  1.1       leo 		if (viewopen(0, 0, 0, NULL))
    148  1.1       leo 			return 0;
    149  1.1       leo 		cfdata_grf = cfp;
    150  1.1       leo 		return 1;
    151  1.1       leo 	}
    152  1.1       leo 
    153  1.1       leo 	/*
    154  1.1       leo 	 * Normal config. When we are called directly from the grfbus,
    155  1.1       leo 	 * we only match unit 0. The attach function will call us for
    156  1.1       leo 	 * the other configured units.
    157  1.1       leo 	 */
    158  1.1       leo 	if (grf_auxp->from_bus_match
    159  1.1       leo 	    && ((cfp->cf_unit != 0) || !et_probe_card()))
    160  1.1       leo 		return 0;
    161  1.1       leo 
    162  1.1       leo 	if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
    163  1.1       leo 		return 0;
    164  1.1       leo 
    165  1.1       leo 	/*
    166  1.1       leo 	 * Final constraint: each grf needs a view....
    167  1.1       leo 	 */
    168  1.1       leo 	if((cfdata_grf == NULL) || (cfp->cf_unit != 0)) {
    169  1.1       leo 	    if(viewopen(cfp->cf_unit, 0, 0, NULL))
    170  1.1       leo 		return 0;
    171  1.1       leo 	}
    172  1.1       leo 	return 1;
    173  1.1       leo }
    174  1.1       leo 
    175  1.1       leo /*
    176  1.1       leo  * attach: initialize the grf-structure and try to attach an ite to us.
    177  1.1       leo  * note  : dp is NULL during early console init.
    178  1.1       leo  */
    179  1.1       leo void
    180  1.1       leo grfetattach(pdp, dp, auxp)
    181  1.1       leo struct device	*pdp, *dp;
    182  1.1       leo void		*auxp;
    183  1.1       leo {
    184  1.1       leo 	static struct grf_softc		congrf;
    185  1.1       leo 	       grf_auxp_t		*grf_bus_auxp = auxp;
    186  1.1       leo 	       grf_auxp_t		grf_auxp;
    187  1.1       leo 	       struct grf_softc		*gp;
    188  1.1       leo 	       int			maj;
    189  1.1       leo 
    190  1.1       leo 	/*
    191  1.1       leo 	 * find our major device number
    192  1.1       leo 	 */
    193  1.1       leo 	for(maj = 0; maj < nchrdev; maj++)
    194  1.1       leo 		if (cdevsw[maj].d_open == grfopen)
    195  1.1       leo 			break;
    196  1.1       leo 
    197  1.1       leo 	/*
    198  1.1       leo 	 * Handle exeption case: early console init
    199  1.1       leo 	 */
    200  1.1       leo 	if(dp == NULL) {
    201  1.1       leo 		congrf.g_unit    = 0;
    202  1.1       leo 		congrf.g_grfdev  = makedev(maj, 0);
    203  1.1       leo 		congrf.g_itedev  = (dev_t)-1;
    204  1.1       leo 		congrf.g_flags   = GF_ALIVE;
    205  1.1       leo 		congrf.g_mode    = grf_mode;
    206  1.1       leo 		congrf.g_conpri  = CN_INTERNAL;
    207  1.1       leo 		congrf.g_viewdev = congrf.g_unit;
    208  1.1       leo 		grfet_iteinit(&congrf);
    209  1.1       leo 		grf_viewsync(&congrf);
    210  1.1       leo 
    211  1.1       leo 		/* Attach console ite */
    212  1.1       leo 		atari_config_found(cfdata_grf, NULL, &congrf, grfetprint);
    213  1.1       leo 		return;
    214  1.1       leo 	}
    215  1.1       leo 
    216  1.1       leo 	gp = (struct grf_softc *)dp;
    217  1.1       leo 	gp->g_unit = gp->g_device.dv_unit;
    218  1.1       leo 	grfsp[gp->g_unit] = gp;
    219  1.1       leo 
    220  1.1       leo 	if((cfdata_grf != NULL) && (gp->g_unit == 0)) {
    221  1.1       leo 		/*
    222  1.1       leo 		 * We inited earlier just copy the info, take care
    223  1.1       leo 		 * not to copy the device struct though.
    224  1.1       leo 		 */
    225  1.1       leo 		bcopy(&congrf.g_display, &gp->g_display,
    226  1.1       leo 			(char *)&gp[1] - (char *)&gp->g_display);
    227  1.1       leo 	}
    228  1.1       leo 	else {
    229  1.1       leo 		gp->g_grfdev  = makedev(maj, gp->g_unit);
    230  1.1       leo 		gp->g_itedev  = (dev_t)-1;
    231  1.1       leo 		gp->g_flags   = GF_ALIVE;
    232  1.1       leo 		gp->g_mode    = grf_mode;
    233  1.1       leo 		gp->g_conpri  = 0;
    234  1.1       leo 		gp->g_viewdev = gp->g_unit;
    235  1.1       leo 		grfet_iteinit(gp);
    236  1.1       leo 		grf_viewsync(gp);
    237  1.1       leo 	}
    238  1.1       leo 
    239  1.4  christos 	printf(": %dx%d", gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
    240  1.1       leo 	if(gp->g_display.gd_colors == 2)
    241  1.4  christos 		printf(" monochrome\n");
    242  1.4  christos 	else printf(" colors %d\n", gp->g_display.gd_colors);
    243  1.1       leo 
    244  1.1       leo 	/*
    245  1.1       leo 	 * try and attach an ite
    246  1.1       leo 	 */
    247  1.1       leo 	config_found(dp, gp, grfetprint);
    248  1.1       leo 
    249  1.1       leo 	/*
    250  1.1       leo 	 * If attaching unit 0, go ahead and 'find' the rest of us
    251  1.1       leo 	 */
    252  1.1       leo 	if (gp->g_unit == 0) {
    253  1.1       leo 		grf_auxp.from_bus_match = 0;
    254  1.1       leo 		for (grf_auxp.unit=0; grf_auxp.unit < NGRFET; grf_auxp.unit++) {
    255  1.1       leo 		    config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
    256  1.1       leo 		}
    257  1.1       leo 	}
    258  1.1       leo }
    259  1.1       leo 
    260  1.1       leo int
    261  1.1       leo grfetprint(auxp, pnp)
    262  1.1       leo void *auxp;
    263  1.1       leo const char *pnp;
    264  1.1       leo {
    265  1.1       leo 	if(pnp) /* XXX */
    266  1.4  christos 		printf("ite at %s", pnp);
    267  1.1       leo 	return(UNCONF);
    268  1.1       leo }
    269  1.1       leo 
    270  1.1       leo /*
    271  1.1       leo  * Init ite portion of grf_softc struct
    272  1.1       leo  */
    273  1.1       leo static void
    274  1.1       leo grfet_iteinit(gp)
    275  1.1       leo struct grf_softc *gp;
    276  1.1       leo {
    277  1.1       leo 
    278  1.1       leo 	gp->g_itecursor = et_cursor;
    279  1.1       leo 	gp->g_iteputc   = et_putc;
    280  1.1       leo 	gp->g_iteclear  = et_clear;
    281  1.1       leo 	gp->g_itescroll = et_scroll;
    282  1.1       leo 	gp->g_iteinit   = view_init;
    283  1.1       leo 	gp->g_itedeinit = view_deinit;
    284  1.1       leo }
    285  1.1       leo 
    286  1.1       leo static void
    287  1.1       leo view_deinit(ip)
    288  1.1       leo struct ite_softc	*ip;
    289  1.1       leo {
    290  1.1       leo 	ip->flags &= ~ITE_INITED;
    291  1.1       leo }
    292  1.1       leo 
    293  1.1       leo static void
    294  1.1       leo view_init(ip)
    295  1.1       leo register struct ite_softc *ip;
    296  1.1       leo {
    297  1.1       leo 	struct itewinsize	wsz;
    298  1.1       leo 	ipriv_t			*cci;
    299  1.1       leo 	view_t			*view;
    300  1.3       leo 	save_area_t		*et_save;
    301  1.1       leo 
    302  1.1       leo 	if((cci = ip->priv) != NULL)
    303  1.1       leo 		return;
    304  1.1       leo 
    305  1.3       leo 	ip->itexx_ioctl = iteet_ioctl;
    306  1.3       leo 
    307  1.1       leo #if defined(KFONT_8X8)
    308  1.1       leo 	ip->font = font_info_8x8;
    309  1.1       leo #else
    310  1.1       leo 	ip->font = font_info_8x16;
    311  1.1       leo #endif
    312  1.1       leo 
    313  1.1       leo 	/* Find the correct set of rendering routines for this font.  */
    314  1.1       leo 	if(ip->font.width != 8)
    315  1.1       leo 		panic("kernel font size not supported");
    316  1.1       leo 
    317  1.1       leo 	if(!atari_realconfig)
    318  1.1       leo 		ip->priv = cci = &con_ipriv;
    319  1.1       leo 	else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
    320  1.1       leo 	if(cci == NULL)
    321  1.1       leo 		panic("No memory for ite-view");
    322  1.1       leo 	bzero(cci, sizeof(*cci));
    323  1.1       leo 
    324  1.1       leo 	wsz.x      = ite_default_x;
    325  1.1       leo 	wsz.y      = ite_default_y;
    326  1.1       leo 	wsz.width  = ite_default_width;
    327  1.1       leo 	wsz.height = ite_default_height;
    328  1.1       leo 	wsz.depth  = ite_default_depth;
    329  1.1       leo 
    330  1.1       leo 	ite_newsize (ip, &wsz);
    331  1.1       leo 
    332  1.1       leo 	view  = viewview(ip->grf->g_viewdev);
    333  1.1       leo 	cci->regkva = view->bitmap->regs;
    334  1.1       leo 
    335  1.1       leo 	/*
    336  1.1       leo 	 * Only console will be turned on by default..
    337  1.1       leo 	 */
    338  1.1       leo 	if(ip->flags & ITE_ISCONS)
    339  1.1       leo 		ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
    340  1.1       leo 
    341  1.3       leo 	/*
    342  1.3       leo 	 * Activate text-mode settings
    343  1.3       leo 	 */
    344  1.3       leo 	et_save = (save_area_t *)view->save_area;
    345  1.3       leo 	if (et_save == NULL)
    346  1.3       leo 		et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
    347  1.3       leo 	else {
    348  1.3       leo 		et_inittextmode(ip, &et_save->sv_regs, view->flags&VF_DISPLAY);
    349  1.3       leo 		et_save->fb_size = ip->cols * ip->rows;
    350  1.3       leo 	}
    351  1.1       leo }
    352  1.1       leo 
    353  1.1       leo static int
    354  1.1       leo ite_newsize(ip, winsz)
    355  1.1       leo struct ite_softc	*ip;
    356  1.1       leo struct itewinsize	*winsz;
    357  1.1       leo {
    358  1.1       leo 	struct view_size	vs;
    359  1.1       leo 	int			error = 0;
    360  1.3       leo 	save_area_t		*et_save;
    361  1.1       leo 	view_t			*view;
    362  1.1       leo 
    363  1.1       leo 	vs.x      = winsz->x;
    364  1.1       leo 	vs.y      = winsz->y;
    365  1.1       leo 	vs.width  = winsz->width;
    366  1.1       leo 	vs.height = winsz->height;
    367  1.1       leo 	vs.depth  = winsz->depth;
    368  1.1       leo 
    369  1.1       leo 	error = viewioctl(ip->grf->g_viewdev, VIOCSSIZE, (caddr_t)&vs, 0,
    370  1.1       leo 								NOPROC);
    371  1.1       leo 	view  = viewview(ip->grf->g_viewdev);
    372  1.1       leo 
    373  1.1       leo 	/*
    374  1.1       leo 	 * Reinitialize our structs
    375  1.1       leo 	 */
    376  1.1       leo 	ip->cols = view->display.width  / ip->font.width;
    377  1.1       leo 	ip->rows = view->display.height / ip->font.height;
    378  1.1       leo 
    379  1.1       leo 	/*
    380  1.1       leo 	 * save new values so that future opens use them
    381  1.1       leo 	 * this may not be correct when we implement Virtual Consoles
    382  1.1       leo 	 */
    383  1.1       leo 	ite_default_height = view->display.height;
    384  1.1       leo 	ite_default_width  = view->display.width;
    385  1.1       leo 	ite_default_x      = view->display.x;
    386  1.1       leo 	ite_default_y      = view->display.y;
    387  1.1       leo 	ite_default_depth  = view->bitmap->depth;
    388  1.1       leo 
    389  1.3       leo 	et_save = (save_area_t *)view->save_area;
    390  1.3       leo 	if (et_save == NULL)
    391  1.3       leo 	    et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
    392  1.3       leo 	else {
    393  1.3       leo 	    et_inittextmode(ip, &et_save->sv_regs, view->flags & VF_DISPLAY);
    394  1.3       leo 	    et_save->fb_size = ip->cols * ip->rows;
    395  1.3       leo 	}
    396  1.3       leo 	et_clear(ip, 0, 0, ip->rows, ip->cols);
    397  1.3       leo 
    398  1.1       leo 	return(error);
    399  1.1       leo }
    400  1.1       leo 
    401  1.3       leo int
    402  1.3       leo iteet_ioctl(ip, cmd, addr, flag, p)
    403  1.3       leo struct ite_softc	*ip;
    404  1.3       leo u_long			cmd;
    405  1.3       leo caddr_t			addr;
    406  1.3       leo int			flag;
    407  1.3       leo struct proc		*p;
    408  1.3       leo {
    409  1.3       leo 	struct winsize		ws;
    410  1.3       leo 	struct itewinsize	*is;
    411  1.3       leo 	int			error = 0;
    412  1.3       leo 	view_t			*view = viewview(ip->grf->g_viewdev);
    413  1.3       leo #if 0 /* LWP: notyet */
    414  1.3       leo 	struct itebell		*ib;
    415  1.3       leo #endif
    416  1.3       leo 
    417  1.3       leo 	switch (cmd) {
    418  1.3       leo 	case ITEIOCSWINSZ:
    419  1.3       leo 		is = (struct itewinsize *)addr;
    420  1.3       leo 
    421  1.3       leo 		if(ite_newsize(ip, is))
    422  1.3       leo 			error = ENOMEM;
    423  1.3       leo 		else {
    424  1.3       leo 			view         = viewview(ip->grf->g_viewdev);
    425  1.3       leo 			ws.ws_row    = ip->rows;
    426  1.3       leo 			ws.ws_col    = ip->cols;
    427  1.3       leo 			ws.ws_xpixel = view->display.width;
    428  1.3       leo 			ws.ws_ypixel = view->display.height;
    429  1.3       leo 			ite_reset(ip);
    430  1.3       leo 			/*
    431  1.3       leo 			 * XXX tell tty about the change
    432  1.3       leo 			 * XXX this is messy, but works
    433  1.3       leo 			 */
    434  1.3       leo 			iteioctl(ip->grf->g_itedev,TIOCSWINSZ,(caddr_t)&ws,0,p);
    435  1.3       leo 		}
    436  1.3       leo 		break;
    437  1.3       leo 	case ITEIOCGBELL:
    438  1.3       leo #if 0 /* LWP */
    439  1.3       leo 		/* XXX This won't work now			*/
    440  1.3       leo 		/* XXX Should the bell be device dependent?	*/
    441  1.3       leo 		ib         = (struct itebell *)addr;
    442  1.3       leo 		ib->volume = bvolume;
    443  1.3       leo 		ib->pitch  = bpitch;
    444  1.3       leo 		ib->msec   = bmsec;
    445  1.3       leo #endif
    446  1.3       leo 		break;
    447  1.3       leo 	case ITEIOCSBELL:
    448  1.3       leo #if 0 /* LWP */
    449  1.3       leo 		/* XXX See above				*/
    450  1.3       leo 		ib = (struct itebell *)addr;
    451  1.3       leo 		/* bounds check */
    452  1.3       leo 		if(ib->pitch > MAXBPITCH || ib->pitch < MINBPITCH ||
    453  1.3       leo 		    ib->volume > MAXBVOLUME || ib->msec > MAXBTIME)
    454  1.3       leo 			error = EINVAL;
    455  1.3       leo 		else {
    456  1.3       leo 			bvolume = ib->volume;
    457  1.3       leo 			bpitch  = ib->pitch;
    458  1.3       leo 			bmsec   = ib->msec;
    459  1.3       leo 		}
    460  1.3       leo #endif
    461  1.3       leo 		break;
    462  1.3       leo 	case VIOCSCMAP:
    463  1.3       leo 	case VIOCGCMAP:
    464  1.3       leo 		/*
    465  1.3       leo 		 * XXX watchout for that NOPROC. its not really the kernel
    466  1.3       leo 		 * XXX talking these two commands don't use the proc pointer
    467  1.3       leo 		 * XXX though.
    468  1.3       leo 		 */
    469  1.3       leo 		error = viewioctl(ip->grf->g_viewdev, cmd, addr, flag, NOPROC);
    470  1.3       leo 		break;
    471  1.3       leo 	default:
    472  1.3       leo 		error = -1;
    473  1.3       leo 		break;
    474  1.3       leo 	}
    475  1.3       leo 	return (error);
    476  1.3       leo }
    477  1.3       leo 
    478  1.1       leo void
    479  1.1       leo et_cursor(ip, flag)
    480  1.1       leo 	struct ite_softc *ip;
    481  1.1       leo 	int flag;
    482  1.1       leo {
    483  1.1       leo 	volatile u_char	*ba;
    484  1.1       leo 		 view_t	*v;
    485  1.1       leo 		 u_long cpos;
    486  1.1       leo 
    487  1.1       leo 	ba = ((ipriv_t*)ip->priv)->regkva;
    488  1.1       leo 	v  = viewview(ip->grf->g_viewdev);
    489  1.1       leo 
    490  1.1       leo 	/*
    491  1.1       leo 	 * Don't update the cursor when not on display
    492  1.1       leo 	 */
    493  1.1       leo 	if (!(v->flags & VF_DISPLAY))
    494  1.1       leo 		return;
    495  1.1       leo 
    496  1.1       leo 	switch (flag) {
    497  1.1       leo  	    case DRAW_CURSOR:
    498  1.1       leo 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
    499  1.1       leo 	    case MOVE_CURSOR:
    500  1.1       leo 		cpos  =  RCrt(ba, CRT_ID_START_ADDR_LOW) & 0xff;
    501  1.1       leo 		cpos |= (RCrt(ba, CRT_ID_START_ADDR_HIGH) & 0xff) << 8;
    502  1.1       leo 		cpos += ip->curx + ip->cury * ip->cols;
    503  1.1       leo 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, cpos & 0xff);
    504  1.1       leo 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (cpos >> 8) & 0xff);
    505  1.1       leo 		WCrt(ba, CTR_ID_EXT_START, (cpos >> (16-2)) & 0x0c);
    506  1.1       leo 
    507  1.1       leo 		ip->cursorx = ip->curx;
    508  1.1       leo 		ip->cursory = ip->cury;
    509  1.1       leo 		break;
    510  1.1       leo 	    case ERASE_CURSOR:
    511  1.1       leo 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
    512  1.1       leo 	    case START_CURSOROPT:
    513  1.1       leo 	    case END_CURSOROPT:
    514  1.1       leo 	    default:
    515  1.1       leo 		break;
    516  1.1       leo     	}
    517  1.1       leo }
    518  1.1       leo 
    519  1.1       leo void
    520  1.1       leo et_putc(ip, c, dy, dx, mode)
    521  1.1       leo 	struct ite_softc *ip;
    522  1.1       leo 	int c;
    523  1.1       leo 	int dy;
    524  1.1       leo 	int dx;
    525  1.1       leo 	int mode;
    526  1.1       leo {
    527  1.1       leo 	view_t	*v   = viewview(ip->grf->g_viewdev);
    528  1.1       leo 	u_char	attr;
    529  1.1       leo 	u_short	*cp;
    530  1.1       leo 
    531  1.1       leo 	attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    532  1.1       leo 	if (mode & ATTR_UL)     attr |= 0x01;
    533  1.1       leo 	if (mode & ATTR_BOLD)   attr |= 0x08;
    534  1.1       leo 	if (mode & ATTR_BLINK)  attr |= 0x80;
    535  1.1       leo 
    536  1.1       leo 	cp  = (u_short*)v->bitmap->plane;
    537  1.1       leo 	cp[(dy * ip->cols) + dx] = (c << 8) | attr;
    538  1.1       leo }
    539  1.1       leo 
    540  1.1       leo void
    541  1.1       leo et_clear(ip, sy, sx, h, w)
    542  1.1       leo 	struct ite_softc *ip;
    543  1.1       leo 	int sy;
    544  1.1       leo 	int sx;
    545  1.1       leo 	int h;
    546  1.1       leo 	int w;
    547  1.1       leo {
    548  1.1       leo 	/* cl_clear and cl_scroll both rely on ite passing arguments
    549  1.1       leo 	 * which describe continuous regions.  For a VT200 terminal,
    550  1.1       leo 	 * this is safe behavior.
    551  1.1       leo 	 */
    552  1.1       leo 	view_t		*v   = viewview(ip->grf->g_viewdev);
    553  1.1       leo 	u_short		*dest;
    554  1.1       leo 	int		len;
    555  1.1       leo 
    556  1.1       leo 	dest = (u_short *)v->bitmap->plane + (sy * ip->cols) + sx;
    557  1.1       leo 	for(len = w * h; len-- ;)
    558  1.1       leo 		*dest++ = 0x2007;
    559  1.1       leo }
    560  1.1       leo 
    561  1.1       leo void
    562  1.1       leo et_scroll(ip, sy, sx, count, dir)
    563  1.1       leo 	struct ite_softc *ip;
    564  1.1       leo 	int	sy;
    565  1.1       leo 	int	sx;
    566  1.1       leo 	int	count;
    567  1.1       leo 	int	dir;
    568  1.1       leo {
    569  1.1       leo 	view_t	*v   = viewview(ip->grf->g_viewdev);
    570  1.1       leo 	u_short	*fb;
    571  1.1       leo 	u_short	*src, *dst;
    572  1.1       leo 	int	len;
    573  1.1       leo 
    574  1.1       leo 	fb = (u_short*)v->bitmap->plane + sy * ip->cols;
    575  1.1       leo 	switch (dir) {
    576  1.1       leo 	    case SCROLL_UP:
    577  1.1       leo 			src = fb;
    578  1.1       leo 			dst = fb - count * ip->cols;
    579  1.1       leo 			len = (ip->bottom_margin + 1 - sy) * ip->cols;
    580  1.1       leo 			break;
    581  1.1       leo 	    case SCROLL_DOWN:
    582  1.1       leo 			src = fb;
    583  1.1       leo 			dst = fb + count * ip->cols;
    584  1.1       leo 			len = (ip->bottom_margin + 1 - (sy + count)) * ip->cols;
    585  1.1       leo 			break;
    586  1.1       leo 	    case SCROLL_RIGHT:
    587  1.1       leo 			src = fb + sx;
    588  1.1       leo 			dst = fb + sx + count;
    589  1.1       leo 			len = ip->cols - sx + count;
    590  1.1       leo 			break;
    591  1.1       leo 	    case SCROLL_LEFT:
    592  1.1       leo 			src = fb + sx;
    593  1.1       leo 			dst = fb + sx - count;
    594  1.1       leo 			len = ip->cols - sx;
    595  1.1       leo 			break;
    596  1.1       leo 	    default:
    597  1.1       leo 			return;
    598  1.1       leo 	}
    599  1.1       leo 	if (src > dst) {
    600  1.1       leo 		while (len--)
    601  1.1       leo 			*dst++ = *src++;
    602  1.1       leo 	}
    603  1.1       leo 	else {
    604  1.1       leo 		src = &src[len];
    605  1.1       leo 		dst = &dst[len];
    606  1.1       leo 		while (len--)
    607  1.1       leo 			*--dst = *--src;
    608  1.1       leo 	}
    609  1.1       leo }
    610  1.1       leo 
    611  1.1       leo static void
    612  1.3       leo et_inittextmode(ip, etregs, loadfont)
    613  1.1       leo 	struct ite_softc *ip;
    614  1.3       leo 	et_sv_reg_t	 *etregs;
    615  1.3       leo 	int		 loadfont;
    616  1.1       leo {
    617  1.1       leo 	volatile u_char *ba;
    618  1.1       leo 	font_info	*fd;
    619  1.1       leo 	u_char		*fb;
    620  1.1       leo 	u_char		*c, *f, tmp;
    621  1.1       leo 	u_short		z, y;
    622  1.1       leo 	int		s;
    623  1.1       leo 	view_t		*v   = viewview(ip->grf->g_viewdev);
    624  1.3       leo 	et_sv_reg_t	loc_regs;
    625  1.1       leo 
    626  1.3       leo 	if (etregs == NULL) {
    627  1.3       leo 		etregs = &loc_regs;
    628  1.3       leo 		et_hwsave(etregs);
    629  1.3       leo 	}
    630  1.1       leo 
    631  1.1       leo 	ba = ((ipriv_t*)ip->priv)->regkva;
    632  1.1       leo 	fb = v->bitmap->plane;
    633  1.1       leo 
    634  1.1       leo #if defined(KFONT_8X8)
    635  1.1       leo 	fd = &font_info_8x8;
    636  1.1       leo #else
    637  1.1       leo 	fd = &font_info_8x16;
    638  1.1       leo #endif
    639  1.1       leo 
    640  1.3       leo 	if (loadfont) { /* XXX: We should set the colormap */
    641  1.3       leo 		/*
    642  1.3       leo 		 * set colors (B&W)
    643  1.3       leo 		 */
    644  1.3       leo 		vgaw(ba, VDAC_ADDRESS_W, 0);
    645  1.3       leo 		for (z = 0; z < 256; z++) {
    646  1.3       leo 			y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
    647  1.1       leo 
    648  1.3       leo 			vgaw(ba, VDAC_DATA, etconscolors[y][0]);
    649  1.3       leo 			vgaw(ba, VDAC_DATA, etconscolors[y][1]);
    650  1.3       leo 			vgaw(ba, VDAC_DATA, etconscolors[y][2]);
    651  1.3       leo 		}
    652  1.1       leo 
    653  1.3       leo 		/*
    654  1.3       leo 		 * Enter a suitable mode to download the font. This
    655  1.3       leo 		 * basically means sequential addressing mode
    656  1.3       leo 		 */
    657  1.3       leo 		s = splhigh();
    658  1.1       leo 
    659  1.3       leo 		WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
    660  1.3       leo 		WSeq(ba, SEQ_ID_MAP_MASK,	 0x04);
    661  1.3       leo 		WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x06);
    662  1.3       leo 		WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
    663  1.3       leo 		WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x00);
    664  1.3       leo 		WGfx(ba, GCT_ID_MISC,		 0x04);
    665  1.3       leo 		splx(s);
    666  1.1       leo 
    667  1.3       leo 		/*
    668  1.3       leo 		 * load text font into beginning of display memory. Each
    669  1.3       leo 		 * character cell is 32 bytes long (enough for 4 planes)
    670  1.3       leo 		 */
    671  1.3       leo 		for (z = 0, c = fb; z < 256 * 32; z++)
    672  1.3       leo 			*c++ = 0;
    673  1.1       leo 
    674  1.3       leo 		c = (unsigned char *) (fb) + (32 * fd->font_lo);
    675  1.3       leo 		f = fd->font_p;
    676  1.3       leo 		z = fd->font_lo;
    677  1.3       leo 		for (; z <= fd->font_hi; z++, c += (32 - fd->height))
    678  1.3       leo 			for (y = 0; y < fd->height; y++) {
    679  1.3       leo 				*c++ = *f++;
    680  1.3       leo 			}
    681  1.3       leo 	}
    682  1.1       leo 
    683  1.1       leo 	/*
    684  1.1       leo 	 * Odd/Even addressing
    685  1.1       leo 	 */
    686  1.3       leo 	etregs->seq[SEQ_ID_MAP_MASK]        = 0x03;
    687  1.3       leo 	etregs->seq[SEQ_ID_MEMORY_MODE]     = 0x03;
    688  1.3       leo 	etregs->grf[GCT_ID_READ_MAP_SELECT] = 0x00;
    689  1.3       leo 	etregs->grf[GCT_ID_GRAPHICS_MODE]   = 0x10;
    690  1.3       leo 	etregs->grf[GCT_ID_MISC]            = 0x06;
    691  1.1       leo 
    692  1.1       leo 	/*
    693  1.1       leo 	 * Font height + underline location
    694  1.1       leo 	 */
    695  1.3       leo 	tmp = etregs->crt[CRT_ID_MAX_ROW_ADDRESS] & 0xe0;
    696  1.3       leo 	etregs->crt[CRT_ID_MAX_ROW_ADDRESS] = tmp | (fd->height - 1);
    697  1.3       leo 	tmp = etregs->crt[CRT_ID_UNDERLINE_LOC] & 0xe0;
    698  1.3       leo 	etregs->crt[CRT_ID_UNDERLINE_LOC] = tmp | (fd->height - 1);
    699  1.1       leo 
    700  1.1       leo 	/*
    701  1.1       leo 	 * Cursor setup
    702  1.1       leo 	 */
    703  1.3       leo 	etregs->crt[CRT_ID_CURSOR_START]    = 0x00;
    704  1.3       leo 	etregs->crt[CRT_ID_CURSOR_END]      = fd->height - 1;
    705  1.3       leo 	etregs->crt[CRT_ID_CURSOR_LOC_HIGH] = 0x00;
    706  1.3       leo 	etregs->crt[CRT_ID_CURSOR_LOC_LOW]  = 0x00;
    707  1.1       leo 
    708  1.3       leo 	/*
    709  1.3       leo 	 * Enter text mode
    710  1.3       leo 	 */
    711  1.3       leo 	etregs->crt[CRT_ID_MODE_CONTROL]    = 0xa3;
    712  1.3       leo 	etregs->attr[ACT_ID_ATTR_MODE_CNTL] = 0x0a;
    713  1.1       leo 
    714  1.3       leo #if 1
    715  1.3       leo 	if (loadfont || (etregs == &loc_regs))
    716  1.3       leo #else
    717  1.3       leo 	if (etregs == &loc_regs)
    718  1.3       leo #endif
    719  1.3       leo 		et_hwrest(etregs);
    720  1.1       leo }
    721