Home | History | Annotate | Line # | Download | only in dev
grf_cl.c revision 1.11.4.1
      1  1.11.4.1       is /*      $NetBSD: grf_cl.c,v 1.11.4.1 1996/05/27 10:50:40 is Exp $        */
      2       1.1   chopps 
      3       1.1   chopps /*
      4       1.1   chopps  * Copyright (c) 1995 Ezra Story
      5       1.1   chopps  * Copyright (c) 1995 Kari Mettinen
      6       1.1   chopps  * Copyright (c) 1994 Markus Wild
      7       1.1   chopps  * Copyright (c) 1994 Lutz Vieweg
      8       1.1   chopps  * All rights reserved.
      9       1.1   chopps  *
     10       1.1   chopps  * Redistribution and use in source and binary forms, with or without
     11       1.1   chopps  * modification, are permitted provided that the following conditions
     12       1.1   chopps  * are met:
     13       1.1   chopps  * 1. Redistributions of source code must retain the above copyright
     14       1.1   chopps  *    notice, this list of conditions and the following disclaimer.
     15       1.1   chopps  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   chopps  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   chopps  *    documentation and/or other materials provided with the distribution.
     18       1.1   chopps  * 3. All advertising materials mentioning features or use of this software
     19       1.1   chopps  *    must display the following acknowledgement:
     20       1.1   chopps  *      This product includes software developed by Lutz Vieweg.
     21       1.1   chopps  * 4. The name of the author may not be used to endorse or promote products
     22       1.1   chopps  *    derived from this software without specific prior written permission
     23       1.1   chopps  *
     24       1.1   chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25       1.1   chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26       1.1   chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27       1.1   chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28       1.1   chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29       1.1   chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30       1.1   chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31       1.1   chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32       1.1   chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33       1.5   chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34       1.1   chopps  */
     35       1.5   chopps #include "grfcl.h"
     36       1.5   chopps #if NGRFCL > 0
     37       1.1   chopps 
     38       1.1   chopps /*
     39       1.1   chopps  * Graphics routines for Cirrus CL GD 5426 boards,
     40       1.1   chopps  *
     41       1.1   chopps  * This code offers low-level routines to access Cirrus Cl GD 5426
     42       1.1   chopps  * graphics-boards from within NetBSD for the Amiga.
     43       1.1   chopps  * No warranties for any kind of function at all - this
     44       1.1   chopps  * code may crash your hardware and scratch your harddisk.  Use at your
     45       1.1   chopps  * own risk.  Freely distributable.
     46       1.1   chopps  *
     47       1.1   chopps  * Modified for Cirrus CL GD 5426 from
     48       1.1   chopps  * Lutz Vieweg's retina driver by Kari Mettinen 08/94
     49       1.1   chopps  * Contributions by Ill, ScottE, MiL
     50       1.1   chopps  * Extensively hacked and rewritten by Ezra Story (Ezy) 01/95
     51       1.6       is  * Picasso/040 patches (wee!) by crest 01/96
     52       1.1   chopps  *
     53       1.1   chopps  * Thanks to Village Tronic Marketing Gmbh for providing me with
     54       1.1   chopps  * a Picasso-II board.
     55       1.1   chopps  * Thanks for Integrated Electronics Oy Ab for providing me with
     56       1.1   chopps  * Cirrus CL GD 542x family documentation.
     57       1.1   chopps  *
     58       1.1   chopps  * TODO:
     59       1.5   chopps  *    Mouse support (almost there! :-))
     60       1.1   chopps  *    Blitter support
     61       1.1   chopps  *
     62       1.1   chopps  */
     63       1.1   chopps 
     64       1.1   chopps #include <sys/param.h>
     65       1.4   chopps #include <sys/systm.h>
     66       1.1   chopps #include <sys/errno.h>
     67       1.1   chopps #include <sys/ioctl.h>
     68       1.1   chopps #include <sys/device.h>
     69       1.1   chopps #include <sys/malloc.h>
     70       1.5   chopps 
     71       1.1   chopps #include <machine/cpu.h>
     72       1.1   chopps #include <dev/cons.h>
     73       1.9    veego #include <amiga/dev/itevar.h>
     74       1.1   chopps #include <amiga/amiga/device.h>
     75       1.1   chopps #include <amiga/dev/grfioctl.h>
     76       1.1   chopps #include <amiga/dev/grfvar.h>
     77       1.1   chopps #include <amiga/dev/grf_clreg.h>
     78       1.1   chopps #include <amiga/dev/zbusvar.h>
     79       1.1   chopps 
     80  1.11.4.1       is int cl_mondefok __P((struct grfvideo_mode *));
     81  1.11.4.1       is void cl_boardinit __P((struct grf_softc *));
     82      1.11    veego static void cl_CompFQ __P((u_int, u_char *, u_char *));
     83  1.11.4.1       is int cl_getvmode __P((struct grf_softc *, struct grfvideo_mode *));
     84  1.11.4.1       is int cl_setvmode __P((struct grf_softc *, unsigned int));
     85  1.11.4.1       is int cl_toggle __P((struct grf_softc *, unsigned short));
     86  1.11.4.1       is int cl_getcmap __P((struct grf_softc *, struct grf_colormap *));
     87  1.11.4.1       is int cl_putcmap __P((struct grf_softc *, struct grf_colormap *));
     88       1.9    veego #ifndef CL5426CONSOLE
     89  1.11.4.1       is void cl_off __P((struct grf_softc *));
     90       1.9    veego #endif
     91  1.11.4.1       is void cl_inittextmode __P((struct grf_softc *));
     92  1.11.4.1       is int cl_ioctl __P((register struct grf_softc *, u_long, void *));
     93  1.11.4.1       is int cl_getmousepos __P((struct grf_softc *, struct grf_position *));
     94  1.11.4.1       is int cl_setmousepos __P((struct grf_softc *, struct grf_position *));
     95       1.9    veego static int cl_setspriteinfo __P((struct grf_softc *, struct grf_spriteinfo *));
     96  1.11.4.1       is int cl_getspriteinfo __P((struct grf_softc *, struct grf_spriteinfo *));
     97       1.9    veego static int cl_getspritemax __P((struct grf_softc *, struct grf_position *));
     98  1.11.4.1       is int cl_blank __P((struct grf_softc *, int *));
     99       1.9    veego int cl_setmonitor __P((struct grf_softc *, struct grfvideo_mode *));
    100       1.9    veego void cl_writesprpos __P((volatile char *, short, short));
    101       1.9    veego void writeshifted __P((volatile char *, char, char));
    102       1.1   chopps 
    103  1.11.4.1       is static void RegWakeup __P((volatile caddr_t));
    104  1.11.4.1       is static void RegOnpass __P((volatile caddr_t));
    105  1.11.4.1       is static void RegOffpass __P((volatile caddr_t));
    106  1.11.4.1       is 
    107       1.1   chopps void grfclattach __P((struct device *, struct device *, void *));
    108       1.5   chopps int grfclprint __P((void *, char *));
    109       1.7  thorpej int grfclmatch __P((struct device *, void *, void *));
    110       1.9    veego void cl_memset __P((unsigned char *, unsigned char, int));
    111       1.1   chopps 
    112       1.5   chopps /* Graphics display definitions.
    113       1.1   chopps  * These are filled by 'grfconfig' using GRFIOCSETMON.
    114       1.1   chopps  */
    115       1.1   chopps #define monitor_def_max 8
    116       1.1   chopps static struct grfvideo_mode monitor_def[8] = {
    117       1.1   chopps 	{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}
    118       1.1   chopps };
    119       1.1   chopps static struct grfvideo_mode *monitor_current = &monitor_def[0];
    120       1.1   chopps 
    121       1.1   chopps /* Patchable maximum pixel clock */
    122       1.5   chopps unsigned long cl_maxpixelclock = 86000000;
    123       1.1   chopps 
    124       1.1   chopps /* Console display definition.
    125       1.1   chopps  *   Default hardcoded text mode.  This grf_cl is set up to
    126       1.1   chopps  *   use one text mode only, and this is it.  You may use
    127       1.1   chopps  *   grfconfig to change the mode after boot.
    128       1.5   chopps  */
    129       1.1   chopps /* Console font */
    130       1.2   chopps #ifdef KFONT_8X11
    131       1.2   chopps #define CIRRUSFONT kernel_font_8x11
    132       1.2   chopps #define CIRRUSFONTY 11
    133       1.2   chopps #else
    134       1.1   chopps #define CIRRUSFONT kernel_font_8x8
    135       1.1   chopps #define CIRRUSFONTY 8
    136       1.2   chopps #endif
    137       1.1   chopps extern unsigned char CIRRUSFONT[];
    138       1.1   chopps 
    139       1.1   chopps struct grfcltext_mode clconsole_mode = {
    140       1.5   chopps 	{255, "", 25200000, 640, 480, 4, 80, 100, 94, 99, 100, 481, 522, 490,
    141       1.5   chopps 	498, 522},
    142       1.5   chopps 	8, CIRRUSFONTY, 80, 480 / CIRRUSFONTY, CIRRUSFONT, 32, 255
    143       1.1   chopps };
    144       1.1   chopps /* Console colors */
    145       1.5   chopps unsigned char clconscolors[3][3] = {	/* background, foreground, hilite */
    146       1.5   chopps 	{0, 0x40, 0x50}, {152, 152, 152}, {255, 255, 255}
    147       1.1   chopps };
    148       1.1   chopps 
    149      1.11    veego int	cltype = 0;		/* Picasso, Spectrum or Piccolo */
    150      1.11    veego int	cl_sd64 = 0;
    151       1.5   chopps unsigned char pass_toggle;	/* passthru status tracker */
    152       1.1   chopps 
    153       1.5   chopps /* because all 5426-boards have 2 configdev entries, one for
    154       1.1   chopps  * framebuffer mem and the other for regs, we have to hold onto
    155       1.1   chopps  * the pointers globally until we match on both.  This and 'cltype'
    156       1.1   chopps  * are the primary obsticles to multiple board support, but if you
    157       1.1   chopps  * have multiple boards you have bigger problems than grf_cl.
    158       1.1   chopps  */
    159       1.5   chopps static void *cl_fbaddr = 0;	/* framebuffer */
    160       1.5   chopps static void *cl_regaddr = 0;	/* registers */
    161       1.5   chopps static int cl_fbsize;		/* framebuffer size */
    162       1.5   chopps 
    163       1.5   chopps /* current sprite info, if you add summport for multiple boards
    164       1.5   chopps  * make this an array or something
    165       1.5   chopps  */
    166       1.5   chopps struct grf_spriteinfo cl_cursprite;
    167       1.5   chopps 
    168       1.5   chopps /* sprite bitmaps in kernel stack, you'll need to arrayize these too if
    169       1.5   chopps  * you add multiple board support
    170       1.5   chopps  */
    171       1.5   chopps static unsigned char cl_imageptr[8 * 64], cl_maskptr[8 * 64];
    172       1.5   chopps static unsigned char cl_sprred[2], cl_sprgreen[2], cl_sprblue[2];
    173       1.1   chopps 
    174       1.1   chopps /* standard driver stuff */
    175       1.8   mhitch struct cfattach grfcl_ca = {
    176       1.7  thorpej 	sizeof(struct grf_softc), grfclmatch, grfclattach
    177       1.7  thorpej };
    178       1.7  thorpej 
    179       1.7  thorpej struct cfdriver grfcl_cd = {
    180       1.7  thorpej 	NULL, "grfcl", DV_DULL, NULL, 0
    181       1.1   chopps };
    182       1.1   chopps static struct cfdata *cfdata;
    183       1.1   chopps 
    184       1.1   chopps int
    185       1.7  thorpej grfclmatch(pdp, match, auxp)
    186       1.1   chopps 	struct device *pdp;
    187       1.7  thorpej 	void   *match, *auxp;
    188       1.1   chopps {
    189      1.10   mhitch #ifdef CL5426CONSOLE
    190       1.7  thorpej 	struct cfdata *cfp = match;
    191      1.10   mhitch #endif
    192       1.1   chopps 	struct zbus_args *zap;
    193       1.1   chopps 	static int regprod, fbprod;
    194      1.11    veego 	int error;
    195       1.1   chopps 
    196       1.1   chopps 	zap = auxp;
    197       1.1   chopps 
    198       1.1   chopps #ifndef CL5426CONSOLE
    199       1.1   chopps 	if (amiga_realconfig == 0)
    200       1.5   chopps 		return (0);
    201       1.1   chopps #endif
    202       1.1   chopps 
    203       1.5   chopps 	/* Grab the first board we encounter as the preferred one.  This will
    204       1.5   chopps 	 * allow one board to work in a multiple 5426 board system, but not
    205       1.5   chopps 	 * multiple boards at the same time.  */
    206       1.1   chopps 	if (cltype == 0) {
    207       1.1   chopps 		switch (zap->manid) {
    208      1.11    veego 		    case PICASSO:
    209       1.3   chopps 			if (zap->prodid != 12 && zap->prodid != 11)
    210       1.3   chopps 				return (0);
    211       1.1   chopps 			regprod = 12;
    212       1.1   chopps 			fbprod = 11;
    213       1.1   chopps 			break;
    214      1.11    veego 		    case SPECTRUM:
    215       1.3   chopps 			if (zap->prodid != 2 && zap->prodid != 1)
    216       1.3   chopps 				return (0);
    217       1.1   chopps 			regprod = 2;
    218       1.1   chopps 			fbprod = 1;
    219       1.1   chopps 			break;
    220      1.11    veego 		    case PICCOLO:
    221      1.11    veego 			switch (zap->prodid) {
    222      1.11    veego 			    case 5:
    223      1.11    veego 			    case 6:
    224      1.11    veego 				regprod = 6;
    225      1.11    veego 				fbprod = 5;
    226      1.11    veego 				error = 0;
    227      1.11    veego 				break;
    228      1.11    veego 			    case 10:
    229      1.11    veego 			    case 11:
    230      1.11    veego 				regprod = 11;
    231      1.11    veego 				fbprod = 10;
    232      1.11    veego 				cl_sd64 = 1;
    233      1.11    veego 				error = 0;
    234      1.11    veego 				break;
    235      1.11    veego 		    	    default:
    236      1.11    veego 				error = 1;
    237      1.11    veego 				break;
    238      1.11    veego 			}
    239      1.11    veego 			if (error == 1)
    240      1.11    veego 			    return (0);
    241      1.11    veego 			else
    242      1.11    veego 			    break;
    243      1.11    veego 		    default:
    244       1.5   chopps 			return (0);
    245       1.1   chopps 		}
    246       1.1   chopps 		cltype = zap->manid;
    247       1.1   chopps 	} else {
    248       1.1   chopps 		if (cltype != zap->manid) {
    249       1.5   chopps 			return (0);
    250       1.1   chopps 		}
    251       1.1   chopps 	}
    252       1.1   chopps 
    253       1.5   chopps 	/* Configure either registers or framebuffer in any order */
    254       1.1   chopps 	if (zap->prodid == regprod)
    255       1.1   chopps 		cl_regaddr = zap->va;
    256       1.5   chopps 	else
    257       1.5   chopps 		if (zap->prodid == fbprod) {
    258       1.5   chopps 			cl_fbaddr = zap->va;
    259       1.5   chopps 			cl_fbsize = zap->size;
    260       1.5   chopps 		} else
    261       1.5   chopps 			return (0);
    262       1.1   chopps 
    263       1.1   chopps #ifdef CL5426CONSOLE
    264       1.1   chopps 	if (amiga_realconfig == 0) {
    265       1.1   chopps 		cfdata = cfp;
    266       1.1   chopps 	}
    267       1.5   chopps #endif
    268       1.1   chopps 
    269       1.5   chopps 	return (1);
    270       1.1   chopps }
    271       1.1   chopps 
    272       1.1   chopps void
    273       1.1   chopps grfclattach(pdp, dp, auxp)
    274       1.1   chopps 	struct device *pdp, *dp;
    275       1.5   chopps 	void   *auxp;
    276       1.1   chopps {
    277       1.1   chopps 	static struct grf_softc congrf;
    278       1.1   chopps 	struct zbus_args *zap;
    279       1.1   chopps 	struct grf_softc *gp;
    280       1.1   chopps 	static char attachflag = 0;
    281       1.1   chopps 
    282       1.1   chopps 	zap = auxp;
    283       1.1   chopps 
    284       1.1   chopps 	printf("\n");
    285       1.1   chopps 
    286       1.1   chopps 	/* make sure both halves have matched */
    287       1.1   chopps 	if (!cl_regaddr || !cl_fbaddr)
    288       1.1   chopps 		return;
    289       1.1   chopps 
    290       1.1   chopps 	/* do all that messy console/grf stuff */
    291       1.1   chopps 	if (dp == NULL)
    292       1.1   chopps 		gp = &congrf;
    293       1.1   chopps 	else
    294       1.5   chopps 		gp = (struct grf_softc *) dp;
    295       1.1   chopps 
    296       1.1   chopps 	if (dp != NULL && congrf.g_regkva != 0) {
    297       1.1   chopps 		/*
    298       1.1   chopps 		 * inited earlier, just copy (not device struct)
    299       1.1   chopps 		 */
    300       1.1   chopps 		bcopy(&congrf.g_display, &gp->g_display,
    301       1.5   chopps 		    (char *) &gp[1] - (char *) &gp->g_display);
    302       1.1   chopps 	} else {
    303       1.5   chopps 		gp->g_regkva = (volatile caddr_t) cl_regaddr;
    304       1.5   chopps 		gp->g_fbkva = (volatile caddr_t) cl_fbaddr;
    305       1.1   chopps 
    306       1.1   chopps 		gp->g_unit = GRF_CL5426_UNIT;
    307       1.1   chopps 		gp->g_mode = cl_mode;
    308       1.1   chopps 		gp->g_conpri = grfcl_cnprobe();
    309       1.1   chopps 		gp->g_flags = GF_ALIVE;
    310       1.1   chopps 
    311       1.1   chopps 		/* wakeup the board */
    312       1.1   chopps 		cl_boardinit(gp);
    313       1.1   chopps #ifdef CL5426CONSOLE
    314       1.1   chopps 		grfcl_iteinit(gp);
    315       1.5   chopps 		(void) cl_load_mon(gp, &clconsole_mode);
    316       1.1   chopps #endif
    317       1.1   chopps 
    318       1.1   chopps 	}
    319       1.1   chopps 
    320       1.1   chopps 	/*
    321       1.1   chopps 	 * attach grf (once)
    322       1.1   chopps 	 */
    323       1.1   chopps 	if (amiga_config_found(cfdata, &gp->g_device, gp, grfclprint)) {
    324       1.1   chopps 		attachflag = 1;
    325       1.5   chopps 		printf("grfcl: %dMB ", cl_fbsize / 0x100000);
    326       1.1   chopps 		switch (cltype) {
    327      1.11    veego 		    case PICASSO:
    328       1.1   chopps 			printf("Picasso II");
    329       1.5   chopps                         cl_maxpixelclock = 86000000;
    330       1.1   chopps 			break;
    331      1.11    veego 		    case SPECTRUM:
    332       1.1   chopps 			printf("Spectrum");
    333       1.5   chopps                         cl_maxpixelclock = 90000000;
    334       1.1   chopps 			break;
    335      1.11    veego 		    case PICCOLO:
    336      1.11    veego 			if (cl_sd64 == 1) {
    337      1.11    veego 				printf("Piccolo SD64");
    338      1.11    veego 				/* 110MHz will be supported if we
    339      1.11    veego 				 * have a palette doubling mode.
    340      1.11    veego 				 */
    341      1.11    veego 				cl_maxpixelclock = 90000000;
    342      1.11    veego 			} else {
    343      1.11    veego 				printf("Piccolo");
    344      1.11    veego 				cl_maxpixelclock = 90000000;
    345      1.11    veego 			}
    346       1.1   chopps 			break;
    347       1.1   chopps 		}
    348       1.1   chopps 		printf(" being used\n");
    349       1.5   chopps #ifdef CL_OVERCLOCK
    350       1.5   chopps                 cl_maxpixelclock = 115000000;
    351       1.5   chopps #endif
    352       1.1   chopps 	} else {
    353       1.1   chopps 		if (!attachflag)
    354       1.1   chopps 			printf("grfcl unattached!!\n");
    355       1.1   chopps 	}
    356       1.1   chopps }
    357       1.1   chopps 
    358       1.1   chopps int
    359       1.1   chopps grfclprint(auxp, pnp)
    360       1.5   chopps 	void   *auxp;
    361       1.5   chopps 	char   *pnp;
    362       1.1   chopps {
    363       1.1   chopps 	if (pnp)
    364       1.1   chopps 		printf("ite at %s: ", pnp);
    365       1.5   chopps 	return (UNCONF);
    366       1.1   chopps }
    367       1.1   chopps 
    368       1.1   chopps void
    369       1.1   chopps cl_boardinit(gp)
    370       1.5   chopps 	struct grf_softc *gp;
    371       1.1   chopps {
    372       1.1   chopps 	unsigned char *ba = gp->g_regkva;
    373       1.5   chopps 	int     x;
    374       1.1   chopps 
    375       1.1   chopps 	/* wakeup board and flip passthru OFF */
    376       1.1   chopps 
    377       1.1   chopps 	RegWakeup(ba);
    378       1.1   chopps 	RegOnpass(ba);
    379       1.1   chopps 
    380       1.1   chopps 	vgaw(ba, 0x46e8, 0x16);
    381       1.1   chopps 	vgaw(ba, 0x102, 1);
    382       1.1   chopps 	vgaw(ba, 0x46e8, 0x0e);
    383  1.11.4.1       is 	if (cl_sd64 != 1)
    384  1.11.4.1       is 		vgaw(ba, 0x3c3, 1);
    385       1.1   chopps 
    386       1.1   chopps 	/* setup initial unchanging parameters */
    387       1.1   chopps 
    388       1.5   chopps 	WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x21);	/* 8 dot - display off */
    389      1.11    veego 	vgaw(ba, GREG_MISC_OUTPUT_W, 0xed);	/* mem disable */
    390       1.1   chopps 
    391       1.5   chopps 	WGfx(ba, GCT_ID_OFFSET_1, 0xec);	/* magic cookie */
    392       1.5   chopps 	WSeq(ba, SEQ_ID_UNLOCK_EXT, 0x12);	/* yum! cookies! */
    393       1.1   chopps 
    394      1.11    veego 	if (cl_sd64 == 1) {
    395      1.11    veego 		WSeq(ba, SEQ_ID_CONF_RBACK, 0x00);
    396      1.11    veego 		WSeq(ba, SEQ_ID_DRAM_CNTL, (cl_fbsize / 0x100000 == 2) ? 0x38 : 0xb8);
    397      1.11    veego 	} else {
    398      1.11    veego 		WSeq(ba, SEQ_ID_DRAM_CNTL, 0xb0);
    399      1.11    veego 	}
    400       1.5   chopps 	WSeq(ba, SEQ_ID_RESET, 0x03);
    401       1.1   chopps 	WSeq(ba, SEQ_ID_MAP_MASK, 0xff);
    402       1.5   chopps 	WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
    403       1.5   chopps 	WSeq(ba, SEQ_ID_MEMORY_MODE, 0x0e);	/* a or 6? */
    404       1.1   chopps 	WSeq(ba, SEQ_ID_EXT_SEQ_MODE, (cltype == PICASSO) ? 0x20 : 0x80);
    405       1.1   chopps 	WSeq(ba, SEQ_ID_EEPROM_CNTL, 0x00);
    406  1.11.4.1       is 	if (cl_sd64 == 1)
    407  1.11.4.1       is 		WSeq(ba, SEQ_ID_PERF_TUNE, 0x5a);
    408  1.11.4.1       is 	else
    409  1.11.4.1       is 		WSeq(ba, SEQ_ID_PERF_TUNE, 0x0a);	/* mouse 0a fa */
    410       1.1   chopps 	WSeq(ba, SEQ_ID_SIG_CNTL, 0x02);
    411       1.5   chopps 	WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x04);
    412       1.1   chopps 
    413  1.11.4.1       is 	if (cl_sd64 == 1)
    414  1.11.4.1       is 		WSeq(ba, SEQ_ID_MCLK_SELECT, 0x1c);
    415  1.11.4.1       is 	else
    416  1.11.4.1       is 		WSeq(ba, SEQ_ID_MCLK_SELECT, 0x22);
    417       1.1   chopps 
    418       1.1   chopps 	WCrt(ba, CRT_ID_PRESET_ROW_SCAN, 0x00);
    419       1.1   chopps 	WCrt(ba, CRT_ID_CURSOR_START, 0x00);
    420       1.1   chopps 	WCrt(ba, CRT_ID_CURSOR_END, 0x08);
    421       1.1   chopps 	WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
    422       1.1   chopps 	WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
    423       1.1   chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
    424       1.1   chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
    425       1.1   chopps 
    426       1.1   chopps 	WCrt(ba, CRT_ID_UNDERLINE_LOC, 0x07);
    427       1.5   chopps 	WCrt(ba, CRT_ID_MODE_CONTROL, 0xa3);	/* c3 */
    428       1.5   chopps 	WCrt(ba, CRT_ID_LINE_COMPARE, 0xff);	/* ff */
    429       1.1   chopps 	WCrt(ba, CRT_ID_EXT_DISP_CNTL, 0x22);
    430      1.11    veego 	if (cl_sd64 == 1) {
    431      1.11    veego 		WCrt(ba, CRT_ID_SYNC_ADJ_GENLOCK, 0x00);
    432      1.11    veego 		WCrt(ba, CRT_ID_OVERLAY_EXT_CTRL_REG, 0x40);
    433      1.11    veego 	}
    434       1.5   chopps 	WSeq(ba, SEQ_ID_CURSOR_STORE, 0x3c);	/* mouse 0x00 */
    435       1.1   chopps 
    436       1.1   chopps 	WGfx(ba, GCT_ID_SET_RESET, 0x00);
    437       1.1   chopps 	WGfx(ba, GCT_ID_ENABLE_SET_RESET, 0x00);
    438       1.1   chopps 	WGfx(ba, GCT_ID_DATA_ROTATE, 0x00);
    439       1.1   chopps 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
    440       1.1   chopps 	WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
    441       1.1   chopps 	WGfx(ba, GCT_ID_MISC, 0x01);
    442       1.1   chopps 	WGfx(ba, GCT_ID_COLOR_XCARE, 0x0f);
    443       1.1   chopps 	WGfx(ba, GCT_ID_BITMASK, 0xff);
    444       1.1   chopps 	WGfx(ba, GCT_ID_MODE_EXT, 0x28);
    445       1.1   chopps 
    446       1.5   chopps 	for (x = 0; x < 0x10; x++)
    447       1.5   chopps 		WAttr(ba, x, x);
    448       1.1   chopps 	WAttr(ba, ACT_ID_ATTR_MODE_CNTL, 0x01);
    449       1.1   chopps 	WAttr(ba, ACT_ID_OVERSCAN_COLOR, 0x00);
    450       1.1   chopps 	WAttr(ba, ACT_ID_COLOR_PLANE_ENA, 0x0f);
    451       1.1   chopps 	WAttr(ba, ACT_ID_HOR_PEL_PANNING, 0x00);
    452       1.1   chopps 	WAttr(ba, ACT_ID_COLOR_SELECT, 0x00);
    453       1.1   chopps 
    454       1.1   chopps 	delay(200000);
    455       1.5   chopps 	WAttr(ba, 0x34, 0x00);
    456       1.1   chopps 	delay(200000);
    457       1.1   chopps 
    458       1.1   chopps 	vgaw(ba, VDAC_MASK, 0xff);
    459       1.1   chopps 	delay(200000);
    460      1.11    veego 	vgaw(ba, GREG_MISC_OUTPUT_W, 0xef);
    461       1.1   chopps 
    462  1.11.4.1       is 	WGfx(ba, GCT_ID_BLT_STAT_START, 0x04);
    463       1.1   chopps 	WGfx(ba, GCT_ID_BLT_STAT_START, 0x00);
    464       1.1   chopps 
    465       1.1   chopps 	/* colors initially set to greyscale */
    466       1.1   chopps 
    467       1.1   chopps 	vgaw(ba, VDAC_ADDRESS_W, 0);
    468       1.5   chopps 	for (x = 255; x >= 0; x--) {
    469       1.1   chopps 		vgaw(ba, VDAC_DATA, x);
    470       1.1   chopps 		vgaw(ba, VDAC_DATA, x);
    471       1.1   chopps 		vgaw(ba, VDAC_DATA, x);
    472       1.1   chopps 	}
    473       1.5   chopps 	/* set sprite bitmap pointers */
    474       1.5   chopps 	cl_cursprite.image = cl_imageptr;
    475       1.5   chopps 	cl_cursprite.mask = cl_maskptr;
    476       1.5   chopps 	cl_cursprite.cmap.red = cl_sprred;
    477       1.5   chopps 	cl_cursprite.cmap.green = cl_sprgreen;
    478       1.5   chopps 	cl_cursprite.cmap.blue = cl_sprblue;
    479       1.1   chopps }
    480       1.1   chopps 
    481       1.1   chopps 
    482       1.1   chopps int
    483       1.1   chopps cl_getvmode(gp, vm)
    484       1.1   chopps 	struct grf_softc *gp;
    485       1.1   chopps 	struct grfvideo_mode *vm;
    486       1.1   chopps {
    487       1.1   chopps 	struct grfvideo_mode *gv;
    488       1.1   chopps 
    489       1.1   chopps #ifdef CL5426CONSOLE
    490       1.1   chopps 	/* Handle grabbing console mode */
    491       1.1   chopps 	if (vm->mode_num == 255) {
    492       1.1   chopps 		bcopy(&clconsole_mode, vm, sizeof(struct grfvideo_mode));
    493       1.5   chopps 		/* XXX so grfconfig can tell us the correct text dimensions. */
    494       1.1   chopps 		vm->depth = clconsole_mode.fy;
    495       1.5   chopps 	} else
    496       1.1   chopps #endif
    497       1.5   chopps         {
    498       1.5   chopps                 if (vm->mode_num == 0)
    499       1.5   chopps                         vm->mode_num = (monitor_current - monitor_def) + 1;
    500       1.5   chopps                 if (vm->mode_num < 1 || vm->mode_num > monitor_def_max)
    501       1.5   chopps                         return (EINVAL);
    502       1.5   chopps                 gv = monitor_def + (vm->mode_num - 1);
    503       1.5   chopps                 if (gv->mode_num == 0)
    504       1.5   chopps                         return (EINVAL);
    505       1.5   chopps 
    506       1.5   chopps                 bcopy(gv, vm, sizeof(struct grfvideo_mode));
    507       1.5   chopps         }
    508       1.5   chopps 
    509       1.5   chopps         /* adjust internal values to pixel values */
    510       1.5   chopps 
    511       1.5   chopps         vm->hblank_start *= 8;
    512       1.5   chopps         vm->hblank_stop *= 8;
    513       1.5   chopps         vm->hsync_start *= 8;
    514       1.5   chopps         vm->hsync_stop *= 8;
    515       1.5   chopps         vm->htotal *= 8;
    516       1.5   chopps 
    517       1.5   chopps 	return (0);
    518       1.1   chopps }
    519       1.1   chopps 
    520       1.1   chopps 
    521       1.1   chopps int
    522       1.1   chopps cl_setvmode(gp, mode)
    523       1.1   chopps 	struct grf_softc *gp;
    524       1.1   chopps 	unsigned mode;
    525       1.1   chopps {
    526       1.5   chopps 	if (!mode || (mode > monitor_def_max) ||
    527       1.5   chopps 	    monitor_def[mode - 1].mode_num == 0)
    528       1.5   chopps 		return (EINVAL);
    529       1.1   chopps 
    530       1.1   chopps 	monitor_current = monitor_def + (mode - 1);
    531       1.1   chopps 
    532       1.5   chopps 	return (0);
    533       1.1   chopps }
    534       1.1   chopps 
    535       1.9    veego #ifndef CL5426CONSOLE
    536       1.1   chopps void
    537       1.1   chopps cl_off(gp)
    538       1.5   chopps 	struct grf_softc *gp;
    539       1.1   chopps {
    540       1.5   chopps 	char   *ba = gp->g_regkva;
    541       1.1   chopps 
    542       1.5   chopps 	/* we'll put the pass-through on for cc ite and set Full Bandwidth bit
    543       1.5   chopps 	 * on just in case it didn't work...but then it doesn't matter does
    544       1.5   chopps 	 * it? =) */
    545       1.1   chopps 	RegOnpass(ba);
    546       1.1   chopps 	WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x21);
    547       1.1   chopps }
    548       1.9    veego #endif
    549       1.1   chopps 
    550       1.5   chopps int
    551       1.5   chopps cl_blank(gp, on)
    552       1.5   chopps         struct grf_softc *gp;
    553       1.5   chopps         int *on;
    554       1.5   chopps {
    555  1.11.4.1       is         WSeq(gp->g_regkva, SEQ_ID_CLOCKING_MODE, *on ? 0x01 : 0x21);
    556       1.5   chopps         return(0);
    557       1.5   chopps }
    558       1.5   chopps 
    559       1.1   chopps /*
    560       1.1   chopps  * Change the mode of the display.
    561       1.1   chopps  * Return a UNIX error number or 0 for success.
    562       1.1   chopps  */
    563       1.9    veego int
    564       1.1   chopps cl_mode(gp, cmd, arg, a2, a3)
    565       1.1   chopps 	register struct grf_softc *gp;
    566       1.9    veego 	u_long cmd;
    567       1.9    veego 	void *arg;
    568       1.9    veego 	u_long a2;
    569       1.9    veego 	int a3;
    570       1.1   chopps {
    571       1.5   chopps 	int     error;
    572       1.1   chopps 
    573       1.1   chopps 	switch (cmd) {
    574      1.11    veego 	    case GM_GRFON:
    575       1.5   chopps 		error = cl_load_mon(gp,
    576       1.1   chopps 		    (struct grfcltext_mode *) monitor_current) ? 0 : EINVAL;
    577       1.5   chopps 		return (error);
    578       1.1   chopps 
    579      1.11    veego 	    case GM_GRFOFF:
    580       1.1   chopps #ifndef CL5426CONSOLE
    581       1.1   chopps 		cl_off(gp);
    582       1.1   chopps #else
    583       1.1   chopps 		cl_load_mon(gp, &clconsole_mode);
    584       1.1   chopps #endif
    585       1.5   chopps 		return (0);
    586       1.1   chopps 
    587      1.11    veego 	    case GM_GRFCONFIG:
    588       1.5   chopps 		return (0);
    589       1.1   chopps 
    590      1.11    veego 	    case GM_GRFGETVMODE:
    591       1.5   chopps 		return (cl_getvmode(gp, (struct grfvideo_mode *) arg));
    592       1.1   chopps 
    593      1.11    veego 	    case GM_GRFSETVMODE:
    594       1.5   chopps 		error = cl_setvmode(gp, *(unsigned *) arg);
    595       1.5   chopps 		if (!error && (gp->g_flags & GF_GRFON))
    596       1.5   chopps 			cl_load_mon(gp,
    597       1.1   chopps 			    (struct grfcltext_mode *) monitor_current);
    598       1.5   chopps 		return (error);
    599       1.1   chopps 
    600      1.11    veego 	    case GM_GRFGETNUMVM:
    601       1.5   chopps 		*(int *) arg = monitor_def_max;
    602       1.5   chopps 		return (0);
    603       1.1   chopps 
    604      1.11    veego 	    case GM_GRFIOCTL:
    605       1.9    veego 		return (cl_ioctl(gp, a2, arg));
    606       1.1   chopps 
    607      1.11    veego 	    default:
    608       1.1   chopps 		break;
    609       1.1   chopps 	}
    610       1.1   chopps 
    611       1.5   chopps 	return (EINVAL);
    612       1.1   chopps }
    613       1.1   chopps 
    614       1.1   chopps int
    615       1.5   chopps cl_ioctl(gp, cmd, data)
    616       1.1   chopps 	register struct grf_softc *gp;
    617       1.9    veego 	u_long cmd;
    618       1.5   chopps 	void   *data;
    619       1.1   chopps {
    620       1.1   chopps 	switch (cmd) {
    621      1.11    veego 	    case GRFIOCGSPRITEPOS:
    622       1.5   chopps 		return (cl_getmousepos(gp, (struct grf_position *) data));
    623       1.5   chopps 
    624      1.11    veego 	    case GRFIOCSSPRITEPOS:
    625       1.5   chopps 		return (cl_setmousepos(gp, (struct grf_position *) data));
    626       1.5   chopps 
    627      1.11    veego 	    case GRFIOCSSPRITEINF:
    628       1.5   chopps 		return (cl_setspriteinfo(gp, (struct grf_spriteinfo *) data));
    629       1.5   chopps 
    630      1.11    veego 	    case GRFIOCGSPRITEINF:
    631       1.5   chopps 		return (cl_getspriteinfo(gp, (struct grf_spriteinfo *) data));
    632       1.5   chopps 
    633      1.11    veego 	    case GRFIOCGSPRITEMAX:
    634       1.5   chopps 		return (cl_getspritemax(gp, (struct grf_position *) data));
    635       1.1   chopps 
    636      1.11    veego 	    case GRFIOCGETCMAP:
    637       1.5   chopps 		return (cl_getcmap(gp, (struct grf_colormap *) data));
    638       1.1   chopps 
    639      1.11    veego 	    case GRFIOCPUTCMAP:
    640       1.5   chopps 		return (cl_putcmap(gp, (struct grf_colormap *) data));
    641       1.1   chopps 
    642      1.11    veego 	    case GRFIOCBITBLT:
    643       1.1   chopps 		break;
    644       1.1   chopps 
    645      1.11    veego 	    case GRFTOGGLE:
    646       1.5   chopps 		return (cl_toggle(gp, 0));
    647       1.1   chopps 
    648      1.11    veego 	    case GRFIOCSETMON:
    649       1.5   chopps 		return (cl_setmonitor(gp, (struct grfvideo_mode *) data));
    650       1.5   chopps 
    651      1.11    veego             case GRFIOCBLANK:
    652       1.5   chopps                 return (cl_blank(gp, (int *)data));
    653       1.5   chopps 
    654       1.5   chopps 	}
    655       1.5   chopps 	return (EINVAL);
    656       1.5   chopps }
    657       1.5   chopps 
    658       1.5   chopps int
    659       1.5   chopps cl_getmousepos(gp, data)
    660       1.5   chopps 	struct grf_softc *gp;
    661       1.5   chopps 	struct grf_position *data;
    662       1.5   chopps {
    663       1.5   chopps 	data->x = cl_cursprite.pos.x;
    664       1.5   chopps 	data->y = cl_cursprite.pos.y;
    665       1.5   chopps 	return (0);
    666       1.5   chopps }
    667       1.5   chopps 
    668       1.5   chopps void
    669       1.5   chopps cl_writesprpos(ba, x, y)
    670       1.5   chopps 	volatile char *ba;
    671       1.5   chopps 	short   x;
    672       1.5   chopps 	short   y;
    673       1.5   chopps {
    674       1.5   chopps 	/* we want to use a 16-bit write to 3c4 so no macros used */
    675       1.5   chopps 	volatile unsigned char *cwp;
    676       1.5   chopps         volatile unsigned short *wp;
    677       1.5   chopps 
    678       1.5   chopps 	cwp = ba + 0x3c4;
    679       1.5   chopps         wp = (unsigned short *)cwp;
    680       1.5   chopps 
    681       1.5   chopps 	/* don't ask me why, but apparently you can't do a 16-bit write with
    682       1.5   chopps 	 * x-position like with y-position below (dagge) */
    683       1.5   chopps         cwp[0] = 0x10 | ((x << 5) & 0xff);
    684       1.5   chopps         cwp[1] = (x >> 3) & 0xff;
    685       1.5   chopps 
    686       1.5   chopps         *wp = 0x1100 | ((y & 7) << 13) | ((y >> 3) & 0xff);
    687       1.5   chopps 
    688       1.5   chopps }
    689       1.5   chopps 
    690       1.5   chopps void
    691       1.5   chopps writeshifted(to, shiftx, shifty)
    692       1.9    veego 	volatile char *to;
    693       1.5   chopps 	char    shiftx;
    694       1.5   chopps 	char    shifty;
    695       1.5   chopps {
    696       1.5   chopps 	register char y;
    697       1.5   chopps 	unsigned long long *tptr, *iptr, *mptr, line;
    698       1.5   chopps 
    699       1.5   chopps 	tptr = (unsigned long long *) to;
    700       1.5   chopps         iptr = (unsigned long long *) cl_cursprite.image;
    701       1.5   chopps         mptr = (unsigned long long *) cl_cursprite.mask;
    702       1.5   chopps 
    703       1.5   chopps         shiftx = shiftx < 0 ? 0 : shiftx;
    704       1.5   chopps         shifty = shifty < 0 ? 0 : shifty;
    705       1.5   chopps 
    706       1.5   chopps         /* start reading shifty lines down, and
    707       1.5   chopps          * shift each line in by shiftx
    708       1.5   chopps          */
    709       1.5   chopps         for (y = shifty; y < 64; y++) {
    710       1.5   chopps 
    711       1.5   chopps                 /* image */
    712       1.5   chopps                 line = iptr[y];
    713       1.5   chopps 		*tptr++ = line << shiftx;
    714       1.5   chopps 
    715       1.5   chopps                 /* mask */
    716       1.5   chopps                 line = mptr[y];
    717       1.5   chopps 		*tptr++ = line << shiftx;
    718       1.5   chopps 	}
    719       1.5   chopps 
    720       1.5   chopps         /* clear the remainder */
    721       1.5   chopps         for (y = shifty; y > 0; y--) {
    722       1.5   chopps                 *tptr++ = 0;
    723       1.5   chopps                 *tptr++ = 0;
    724       1.5   chopps         }
    725       1.5   chopps }
    726       1.5   chopps 
    727       1.5   chopps int
    728       1.5   chopps cl_setmousepos(gp, data)
    729       1.5   chopps 	struct grf_softc *gp;
    730       1.5   chopps 	struct grf_position *data;
    731       1.5   chopps {
    732       1.5   chopps 	volatile char *ba = gp->g_regkva;
    733       1.9    veego         short rx, ry, prx, pry;
    734       1.9    veego #ifdef CL_SHIFTSPRITE
    735       1.5   chopps 	volatile char *fb = gp->g_fbkva;
    736       1.5   chopps         volatile char *sprite = fb + (cl_fbsize - 1024);
    737       1.9    veego #endif
    738       1.5   chopps 
    739       1.5   chopps         /* no movement */
    740       1.5   chopps 	if (cl_cursprite.pos.x == data->x && cl_cursprite.pos.y == data->y)
    741       1.5   chopps 		return (0);
    742       1.5   chopps 
    743       1.5   chopps         /* current and previous real coordinates */
    744       1.5   chopps 	rx = data->x - cl_cursprite.hot.x;
    745       1.5   chopps 	ry = data->y - cl_cursprite.hot.y;
    746       1.5   chopps 	prx = cl_cursprite.pos.x - cl_cursprite.hot.x;
    747       1.5   chopps 	pry = cl_cursprite.pos.y - cl_cursprite.hot.y;
    748       1.5   chopps 
    749       1.5   chopps         /* if we are/were on an edge, create (un)shifted bitmap --
    750       1.5   chopps          * ripped out optimization (not extremely worthwhile,
    751       1.5   chopps          * and kind of buggy anyhow).
    752       1.5   chopps          */
    753       1.5   chopps #ifdef CL_SHIFTSPRITE
    754       1.5   chopps         if (rx < 0 || ry < 0 || prx < 0 || pry < 0) {
    755       1.5   chopps                 writeshifted(sprite, rx < 0 ? -rx : 0, ry < 0 ? -ry : 0);
    756       1.5   chopps         }
    757       1.5   chopps #endif
    758       1.5   chopps 
    759       1.5   chopps         /* do movement, save position */
    760       1.5   chopps         cl_writesprpos(ba, rx < 0 ? 0 : rx, ry < 0 ? 0 : ry);
    761       1.5   chopps 	cl_cursprite.pos.x = data->x;
    762       1.5   chopps 	cl_cursprite.pos.y = data->y;
    763       1.5   chopps 
    764       1.5   chopps 	return (0);
    765       1.5   chopps }
    766       1.5   chopps 
    767       1.5   chopps int
    768       1.5   chopps cl_getspriteinfo(gp, data)
    769       1.5   chopps 	struct grf_softc *gp;
    770       1.5   chopps 	struct grf_spriteinfo *data;
    771       1.5   chopps {
    772       1.5   chopps 	copyout(&cl_cursprite, data, sizeof(struct grf_spriteinfo));
    773       1.5   chopps 	copyout(cl_cursprite.image, data->image, 64 * 8);
    774       1.5   chopps 	copyout(cl_cursprite.mask, data->mask, 64 * 8);
    775       1.5   chopps 	return (0);
    776       1.5   chopps }
    777       1.5   chopps 
    778  1.11.4.1       is static int
    779       1.5   chopps cl_setspriteinfo(gp, data)
    780       1.5   chopps 	struct grf_softc *gp;
    781       1.5   chopps 	struct grf_spriteinfo *data;
    782       1.5   chopps {
    783       1.5   chopps 	volatile unsigned char *ba = gp->g_regkva, *fb = gp->g_fbkva;
    784       1.5   chopps         volatile char *sprite = fb + (cl_fbsize - 1024);
    785       1.5   chopps 
    786       1.5   chopps 	if (data->set & GRFSPRSET_SHAPE) {
    787       1.5   chopps 
    788       1.5   chopps                 short dsx, dsy, i;
    789       1.5   chopps                 unsigned long *di, *dm, *si, *sm;
    790       1.5   chopps                 unsigned long ssi[128], ssm[128];
    791       1.5   chopps                 struct grf_position gpos;
    792       1.5   chopps 
    793       1.5   chopps 
    794       1.5   chopps                 /* check for a too large sprite (no clipping!) */
    795       1.5   chopps                 dsy = data->size.y;
    796       1.5   chopps                 dsx = data->size.x;
    797       1.5   chopps                 if (dsy > 64 || dsx > 64)
    798       1.5   chopps                         return(EINVAL);
    799       1.5   chopps 
    800       1.5   chopps                 /* prepare destination */
    801       1.5   chopps                 di = (unsigned long *)cl_cursprite.image;
    802       1.5   chopps                 dm = (unsigned long *)cl_cursprite.mask;
    803       1.5   chopps                 cl_memset((unsigned char *)di, 0, 8*64);
    804       1.5   chopps                 cl_memset((unsigned char *)dm, 0, 8*64);
    805       1.5   chopps 
    806       1.5   chopps                 /* two alternatives:  64 across, then it's
    807       1.5   chopps                  * the same format we use, just copy.  Otherwise,
    808       1.5   chopps                  * copy into tmp buf and recopy skipping the
    809       1.5   chopps                  * unused 32 bits.
    810       1.5   chopps                  */
    811       1.5   chopps                 if ((dsx - 1) / 32) {
    812       1.5   chopps                         copyin(data->image, di, 8 * dsy);
    813       1.5   chopps                         copyin(data->mask, dm, 8 * dsy);
    814       1.5   chopps                 } else {
    815       1.5   chopps                         si = ssi; sm = ssm;
    816       1.5   chopps                         copyin(data->image, si, 4 * dsy);
    817       1.5   chopps                         copyin(data->mask, sm, 4 * dsy);
    818       1.5   chopps                         for (i = 0; i < dsy; i++) {
    819       1.5   chopps                                 *di = *si++;
    820       1.5   chopps                                 *dm = *sm++;
    821       1.5   chopps                                 di += 2;
    822       1.5   chopps                                 dm += 2;
    823       1.5   chopps                         }
    824       1.5   chopps                 }
    825       1.5   chopps 
    826       1.5   chopps                 /* set size */
    827       1.5   chopps 		cl_cursprite.size.x = data->size.x;
    828       1.5   chopps 		cl_cursprite.size.y = data->size.y;
    829       1.5   chopps 
    830       1.5   chopps                 /* forcably load into board */
    831       1.5   chopps                 gpos.x = cl_cursprite.pos.x;
    832       1.5   chopps                 gpos.y = cl_cursprite.pos.y;
    833       1.5   chopps                 cl_cursprite.pos.x = -1;
    834       1.5   chopps                 cl_cursprite.pos.y = -1;
    835       1.5   chopps                 writeshifted(sprite, 0, 0);
    836       1.5   chopps                 cl_setmousepos(gp, &gpos);
    837       1.5   chopps 
    838       1.5   chopps 	}
    839       1.5   chopps 	if (data->set & GRFSPRSET_HOT) {
    840       1.5   chopps 
    841       1.5   chopps 		cl_cursprite.hot = data->hot;
    842       1.5   chopps 
    843       1.5   chopps 	}
    844       1.5   chopps 	if (data->set & GRFSPRSET_CMAP) {
    845       1.5   chopps 
    846       1.5   chopps 		u_char  red[2], green[2], blue[2];
    847       1.5   chopps 
    848       1.5   chopps 		copyin(data->cmap.red, red, 2);
    849       1.5   chopps 		copyin(data->cmap.green, green, 2);
    850       1.5   chopps 		copyin(data->cmap.blue, blue, 2);
    851       1.5   chopps 		bcopy(red, cl_cursprite.cmap.red, 2);
    852       1.5   chopps 		bcopy(green, cl_cursprite.cmap.green, 2);
    853       1.5   chopps 		bcopy(blue, cl_cursprite.cmap.blue, 2);
    854       1.5   chopps 
    855       1.5   chopps                 /* enable and load colors 256 & 257 */
    856       1.5   chopps 		WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x06);
    857       1.5   chopps 
    858       1.5   chopps                 /* 256 */
    859       1.5   chopps 		vgaw(ba, VDAC_ADDRESS_W, 0x00);
    860       1.5   chopps 		if (cltype == PICASSO) {
    861       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (red[0] >> 2));
    862       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (green[0] >> 2));
    863       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (blue[0] >> 2));
    864       1.5   chopps 		} else {
    865       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (blue[0] >> 2));
    866       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (green[0] >> 2));
    867       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (red[0] >> 2));
    868       1.5   chopps 		}
    869       1.5   chopps 
    870       1.5   chopps                 /* 257 */
    871       1.5   chopps 		vgaw(ba, VDAC_ADDRESS_W, 0x0f);
    872       1.5   chopps 		if (cltype == PICASSO) {
    873       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (red[1] >> 2));
    874       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (green[1] >> 2));
    875       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (blue[1] >> 2));
    876       1.5   chopps 		} else {
    877       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (blue[1] >> 2));
    878       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (green[1] >> 2));
    879       1.5   chopps 			vgaw(ba, VDAC_DATA, (u_char) (red[1] >> 2));
    880       1.5   chopps 		}
    881       1.5   chopps 
    882       1.5   chopps                 /* turn on/off sprite */
    883       1.5   chopps 		if (cl_cursprite.enable) {
    884       1.5   chopps 			WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x05);
    885       1.5   chopps 		} else {
    886       1.5   chopps 			WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x04);
    887       1.5   chopps 		}
    888       1.5   chopps 
    889       1.5   chopps 	}
    890       1.5   chopps 	if (data->set & GRFSPRSET_ENABLE) {
    891       1.5   chopps 
    892       1.5   chopps 		if (data->enable == 1) {
    893       1.5   chopps 			WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x05);
    894       1.5   chopps 			cl_cursprite.enable = 1;
    895       1.5   chopps 		} else {
    896       1.5   chopps 			WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x04);
    897       1.5   chopps 			cl_cursprite.enable = 0;
    898       1.5   chopps 		}
    899       1.5   chopps 
    900       1.5   chopps 	}
    901       1.5   chopps 	if (data->set & GRFSPRSET_POS) {
    902       1.5   chopps 
    903       1.5   chopps                 /* force placement */
    904       1.5   chopps                 cl_cursprite.pos.x = -1;
    905       1.5   chopps                 cl_cursprite.pos.y = -1;
    906       1.1   chopps 
    907       1.5   chopps                 /* do it */
    908       1.5   chopps                 cl_setmousepos(gp, &data->pos);
    909       1.5   chopps 
    910       1.1   chopps 	}
    911       1.5   chopps 	return (0);
    912       1.5   chopps }
    913       1.5   chopps 
    914  1.11.4.1       is static int
    915       1.5   chopps cl_getspritemax(gp, data)
    916       1.5   chopps 	struct grf_softc *gp;
    917       1.5   chopps 	struct grf_position *data;
    918       1.5   chopps {
    919       1.5   chopps 	if (gp->g_display.gd_planes == 24)
    920       1.5   chopps 		return (EINVAL);
    921       1.5   chopps 	data->x = 64;
    922       1.5   chopps 	data->y = 64;
    923       1.5   chopps 	return (0);
    924       1.1   chopps }
    925       1.1   chopps 
    926       1.1   chopps int
    927       1.1   chopps cl_setmonitor(gp, gv)
    928       1.1   chopps 	struct grf_softc *gp;
    929       1.1   chopps 	struct grfvideo_mode *gv;
    930       1.1   chopps {
    931       1.5   chopps 	struct grfvideo_mode *md;
    932       1.5   chopps 
    933       1.5   chopps         if (!cl_mondefok(gv))
    934       1.5   chopps                 return(EINVAL);
    935       1.1   chopps 
    936       1.1   chopps #ifdef CL5426CONSOLE
    937       1.1   chopps 	/* handle interactive setting of console mode */
    938       1.5   chopps 	if (gv->mode_num == 255) {
    939       1.1   chopps 		bcopy(gv, &clconsole_mode.gv, sizeof(struct grfvideo_mode));
    940       1.5   chopps                 clconsole_mode.gv.hblank_start /= 8;
    941       1.5   chopps                 clconsole_mode.gv.hblank_stop /= 8;
    942       1.5   chopps                 clconsole_mode.gv.hsync_start /= 8;
    943       1.5   chopps                 clconsole_mode.gv.hsync_stop /= 8;
    944       1.5   chopps                 clconsole_mode.gv.htotal /= 8;
    945       1.1   chopps 		clconsole_mode.rows = gv->disp_height / clconsole_mode.fy;
    946       1.1   chopps 		clconsole_mode.cols = gv->disp_width / clconsole_mode.fx;
    947       1.1   chopps 		if (!(gp->g_flags & GF_GRFON))
    948       1.5   chopps 			cl_load_mon(gp, &clconsole_mode);
    949       1.1   chopps 		ite_reinit(gp->g_itedev);
    950       1.5   chopps 		return (0);
    951       1.1   chopps 	}
    952       1.1   chopps #endif
    953       1.1   chopps 
    954       1.5   chopps 	md = monitor_def + (gv->mode_num - 1);
    955       1.5   chopps 	bcopy(gv, md, sizeof(struct grfvideo_mode));
    956       1.5   chopps 
    957       1.5   chopps         /* adjust pixel oriented values to internal rep. */
    958       1.1   chopps 
    959       1.5   chopps         md->hblank_start /= 8;
    960       1.5   chopps         md->hblank_stop /= 8;
    961       1.5   chopps         md->hsync_start /= 8;
    962       1.5   chopps         md->hsync_stop /= 8;
    963       1.5   chopps         md->htotal /= 8;
    964       1.1   chopps 
    965       1.5   chopps 	return (0);
    966       1.1   chopps }
    967       1.1   chopps 
    968       1.1   chopps int
    969       1.5   chopps cl_getcmap(gfp, cmap)
    970       1.1   chopps 	struct grf_softc *gfp;
    971       1.1   chopps 	struct grf_colormap *cmap;
    972       1.1   chopps {
    973       1.1   chopps 	volatile unsigned char *ba;
    974       1.5   chopps 	u_char  red[256], green[256], blue[256], *rp, *gp, *bp;
    975       1.5   chopps 	short   x;
    976       1.5   chopps 	int     error;
    977       1.1   chopps 
    978       1.1   chopps 	if (cmap->count == 0 || cmap->index >= 256)
    979       1.1   chopps 		return 0;
    980       1.1   chopps 
    981       1.1   chopps 	if (cmap->index + cmap->count > 256)
    982       1.1   chopps 		cmap->count = 256 - cmap->index;
    983       1.1   chopps 
    984       1.1   chopps 	ba = gfp->g_regkva;
    985       1.1   chopps 	/* first read colors out of the chip, then copyout to userspace */
    986       1.6       is 	vgaw(ba, VDAC_ADDRESS_R, cmap->index);
    987       1.1   chopps 	x = cmap->count - 1;
    988       1.1   chopps 
    989       1.1   chopps /* Some sort 'o Magic. Spectrum has some changes on the board to speed
    990       1.1   chopps  * up 15 and 16Bit modes. They can access these modes with easy-to-programm
    991       1.1   chopps  * rgbrgbrgb instead of rrrgggbbb. Side effect: when in 8Bit mode, rgb
    992       1.1   chopps  * is swapped to bgr. I wonder if we need to check for 8Bit though, ill
    993       1.1   chopps  */
    994       1.1   chopps 
    995       1.5   chopps 	switch (cltype) {
    996      1.11    veego 	    case SPECTRUM:
    997      1.11    veego 	    case PICCOLO:
    998       1.5   chopps 		rp = blue + cmap->index;
    999       1.1   chopps 		gp = green + cmap->index;
   1000       1.1   chopps 		bp = red + cmap->index;
   1001       1.1   chopps 		break;
   1002      1.11    veego 	    case PICASSO:
   1003       1.5   chopps 		rp = red + cmap->index;
   1004       1.1   chopps 		gp = green + cmap->index;
   1005       1.1   chopps 		bp = blue + cmap->index;
   1006       1.1   chopps 		break;
   1007      1.11    veego 	    default:
   1008       1.9    veego 		rp = gp = bp = 0;
   1009       1.9    veego 		break;
   1010       1.1   chopps 	}
   1011       1.1   chopps 
   1012       1.1   chopps 	do {
   1013       1.5   chopps 		*rp++ = vgar(ba, VDAC_DATA) << 2;
   1014       1.5   chopps 		*gp++ = vgar(ba, VDAC_DATA) << 2;
   1015       1.5   chopps 		*bp++ = vgar(ba, VDAC_DATA) << 2;
   1016       1.1   chopps 	} while (x-- > 0);
   1017       1.1   chopps 
   1018       1.5   chopps 	if (!(error = copyout(red + cmap->index, cmap->red, cmap->count))
   1019       1.5   chopps 	    && !(error = copyout(green + cmap->index, cmap->green, cmap->count))
   1020       1.5   chopps 	    && !(error = copyout(blue + cmap->index, cmap->blue, cmap->count)))
   1021       1.5   chopps 		return (0);
   1022       1.1   chopps 
   1023       1.5   chopps 	return (error);
   1024       1.1   chopps }
   1025       1.1   chopps 
   1026       1.1   chopps int
   1027       1.5   chopps cl_putcmap(gfp, cmap)
   1028       1.1   chopps 	struct grf_softc *gfp;
   1029       1.1   chopps 	struct grf_colormap *cmap;
   1030       1.1   chopps {
   1031       1.1   chopps 	volatile unsigned char *ba;
   1032       1.5   chopps 	u_char  red[256], green[256], blue[256], *rp, *gp, *bp;
   1033       1.5   chopps 	short   x;
   1034       1.5   chopps 	int     error;
   1035       1.1   chopps 
   1036       1.1   chopps 	if (cmap->count == 0 || cmap->index >= 256)
   1037       1.5   chopps 		return (0);
   1038       1.1   chopps 
   1039       1.1   chopps 	if (cmap->index + cmap->count > 256)
   1040       1.1   chopps 		cmap->count = 256 - cmap->index;
   1041       1.1   chopps 
   1042       1.1   chopps 	/* first copy the colors into kernelspace */
   1043       1.5   chopps 	if (!(error = copyin(cmap->red, red + cmap->index, cmap->count))
   1044       1.5   chopps 	    && !(error = copyin(cmap->green, green + cmap->index, cmap->count))
   1045       1.5   chopps 	    && !(error = copyin(cmap->blue, blue + cmap->index, cmap->count))) {
   1046       1.1   chopps 		ba = gfp->g_regkva;
   1047       1.5   chopps 		vgaw(ba, VDAC_ADDRESS_W, cmap->index);
   1048       1.1   chopps 		x = cmap->count - 1;
   1049       1.1   chopps 
   1050       1.5   chopps 		switch (cltype) {
   1051      1.11    veego 		    case SPECTRUM:
   1052      1.11    veego 		    case PICCOLO:
   1053       1.1   chopps 			rp = blue + cmap->index;
   1054       1.1   chopps 			gp = green + cmap->index;
   1055       1.1   chopps 			bp = red + cmap->index;
   1056       1.1   chopps 			break;
   1057      1.11    veego 		    case PICASSO:
   1058       1.1   chopps 			rp = red + cmap->index;
   1059       1.1   chopps 			gp = green + cmap->index;
   1060       1.1   chopps 			bp = blue + cmap->index;
   1061       1.1   chopps 			break;
   1062      1.11    veego 		    default:
   1063       1.9    veego 			rp = gp = bp = 0;
   1064       1.9    veego 			break;
   1065       1.5   chopps 		}
   1066       1.1   chopps 
   1067       1.1   chopps 		do {
   1068       1.5   chopps 			vgaw(ba, VDAC_DATA, *rp++ >> 2);
   1069       1.5   chopps 			vgaw(ba, VDAC_DATA, *gp++ >> 2);
   1070       1.5   chopps 			vgaw(ba, VDAC_DATA, *bp++ >> 2);
   1071       1.1   chopps 		} while (x-- > 0);
   1072       1.5   chopps 		return (0);
   1073       1.5   chopps 	} else
   1074       1.5   chopps 		return (error);
   1075       1.1   chopps }
   1076       1.1   chopps 
   1077       1.1   chopps 
   1078       1.1   chopps int
   1079       1.5   chopps cl_toggle(gp, wopp)
   1080       1.1   chopps 	struct grf_softc *gp;
   1081       1.5   chopps 	unsigned short wopp;	/* don't need that one yet, ill */
   1082       1.1   chopps {
   1083  1.11.4.1       is 	volatile caddr_t ba;
   1084       1.1   chopps 
   1085       1.1   chopps 	ba = gp->g_regkva;
   1086       1.1   chopps 
   1087       1.1   chopps 	if (pass_toggle) {
   1088       1.1   chopps 		RegOffpass(ba);
   1089       1.1   chopps 	} else {
   1090       1.1   chopps 		/* This was in the original.. is it needed? */
   1091       1.1   chopps 		if (cltype == PICASSO || cltype == PICCOLO)
   1092       1.1   chopps 			RegWakeup(ba);
   1093       1.1   chopps 		RegOnpass(ba);
   1094       1.1   chopps 	}
   1095       1.5   chopps 	return (0);
   1096       1.1   chopps }
   1097       1.1   chopps 
   1098       1.1   chopps static void
   1099      1.11    veego cl_CompFQ(fq, num, denom)
   1100       1.5   chopps 	u_int   fq;
   1101       1.5   chopps 	u_char *num;
   1102       1.5   chopps 	u_char *denom;
   1103       1.1   chopps {
   1104       1.1   chopps #define OSC     14318180
   1105       1.1   chopps /* OK, here's what we're doing here:
   1106       1.5   chopps  *
   1107       1.1   chopps  *             OSC * NUMERATOR
   1108       1.1   chopps  *      VCLK = -------------------  Hz
   1109       1.1   chopps  *             DENOMINATOR * (1+P)
   1110       1.1   chopps  *
   1111       1.1   chopps  * so we're given VCLK and we should give out some useful
   1112       1.1   chopps  * values....
   1113       1.1   chopps  *
   1114       1.5   chopps  * NUMERATOR is 7 bits wide
   1115       1.1   chopps  * DENOMINATOR is 5 bits wide with bit P in the same char as bit 0.
   1116       1.1   chopps  *
   1117       1.1   chopps  * We run through all the possible combinations and
   1118       1.1   chopps  * return the values which deviate the least from the chosen frequency.
   1119       1.5   chopps  *
   1120       1.1   chopps  */
   1121       1.1   chopps #define OSC     14318180
   1122       1.1   chopps #define count(n,d,p)    ((OSC * n)/(d * (1+p)))
   1123       1.1   chopps 
   1124       1.9    veego 	unsigned char n, d, p, minn, mind, minp = 0;
   1125       1.1   chopps 	unsigned long err, minerr;
   1126       1.1   chopps 
   1127       1.1   chopps /*
   1128       1.5   chopps numer = 0x00 - 0x7f
   1129       1.1   chopps denom = 0x00 - 0x1f (1) 0x20 - 0x3e (even)
   1130       1.1   chopps */
   1131       1.1   chopps 
   1132       1.5   chopps 	/* find lowest error in 6144 iterations. */
   1133       1.1   chopps 	minerr = fq;
   1134       1.1   chopps 	minn = 0;
   1135       1.1   chopps 	mind = 0;
   1136       1.1   chopps 	p = 0;
   1137       1.1   chopps 
   1138       1.5   chopps 	for (d = 1; d < 0x20; d++) {
   1139       1.5   chopps 		for (n = 1; n < 0x80; n++) {
   1140       1.1   chopps 			err = abs(count(n, d, p) - fq);
   1141       1.1   chopps 			if (err < minerr) {
   1142       1.1   chopps 				minerr = err;
   1143       1.1   chopps 				minn = n;
   1144       1.1   chopps 				mind = d;
   1145       1.1   chopps 				minp = p;
   1146       1.1   chopps 			}
   1147       1.1   chopps 		}
   1148       1.1   chopps 		if (d == 0x1f && p == 0) {
   1149       1.1   chopps 			p = 1;
   1150       1.1   chopps 			d = 0x0f;
   1151       1.1   chopps 		}
   1152       1.1   chopps 	}
   1153       1.1   chopps 
   1154       1.1   chopps 	*num = minn;
   1155       1.1   chopps 	*denom = (mind << 1) | minp;
   1156       1.1   chopps 	if (minerr > 500000)
   1157       1.9    veego 		printf("Warning: CompFQ minimum error = %ld\n", minerr);
   1158       1.1   chopps 	return;
   1159       1.1   chopps }
   1160       1.1   chopps 
   1161       1.1   chopps int
   1162       1.5   chopps cl_mondefok(gv)
   1163       1.5   chopps 	struct grfvideo_mode *gv;
   1164       1.1   chopps {
   1165       1.5   chopps         unsigned long maxpix;
   1166       1.5   chopps 
   1167       1.5   chopps 	if (gv->mode_num < 1 || gv->mode_num > monitor_def_max)
   1168       1.5   chopps                 if (gv->mode_num != 255 || gv->depth != 4)
   1169       1.5   chopps                         return(0);
   1170       1.1   chopps 
   1171       1.5   chopps 	switch (gv->depth) {
   1172      1.11    veego 	    case 4:
   1173       1.5   chopps                 if (gv->mode_num != 255)
   1174       1.5   chopps                         return(0);
   1175      1.11    veego 	    case 1:
   1176      1.11    veego 	    case 8:
   1177       1.5   chopps                 maxpix = cl_maxpixelclock;
   1178       1.5   chopps                 break;
   1179      1.11    veego 	    case 15:
   1180      1.11    veego 	    case 16:
   1181       1.5   chopps                 maxpix = cl_maxpixelclock - (cl_maxpixelclock / 3);
   1182       1.5   chopps                 break;
   1183      1.11    veego 	    case 24:
   1184       1.5   chopps                 maxpix = cl_maxpixelclock / 3;
   1185       1.5   chopps                 break;
   1186       1.1   chopps 	default:
   1187       1.5   chopps 		return (0);
   1188       1.1   chopps 	}
   1189       1.5   chopps         if (gv->pixel_clock > maxpix)
   1190       1.5   chopps                 return (0);
   1191       1.5   chopps         return (1);
   1192       1.1   chopps }
   1193       1.1   chopps 
   1194       1.1   chopps int
   1195       1.1   chopps cl_load_mon(gp, md)
   1196       1.1   chopps 	struct grf_softc *gp;
   1197       1.1   chopps 	struct grfcltext_mode *md;
   1198       1.1   chopps {
   1199       1.1   chopps 	struct grfvideo_mode *gv;
   1200       1.1   chopps 	struct grfinfo *gi;
   1201  1.11.4.1       is 	volatile caddr_t ba, fb;
   1202       1.5   chopps 	unsigned char num0, denom0;
   1203       1.5   chopps 	unsigned short HT, HDE, HBS, HBE, HSS, HSE, VDE, VBS, VBE, VSS,
   1204       1.5   chopps 	        VSE, VT;
   1205       1.5   chopps 	char    LACE, DBLSCAN, TEXT;
   1206       1.9    veego 	unsigned short clkdiv;
   1207       1.5   chopps 	int     uplim, lowlim;
   1208      1.11    veego 	int	sr15;
   1209       1.1   chopps 
   1210       1.1   chopps 	/* identity */
   1211       1.1   chopps 	gv = &md->gv;
   1212       1.1   chopps 	TEXT = (gv->depth == 4);
   1213       1.1   chopps 
   1214       1.1   chopps 	if (!cl_mondefok(gv)) {
   1215       1.1   chopps 		printf("mondef not ok\n");
   1216       1.5   chopps 		return (0);
   1217       1.1   chopps 	}
   1218       1.1   chopps 	ba = gp->g_regkva;
   1219       1.1   chopps 	fb = gp->g_fbkva;
   1220       1.1   chopps 
   1221       1.5   chopps 	/* provide all needed information in grf device-independant locations */
   1222       1.5   chopps 	gp->g_data = (caddr_t) gv;
   1223       1.1   chopps 	gi = &gp->g_display;
   1224       1.5   chopps 	gi->gd_regaddr = (caddr_t) ztwopa(ba);
   1225       1.5   chopps 	gi->gd_regsize = 64 * 1024;
   1226       1.5   chopps 	gi->gd_fbaddr = (caddr_t) kvtop(fb);
   1227       1.5   chopps 	gi->gd_fbsize = cl_fbsize;
   1228       1.5   chopps 	gi->gd_colors = 1 << gv->depth;
   1229       1.5   chopps 	gi->gd_planes = gv->depth;
   1230       1.5   chopps 	gi->gd_fbwidth = gv->disp_width;
   1231       1.5   chopps 	gi->gd_fbheight = gv->disp_height;
   1232       1.5   chopps 	gi->gd_fbx = 0;
   1233       1.5   chopps 	gi->gd_fby = 0;
   1234       1.1   chopps 	if (TEXT) {
   1235       1.5   chopps 		gi->gd_dwidth = md->fx * md->cols;
   1236       1.5   chopps 		gi->gd_dheight = md->fy * md->rows;
   1237       1.1   chopps 	} else {
   1238       1.5   chopps 		gi->gd_dwidth = gv->disp_width;
   1239       1.5   chopps 		gi->gd_dheight = gv->disp_height;
   1240       1.1   chopps 	}
   1241       1.5   chopps 	gi->gd_dx = 0;
   1242       1.5   chopps 	gi->gd_dy = 0;
   1243       1.1   chopps 
   1244       1.1   chopps 	/* get display mode parameters */
   1245       1.1   chopps 
   1246       1.1   chopps 	HBS = gv->hblank_start;
   1247       1.1   chopps 	HBE = gv->hblank_stop;
   1248       1.1   chopps 	HSS = gv->hsync_start;
   1249       1.1   chopps 	HSE = gv->hsync_stop;
   1250       1.5   chopps 	HT = gv->htotal;
   1251       1.1   chopps 	VBS = gv->vblank_start;
   1252       1.1   chopps 	VSS = gv->vsync_start;
   1253       1.1   chopps 	VSE = gv->vsync_stop;
   1254       1.1   chopps 	VBE = gv->vblank_stop;
   1255       1.5   chopps 	VT = gv->vtotal;
   1256       1.1   chopps 
   1257       1.5   chopps 	if (TEXT)
   1258       1.5   chopps 		HDE = ((gv->disp_width + md->fx - 1) / md->fx) - 1;
   1259       1.1   chopps 	else
   1260       1.5   chopps 		HDE = (gv->disp_width + 3) / 8 - 1;	/* HBS; */
   1261       1.5   chopps 	VDE = gv->disp_height - 1;
   1262       1.1   chopps 
   1263       1.1   chopps 	/* figure out whether lace or dblscan is needed */
   1264       1.1   chopps 
   1265       1.1   chopps 	uplim = gv->disp_height + (gv->disp_height / 4);
   1266       1.5   chopps 	lowlim = gv->disp_height - (gv->disp_height / 4);
   1267       1.5   chopps 	LACE = (((VT * 2) > lowlim) && ((VT * 2) < uplim)) ? 1 : 0;
   1268       1.5   chopps 	DBLSCAN = (((VT / 2) > lowlim) && ((VT / 2) < uplim)) ? 1 : 0;
   1269       1.1   chopps 
   1270       1.1   chopps 	/* adjustments */
   1271       1.1   chopps 
   1272       1.1   chopps 	if (LACE)
   1273       1.1   chopps 		VDE /= 2;
   1274       1.1   chopps 
   1275       1.1   chopps 	WSeq(ba, SEQ_ID_MEMORY_MODE, (TEXT || (gv->depth == 1)) ? 0x06 : 0x0e);
   1276      1.11    veego 	if (cl_sd64 == 1) {
   1277      1.11    veego 	    if (TEXT || (gv->depth == 1))
   1278      1.11    veego 		sr15 = 0x90;
   1279      1.11    veego 	    else
   1280      1.11    veego 		sr15 = ((cl_fbsize / 0x100000 == 2) ? 0x38 : 0xb8);
   1281      1.11    veego 	    WSeq(ba, SEQ_ID_CONF_RBACK, 0x00);
   1282      1.11    veego 	} else {
   1283      1.11    veego 		sr15 = (TEXT || (gv->depth == 1)) ? 0x90 : 0xb0;
   1284      1.11    veego 	}
   1285      1.11    veego 	WSeq(ba, SEQ_ID_DRAM_CNTL, sr15);
   1286       1.5   chopps 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
   1287       1.1   chopps 	WSeq(ba, SEQ_ID_MAP_MASK, (gv->depth == 1) ? 0x01 : 0xff);
   1288       1.5   chopps 	WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
   1289       1.1   chopps 
   1290       1.1   chopps 	/* Set clock */
   1291       1.1   chopps 
   1292      1.11    veego 	cl_CompFQ((gv->depth == 24) ? gv->pixel_clock * 3 : gv->pixel_clock,
   1293       1.1   chopps 	    &num0, &denom0);
   1294      1.11    veego 	WSeq(ba, SEQ_ID_VCLK_3_NUM, num0);
   1295      1.11    veego 	WSeq(ba, SEQ_ID_VCLK_3_DENOM, denom0);
   1296       1.1   chopps 
   1297       1.1   chopps 	/* load display parameters into board */
   1298       1.1   chopps 
   1299       1.1   chopps 	WCrt(ba, CRT_ID_HOR_TOTAL, HT);
   1300       1.5   chopps 	WCrt(ba, CRT_ID_HOR_DISP_ENA_END, ((HDE >= HBS) ? HBS - 1 : HDE));
   1301       1.1   chopps 	WCrt(ba, CRT_ID_START_HOR_BLANK, HBS);
   1302       1.5   chopps 	WCrt(ba, CRT_ID_END_HOR_BLANK, (HBE & 0x1f) | 0x80);	/* | 0x80? */
   1303       1.1   chopps 	WCrt(ba, CRT_ID_START_HOR_RETR, HSS);
   1304       1.1   chopps 	WCrt(ba, CRT_ID_END_HOR_RETR,
   1305       1.5   chopps 	    (HSE & 0x1f) |
   1306       1.5   chopps 	    ((HBE & 0x20) ? 0x80 : 0x00));
   1307       1.1   chopps 	WCrt(ba, CRT_ID_VER_TOTAL, VT);
   1308       1.1   chopps 	WCrt(ba, CRT_ID_OVERFLOW,
   1309       1.1   chopps 	    0x10 |
   1310       1.5   chopps 	    ((VT & 0x100) ? 0x01 : 0x00) |
   1311       1.1   chopps 	    ((VDE & 0x100) ? 0x02 : 0x00) |
   1312       1.1   chopps 	    ((VSS & 0x100) ? 0x04 : 0x00) |
   1313       1.1   chopps 	    ((VBS & 0x100) ? 0x08 : 0x00) |
   1314       1.5   chopps 	    ((VT & 0x200) ? 0x20 : 0x00) |
   1315       1.1   chopps 	    ((VDE & 0x200) ? 0x40 : 0x00) |
   1316       1.5   chopps 	    ((VSS & 0x200) ? 0x80 : 0x00));
   1317       1.1   chopps 
   1318       1.1   chopps 
   1319       1.1   chopps 	WCrt(ba, CRT_ID_CHAR_HEIGHT,
   1320       1.5   chopps 	    0x40 |		/* TEXT ? 0x00 ??? */
   1321       1.1   chopps 	    (DBLSCAN ? 0x80 : 0x00) |
   1322       1.1   chopps 	    ((VBS & 0x200) ? 0x20 : 0x00) |
   1323       1.5   chopps 	    (TEXT ? ((md->fy - 1) & 0x1f) : 0x00));
   1324  1.11.4.1       is 	WCrt(ba, CRT_ID_MODE_CONTROL, 0xe3);
   1325       1.1   chopps 
   1326       1.1   chopps 	/* text cursor */
   1327       1.1   chopps 
   1328       1.1   chopps 	if (TEXT) {
   1329       1.5   chopps #if CL_ULCURSOR
   1330       1.1   chopps 		WCrt(ba, CRT_ID_CURSOR_START, (md->fy & 0x1f) - 2);
   1331       1.1   chopps 		WCrt(ba, CRT_ID_CURSOR_END, (md->fy & 0x1f) - 1);
   1332       1.1   chopps #else
   1333       1.1   chopps 		WCrt(ba, CRT_ID_CURSOR_START, 0x00);
   1334       1.1   chopps 		WCrt(ba, CRT_ID_CURSOR_END, md->fy & 0x1f);
   1335       1.1   chopps #endif
   1336       1.9    veego 		WCrt(ba, CRT_ID_UNDERLINE_LOC, (md->fy - 1) & 0x1f);
   1337       1.1   chopps 
   1338       1.1   chopps 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
   1339       1.5   chopps 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
   1340       1.1   chopps 	}
   1341       1.1   chopps 	WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
   1342       1.1   chopps 	WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
   1343       1.1   chopps 
   1344       1.1   chopps 	WCrt(ba, CRT_ID_START_VER_RETR, VSS);
   1345  1.11.4.1       is 	WCrt(ba, CRT_ID_END_VER_RETR, (VSE & 0x0f) | 0x20);
   1346       1.1   chopps 	WCrt(ba, CRT_ID_VER_DISP_ENA_END, VDE);
   1347       1.1   chopps 	WCrt(ba, CRT_ID_START_VER_BLANK, VBS);
   1348       1.1   chopps 	WCrt(ba, CRT_ID_END_VER_BLANK, VBE);
   1349       1.1   chopps 
   1350       1.1   chopps 	WCrt(ba, CRT_ID_LINE_COMPARE, 0xff);
   1351       1.5   chopps 	WCrt(ba, CRT_ID_LACE_END, HT / 2);	/* MW/16 */
   1352       1.1   chopps 	WCrt(ba, CRT_ID_LACE_CNTL,
   1353       1.1   chopps 	    (LACE ? 0x01 : 0x00) |
   1354       1.1   chopps 	    ((HBE & 0x40) ? 0x10 : 0x00) |
   1355       1.1   chopps 	    ((HBE & 0x80) ? 0x20 : 0x00) |
   1356       1.1   chopps 	    ((VBE & 0x100) ? 0x40 : 0x00) |
   1357       1.5   chopps 	    ((VBE & 0x200) ? 0x80 : 0x00));
   1358       1.1   chopps 
   1359       1.1   chopps 	/* depth dependent stuff */
   1360       1.1   chopps 
   1361       1.1   chopps 	switch (gv->depth) {
   1362      1.11    veego 	    case 1:
   1363      1.11    veego 	    case 4:
   1364      1.11    veego 	    case 8:
   1365       1.5   chopps 		clkdiv = 0;
   1366       1.5   chopps 		break;
   1367      1.11    veego 	    case 15:
   1368      1.11    veego 	    case 16:
   1369       1.5   chopps 		clkdiv = 3;
   1370       1.5   chopps 		break;
   1371      1.11    veego 	    case 24:
   1372       1.5   chopps 		clkdiv = 2;
   1373       1.9    veego 		break;
   1374      1.11    veego 	    default:
   1375       1.9    veego 		clkdiv = 0;
   1376       1.9    veego 		panic("grfcl: Unsuported depth: %i", gv->depth);
   1377       1.5   chopps 		break;
   1378       1.1   chopps 	}
   1379       1.5   chopps 
   1380       1.5   chopps 	WGfx(ba, GCT_ID_GRAPHICS_MODE,
   1381       1.1   chopps 	    ((TEXT || (gv->depth == 1)) ? 0x00 : 0x40));
   1382       1.1   chopps 	WGfx(ba, GCT_ID_MISC, (TEXT ? 0x04 : 0x01));
   1383       1.1   chopps 
   1384       1.5   chopps 	WSeq(ba, SEQ_ID_EXT_SEQ_MODE,
   1385       1.5   chopps 	    ((TEXT || (gv->depth == 1)) ? 0x00 : 0x01) |
   1386       1.5   chopps 	    ((cltype == PICASSO) ? 0x20 : 0x80) |
   1387       1.5   chopps 	    (clkdiv << 1));
   1388       1.1   chopps 
   1389       1.5   chopps 	delay(200000);
   1390       1.6       is 
   1391       1.6       is 	/* write 0x00 to VDAC_MASK before accessing HDR this helps
   1392       1.6       is 	   sometimes, out of "secret" application note (crest) */
   1393       1.6       is 	vgaw(ba, VDAC_MASK, 0);
   1394       1.6       is 	delay(200000);
   1395       1.6       is 	/* reset HDR "magic" access counter (crest) */
   1396       1.6       is 	vgar(ba, VDAC_ADDRESS);
   1397       1.6       is 
   1398       1.1   chopps 	delay(200000);
   1399       1.1   chopps 	vgar(ba, VDAC_MASK);
   1400       1.1   chopps 	delay(200000);
   1401       1.1   chopps 	vgar(ba, VDAC_MASK);
   1402       1.1   chopps 	delay(200000);
   1403       1.1   chopps 	vgar(ba, VDAC_MASK);
   1404       1.1   chopps 	delay(200000);
   1405       1.1   chopps 	vgar(ba, VDAC_MASK);
   1406       1.1   chopps 	delay(200000);
   1407       1.1   chopps 	switch (gv->depth) {
   1408      1.11    veego 	    case 1:
   1409      1.11    veego 	    case 4:		/* text */
   1410       1.1   chopps 		vgaw(ba, VDAC_MASK, 0);
   1411       1.1   chopps 		HDE = gv->disp_width / 16;
   1412       1.1   chopps 		break;
   1413      1.11    veego 	    case 8:
   1414       1.1   chopps 		vgaw(ba, VDAC_MASK, 0);
   1415       1.1   chopps 		HDE = gv->disp_width / 8;
   1416       1.1   chopps 		break;
   1417      1.11    veego 	    case 15:
   1418       1.1   chopps 		vgaw(ba, VDAC_MASK, 0xd0);
   1419       1.1   chopps 		HDE = gv->disp_width / 4;
   1420       1.1   chopps 		break;
   1421      1.11    veego 	    case 16:
   1422       1.5   chopps 		vgaw(ba, VDAC_MASK, 0xc1);
   1423       1.1   chopps 		HDE = gv->disp_width / 4;
   1424       1.1   chopps 		break;
   1425      1.11    veego 	    case 24:
   1426       1.5   chopps 		vgaw(ba, VDAC_MASK, 0xc5);
   1427       1.1   chopps 		HDE = (gv->disp_width / 8) * 3;
   1428       1.1   chopps 		break;
   1429       1.1   chopps 	}
   1430       1.6       is 	delay(20000);
   1431       1.6       is 
   1432       1.6       is 	/* reset HDR "magic" access counter (crest) */
   1433       1.6       is 	vgar(ba, VDAC_ADDRESS);
   1434       1.1   chopps 	delay(200000);
   1435       1.6       is 	/* then enable all bit in VDAC_MASK afterwards (crest) */
   1436       1.6       is 	vgaw(ba, VDAC_MASK, 0xff);
   1437       1.6       is 	delay(20000);
   1438       1.1   chopps 
   1439       1.5   chopps 	WCrt(ba, CRT_ID_OFFSET, HDE);
   1440      1.11    veego 	if (cl_sd64 == 1) {
   1441      1.11    veego 		WCrt(ba, CRT_ID_SYNC_ADJ_GENLOCK, 0x00);
   1442      1.11    veego 		WCrt(ba, CRT_ID_OVERLAY_EXT_CTRL_REG, 0x40);
   1443      1.11    veego 	}
   1444       1.5   chopps 	WCrt(ba, CRT_ID_EXT_DISP_CNTL,
   1445       1.1   chopps 	    ((TEXT && gv->pixel_clock > 29000000) ? 0x40 : 0x00) |
   1446       1.5   chopps 	    0x22 |
   1447       1.5   chopps 	    ((HDE > 0xff) ? 0x10 : 0x00));	/* text? */
   1448       1.1   chopps 
   1449       1.1   chopps 	delay(200000);
   1450       1.1   chopps 	WAttr(ba, ACT_ID_ATTR_MODE_CNTL, (TEXT ? 0x0a : 0x01));
   1451       1.1   chopps 	delay(200000);
   1452       1.5   chopps 	WAttr(ba, 0x20 | ACT_ID_COLOR_PLANE_ENA,
   1453       1.1   chopps 	    (gv->depth == 1) ? 0x01 : 0x0f);
   1454       1.1   chopps 	delay(200000);
   1455       1.1   chopps 
   1456       1.1   chopps 	/* text initialization */
   1457       1.1   chopps 
   1458       1.1   chopps 	if (TEXT) {
   1459       1.1   chopps 		cl_inittextmode(gp);
   1460       1.1   chopps 	}
   1461       1.1   chopps 	WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x14);
   1462       1.1   chopps 	WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x01);
   1463       1.1   chopps 
   1464       1.1   chopps 	/* Pass-through */
   1465       1.1   chopps 
   1466       1.1   chopps 	RegOffpass(ba);
   1467       1.1   chopps 
   1468       1.5   chopps 	return (1);
   1469       1.1   chopps }
   1470       1.1   chopps 
   1471       1.1   chopps void
   1472       1.1   chopps cl_inittextmode(gp)
   1473       1.1   chopps 	struct grf_softc *gp;
   1474       1.1   chopps {
   1475       1.5   chopps 	struct grfcltext_mode *tm = (struct grfcltext_mode *) gp->g_data;
   1476       1.1   chopps 	volatile unsigned char *ba = gp->g_regkva;
   1477       1.1   chopps 	unsigned char *fb = gp->g_fbkva;
   1478       1.1   chopps 	unsigned char *c, *f, y;
   1479       1.1   chopps 	unsigned short z;
   1480       1.1   chopps 
   1481       1.1   chopps 
   1482       1.5   chopps 	/* load text font into beginning of display memory. Each character
   1483       1.5   chopps 	 * cell is 32 bytes long (enough for 4 planes) */
   1484       1.1   chopps 
   1485       1.1   chopps 	SetTextPlane(ba, 0x02);
   1486       1.5   chopps         cl_memset(fb, 0, 256 * 32);
   1487       1.5   chopps 	c = (unsigned char *) (fb) + (32 * tm->fdstart);
   1488       1.1   chopps 	f = tm->fdata;
   1489       1.5   chopps 	for (z = tm->fdstart; z <= tm->fdend; z++, c += (32 - tm->fy))
   1490       1.5   chopps 		for (y = 0; y < tm->fy; y++)
   1491       1.1   chopps 			*c++ = *f++;
   1492       1.1   chopps 
   1493       1.1   chopps 	/* clear out text/attr planes (three screens worth) */
   1494       1.1   chopps 
   1495       1.1   chopps 	SetTextPlane(ba, 0x01);
   1496       1.5   chopps 	cl_memset(fb, 0x07, tm->cols * tm->rows * 3);
   1497       1.1   chopps 	SetTextPlane(ba, 0x00);
   1498       1.5   chopps 	cl_memset(fb, 0x20, tm->cols * tm->rows * 3);
   1499       1.1   chopps 
   1500       1.1   chopps 	/* print out a little init msg */
   1501       1.1   chopps 
   1502       1.5   chopps 	c = (unsigned char *) (fb) + (tm->cols - 16);
   1503       1.1   chopps 	strcpy(c, "CIRRUS");
   1504       1.1   chopps 	c[6] = 0x20;
   1505       1.1   chopps 
   1506       1.1   chopps 	/* set colors (B&W) */
   1507       1.1   chopps 
   1508       1.1   chopps 
   1509       1.1   chopps 	vgaw(ba, VDAC_ADDRESS_W, 0);
   1510       1.5   chopps 	for (z = 0; z < 256; z++) {
   1511       1.1   chopps 		unsigned char r, g, b;
   1512       1.1   chopps 
   1513       1.1   chopps 		y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
   1514       1.1   chopps 
   1515       1.1   chopps 		if (cltype == PICASSO) {
   1516       1.1   chopps 			r = clconscolors[y][0];
   1517       1.1   chopps 			g = clconscolors[y][1];
   1518       1.1   chopps 			b = clconscolors[y][2];
   1519       1.1   chopps 		} else {
   1520       1.1   chopps 			b = clconscolors[y][0];
   1521       1.1   chopps 			g = clconscolors[y][1];
   1522       1.1   chopps 			r = clconscolors[y][2];
   1523       1.1   chopps 		}
   1524       1.1   chopps 		vgaw(ba, VDAC_DATA, r >> 2);
   1525       1.1   chopps 		vgaw(ba, VDAC_DATA, g >> 2);
   1526       1.1   chopps 		vgaw(ba, VDAC_DATA, b >> 2);
   1527       1.1   chopps 	}
   1528       1.1   chopps }
   1529       1.1   chopps 
   1530       1.1   chopps void
   1531       1.5   chopps cl_memset(d, c, l)
   1532       1.1   chopps 	unsigned char *d;
   1533       1.1   chopps 	unsigned char c;
   1534       1.5   chopps 	int     l;
   1535       1.1   chopps {
   1536       1.5   chopps 	for (; l > 0; l--)
   1537       1.1   chopps 		*d++ = c;
   1538       1.1   chopps }
   1539  1.11.4.1       is 
   1540  1.11.4.1       is /* Special wakeup/passthrough registers on graphics boards
   1541  1.11.4.1       is  *
   1542  1.11.4.1       is  * The methods have diverged a bit for each board, so
   1543  1.11.4.1       is  * WPass(P) has been converted into a set of specific
   1544  1.11.4.1       is  * inline functions.
   1545  1.11.4.1       is  */
   1546  1.11.4.1       is static void
   1547  1.11.4.1       is RegWakeup(ba)
   1548  1.11.4.1       is 	volatile caddr_t ba;
   1549  1.11.4.1       is {
   1550  1.11.4.1       is 
   1551  1.11.4.1       is 	switch (cltype) {
   1552  1.11.4.1       is 	    case SPECTRUM:
   1553  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_W, 0x1f);
   1554  1.11.4.1       is 		break;
   1555  1.11.4.1       is 	    case PICASSO:
   1556  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_W, 0xff);
   1557  1.11.4.1       is 		break;
   1558  1.11.4.1       is 	    case PICCOLO:
   1559  1.11.4.1       is 		if (cl_sd64 == 1)
   1560  1.11.4.1       is 			vgaw(ba, PASS_ADDRESS_W, 0x1f);
   1561  1.11.4.1       is 		else
   1562  1.11.4.1       is 			vgaw(ba, PASS_ADDRESS_W, vgar(ba, PASS_ADDRESS) | 0x10);
   1563  1.11.4.1       is 		break;
   1564  1.11.4.1       is 	}
   1565  1.11.4.1       is 	delay(200000);
   1566  1.11.4.1       is }
   1567  1.11.4.1       is 
   1568  1.11.4.1       is static void
   1569  1.11.4.1       is RegOnpass(ba)
   1570  1.11.4.1       is 	volatile caddr_t ba;
   1571  1.11.4.1       is {
   1572  1.11.4.1       is 
   1573  1.11.4.1       is 	switch (cltype) {
   1574  1.11.4.1       is 	    case SPECTRUM:
   1575  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_W, 0x4f);
   1576  1.11.4.1       is 		break;
   1577  1.11.4.1       is 	    case PICASSO:
   1578  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_WP, 0x01);
   1579  1.11.4.1       is 		break;
   1580  1.11.4.1       is 	    case PICCOLO:
   1581  1.11.4.1       is 		if (cl_sd64 == 1)
   1582  1.11.4.1       is 			vgaw(ba, PASS_ADDRESS_W, 0x4f);
   1583  1.11.4.1       is 		else
   1584  1.11.4.1       is 			vgaw(ba, PASS_ADDRESS_W, vgar(ba, PASS_ADDRESS) & 0xdf);
   1585  1.11.4.1       is 		break;
   1586  1.11.4.1       is 	}
   1587  1.11.4.1       is 	pass_toggle = 1;
   1588  1.11.4.1       is 	delay(200000);
   1589  1.11.4.1       is }
   1590  1.11.4.1       is 
   1591  1.11.4.1       is static void
   1592  1.11.4.1       is RegOffpass(ba)
   1593  1.11.4.1       is 	volatile caddr_t ba;
   1594  1.11.4.1       is {
   1595  1.11.4.1       is 
   1596  1.11.4.1       is 	switch (cltype) {
   1597  1.11.4.1       is 	    case SPECTRUM:
   1598  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_W, 0x6f);
   1599  1.11.4.1       is 		break;
   1600  1.11.4.1       is 	    case PICASSO:
   1601  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_W, 0xff);
   1602  1.11.4.1       is 		delay(200000);
   1603  1.11.4.1       is 		vgaw(ba, PASS_ADDRESS_W, 0xff);
   1604  1.11.4.1       is 		break;
   1605  1.11.4.1       is 	    case PICCOLO:
   1606  1.11.4.1       is 		if (cl_sd64 == 1)
   1607  1.11.4.1       is 			vgaw(ba, PASS_ADDRESS_W, 0x6f);
   1608  1.11.4.1       is 		else
   1609  1.11.4.1       is 			vgaw(ba, PASS_ADDRESS_W, vgar(ba, PASS_ADDRESS) | 0x20);
   1610  1.11.4.1       is 		break;
   1611  1.11.4.1       is 	}
   1612  1.11.4.1       is 	pass_toggle = 0;
   1613  1.11.4.1       is 	delay(200000);
   1614  1.11.4.1       is }
   1615  1.11.4.1       is 
   1616       1.5   chopps #endif /* NGRFCL */
   1617