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