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