Home | History | Annotate | Line # | Download | only in dev
grf_rh.c revision 1.5
      1  1.5  chopps /*	$NetBSD: grf_rh.c,v 1.5 1994/12/28 09:25:09 chopps Exp $	*/
      2  1.1  chopps 
      3  1.2  chopps #include "grfrh.h"
      4  1.2  chopps #if NGRFRH > 0
      5  1.1  chopps 
      6  1.1  chopps /*
      7  1.1  chopps  * Graphics routines for the Retina BLT Z3 board,
      8  1.1  chopps  * using the NCR 77C32BLT VGA controller.
      9  1.1  chopps */
     10  1.1  chopps 
     11  1.1  chopps #include <sys/param.h>
     12  1.1  chopps #include <sys/errno.h>
     13  1.1  chopps #include <sys/ioctl.h>
     14  1.1  chopps #include <sys/device.h>
     15  1.1  chopps #include <sys/malloc.h>
     16  1.1  chopps #include <machine/cpu.h>
     17  1.1  chopps #include <amiga/amiga/device.h>
     18  1.1  chopps #include <amiga/dev/grfioctl.h>
     19  1.1  chopps #include <amiga/dev/grfvar.h>
     20  1.1  chopps #include <amiga/dev/grf_rhreg.h>
     21  1.5  chopps #include <amiga/dev/zbusvar.h>
     22  1.1  chopps 
     23  1.1  chopps int rh_mondefok __P((struct MonDef *));
     24  1.1  chopps 
     25  1.1  chopps u_short CompFQ __P((u_int fq));
     26  1.1  chopps int rh_load_mon __P((struct grf_softc *gp, struct MonDef *md));
     27  1.1  chopps int rh_getvmode __P((struct grf_softc *gp, struct grfvideo_mode *vm));
     28  1.1  chopps int rh_setvmode __P((struct grf_softc *gp, unsigned int mode, int txtonly));
     29  1.1  chopps 
     30  1.1  chopps 
     31  1.1  chopps extern unsigned char kernel_font_8x8_width, kernel_font_8x8_height;
     32  1.1  chopps extern unsigned char kernel_font_8x8_lo, kernel_font_8x8_hi;
     33  1.1  chopps extern unsigned char kernel_font_8x8[];
     34  1.2  chopps #ifdef KFONT_8X11
     35  1.2  chopps extern unsigned char kernel_font_8x11_width, kernel_font_8x11_height;
     36  1.2  chopps extern unsigned char kernel_font_8x11_lo, kernel_font_8x11_hi;
     37  1.2  chopps extern unsigned char kernel_font_8x11[];
     38  1.2  chopps #endif
     39  1.1  chopps 
     40  1.1  chopps 
     41  1.1  chopps /*
     42  1.1  chopps  * NOTE: this driver for the MacroSystem Retina board was only possible,
     43  1.1  chopps  *       because MacroSystem provided information about the pecularities
     44  1.1  chopps  *       of the board. THANKS! Competition in Europe among gfx board
     45  1.1  chopps  *       manufacturers is rather tough, so Lutz Vieweg, who wrote the
     46  1.1  chopps  *       initial driver, has made an agreement with MS not to document
     47  1.1  chopps  *       the driver source (see also his Copyright disclaimer below).
     48  1.1  chopps  *       -> ALL comments after
     49  1.1  chopps  *       -> "/* -------------- START OF CODE -------------- * /"
     50  1.1  chopps  *       -> have been added by myself (mw) from studying the publically
     51  1.1  chopps  *       -> available "NCR 77C32BLT" Data Manual
     52  1.1  chopps  *
     53  1.1  chopps  *       Lutz' original driver source (without any of my comments) is
     54  1.1  chopps  *       available on request.
     55  1.1  chopps  */
     56  1.1  chopps 
     57  1.1  chopps /* This code offers low-level routines to access the Retina BLT Z3
     58  1.1  chopps  * graphics-board manufactured by MS MacroSystem GmbH from within NetBSD
     59  1.1  chopps  * for the Amiga.  * No warranties for any kind of function at all - this
     60  1.1  chopps  * code may crash your hardware and scratch your harddisk.  Use at your
     61  1.1  chopps  * own risk.  Freely distributable.
     62  1.1  chopps  *
     63  1.1  chopps  * Written by Lutz Vieweg 02/94
     64  1.1  chopps  *
     65  1.1  chopps  * Thanks to MacroSystem for providing me with the neccessary information
     66  1.1  chopps  * to create theese routines. The sparse documentation of this code
     67  1.1  chopps  * results from the agreements between MS and me.
     68  1.1  chopps  */
     69  1.1  chopps 
     70  1.1  chopps 
     71  1.1  chopps 
     72  1.1  chopps #define MDF_DBL 1
     73  1.1  chopps #define MDF_LACE 2
     74  1.1  chopps #define MDF_CLKDIV2 4
     75  1.1  chopps 
     76  1.1  chopps 
     77  1.1  chopps /* -------------- START OF CODE -------------- */
     78  1.1  chopps 
     79  1.1  chopps /* Convert big-endian long into little-endian long. */
     80  1.1  chopps 
     81  1.1  chopps #define M2I(val)                                                     \
     82  1.1  chopps 	asm volatile (" rorw #8,%0   ;                               \
     83  1.1  chopps 	                swap %0      ;                               \
     84  1.1  chopps 	                rorw #8,%0   ; " : "=d" (val) : "0" (val));
     85  1.1  chopps 
     86  1.1  chopps #define M2INS(val)                                                   \
     87  1.1  chopps 	asm volatile (" rorw #8,%0   ;                               \
     88  1.1  chopps 	                swap %0      ;                               \
     89  1.1  chopps 	                rorw #8,%0   ;                               \
     90  1.1  chopps  			swap %0	     ; " : "=d" (val) : "0" (val));
     91  1.1  chopps 
     92  1.1  chopps #define ACM_OFFSET	(0x00b00000)
     93  1.1  chopps #define LM_OFFSET	(0x00c00000)
     94  1.1  chopps 
     95  1.1  chopps static unsigned char optab[] = {
     96  1.1  chopps 	0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
     97  1.1  chopps 	0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0
     98  1.1  chopps };
     99  1.1  chopps static char optabs[] = {
    100  1.1  chopps 	   0,   -1,   -1,   -1,   -1,    0,   -1,   -1,
    101  1.1  chopps 	  -1,   -1,    0,   -1,   -1,   -1,   -1,    0
    102  1.1  chopps };
    103  1.1  chopps 
    104  1.1  chopps void
    105  1.1  chopps RZ3DisableHWC(gp)
    106  1.1  chopps 	struct grf_softc *gp;
    107  1.1  chopps {
    108  1.1  chopps 	volatile void *ba = gp->g_regkva;
    109  1.1  chopps 
    110  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_Y_INDEX, 0x00);
    111  1.1  chopps }
    112  1.1  chopps 
    113  1.1  chopps void
    114  1.1  chopps RZ3SetupHWC(gp, col1, col2, hsx, hsy, data)
    115  1.1  chopps 	struct grf_softc *gp;
    116  1.1  chopps 	unsigned char col1;
    117  1.1  chopps 	unsigned col2;
    118  1.1  chopps 	unsigned char hsx;
    119  1.1  chopps 	unsigned char hsy;
    120  1.1  chopps 	const unsigned long *data;
    121  1.1  chopps {
    122  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    123  1.1  chopps 	unsigned long *c = (unsigned long *)(ba + LM_OFFSET + HWC_MEM_OFF);
    124  1.1  chopps 	const unsigned long *s = data;
    125  1.1  chopps 	struct MonDef *MonitorDef = (struct MonDef *) gp->g_data;
    126  1.1  chopps 	short x = (HWC_MEM_SIZE / (4*4)) - 1;
    127  1.1  chopps 	/* copy only, if there is a data pointer. */
    128  1.1  chopps 	if (data) do {
    129  1.1  chopps 		*c++ = *s++;
    130  1.1  chopps 		*c++ = *s++;
    131  1.1  chopps 		*c++ = *s++;
    132  1.1  chopps 		*c++ = *s++;
    133  1.1  chopps 	} while (x-- > 0);
    134  1.1  chopps 
    135  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_COLOR1, col1);
    136  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_COLOR0, col2);
    137  1.1  chopps 	if (MonitorDef->DEP < 16)
    138  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_CONTROL, 0x85);
    139  1.1  chopps 	else
    140  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_CONTROL, 0xa5);
    141  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_X_LOC_HI, 0x00);
    142  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_X_LOC_LO, 0x00);
    143  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_Y_LOC_HI, 0x00);
    144  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_Y_LOC_LO, 0x00);
    145  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_X_INDEX, hsx);
    146  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_Y_INDEX, hsy);
    147  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_STORE_HI, 0x00);
    148  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_STORE_LO,  ((HWC_MEM_OFF / 4) & 0x0000f));
    149  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_ST_OFF_HI, (((HWC_MEM_OFF / 4) & 0xff000) >> 12));
    150  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_ST_OFF_LO, (((HWC_MEM_OFF / 4) & 0x00ff0) >>  4));
    151  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_PIXELMASK, 0xff);
    152  1.1  chopps }
    153  1.1  chopps 
    154  1.1  chopps void
    155  1.1  chopps RZ3AlphaErase (gp, xd, yd, w, h)
    156  1.1  chopps 	struct grf_softc *gp;
    157  1.1  chopps 	unsigned short xd;
    158  1.1  chopps 	unsigned short yd;
    159  1.1  chopps 	unsigned short  w;
    160  1.1  chopps 	unsigned short  h;
    161  1.1  chopps {
    162  1.1  chopps 	const struct MonDef * md = (struct MonDef *) gp->g_data;
    163  1.1  chopps 	RZ3AlphaCopy(gp, xd, yd+md->TY, xd, yd, w, h);
    164  1.1  chopps }
    165  1.1  chopps 
    166  1.1  chopps void
    167  1.1  chopps RZ3AlphaCopy (gp, xs, ys, xd, yd, w, h)
    168  1.1  chopps 	struct grf_softc *gp;
    169  1.1  chopps 	unsigned short xs;
    170  1.1  chopps 	unsigned short ys;
    171  1.1  chopps 	unsigned short xd;
    172  1.1  chopps 	unsigned short yd;
    173  1.1  chopps 	unsigned short  w;
    174  1.1  chopps 	unsigned short  h;
    175  1.1  chopps {
    176  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    177  1.1  chopps 	const struct MonDef *md = (struct MonDef *) gp->g_data;
    178  1.1  chopps 	volatile unsigned long *acm = (unsigned long *) (ba + ACM_OFFSET);
    179  1.1  chopps 	unsigned short mod;
    180  1.1  chopps 
    181  1.1  chopps 	xs *= 4;
    182  1.1  chopps 	ys *= 4;
    183  1.1  chopps 	xd *= 4;
    184  1.1  chopps 	yd *= 4;
    185  1.1  chopps 	w  *= 4;
    186  1.1  chopps 
    187  1.1  chopps 	{
    188  1.1  chopps 		/* anyone got Windoze GDI opcodes handy?... */
    189  1.1  chopps 		unsigned long tmp = 0x0000ca00;
    190  1.1  chopps 		*(acm + ACM_RASTEROP_ROTATION/4) = tmp;
    191  1.1  chopps 	}
    192  1.1  chopps 
    193  1.1  chopps 	mod = 0xc0c2;
    194  1.1  chopps 
    195  1.1  chopps 	{
    196  1.1  chopps 		unsigned long pat = 8 * PAT_MEM_OFF;
    197  1.1  chopps 		unsigned long dst = 8 * (xd + yd * md->TX);
    198  1.1  chopps 
    199  1.1  chopps 		unsigned long src = 8 * (xs + ys * md->TX);
    200  1.1  chopps 
    201  1.1  chopps 		if (xd > xs) {
    202  1.1  chopps 			mod &= ~0x8000;
    203  1.1  chopps 			src += 8 * (w - 1);
    204  1.1  chopps 			dst += 8 * (w - 1);
    205  1.1  chopps 			pat += 8 * 2;
    206  1.1  chopps 		}
    207  1.1  chopps 		if (yd > ys) {
    208  1.1  chopps 			mod &= ~0x4000;
    209  1.1  chopps 			src += 8 * (h - 1) * md->TX * 4;
    210  1.1  chopps 			dst += 8 * (h - 1) * md->TX * 4;
    211  1.1  chopps 			pat += 8 * 4;
    212  1.1  chopps 		}
    213  1.1  chopps 
    214  1.1  chopps 		M2I(src);
    215  1.1  chopps 		*(acm + ACM_SOURCE/4) = src;
    216  1.1  chopps 
    217  1.1  chopps 		M2I(pat);
    218  1.1  chopps 		*(acm + ACM_PATTERN/4) = pat;
    219  1.1  chopps 
    220  1.1  chopps 		M2I(dst);
    221  1.1  chopps 		*(acm + ACM_DESTINATION/4) = dst;
    222  1.1  chopps 	}
    223  1.1  chopps 	{
    224  1.1  chopps 
    225  1.1  chopps 		unsigned long tmp = mod << 16;
    226  1.1  chopps 		*(acm + ACM_CONTROL/4) = tmp;
    227  1.1  chopps 	}
    228  1.1  chopps 	{
    229  1.1  chopps 
    230  1.1  chopps 		unsigned long tmp  = w | (h << 16);
    231  1.1  chopps 		M2I(tmp);
    232  1.1  chopps 		*(acm + ACM_BITMAP_DIMENSION/4) = tmp;
    233  1.1  chopps 	}
    234  1.1  chopps 
    235  1.1  chopps 	*(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x00;
    236  1.1  chopps 	*(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x01;
    237  1.1  chopps 
    238  1.1  chopps 	while ((*(((volatile unsigned char *)acm) +
    239  1.1  chopps 	    (ACM_START_STATUS + 2)) & 1) == 0);
    240  1.1  chopps }
    241  1.1  chopps 
    242  1.1  chopps void
    243  1.1  chopps RZ3BitBlit (gp, gbb)
    244  1.1  chopps 	struct grf_softc *gp;
    245  1.1  chopps 	struct grf_bitblt * gbb;
    246  1.1  chopps {
    247  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    248  1.1  chopps 	volatile unsigned char *lm = ba + LM_OFFSET;
    249  1.1  chopps 	volatile unsigned long *acm = (unsigned long *) (ba + ACM_OFFSET);
    250  1.1  chopps 	const struct MonDef *md = (struct MonDef *) gp->g_data;
    251  1.1  chopps 	unsigned short mod;
    252  1.1  chopps 
    253  1.1  chopps 	{
    254  1.1  chopps 		unsigned long * pt = (unsigned long *) (lm + PAT_MEM_OFF);
    255  1.1  chopps 		unsigned long tmp  = gbb->mask | ((unsigned long)gbb->mask << 16);
    256  1.1  chopps 		*pt++ = tmp;
    257  1.1  chopps 		*pt   = tmp;
    258  1.1  chopps 	}
    259  1.1  chopps 
    260  1.1  chopps 	{
    261  1.1  chopps 
    262  1.1  chopps 		unsigned long tmp = optab[ gbb->op ] << 8;
    263  1.1  chopps 		*(acm + ACM_RASTEROP_ROTATION/4) = tmp;
    264  1.1  chopps 	}
    265  1.1  chopps 
    266  1.1  chopps 	mod = 0xc0c2;
    267  1.1  chopps 
    268  1.1  chopps 	{
    269  1.1  chopps 		unsigned long pat = 8 * PAT_MEM_OFF;
    270  1.1  chopps 		unsigned long dst = 8 * (gbb->dst_x + gbb->dst_y * md->TX);
    271  1.1  chopps 
    272  1.1  chopps 		if (optabs[gbb->op]) {
    273  1.1  chopps 			unsigned long src = 8 * (gbb->src_x + gbb->src_y * md->TX);
    274  1.1  chopps 
    275  1.1  chopps 			if (gbb->dst_x > gbb->src_x) {
    276  1.1  chopps 				mod &= ~0x8000;
    277  1.1  chopps 				src += 8 * (gbb->w - 1);
    278  1.1  chopps 				dst += 8 * (gbb->w - 1);
    279  1.1  chopps 				pat += 8 * 2;
    280  1.1  chopps 			}
    281  1.1  chopps 			if (gbb->dst_y > gbb->src_y) {
    282  1.1  chopps 				mod &= ~0x4000;
    283  1.1  chopps 				src += 8 * (gbb->h - 1) * md->TX;
    284  1.1  chopps 				dst += 8 * (gbb->h - 1) * md->TX;
    285  1.1  chopps 				pat += 8 * 4;
    286  1.1  chopps 			}
    287  1.1  chopps 
    288  1.1  chopps 			M2I(src);
    289  1.1  chopps 			*(acm + ACM_SOURCE/4) = src;
    290  1.1  chopps 		}
    291  1.1  chopps 
    292  1.1  chopps 		M2I(pat);
    293  1.1  chopps 		*(acm + ACM_PATTERN/4) = pat;
    294  1.1  chopps 
    295  1.1  chopps 		M2I(dst);
    296  1.1  chopps 		*(acm + ACM_DESTINATION/4) = dst;
    297  1.1  chopps 	}
    298  1.1  chopps 	{
    299  1.1  chopps 
    300  1.1  chopps 		unsigned long tmp = mod << 16;
    301  1.1  chopps 		*(acm + ACM_CONTROL/4) = tmp;
    302  1.1  chopps 	}
    303  1.1  chopps 	{
    304  1.1  chopps 		unsigned long tmp  = gbb->w | (gbb->h << 16);
    305  1.1  chopps 		M2I(tmp);
    306  1.1  chopps 		*(acm + ACM_BITMAP_DIMENSION/4) = tmp;
    307  1.1  chopps 	}
    308  1.1  chopps 
    309  1.1  chopps 	*(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x00;
    310  1.1  chopps 	*(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x01;
    311  1.1  chopps 
    312  1.1  chopps 	while ((*(((volatile unsigned char *)acm) +
    313  1.1  chopps 	    (ACM_START_STATUS + 2)) & 1) == 0);
    314  1.1  chopps }
    315  1.1  chopps 
    316  1.1  chopps void
    317  1.1  chopps RZ3BitBlit16 (gp, gbb)
    318  1.1  chopps 	struct grf_softc *gp;
    319  1.1  chopps 	struct grf_bitblt * gbb;
    320  1.1  chopps {
    321  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    322  1.1  chopps 	volatile unsigned char *lm = ba + LM_OFFSET;
    323  1.1  chopps 	volatile unsigned long * acm = (unsigned long *) (ba + ACM_OFFSET);
    324  1.1  chopps 	const struct MonDef * md = (struct MonDef *) gp->g_data;
    325  1.1  chopps 	unsigned short mod;
    326  1.1  chopps 
    327  1.1  chopps 	{
    328  1.1  chopps 		unsigned long * pt = (unsigned long *) (lm + PAT_MEM_OFF);
    329  1.1  chopps 		unsigned long tmp  = gbb->mask | ((unsigned long)gbb->mask << 16);
    330  1.1  chopps 		*pt++ = tmp;
    331  1.1  chopps 		*pt++ = tmp;
    332  1.1  chopps 		*pt++ = tmp;
    333  1.1  chopps 		*pt   = tmp;
    334  1.1  chopps 	}
    335  1.1  chopps 
    336  1.1  chopps 	{
    337  1.1  chopps 
    338  1.1  chopps 		unsigned long tmp = optab[ gbb->op ] << 8;
    339  1.1  chopps 		*(acm + ACM_RASTEROP_ROTATION/4) = tmp;
    340  1.1  chopps 	}
    341  1.1  chopps 
    342  1.1  chopps 	mod = 0xc0c2;
    343  1.1  chopps 
    344  1.1  chopps 	{
    345  1.1  chopps 		unsigned long pat = 8 * PAT_MEM_OFF;
    346  1.1  chopps 		unsigned long dst = 8 * 2 * (gbb->dst_x + gbb->dst_y * md->TX);
    347  1.1  chopps 
    348  1.1  chopps 		if (optabs[gbb->op]) {
    349  1.1  chopps 			unsigned long src = 8 * 2 * (gbb->src_x + gbb->src_y * md->TX);
    350  1.1  chopps 
    351  1.1  chopps 			if (gbb->dst_x > gbb->src_x) {
    352  1.1  chopps 				mod &= ~0x8000;
    353  1.1  chopps 				src += 8 * 2 * (gbb->w);
    354  1.1  chopps 				dst += 8 * 2 * (gbb->w);
    355  1.1  chopps 				pat += 8 * 2 * 2;
    356  1.1  chopps 			}
    357  1.1  chopps 			if (gbb->dst_y > gbb->src_y) {
    358  1.1  chopps 				mod &= ~0x4000;
    359  1.1  chopps 				src += 8 * 2 * (gbb->h - 1) * md->TX;
    360  1.1  chopps 				dst += 8 * 2 * (gbb->h - 1) * md->TX;
    361  1.1  chopps 				pat += 8 * 4 * 2;
    362  1.1  chopps 			}
    363  1.1  chopps 
    364  1.1  chopps 			M2I(src);
    365  1.1  chopps 			*(acm + ACM_SOURCE/4) = src;
    366  1.1  chopps 		}
    367  1.1  chopps 
    368  1.1  chopps 		M2I(pat);
    369  1.1  chopps 		*(acm + ACM_PATTERN/4) = pat;
    370  1.1  chopps 
    371  1.1  chopps 		M2I(dst);
    372  1.1  chopps 		*(acm + ACM_DESTINATION/4) = dst;
    373  1.1  chopps 	}
    374  1.1  chopps 	{
    375  1.1  chopps 
    376  1.1  chopps 		unsigned long tmp = mod << 16;
    377  1.1  chopps 		*(acm + ACM_CONTROL/4) = tmp;
    378  1.1  chopps 	}
    379  1.1  chopps 	{
    380  1.1  chopps 
    381  1.1  chopps 		unsigned long tmp  = gbb->w | (gbb->h << 16);
    382  1.1  chopps 		M2I(tmp);
    383  1.1  chopps 		*(acm + ACM_BITMAP_DIMENSION/4) = tmp;
    384  1.1  chopps 	}
    385  1.1  chopps 
    386  1.1  chopps 	*(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x00;
    387  1.1  chopps 	*(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x01;
    388  1.1  chopps 
    389  1.1  chopps 	while ((*(((volatile unsigned char *)acm) +
    390  1.1  chopps 	    (ACM_START_STATUS+ 2)) & 1) == 0);
    391  1.1  chopps }
    392  1.1  chopps 
    393  1.1  chopps void
    394  1.1  chopps RZ3SetCursorPos (gp, pos)
    395  1.1  chopps 	struct grf_softc *gp;
    396  1.1  chopps 	unsigned short pos;
    397  1.1  chopps {
    398  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    399  1.1  chopps 
    400  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_LOW, (unsigned char)pos);
    401  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (unsigned char)(pos >> 8));
    402  1.1  chopps 
    403  1.1  chopps }
    404  1.1  chopps 
    405  1.1  chopps void
    406  1.1  chopps RZ3LoadPalette (gp, pal, firstcol, colors)
    407  1.1  chopps 	struct grf_softc *gp;
    408  1.1  chopps 	unsigned char * pal;
    409  1.1  chopps 	unsigned char firstcol;
    410  1.1  chopps 	unsigned char colors;
    411  1.1  chopps {
    412  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    413  1.1  chopps 
    414  1.1  chopps 	if (colors == 0)
    415  1.1  chopps 		return;
    416  1.1  chopps 
    417  1.1  chopps 	vgaw(ba, VDAC_ADDRESS_W, firstcol);
    418  1.1  chopps 
    419  1.1  chopps 	{
    420  1.1  chopps 
    421  1.1  chopps 		short x = colors-1;
    422  1.1  chopps 		const unsigned char * col = pal;
    423  1.1  chopps 		do {
    424  1.1  chopps 
    425  1.1  chopps 			vgaw(ba, VDAC_DATA, (*col++ >> 2));
    426  1.1  chopps 			vgaw(ba, VDAC_DATA, (*col++ >> 2));
    427  1.1  chopps 			vgaw(ba, VDAC_DATA, (*col++ >> 2));
    428  1.1  chopps 
    429  1.1  chopps 		} while (x-- > 0);
    430  1.1  chopps 
    431  1.1  chopps 	}
    432  1.1  chopps }
    433  1.1  chopps 
    434  1.1  chopps void
    435  1.1  chopps RZ3SetPalette (gp, colornum, red, green, blue)
    436  1.1  chopps 	struct grf_softc *gp;
    437  1.1  chopps 	unsigned char colornum;
    438  1.1  chopps 	unsigned char red, green, blue;
    439  1.1  chopps {
    440  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    441  1.1  chopps 
    442  1.1  chopps 	vgaw(ba, VDAC_ADDRESS_W, colornum);
    443  1.1  chopps 
    444  1.1  chopps 	vgaw(ba, VDAC_DATA, (red >> 2));
    445  1.1  chopps 	vgaw(ba, VDAC_DATA, (green >> 2));
    446  1.1  chopps 	vgaw(ba, VDAC_DATA, (blue >> 2));
    447  1.1  chopps 
    448  1.1  chopps }
    449  1.1  chopps 
    450  1.1  chopps /* XXXXXXXXX !! */
    451  1.1  chopps static unsigned short xpan;
    452  1.1  chopps static unsigned short ypan;
    453  1.1  chopps 
    454  1.1  chopps void
    455  1.1  chopps RZ3SetPanning (gp, xoff, yoff)
    456  1.1  chopps 	struct grf_softc *gp;
    457  1.1  chopps 	unsigned short xoff, yoff;
    458  1.1  chopps {
    459  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    460  1.1  chopps 	const struct MonDef * md = (struct MonDef *) gp->g_data;
    461  1.1  chopps 	unsigned long off;
    462  1.1  chopps 
    463  1.1  chopps 	xpan = xoff;
    464  1.1  chopps 	ypan = yoff;
    465  1.1  chopps 
    466  1.1  chopps 
    467  1.1  chopps 	if (md->DEP > 8)
    468  1.1  chopps 		xoff *= 2;
    469  1.1  chopps 
    470  1.1  chopps 	vgar(ba, ACT_ADDRESS_RESET);
    471  1.1  chopps 	WAttr(ba, ACT_ID_HOR_PEL_PANNING, (unsigned char)((xoff << 1) & 0x07));
    472  1.1  chopps 	/* have the color lookup function normally again */
    473  1.1  chopps 	vgaw(ba,  ACT_ADDRESS_W, 0x20);
    474  1.1  chopps 
    475  1.1  chopps 	if (md->DEP == 8)
    476  1.1  chopps 		off = ((yoff * md->TX)/ 4) + (xoff >> 2);
    477  1.1  chopps 	else
    478  1.1  chopps 		off = ((yoff * md->TX * 2)/ 4) + (xoff >> 2);
    479  1.1  chopps 
    480  1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_LOW, ((unsigned char)off));
    481  1.1  chopps 
    482  1.1  chopps 	off >>= 8;
    483  1.1  chopps 
    484  1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_HIGH, ((unsigned char)off));
    485  1.1  chopps 
    486  1.1  chopps 	off >>= 8;
    487  1.1  chopps 
    488  1.1  chopps 	WCrt(ba, CRT_ID_EXT_START_ADDR,
    489  1.1  chopps 	    ((RCrt(ba, CRT_ID_EXT_START_ADDR) & 0xf0) | (off & 0x0f)));
    490  1.1  chopps 
    491  1.1  chopps 
    492  1.1  chopps }
    493  1.1  chopps 
    494  1.1  chopps void
    495  1.1  chopps RZ3SetHWCloc (gp, x, y)
    496  1.1  chopps 	struct grf_softc *gp;
    497  1.1  chopps 	unsigned short x, y;
    498  1.1  chopps {
    499  1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
    500  1.1  chopps 	const struct MonDef *md = (struct MonDef *) gp->g_data;
    501  1.1  chopps 	volatile unsigned char *acm = ba + ACM_OFFSET;
    502  1.1  chopps 
    503  1.1  chopps 	if (x < xpan)
    504  1.1  chopps 		RZ3SetPanning(gp, x, ypan);
    505  1.1  chopps 
    506  1.1  chopps 	if (x >= (xpan+md->MW))
    507  1.1  chopps 		RZ3SetPanning(gp, (1 + x - md->MW) , ypan);
    508  1.1  chopps 
    509  1.1  chopps 	if (y < ypan)
    510  1.1  chopps 		RZ3SetPanning(gp, xpan, y);
    511  1.1  chopps 
    512  1.1  chopps 	if (y >= (ypan+md->MH))
    513  1.1  chopps 		RZ3SetPanning(gp, xpan, (1 + y - md->MH));
    514  1.1  chopps 
    515  1.1  chopps 	x -= xpan;
    516  1.1  chopps 	y -= ypan;
    517  1.1  chopps 
    518  1.1  chopps 	*(acm + (ACM_CURSOR_POSITION+0)) = x & 0xff;
    519  1.1  chopps 	*(acm + (ACM_CURSOR_POSITION+1)) = x >> 8;
    520  1.1  chopps 	*(acm + (ACM_CURSOR_POSITION+2)) = y & 0xff;
    521  1.1  chopps 	*(acm + (ACM_CURSOR_POSITION+3)) = y >> 8;
    522  1.1  chopps }
    523  1.1  chopps 
    524  1.1  chopps u_short
    525  1.1  chopps CompFQ(fq)
    526  1.1  chopps 	u_int fq;
    527  1.1  chopps {
    528  1.1  chopps  	/* yuck... this sure could need some explanation.. */
    529  1.1  chopps 
    530  1.1  chopps 	unsigned long f = fq;
    531  1.1  chopps 	long n2 = 3;
    532  1.1  chopps 	long abw = 0x7fffffff;
    533  1.1  chopps 	long n1 = 3;
    534  1.1  chopps 	unsigned long m;
    535  1.1  chopps 	unsigned short erg = 0;
    536  1.1  chopps 
    537  1.1  chopps 	f *= 8;
    538  1.1  chopps 
    539  1.1  chopps 	do {
    540  1.1  chopps 
    541  1.1  chopps 		if (f <= 250000000)
    542  1.1  chopps 			break;
    543  1.1  chopps 		f /= 2;
    544  1.1  chopps 
    545  1.1  chopps 	} while (n2-- > 0);
    546  1.1  chopps 
    547  1.1  chopps 	if (n2 < 0)
    548  1.1  chopps 		return(0);
    549  1.1  chopps 
    550  1.1  chopps 
    551  1.1  chopps 	do {
    552  1.1  chopps 	  	long tmp;
    553  1.1  chopps 
    554  1.1  chopps 		f = fq;
    555  1.1  chopps 		f >>= 3;
    556  1.1  chopps 		f <<= n2;
    557  1.1  chopps 		f >>= 7;
    558  1.1  chopps 
    559  1.1  chopps 		m = (f * n1) / (14318180/1024);
    560  1.1  chopps 
    561  1.1  chopps 		if (m > 129)
    562  1.1  chopps 			break;
    563  1.1  chopps 
    564  1.1  chopps 		tmp =  (((m * 14318180) >> n2) / n1) - fq;
    565  1.1  chopps 		if (tmp < 0)
    566  1.1  chopps 			tmp = -tmp;
    567  1.1  chopps 
    568  1.1  chopps 		if (tmp < abw) {
    569  1.1  chopps 			abw = tmp;
    570  1.1  chopps 			erg = (((n2 << 5) | (n1-2)) << 8) | (m-2);
    571  1.1  chopps 		}
    572  1.1  chopps 
    573  1.1  chopps 	} while ( (++n1) <= 21);
    574  1.1  chopps 
    575  1.1  chopps 	return(erg);
    576  1.1  chopps }
    577  1.1  chopps 
    578  1.1  chopps int
    579  1.1  chopps rh_mondefok(mdp)
    580  1.1  chopps 	struct MonDef *mdp;
    581  1.1  chopps {
    582  1.1  chopps 	switch(mdp->DEP) {
    583  1.1  chopps 	case 8:
    584  1.1  chopps 	case 16:
    585  1.1  chopps 		return(1);
    586  1.1  chopps 	case 4:
    587  1.1  chopps 		if (mdp->FX == 4 || (mdp->FX >= 7 && mdp->FX <= 16))
    588  1.2  chopps 			return(1);
    589  1.1  chopps 		/*FALLTHROUGH*/
    590  1.1  chopps 	default:
    591  1.1  chopps 		return(0);
    592  1.1  chopps 	}
    593  1.1  chopps }
    594  1.1  chopps 
    595  1.1  chopps 
    596  1.1  chopps int
    597  1.1  chopps rh_load_mon(gp, md)
    598  1.1  chopps 	struct grf_softc *gp;
    599  1.1  chopps 	struct MonDef *md;
    600  1.1  chopps {
    601  1.1  chopps 	struct grfinfo *gi = &gp->g_display;
    602  1.1  chopps 	volatile unsigned char *ba;
    603  1.1  chopps 	volatile unsigned char *fb;
    604  1.1  chopps 	short FW, clksel, HDE, VDE;
    605  1.1  chopps 	unsigned short *c, z;
    606  1.1  chopps 	const unsigned char *f;
    607  1.1  chopps 
    608  1.1  chopps 	ba = gp->g_regkva;;
    609  1.1  chopps 	fb = gp->g_fbkva;
    610  1.1  chopps 
    611  1.1  chopps 	/* provide all needed information in grf device-independant
    612  1.1  chopps 	 * locations */
    613  1.1  chopps 	gp->g_data 		= (caddr_t) md;
    614  1.1  chopps 	gi->gd_regaddr	 	= (caddr_t) kvtop (ba);
    615  1.1  chopps 	gi->gd_regsize		= LM_OFFSET;
    616  1.1  chopps 	gi->gd_fbaddr		= (caddr_t) kvtop (fb);
    617  1.1  chopps 	gi->gd_fbsize		= MEMSIZE *1024*1024;
    618  1.1  chopps #ifdef BANKEDDEVPAGER
    619  1.1  chopps 	/* we're not using banks NO MORE! */
    620  1.1  chopps 	gi->gd_bank_size	= 0;
    621  1.1  chopps #endif
    622  1.1  chopps 	gi->gd_colors		= 1 << md->DEP;
    623  1.1  chopps 	gi->gd_planes		= md->DEP;
    624  1.1  chopps 
    625  1.1  chopps 	if (md->DEP == 4) {
    626  1.1  chopps 		gi->gd_fbwidth	= md->MW;
    627  1.1  chopps 		gi->gd_fbheight	= md->MH;
    628  1.1  chopps 		gi->gd_fbx	= 0;
    629  1.1  chopps 		gi->gd_fby	= 0;
    630  1.1  chopps 		gi->gd_dwidth	= md->TX * md->FX;
    631  1.1  chopps 		gi->gd_dheight	= md->TY * md->FY;
    632  1.1  chopps 		gi->gd_dx	= 0;
    633  1.1  chopps 		gi->gd_dy	= 0;
    634  1.1  chopps 	} else {
    635  1.1  chopps 		gi->gd_fbwidth	= md->TX;
    636  1.1  chopps 		gi->gd_fbheight	= md->TY;
    637  1.1  chopps 		gi->gd_fbx	= 0;
    638  1.1  chopps 		gi->gd_fby	= 0;
    639  1.1  chopps 		gi->gd_dwidth	= md->MW;
    640  1.1  chopps 		gi->gd_dheight	= md->MH;
    641  1.1  chopps 		gi->gd_dx	= 0;
    642  1.1  chopps 		gi->gd_dy	= 0;
    643  1.1  chopps 	}
    644  1.1  chopps 
    645  1.1  chopps 	FW =0;
    646  1.1  chopps 	if (md->DEP == 4) {		/* XXX some text-mode! */
    647  1.1  chopps 		switch (md->FX) {
    648  1.1  chopps 		case 4:
    649  1.1  chopps 			FW = 0;
    650  1.1  chopps 			break;
    651  1.1  chopps 		case 7:
    652  1.1  chopps 			FW = 1;
    653  1.1  chopps 			break;
    654  1.1  chopps 		case 8:
    655  1.1  chopps 			FW = 2;
    656  1.1  chopps 			break;
    657  1.1  chopps 		case 9:
    658  1.1  chopps 			FW = 3;
    659  1.1  chopps 			break;
    660  1.1  chopps 		case 10:
    661  1.1  chopps 			FW = 4;
    662  1.1  chopps 			break;
    663  1.1  chopps 		case 11:
    664  1.1  chopps 			FW = 5;
    665  1.1  chopps 			break;
    666  1.1  chopps 		case 12:
    667  1.1  chopps 			FW = 6;
    668  1.1  chopps 			break;
    669  1.1  chopps 		case 13:
    670  1.1  chopps 			FW = 7;
    671  1.1  chopps 			break;
    672  1.1  chopps 		case 14:
    673  1.1  chopps 			FW = 8;
    674  1.1  chopps 			break;
    675  1.1  chopps 		case 15:
    676  1.1  chopps 			FW = 9;
    677  1.1  chopps 			break;
    678  1.1  chopps 		case 16:
    679  1.1  chopps 			FW = 11;
    680  1.1  chopps 			break;
    681  1.1  chopps 		default:
    682  1.1  chopps 			return(0);
    683  1.1  chopps 			break;
    684  1.1  chopps 		}
    685  1.1  chopps 	}
    686  1.1  chopps 
    687  1.1  chopps 	if (md->DEP == 4)
    688  1.1  chopps 		HDE = (md->MW+md->FX-1)/md->FX;
    689  1.1  chopps 	else if (md->DEP == 8)
    690  1.1  chopps 		HDE = (md->MW+3)/4;
    691  1.1  chopps 	else if (md->DEP == 16)
    692  1.1  chopps 		HDE = (md->MW*2+3)/4;
    693  1.1  chopps 
    694  1.1  chopps 	VDE = md->MH-1;
    695  1.1  chopps 
    696  1.1  chopps 	clksel = 0;
    697  1.1  chopps 
    698  1.1  chopps 	vgaw(ba, GREG_MISC_OUTPUT_W, 0xe3 | ((clksel & 3) * 0x04));
    699  1.1  chopps 	vgaw(ba, GREG_FEATURE_CONTROL_W, 0x00);
    700  1.1  chopps 
    701  1.1  chopps 	WSeq(ba, SEQ_ID_RESET, 0x00);
    702  1.1  chopps 	WSeq(ba, SEQ_ID_RESET, 0x03);
    703  1.1  chopps 	WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x01 | ((md->FLG & MDF_CLKDIV2)/ MDF_CLKDIV2 * 8));
    704  1.1  chopps 	WSeq(ba, SEQ_ID_MAP_MASK, 0x0f);
    705  1.1  chopps 	WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
    706  1.1  chopps 	WSeq(ba, SEQ_ID_MEMORY_MODE, 0x06);
    707  1.1  chopps 	WSeq(ba, SEQ_ID_RESET, 0x01);
    708  1.1  chopps 	WSeq(ba, SEQ_ID_RESET, 0x03);
    709  1.1  chopps 
    710  1.1  chopps 	WSeq(ba, SEQ_ID_EXTENDED_ENABLE, 0x05);
    711  1.1  chopps 	WSeq(ba, SEQ_ID_CURSOR_CONTROL, 0x00);
    712  1.1  chopps 	WSeq(ba, SEQ_ID_PRIM_HOST_OFF_HI, 0x00);
    713  1.1  chopps 	WSeq(ba, SEQ_ID_PRIM_HOST_OFF_HI, 0x00);
    714  1.1  chopps 	WSeq(ba, SEQ_ID_LINEAR_0, 0x4a);
    715  1.1  chopps 	WSeq(ba, SEQ_ID_LINEAR_1, 0x00);
    716  1.1  chopps 
    717  1.1  chopps 	WSeq(ba, SEQ_ID_SEC_HOST_OFF_HI, 0x00);
    718  1.1  chopps 	WSeq(ba, SEQ_ID_SEC_HOST_OFF_LO, 0x00);
    719  1.1  chopps 	WSeq(ba, SEQ_ID_EXTENDED_MEM_ENA, 0x3 | 0x4 | 0x10 | 0x40);
    720  1.1  chopps 	WSeq(ba, SEQ_ID_EXT_CLOCK_MODE, 0x10 | (FW & 0x0f));
    721  1.1  chopps 	WSeq(ba, SEQ_ID_EXT_VIDEO_ADDR, 0x03);
    722  1.1  chopps 	if (md->DEP == 4) {
    723  1.1  chopps 	  	/* 8bit pixel, no gfx byte path */
    724  1.1  chopps 		WSeq(ba, SEQ_ID_EXT_PIXEL_CNTL, 0x00);
    725  1.1  chopps 	} else if (md->DEP == 8) {
    726  1.1  chopps 	  	/* 8bit pixel, gfx byte path */
    727  1.1  chopps 		WSeq(ba, SEQ_ID_EXT_PIXEL_CNTL, 0x01);
    728  1.1  chopps 	} else if (md->DEP == 16) {
    729  1.1  chopps 	  	/* 16bit pixel, gfx byte path */
    730  1.1  chopps 		WSeq(ba, SEQ_ID_EXT_PIXEL_CNTL, 0x11);
    731  1.1  chopps 	}
    732  1.1  chopps 	WSeq(ba, SEQ_ID_BUS_WIDTH_FEEDB, 0x04);
    733  1.1  chopps 	WSeq(ba, SEQ_ID_COLOR_EXP_WFG, 0x01);
    734  1.1  chopps 	WSeq(ba, SEQ_ID_COLOR_EXP_WBG, 0x00);
    735  1.1  chopps 	WSeq(ba, SEQ_ID_EXT_RW_CONTROL, 0x00);
    736  1.1  chopps 	WSeq(ba, SEQ_ID_MISC_FEATURE_SEL, (0x51 | (clksel & 8)));
    737  1.1  chopps 	WSeq(ba, SEQ_ID_COLOR_KEY_CNTL, 0x40);
    738  1.1  chopps 	WSeq(ba, SEQ_ID_COLOR_KEY_MATCH0, 0x00);
    739  1.1  chopps 	WSeq(ba, SEQ_ID_COLOR_KEY_MATCH1, 0x00);
    740  1.1  chopps 	WSeq(ba, SEQ_ID_COLOR_KEY_MATCH2, 0x00);
    741  1.1  chopps 	WSeq(ba, SEQ_ID_CRC_CONTROL, 0x00);
    742  1.1  chopps 	WSeq(ba, SEQ_ID_PERF_SELECT, 0x10);
    743  1.1  chopps 	WSeq(ba, SEQ_ID_ACM_APERTURE_1, 0x00);
    744  1.1  chopps 	WSeq(ba, SEQ_ID_ACM_APERTURE_2, 0x30);
    745  1.1  chopps 	WSeq(ba, SEQ_ID_ACM_APERTURE_3, 0x00);
    746  1.1  chopps 	WSeq(ba, SEQ_ID_MEMORY_MAP_CNTL, 0x07);
    747  1.1  chopps 
    748  1.1  chopps 	WCrt(ba, CRT_ID_END_VER_RETR, (md->VSE & 0xf) | 0x20);
    749  1.1  chopps 	WCrt(ba, CRT_ID_HOR_TOTAL, md->HT    & 0xff);
    750  1.1  chopps 	WCrt(ba, CRT_ID_HOR_DISP_ENA_END, (HDE-1)   & 0xff);
    751  1.1  chopps 	WCrt(ba, CRT_ID_START_HOR_BLANK, md->HBS   & 0xff);
    752  1.1  chopps 	WCrt(ba, CRT_ID_END_HOR_BLANK, (md->HBE   & 0x1f) | 0x80);
    753  1.1  chopps 
    754  1.1  chopps 	WCrt(ba, CRT_ID_START_HOR_RETR, md->HSS   & 0xff);
    755  1.1  chopps 	WCrt(ba, CRT_ID_END_HOR_RETR,
    756  1.1  chopps 	    (md->HSE & 0x1f)   |
    757  1.1  chopps 	    ((md->HBE & 0x20)/ 0x20 * 0x80));
    758  1.1  chopps 	WCrt(ba, CRT_ID_VER_TOTAL,  (md->VT  & 0xff));
    759  1.1  chopps 	WCrt(ba, CRT_ID_OVERFLOW,
    760  1.1  chopps 	    ((md->VSS & 0x200) / 0x200 * 0x80) |
    761  1.1  chopps 	    ((VDE     & 0x200) / 0x200 * 0x40) |
    762  1.1  chopps 	    ((md->VT  & 0x200) / 0x200 * 0x20) |
    763  1.1  chopps 	    0x10                               |
    764  1.1  chopps 	    ((md->VBS & 0x100) / 0x100 * 8)    |
    765  1.1  chopps 	    ((md->VSS & 0x100) / 0x100 * 4)    |
    766  1.1  chopps 	    ((VDE     & 0x100) / 0x100 * 2)    |
    767  1.1  chopps 	    ((md->VT  & 0x100) / 0x100));
    768  1.1  chopps 	WCrt(ba, CRT_ID_PRESET_ROW_SCAN, 0x00);
    769  1.1  chopps 
    770  1.1  chopps 	if (md->DEP == 4) {
    771  1.1  chopps 		WCrt(ba, CRT_ID_MAX_SCAN_LINE,
    772  1.1  chopps 		    ((md->FLG & MDF_DBL)/ MDF_DBL * 0x80) |
    773  1.1  chopps 		    0x40 |
    774  1.1  chopps 		    ((md->VBS & 0x200)/0x200*0x20) |
    775  1.1  chopps 		    ((md->FY-1) & 0x1f));
    776  1.1  chopps 	} else {
    777  1.1  chopps 		WCrt(ba, CRT_ID_MAX_SCAN_LINE,
    778  1.1  chopps 		    ((md->FLG & MDF_DBL)/ MDF_DBL * 0x80) |
    779  1.1  chopps 		    0x40 |
    780  1.1  chopps 		    ((md->VBS & 0x200)/0x200*0x20) |
    781  1.1  chopps 		    (0 & 0x1f));
    782  1.1  chopps 	}
    783  1.1  chopps 
    784  1.1  chopps 	/* I prefer "_" cursor to "block" cursor.. */
    785  1.1  chopps #if 1
    786  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_START, (md->FY & 0x1f) - 2);
    787  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_END, (md->FY & 0x1f) - 1);
    788  1.1  chopps #else
    789  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_START, 0x00);
    790  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_END, md->FY & 0x1f);
    791  1.1  chopps #endif
    792  1.1  chopps 
    793  1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
    794  1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
    795  1.1  chopps 
    796  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
    797  1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
    798  1.1  chopps 
    799  1.1  chopps 	WCrt(ba, CRT_ID_START_VER_RETR, md->VSS & 0xff);
    800  1.1  chopps 	WCrt(ba, CRT_ID_END_VER_RETR, (md->VSE & 0xf) | 0x80 | 0x20);
    801  1.1  chopps 	WCrt(ba, CRT_ID_VER_DISP_ENA_END, VDE  & 0xff);
    802  1.1  chopps 
    803  1.1  chopps 	if (md->DEP == 4)
    804  1.1  chopps 		WCrt(ba, CRT_ID_OFFSET, (HDE / 2) & 0xff);
    805  1.1  chopps 	else if (md->DEP == 8)
    806  1.1  chopps 		WCrt(ba, CRT_ID_OFFSET, (md->TX / 8) & 0xff);
    807  1.1  chopps 	else
    808  1.1  chopps 		WCrt(ba, CRT_ID_OFFSET, (md->TX / 4) & 0xff);
    809  1.1  chopps 
    810  1.1  chopps 	WCrt(ba, CRT_ID_UNDERLINE_LOC, (md->FY-1) & 0x1f);
    811  1.1  chopps 	WCrt(ba, CRT_ID_START_VER_BLANK, md->VBS & 0xff);
    812  1.1  chopps 	WCrt(ba, CRT_ID_END_VER_BLANK, md->VBE & 0xff);
    813  1.1  chopps 	WCrt(ba, CRT_ID_MODE_CONTROL, 0xe3);
    814  1.1  chopps 	WCrt(ba, CRT_ID_LINE_COMPARE, 0xff);
    815  1.1  chopps 
    816  1.1  chopps 	WCrt(ba, CRT_ID_EXT_HOR_TIMING1,
    817  1.1  chopps 		    0 | 0x20                                    |
    818  1.1  chopps 		    ((md->FLG & MDF_LACE)  / MDF_LACE   * 0x10) |
    819  1.1  chopps 		    ((md->HT  & 0x100) / 0x100)                 |
    820  1.1  chopps 		    (((HDE-1) & 0x100) / 0x100 * 2)             |
    821  1.1  chopps 		    ((md->HBS & 0x100) / 0x100 * 4)             |
    822  1.1  chopps 		    ((md->HSS & 0x100) / 0x100 * 8));
    823  1.1  chopps 
    824  1.1  chopps 	if (md->DEP == 4)
    825  1.1  chopps 		WCrt(ba, CRT_ID_EXT_START_ADDR,
    826  1.1  chopps 		    (((HDE / 2) & 0x100)/0x100 * 16));
    827  1.1  chopps 	else if (md->DEP == 8)
    828  1.1  chopps 		WCrt(ba, CRT_ID_EXT_START_ADDR,
    829  1.1  chopps 		    (((md->TX / 8) & 0x100)/0x100 * 16));
    830  1.1  chopps 	else
    831  1.1  chopps 		WCrt(ba, CRT_ID_EXT_START_ADDR,
    832  1.1  chopps 		    (((md->TX / 4) & 0x100)/0x100 * 16));
    833  1.1  chopps 
    834  1.1  chopps 	WCrt(ba, CRT_ID_EXT_HOR_TIMING2,
    835  1.1  chopps 		    ((md->HT  & 0x200)/ 0x200)       |
    836  1.1  chopps 	            (((HDE-1) & 0x200)/ 0x200 * 2  ) |
    837  1.1  chopps 	            ((md->HBS & 0x200)/ 0x200 * 4  ) |
    838  1.1  chopps 	            ((md->HSS & 0x200)/ 0x200 * 8  ) |
    839  1.1  chopps 	            ((md->HBE & 0xc0) / 0x40  * 16 ) |
    840  1.1  chopps 	            ((md->HSE & 0x60) / 0x20  * 64));
    841  1.1  chopps 
    842  1.1  chopps 	WCrt(ba, CRT_ID_EXT_VER_TIMING,
    843  1.1  chopps 		    ((md->VSE & 0x10) / 0x10  * 0x80  ) |
    844  1.1  chopps 		    ((md->VBE & 0x300)/ 0x100 * 0x20  ) |
    845  1.1  chopps 		    0x10                                |
    846  1.1  chopps 		    ((md->VSS & 0x400)/ 0x400 * 8     ) |
    847  1.1  chopps 		    ((md->VBS & 0x400)/ 0x400 * 4     ) |
    848  1.1  chopps 		    ((VDE     & 0x400)/ 0x400 * 2     ) |
    849  1.1  chopps 		    ((md->VT & 0x400)/ 0x400));
    850  1.1  chopps 	WCrt(ba, CRT_ID_MONITOR_POWER, 0x00);
    851  1.1  chopps 
    852  1.1  chopps 	{
    853  1.1  chopps 		unsigned short tmp = CompFQ(md->FQ);
    854  1.1  chopps 		WPLL(ba, 2   , tmp);
    855  1.1  chopps 		tmp = CompFQ(MEMCLK);
    856  1.1  chopps 		WPLL(ba,10   , tmp);
    857  1.1  chopps 		WPLL(ba,14   , 0x22);
    858  1.1  chopps 	}
    859  1.1  chopps 
    860  1.1  chopps 	WGfx(ba, GCT_ID_SET_RESET, 0x00);
    861  1.1  chopps 	WGfx(ba, GCT_ID_ENABLE_SET_RESET, 0x00);
    862  1.1  chopps 	WGfx(ba, GCT_ID_COLOR_COMPARE, 0x00);
    863  1.1  chopps 	WGfx(ba, GCT_ID_DATA_ROTATE, 0x00);
    864  1.1  chopps 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
    865  1.1  chopps 	WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
    866  1.1  chopps 	if (md->DEP == 4)
    867  1.1  chopps 		WGfx(ba, GCT_ID_MISC, 0x04);
    868  1.1  chopps 	else
    869  1.1  chopps 		WGfx(ba, GCT_ID_MISC, 0x05);
    870  1.1  chopps 	WGfx(ba, GCT_ID_COLOR_XCARE, 0x0f);
    871  1.1  chopps 	WGfx(ba, GCT_ID_BITMASK, 0xff);
    872  1.1  chopps 
    873  1.1  chopps 	vgar(ba, ACT_ADDRESS_RESET);
    874  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE0 , 0x00);
    875  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE1 , 0x01);
    876  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE2 , 0x02);
    877  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE3 , 0x03);
    878  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE4 , 0x04);
    879  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE5 , 0x05);
    880  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE6 , 0x06);
    881  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE7 , 0x07);
    882  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE8 , 0x08);
    883  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE9 , 0x09);
    884  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE10, 0x0a);
    885  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE11, 0x0b);
    886  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE12, 0x0c);
    887  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE13, 0x0d);
    888  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE14, 0x0e);
    889  1.1  chopps 	WAttr(ba, ACT_ID_PALETTE15, 0x0f);
    890  1.1  chopps 
    891  1.1  chopps 	vgar(ba, ACT_ADDRESS_RESET);
    892  1.1  chopps 	if (md->DEP == 4)
    893  1.1  chopps 		WAttr(ba, ACT_ID_ATTR_MODE_CNTL, 0x08);
    894  1.1  chopps 	else
    895  1.1  chopps 		WAttr(ba, ACT_ID_ATTR_MODE_CNTL, 0x09);
    896  1.1  chopps 
    897  1.1  chopps 	WAttr(ba, ACT_ID_OVERSCAN_COLOR, 0x00);
    898  1.1  chopps 	WAttr(ba, ACT_ID_COLOR_PLANE_ENA, 0x0f);
    899  1.1  chopps 	WAttr(ba, ACT_ID_HOR_PEL_PANNING, 0x00);
    900  1.1  chopps 	WAttr(ba, ACT_ID_COLOR_SELECT, 0x00);
    901  1.1  chopps 
    902  1.1  chopps 	vgar(ba, ACT_ADDRESS_RESET);
    903  1.1  chopps 	vgaw(ba, ACT_ADDRESS_W, 0x20);
    904  1.1  chopps 
    905  1.1  chopps 	vgaw(ba, VDAC_MASK, 0xff);
    906  1.1  chopps 	if (md->DEP < 16)
    907  1.1  chopps 	  	/* well... probably the PLL chip */
    908  1.1  chopps 		vgaw(ba, 0x83c6, ((0 & 7) << 5));
    909  1.1  chopps 	else if (md->DEP == 16)
    910  1.1  chopps 	  	/* well... */
    911  1.1  chopps 		vgaw(ba, 0x83c6, ((3 & 7) << 5));
    912  1.1  chopps 	vgaw(ba, VDAC_ADDRESS_W, 0x00);
    913  1.1  chopps 
    914  1.1  chopps 	if (md->DEP < 16) {
    915  1.1  chopps 		short x = 256-17;
    916  1.1  chopps 		unsigned char cl = 16;
    917  1.1  chopps 		RZ3LoadPalette(gp, md->PAL, 0, 16);
    918  1.1  chopps 		do {
    919  1.1  chopps 			vgaw(ba, VDAC_DATA, (cl >> 2));
    920  1.1  chopps 			vgaw(ba, VDAC_DATA, (cl >> 2));
    921  1.1  chopps 			vgaw(ba, VDAC_DATA, (cl >> 2));
    922  1.1  chopps 			cl++;
    923  1.1  chopps 		} while (x-- > 0);
    924  1.1  chopps 	}
    925  1.1  chopps 
    926  1.1  chopps 	if (md->DEP == 4) {
    927  1.1  chopps 		{
    928  1.1  chopps 			struct grf_bitblt bb = {
    929  1.1  chopps 				GRFBBOPset,
    930  1.1  chopps 				0, 0,
    931  1.1  chopps 				0, 0,
    932  1.1  chopps 				md->TX*4, 2*md->TY,
    933  1.1  chopps 				EMPTY_ALPHA
    934  1.1  chopps 			};
    935  1.1  chopps 			RZ3BitBlit(gp, &bb);
    936  1.1  chopps 		}
    937  1.1  chopps 
    938  1.1  chopps 		c = (unsigned short *)(ba + LM_OFFSET);
    939  1.1  chopps 		c += 2 * md->FLo*32;
    940  1.1  chopps 		c += 1;
    941  1.1  chopps 		f = md->FData;
    942  1.1  chopps 		for (z = md->FLo; z <= md->FHi; z++) {
    943  1.1  chopps 			short y = md->FY-1;
    944  1.1  chopps 			if (md->FX > 8){
    945  1.1  chopps 				do {
    946  1.1  chopps 					*c = *((const unsigned short *)f);
    947  1.1  chopps 					c += 2;
    948  1.1  chopps 					f += 2;
    949  1.1  chopps 				} while (y-- > 0);
    950  1.1  chopps 			} else {
    951  1.1  chopps 				do {
    952  1.1  chopps 					*c = (*f++) << 8;
    953  1.1  chopps 					c += 2;
    954  1.1  chopps 				} while (y-- > 0);
    955  1.1  chopps 			}
    956  1.1  chopps 
    957  1.1  chopps 			c += 2 * (32-md->FY);
    958  1.1  chopps 		}
    959  1.1  chopps 		{
    960  1.1  chopps 			unsigned long * pt = (unsigned long *) (ba + LM_OFFSET + PAT_MEM_OFF);
    961  1.1  chopps 			unsigned long tmp  = 0xffff0000;
    962  1.1  chopps 			*pt++ = tmp;
    963  1.1  chopps 			*pt = tmp;
    964  1.1  chopps 		}
    965  1.1  chopps 
    966  1.1  chopps 		WSeq(ba, SEQ_ID_MAP_MASK, 3);
    967  1.1  chopps 
    968  1.1  chopps 		c = (unsigned short *)(ba + LM_OFFSET);
    969  1.1  chopps 		c += (md->TX-6)*2;
    970  1.1  chopps 		{
    971  1.1  chopps 		  	/* it's show-time :-) */
    972  1.1  chopps 			static unsigned short init_msg[6] = {
    973  1.1  chopps 				0x520a, 0x450b, 0x540c, 0x490d, 0x4e0e, 0x410f
    974  1.1  chopps 			};
    975  1.1  chopps 			unsigned short * m = init_msg;
    976  1.1  chopps 			short x = 5;
    977  1.1  chopps 			do {
    978  1.1  chopps 				*c = *m++;
    979  1.1  chopps 				c += 2;
    980  1.1  chopps 			} while (x-- > 0);
    981  1.1  chopps 		}
    982  1.1  chopps 
    983  1.1  chopps 		return(1);
    984  1.1  chopps 	} else if (md->DEP == 8) {
    985  1.1  chopps 		struct grf_bitblt bb = {
    986  1.1  chopps 			GRFBBOPset,
    987  1.1  chopps 			0, 0,
    988  1.1  chopps 			0, 0,
    989  1.1  chopps 			md->TX, md->TY,
    990  1.1  chopps 			0x0000
    991  1.1  chopps 		};
    992  1.1  chopps 		WSeq(ba, SEQ_ID_MAP_MASK, 0x0f);
    993  1.1  chopps 
    994  1.1  chopps 		RZ3BitBlit(gp, &bb);
    995  1.1  chopps 
    996  1.1  chopps 		xpan = 0;
    997  1.1  chopps 		ypan = 0;
    998  1.1  chopps 
    999  1.1  chopps 		return(1);
   1000  1.1  chopps 	} else if (md->DEP == 16) {
   1001  1.1  chopps 		struct grf_bitblt bb = {
   1002  1.1  chopps 			GRFBBOPset,
   1003  1.1  chopps 			0, 0,
   1004  1.1  chopps 			0, 0,
   1005  1.1  chopps 			md->TX, md->TY,
   1006  1.1  chopps 			0x0000
   1007  1.1  chopps 		};
   1008  1.1  chopps 		WSeq(ba, SEQ_ID_MAP_MASK, 0x0f);
   1009  1.1  chopps 
   1010  1.1  chopps 		RZ3BitBlit16(gp, &bb);
   1011  1.1  chopps 
   1012  1.1  chopps 		xpan = 0;
   1013  1.1  chopps 		ypan = 0;
   1014  1.1  chopps 
   1015  1.1  chopps 		return(1);
   1016  1.1  chopps 	} else
   1017  1.1  chopps 		return(0);
   1018  1.1  chopps }
   1019  1.1  chopps 
   1020  1.1  chopps /* standard-palette definition */
   1021  1.1  chopps 
   1022  1.1  chopps unsigned char RZ3StdPalette[16*3] = {
   1023  1.1  chopps /*        R   G   B  */
   1024  1.1  chopps 	  0,  0,  0,
   1025  1.1  chopps 	192,192,192,
   1026  1.1  chopps 	128,  0,  0,
   1027  1.1  chopps 	  0,128,  0,
   1028  1.1  chopps 	  0,  0,128,
   1029  1.1  chopps 	128,128,  0,
   1030  1.1  chopps 	  0,128,128,
   1031  1.1  chopps 	128,  0,128,
   1032  1.1  chopps 	 64, 64, 64, /* the higher 8 colors have more intensity for  */
   1033  1.1  chopps 	255,255,255, /* compatibility with standard attributes       */
   1034  1.1  chopps 	255,  0,  0,
   1035  1.1  chopps 	  0,255,  0,
   1036  1.1  chopps 	  0,  0,255,
   1037  1.1  chopps 	255,255,  0,
   1038  1.1  chopps 	  0,255,255,
   1039  1.1  chopps 	255,  0,255
   1040  1.1  chopps };
   1041  1.1  chopps 
   1042  1.1  chopps /*
   1043  1.1  chopps  * The following structures are examples for monitor-definitions. To make one
   1044  1.1  chopps  * of your own, first use "DefineMonitor" and create the 8-bit or 16-bit
   1045  1.1  chopps  * monitor-mode of your dreams. Then save it, and make a structure from the
   1046  1.1  chopps  * values provided in the file DefineMonitor stored - the labels in the comment
   1047  1.1  chopps  * above the structure definition show where to put what value.
   1048  1.1  chopps  *
   1049  1.1  chopps  * If you want to use your definition for the text-mode, you'll need to adapt
   1050  1.1  chopps  * your 8-bit monitor-definition to the font you want to use. Be FX the width of
   1051  1.1  chopps  * the font, then the following modifications have to be applied to your values:
   1052  1.1  chopps  *
   1053  1.1  chopps  * HBS = (HBS * 4) / FX
   1054  1.1  chopps  * HSS = (HSS * 4) / FX
   1055  1.1  chopps  * HSE = (HSE * 4) / FX
   1056  1.1  chopps  * HBE = (HBE * 4) / FX
   1057  1.1  chopps  * HT  = (HT  * 4) / FX
   1058  1.1  chopps  *
   1059  1.1  chopps  * Make sure your maximum width (MW) and height (MH) are even multiples of
   1060  1.1  chopps  * the fonts' width and height.
   1061  1.1  chopps  *
   1062  1.1  chopps  * You may use definitons created by the old DefineMonitor, but you'll get
   1063  1.1  chopps  * better results with the new DefineMonitor supplied along with the Retin Z3.
   1064  1.1  chopps */
   1065  1.1  chopps 
   1066  1.1  chopps /*
   1067  1.1  chopps  *  FQ     FLG    MW   MH   HBS HSS HSE HBE  HT  VBS  VSS  VSE  VBE   VT
   1068  1.1  chopps  * Depth,          PAL, TX,  TY,    XY,FontX, FontY,    FontData,  FLo,  Fhi
   1069  1.1  chopps  */
   1070  1.1  chopps static struct MonDef monitor_defs[] = {
   1071  1.1  chopps   /* Text-mode definitions */
   1072  1.1  chopps 
   1073  1.1  chopps   /* horizontal 31.5 kHz */
   1074  1.2  chopps #ifdef KFONT_8X11
   1075  1.2  chopps   { 50000000,  28,  640, 506,   81, 86, 93, 98, 95, 513, 513, 521, 535, 535,
   1076  1.2  chopps       4, RZ3StdPalette, 80,  46,  3680,    8,    11, kernel_font_8x11, 32,  255},
   1077  1.2  chopps #else
   1078  1.1  chopps   { 50000000,  28,  640, 512,   81, 86, 93, 98, 95, 513, 513, 521, 535, 535,
   1079  1.1  chopps       4, RZ3StdPalette, 80,  64,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1080  1.1  chopps #endif
   1081  1.1  chopps 
   1082  1.1  chopps   /* horizontal 38kHz */
   1083  1.2  chopps #ifdef KFONT_8X11
   1084  1.2  chopps   { 75000000,  28,  768, 594,   97, 99,107,120,117, 601, 615, 625, 638, 638,
   1085  1.2  chopps       4, RZ3StdPalette, 96,  54,  5184,    8,     11, kernel_font_8x11,   32,  255},
   1086  1.2  chopps #else
   1087  1.1  chopps   { 75000000,  28,  768, 600,   97, 99,107,120,117, 601, 615, 625, 638, 638,
   1088  1.1  chopps       4, RZ3StdPalette, 96,  75,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1089  1.2  chopps #endif
   1090  1.1  chopps 
   1091  1.1  chopps   /* horizontal 64kHz */
   1092  1.2  chopps #ifdef KFONT_8X11
   1093  1.2  chopps   { 50000000, 24,  768, 594,   97,104,112,122,119, 601, 606, 616, 628, 628,
   1094  1.2  chopps       4, RZ3StdPalette, 96,  54,  5184,    8,     8, kernel_font_8x8,   32,  255},
   1095  1.2  chopps #else
   1096  1.1  chopps   { 50000000, 24,  768, 600,   97,104,112,122,119, 601, 606, 616, 628, 628,
   1097  1.1  chopps       4, RZ3StdPalette, 96,  75,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1098  1.2  chopps #endif
   1099  1.1  chopps 
   1100  1.1  chopps   /* 8-bit gfx-mode definitions */
   1101  1.1  chopps 
   1102  1.1  chopps   /*
   1103  1.1  chopps    * IMPORTANT: the "logical" screen size can be up to 2048x2048 pixels,
   1104  1.1  chopps    * independent from the "physical" screen size. If your code does NOT
   1105  1.1  chopps    * support panning, please adjust the "logical" screen sizes below to
   1106  1.1  chopps    * match the physical ones
   1107  1.1  chopps    */
   1108  1.1  chopps 
   1109  1.1  chopps   /* 640 x 480, 8 Bit, 31862 Hz, 63 Hz */
   1110  1.1  chopps   { 26000000,  0,  640, 480,  161,175,188,200,199, 481, 483, 491, 502, 502,
   1111  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1112  1.1  chopps   /* This is the logical ^    ^    screen size */
   1113  1.1  chopps 
   1114  1.1  chopps   /* 640 x 480, 8 Bit, 38366 Hz, 76 Hz */
   1115  1.1  chopps  { 31000000,  0,  640, 480,  161,169,182,198,197, 481, 482, 490, 502, 502,
   1116  1.1  chopps      8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1117  1.1  chopps 
   1118  1.1  chopps   /* 800 x 600, 8 Bit, 31620 Hz, 50 Hz (1950) */
   1119  1.1  chopps   { 32000000,  0,  800, 600,  201,202,218,249,248, 601, 602, 612, 628, 628,
   1120  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1121  1.1  chopps   /* 800 x 600, 8 Bit, 38537 Hz, 61 Hz */
   1122  1.1  chopps   { 39000000,  0,  800, 600,  201,211,227,249,248, 601, 603, 613, 628, 628,
   1123  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1124  1.1  chopps 
   1125  1.1  chopps   /* 1024 x 768, 8 Bit, 63862 Hz, 79 Hz */
   1126  1.1  chopps   { 82000000,  0, 1024, 768,  257,257,277,317,316, 769, 771, 784, 804, 804,
   1127  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1128  1.1  chopps 
   1129  1.1  chopps   /* 1120 x 896, 8 Bit, 64000 Hz, 69 Hz */
   1130  1.1  chopps   { 97000000,  0, 1120, 896,  281,283,306,369,368, 897, 898, 913, 938, 938,
   1131  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1132  1.1  chopps 
   1133  1.1  chopps   /* 1152 x 910, 8 Bit, 76177 Hz, 79 Hz */
   1134  1.1  chopps   {110000000,  0, 1152, 910,  289,310,333,357,356, 911, 923, 938, 953, 953,
   1135  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1136  1.1  chopps 
   1137  1.1  chopps   /* 1184 x 848, 8 Bit, 73529 Hz, 82 Hz */
   1138  1.1  chopps   {110000000,  0, 1184, 848,  297,319,342,370,369, 849, 852, 866, 888, 888,
   1139  1.1  chopps       8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1140  1.1  chopps 
   1141  1.1  chopps   /* 1280 x 1024, 8 Bit, 64516 Hz, 60 Hz */
   1142  1.1  chopps   {104000000, 0, 1280,1024,  321,323,348,399,398,1025,1026,1043,1073,1073,
   1143  1.1  chopps      8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1144  1.1  chopps 
   1145  1.1  chopps /* WARNING: THE FOLLOWING MONITOR MODE EXCEEDS THE 110-MHz LIMIT THE PROCESSOR
   1146  1.1  chopps             HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
   1147  1.1  chopps             MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)!     */
   1148  1.1  chopps   /* 1280 x 1024, 8 Bit, 75436 Hz, 70 Hz */
   1149  1.1  chopps   {121000000, 0, 1280,1024,  321,322,347,397,396,1025,1026,1043,1073,1073,
   1150  1.1  chopps      8, RZ3StdPalette,1280,1024,  5120,    8,     8, kernel_font_8x8,   32,  255},
   1151  1.1  chopps 
   1152  1.1  chopps 
   1153  1.1  chopps   /* 16-bit gfx-mode definitions */
   1154  1.1  chopps 
   1155  1.1  chopps   /* 640 x 480, 16 Bit, 31795 Hz, 63 Hz */
   1156  1.1  chopps   { 51000000, 0,  640, 480,  321,344,369,397,396, 481, 482, 490, 502, 502,
   1157  1.1  chopps       16,           0,1280, 1024,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1158  1.1  chopps 
   1159  1.1  chopps   /* 800 x 600, 16 Bit, 38500 Hz, 61 Hz */
   1160  1.1  chopps   { 77000000, 0,  800, 600,  401,418,449,496,495, 601, 602, 612, 628, 628,
   1161  1.1  chopps       16,           0,1280, 1024,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1162  1.1  chopps 
   1163  1.1  chopps   /* 1024 x 768, 16 Bit, 42768 Hz, 53 Hz */
   1164  1.1  chopps   {110000000,  0, 1024, 768,  513,514,554,639,638, 769, 770, 783, 804, 804,
   1165  1.1  chopps       16,           0,1280, 1024,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1166  1.1  chopps 
   1167  1.1  chopps   /* 864 x 648, 16 Bit, 50369 Hz, 74 Hz */
   1168  1.1  chopps   {109000000,  0,  864, 648,  433,434,468,537,536, 649, 650, 661, 678, 678,
   1169  1.1  chopps       16,           0,1280, 1024,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1170  1.1  chopps 
   1171  1.1  chopps /*
   1172  1.1  chopps  * WARNING: THE FOLLOWING MONITOR MODE EXCEEDS THE 110-MHz LIMIT THE PROCESSOR
   1173  1.1  chopps  *          HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
   1174  1.1  chopps  *          MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)!
   1175  1.1  chopps  */
   1176  1.1  chopps   /* 1024 x 768, 16 Bit, 48437 Hz, 60 Hz */
   1177  1.1  chopps   {124000000,  0, 1024, 768,  513,537,577,636,635, 769, 770, 783, 804, 804,
   1178  1.1  chopps       16,           0,1280, 1024,  7200,    8,     8, kernel_font_8x8,   32,  255},
   1179  1.1  chopps };
   1180  1.1  chopps 
   1181  1.1  chopps static const char *monitor_descr[] = {
   1182  1.2  chopps #ifdef KFONT_8X11
   1183  1.2  chopps   "80x46 (640x506) 31.5kHz",
   1184  1.2  chopps   "96x54 (768x594) 38kHz",
   1185  1.2  chopps   "96x54 (768x594) 64kHz",
   1186  1.2  chopps #else
   1187  1.1  chopps   "80x64 (640x512) 31.5kHz",
   1188  1.1  chopps   "96x75 (768x600) 38kHz",
   1189  1.1  chopps   "96x75 (768x600) 64kHz",
   1190  1.2  chopps #endif
   1191  1.1  chopps 
   1192  1.1  chopps   "GFX-8 (640x480) 31.5kHz",
   1193  1.1  chopps   "GFX-8 (640x480) 38kHz",
   1194  1.1  chopps   "GFX-8 (800x600) 31.6kHz",
   1195  1.1  chopps   "GFX-8 (800x600) 38.5kHz",
   1196  1.1  chopps   "GFX-8 (1024x768) 64kHz",
   1197  1.1  chopps   "GFX-8 (1120x896) 64kHz",
   1198  1.1  chopps   "GFX-8 (1152x910) 76kHz",
   1199  1.1  chopps   "GFX-8 (1182x848) 73kHz",
   1200  1.1  chopps   "GFX-8 (1280x1024) 64.5kHz",
   1201  1.1  chopps   "GFX-8 (1280x1024) 75.5kHz ***EXCEEDS CHIP LIMIT!!!***",
   1202  1.1  chopps 
   1203  1.1  chopps   "GFX-16 (640x480) 31.8kHz",
   1204  1.1  chopps   "GFX-16 (800x600) 38.5kHz",
   1205  1.1  chopps   "GFX-16 (1024x768) 42.8kHz",
   1206  1.1  chopps   "GFX-16 (864x648) 50kHz",
   1207  1.1  chopps   "GFX-16 (1024x768) 48.5kHz ***EXCEEDS CHIP LIMIT!!!***",
   1208  1.1  chopps };
   1209  1.1  chopps 
   1210  1.1  chopps int rh_mon_max = sizeof (monitor_defs)/sizeof (monitor_defs[0]);
   1211  1.1  chopps 
   1212  1.1  chopps /* patchable */
   1213  1.1  chopps int rh_default_mon = 0;
   1214  1.1  chopps int rh_default_gfx = 4;
   1215  1.1  chopps 
   1216  1.1  chopps static struct MonDef *current_mon;
   1217  1.1  chopps 
   1218  1.1  chopps int  rh_mode     __P((struct grf_softc *, int, void *, int, int));
   1219  1.1  chopps void grfrhattach __P((struct device *, struct device *, void *));
   1220  1.1  chopps int  grfrhprint  __P((void *, char *));
   1221  1.1  chopps int  grfrhmatch  __P((struct device *, struct cfdata *, void *));
   1222  1.1  chopps 
   1223  1.1  chopps struct cfdriver grfrhcd = {
   1224  1.4  chopps 	NULL, "grfrh", (cfmatch_t)grfrhmatch, grfrhattach,
   1225  1.1  chopps 	DV_DULL, sizeof(struct grf_softc), NULL, 0
   1226  1.1  chopps };
   1227  1.1  chopps 
   1228  1.1  chopps static struct cfdata *cfdata;
   1229  1.1  chopps 
   1230  1.1  chopps int
   1231  1.1  chopps grfrhmatch(pdp, cfp, auxp)
   1232  1.1  chopps 	struct device *pdp;
   1233  1.1  chopps 	struct cfdata *cfp;
   1234  1.1  chopps 	void *auxp;
   1235  1.1  chopps {
   1236  1.1  chopps #ifdef RETINACONSOLE
   1237  1.1  chopps 	static int rhconunit = -1;
   1238  1.1  chopps #endif
   1239  1.5  chopps 	struct zbus_args *zap;
   1240  1.1  chopps 
   1241  1.1  chopps 	zap = auxp;
   1242  1.1  chopps 
   1243  1.1  chopps 	if (amiga_realconfig == 0)
   1244  1.1  chopps #ifdef RETINACONSOLE
   1245  1.1  chopps 		if (rhconunit != -1)
   1246  1.1  chopps #endif
   1247  1.1  chopps 			return(0);
   1248  1.1  chopps 	if (zap->manid != 18260 || zap->prodid != 16)
   1249  1.1  chopps 		return(0);
   1250  1.1  chopps #ifdef RETINACONSOLE
   1251  1.1  chopps 	if (amiga_realconfig == 0 || rhconunit != cfp->cf_unit) {
   1252  1.1  chopps #endif
   1253  1.1  chopps 		if ((unsigned)rh_default_mon >= rh_mon_max ||
   1254  1.1  chopps 		    monitor_defs[rh_default_mon].DEP == 8)
   1255  1.1  chopps 			rh_default_mon = 0;
   1256  1.1  chopps 		current_mon = monitor_defs + rh_default_mon;
   1257  1.1  chopps 		if (rh_mondefok(current_mon) == 0)
   1258  1.1  chopps 			return(0);
   1259  1.1  chopps #ifdef RETINACONSOLE
   1260  1.1  chopps 		if (amiga_realconfig == 0) {
   1261  1.1  chopps 			rhconunit = cfp->cf_unit;
   1262  1.1  chopps 			cfdata = cfp;
   1263  1.1  chopps 		}
   1264  1.1  chopps 	}
   1265  1.1  chopps #endif
   1266  1.1  chopps 	return(1);
   1267  1.1  chopps }
   1268  1.1  chopps 
   1269  1.1  chopps void
   1270  1.1  chopps grfrhattach(pdp, dp, auxp)
   1271  1.1  chopps 	struct device *pdp, *dp;
   1272  1.1  chopps 	void *auxp;
   1273  1.1  chopps {
   1274  1.1  chopps 	static struct grf_softc congrf;
   1275  1.1  chopps 	static int coninited;
   1276  1.5  chopps 	struct zbus_args *zap;
   1277  1.1  chopps 	struct grf_softc *gp;
   1278  1.1  chopps 
   1279  1.1  chopps 	zap = auxp;
   1280  1.1  chopps 
   1281  1.1  chopps 	if (dp == NULL)
   1282  1.1  chopps 		gp = &congrf;
   1283  1.1  chopps 	else
   1284  1.1  chopps 		gp = (struct grf_softc *)dp;
   1285  1.1  chopps 	if (dp != NULL && congrf.g_regkva != 0) {
   1286  1.1  chopps 		/*
   1287  1.1  chopps 		 * inited earlier, just copy (not device struct)
   1288  1.1  chopps 		 */
   1289  1.1  chopps 		bcopy(&congrf.g_display, &gp->g_display,
   1290  1.1  chopps 		    (char *)&gp[1] - (char *)&gp->g_display);
   1291  1.1  chopps 	} else {
   1292  1.1  chopps 		gp->g_regkva = (volatile caddr_t)zap->va;
   1293  1.1  chopps 		gp->g_fbkva = (volatile caddr_t)zap->va + LM_OFFSET;
   1294  1.1  chopps 		gp->g_unit = GRF_RETINAIII_UNIT;
   1295  1.1  chopps 		gp->g_mode = rh_mode;
   1296  1.1  chopps 		gp->g_conpri = grfrh_cnprobe();
   1297  1.1  chopps 		gp->g_flags = GF_ALIVE;
   1298  1.1  chopps 		grfrh_iteinit(gp);
   1299  1.1  chopps 		(void)rh_load_mon(gp, current_mon);
   1300  1.1  chopps 	}
   1301  1.1  chopps 	if (dp != NULL)
   1302  1.1  chopps 		printf("\n");
   1303  1.1  chopps 	/*
   1304  1.1  chopps 	 * attach grf
   1305  1.1  chopps 	 */
   1306  1.1  chopps 	amiga_config_found(cfdata, &gp->g_device, gp, grfrhprint);
   1307  1.1  chopps }
   1308  1.1  chopps 
   1309  1.1  chopps int
   1310  1.1  chopps grfrhprint(auxp, pnp)
   1311  1.1  chopps 	void *auxp;
   1312  1.1  chopps 	char *pnp;
   1313  1.1  chopps {
   1314  1.1  chopps 	if (pnp)
   1315  1.1  chopps 		printf("ite at %s", pnp);
   1316  1.1  chopps 	return(UNCONF);
   1317  1.1  chopps }
   1318  1.1  chopps 
   1319  1.1  chopps int
   1320  1.1  chopps rh_getvmode(gp, vm)
   1321  1.1  chopps 	struct grf_softc *gp;
   1322  1.1  chopps 	struct grfvideo_mode *vm;
   1323  1.1  chopps {
   1324  1.1  chopps 	struct MonDef *md;
   1325  1.1  chopps 
   1326  1.1  chopps 	if (vm->mode_num && vm->mode_num > rh_mon_max)
   1327  1.1  chopps 		return(EINVAL);
   1328  1.1  chopps 
   1329  1.1  chopps 	if (! vm->mode_num)
   1330  1.1  chopps 		vm->mode_num = (current_mon - monitor_defs) + 1;
   1331  1.1  chopps 
   1332  1.1  chopps 	md = monitor_defs + (vm->mode_num - 1);
   1333  1.1  chopps 	strncpy (vm->mode_descr, monitor_descr + (vm->mode_num - 1),
   1334  1.1  chopps 	   sizeof (vm->mode_descr));
   1335  1.1  chopps 	vm->pixel_clock  = md->FQ;
   1336  1.1  chopps 	vm->disp_width   = md->MW;
   1337  1.1  chopps 	vm->disp_height  = md->MH;
   1338  1.1  chopps 	vm->depth        = md->DEP;
   1339  1.1  chopps 	vm->hblank_start = md->HBS;
   1340  1.1  chopps 	vm->hblank_stop  = md->HBE;
   1341  1.1  chopps 	vm->hsync_start  = md->HSS;
   1342  1.1  chopps 	vm->hsync_stop   = md->HSE;
   1343  1.1  chopps 	vm->htotal       = md->HT;
   1344  1.1  chopps 	vm->vblank_start = md->VBS;
   1345  1.1  chopps 	vm->vblank_stop  = md->VBE;
   1346  1.1  chopps 	vm->vsync_start  = md->VSS;
   1347  1.1  chopps 	vm->vsync_stop   = md->VSE;
   1348  1.1  chopps 	vm->vtotal       = md->VT;
   1349  1.1  chopps 
   1350  1.1  chopps 	return(0);
   1351  1.1  chopps }
   1352  1.1  chopps 
   1353  1.1  chopps 
   1354  1.1  chopps int
   1355  1.1  chopps rh_setvmode(gp, mode, txtonly)
   1356  1.1  chopps 	struct grf_softc *gp;
   1357  1.1  chopps 	unsigned mode;
   1358  1.1  chopps 	int txtonly;
   1359  1.1  chopps {
   1360  1.1  chopps 	struct MonDef *md;
   1361  1.1  chopps 	int error;
   1362  1.1  chopps 
   1363  1.1  chopps 	if (!mode || mode > rh_mon_max)
   1364  1.1  chopps 		return(EINVAL);
   1365  1.1  chopps 
   1366  1.1  chopps 	if (txtonly && monitor_defs[mode-1].DEP != 4)
   1367  1.1  chopps 		return(EINVAL);
   1368  1.1  chopps 
   1369  1.1  chopps 	current_mon = monitor_defs + (mode - 1);
   1370  1.1  chopps 
   1371  1.1  chopps 	error = rh_load_mon (gp, current_mon) ? 0 : EINVAL;
   1372  1.1  chopps 
   1373  1.1  chopps 	return(error);
   1374  1.1  chopps }
   1375  1.1  chopps 
   1376  1.1  chopps 
   1377  1.1  chopps /*
   1378  1.1  chopps  * Change the mode of the display.
   1379  1.1  chopps  * Return a UNIX error number or 0 for success.
   1380  1.1  chopps  */
   1381  1.1  chopps rh_mode(gp, cmd, arg, a2, a3)
   1382  1.1  chopps 	register struct grf_softc *gp;
   1383  1.1  chopps 	int cmd;
   1384  1.1  chopps 	void *arg;
   1385  1.1  chopps 	int a2, a3;
   1386  1.1  chopps {
   1387  1.1  chopps   /* implement these later... */
   1388  1.1  chopps 
   1389  1.1  chopps 	switch (cmd) {
   1390  1.1  chopps 	case GM_GRFON:
   1391  1.1  chopps 		rh_setvmode (gp, rh_default_gfx + 1, 0);
   1392  1.1  chopps 		return(0);
   1393  1.1  chopps 
   1394  1.1  chopps 	case GM_GRFOFF:
   1395  1.1  chopps 		rh_setvmode (gp, rh_default_mon + 1, 0);
   1396  1.1  chopps 		return(0);
   1397  1.1  chopps 
   1398  1.1  chopps 	case GM_GRFCONFIG:
   1399  1.1  chopps 		return(0);
   1400  1.1  chopps 
   1401  1.1  chopps 	case GM_GRFGETVMODE:
   1402  1.1  chopps 		return(rh_getvmode (gp, (struct grfvideo_mode *) arg));
   1403  1.1  chopps 
   1404  1.1  chopps 	case GM_GRFSETVMODE:
   1405  1.1  chopps 		return(rh_setvmode (gp, *(unsigned *) arg, 1));
   1406  1.1  chopps 
   1407  1.1  chopps 	case GM_GRFGETNUMVM:
   1408  1.1  chopps 		*(int *)arg = rh_mon_max;
   1409  1.1  chopps 		return(0);
   1410  1.1  chopps 
   1411  1.1  chopps #ifdef BANKEDDEVPAGER
   1412  1.1  chopps 	case GM_GRFGETBANK:
   1413  1.1  chopps 	case GM_GRFGETCURBANK:
   1414  1.1  chopps 	case GM_GRFSETBANK:
   1415  1.1  chopps 		return(EINVAL);
   1416  1.1  chopps #endif
   1417  1.1  chopps 	case GM_GRFIOCTL:
   1418  1.4  chopps 		return(rh_ioctl (gp, (u_long) arg, (caddr_t) a2));
   1419  1.1  chopps 
   1420  1.1  chopps 	default:
   1421  1.1  chopps 		break;
   1422  1.1  chopps 	}
   1423  1.1  chopps 
   1424  1.1  chopps 	return(EINVAL);
   1425  1.1  chopps }
   1426  1.1  chopps 
   1427  1.1  chopps int
   1428  1.1  chopps rh_ioctl (gp, cmd, data)
   1429  1.1  chopps 	register struct grf_softc *gp;
   1430  1.4  chopps 	u_long cmd;
   1431  1.1  chopps 	void *data;
   1432  1.1  chopps {
   1433  1.1  chopps 	switch (cmd) {
   1434  1.1  chopps 	case GRFIOCGSPRITEPOS:
   1435  1.1  chopps 		return(rh_getspritepos (gp, (struct grf_position *) data));
   1436  1.1  chopps 
   1437  1.1  chopps 	case GRFIOCSSPRITEPOS:
   1438  1.1  chopps 		return(rh_setspritepos (gp, (struct grf_position *) data));
   1439  1.1  chopps 
   1440  1.1  chopps 	case GRFIOCSSPRITEINF:
   1441  1.1  chopps 		return(rh_setspriteinfo (gp, (struct grf_spriteinfo *) data));
   1442  1.1  chopps 
   1443  1.1  chopps 	case GRFIOCGSPRITEINF:
   1444  1.1  chopps 		return(rh_getspriteinfo (gp, (struct grf_spriteinfo *) data));
   1445  1.1  chopps 
   1446  1.1  chopps 	case GRFIOCGSPRITEMAX:
   1447  1.1  chopps 		return(rh_getspritemax (gp, (struct grf_position *) data));
   1448  1.1  chopps 
   1449  1.1  chopps 	case GRFIOCGETCMAP:
   1450  1.1  chopps 		return(rh_getcmap (gp, (struct grf_colormap *) data));
   1451  1.1  chopps 
   1452  1.1  chopps 	case GRFIOCPUTCMAP:
   1453  1.1  chopps 		return(rh_putcmap (gp, (struct grf_colormap *) data));
   1454  1.1  chopps 
   1455  1.1  chopps 	case GRFIOCBITBLT:
   1456  1.1  chopps 		return(rh_bitblt (gp, (struct grf_bitblt *) data));
   1457  1.1  chopps 	}
   1458  1.1  chopps 
   1459  1.1  chopps 	return(EINVAL);
   1460  1.1  chopps }
   1461  1.1  chopps 
   1462  1.1  chopps 
   1463  1.1  chopps int
   1464  1.1  chopps rh_getcmap (gfp, cmap)
   1465  1.1  chopps 	struct grf_softc *gfp;
   1466  1.1  chopps 	struct grf_colormap *cmap;
   1467  1.1  chopps {
   1468  1.1  chopps 	volatile unsigned char *ba;
   1469  1.1  chopps 	u_char red[256], green[256], blue[256], *rp, *gp, *bp;
   1470  1.1  chopps 	short x;
   1471  1.1  chopps 	int error;
   1472  1.1  chopps 
   1473  1.1  chopps 	if (cmap->count == 0 || cmap->index >= 256)
   1474  1.1  chopps 		return 0;
   1475  1.1  chopps 
   1476  1.1  chopps 	if (cmap->index + cmap->count > 256)
   1477  1.1  chopps 		cmap->count = 256 - cmap->index;
   1478  1.1  chopps 
   1479  1.1  chopps 	ba = gfp->g_regkva;
   1480  1.1  chopps 	/* first read colors out of the chip, then copyout to userspace */
   1481  1.1  chopps 	vgaw (ba, VDAC_ADDRESS_W, cmap->index);
   1482  1.1  chopps 	x = cmap->count - 1;
   1483  1.1  chopps 	rp = red + cmap->index;
   1484  1.1  chopps 	gp = green + cmap->index;
   1485  1.1  chopps 	bp = blue + cmap->index;
   1486  1.1  chopps 	do {
   1487  1.1  chopps 		*rp++ = vgar (ba, VDAC_DATA) << 2;
   1488  1.1  chopps 		*gp++ = vgar (ba, VDAC_DATA) << 2;
   1489  1.1  chopps 		*bp++ = vgar (ba, VDAC_DATA) << 2;
   1490  1.1  chopps 	} while (x-- > 0);
   1491  1.1  chopps 
   1492  1.1  chopps 	if (!(error = copyout (red + cmap->index, cmap->red, cmap->count))
   1493  1.1  chopps 	    && !(error = copyout (green + cmap->index, cmap->green, cmap->count))
   1494  1.1  chopps 	    && !(error = copyout (blue + cmap->index, cmap->blue, cmap->count)))
   1495  1.1  chopps 		return(0);
   1496  1.1  chopps 
   1497  1.1  chopps 	return(error);
   1498  1.1  chopps }
   1499  1.1  chopps 
   1500  1.1  chopps int
   1501  1.1  chopps rh_putcmap (gfp, cmap)
   1502  1.1  chopps 	struct grf_softc *gfp;
   1503  1.1  chopps 	struct grf_colormap *cmap;
   1504  1.1  chopps {
   1505  1.1  chopps 	volatile unsigned char *ba;
   1506  1.1  chopps 	u_char red[256], green[256], blue[256], *rp, *gp, *bp;
   1507  1.1  chopps 	short x;
   1508  1.1  chopps 	int error;
   1509  1.1  chopps 
   1510  1.1  chopps 	if (cmap->count == 0 || cmap->index >= 256)
   1511  1.1  chopps 		return(0);
   1512  1.1  chopps 
   1513  1.1  chopps 	if (cmap->index + cmap->count > 256)
   1514  1.1  chopps 		cmap->count = 256 - cmap->index;
   1515  1.1  chopps 
   1516  1.1  chopps 	/* first copy the colors into kernelspace */
   1517  1.1  chopps 	if (!(error = copyin (cmap->red, red + cmap->index, cmap->count))
   1518  1.1  chopps 	    && !(error = copyin (cmap->green, green + cmap->index, cmap->count))
   1519  1.1  chopps 	    && !(error = copyin (cmap->blue, blue + cmap->index, cmap->count))) {
   1520  1.1  chopps 		/* argl.. LoadPalette wants a different format, so do it like with
   1521  1.1  chopps 		* Retina2.. */
   1522  1.1  chopps 		ba = gfp->g_regkva;
   1523  1.1  chopps 		vgaw (ba, VDAC_ADDRESS_W, cmap->index);
   1524  1.1  chopps 		x = cmap->count - 1;
   1525  1.1  chopps 		rp = red + cmap->index;
   1526  1.1  chopps 		gp = green + cmap->index;
   1527  1.1  chopps 		bp = blue + cmap->index;
   1528  1.1  chopps 		do {
   1529  1.1  chopps 			vgaw (ba, VDAC_DATA, *rp++ >> 2);
   1530  1.1  chopps 			vgaw (ba, VDAC_DATA, *gp++ >> 2);
   1531  1.1  chopps 			vgaw (ba, VDAC_DATA, *bp++ >> 2);
   1532  1.1  chopps 		} while (x-- > 0);
   1533  1.1  chopps 		return(0);
   1534  1.1  chopps 	}
   1535  1.1  chopps 	else
   1536  1.1  chopps 		return(error);
   1537  1.1  chopps }
   1538  1.1  chopps 
   1539  1.1  chopps int
   1540  1.1  chopps rh_getspritepos (gp, pos)
   1541  1.1  chopps 	struct grf_softc *gp;
   1542  1.1  chopps 	struct grf_position *pos;
   1543  1.1  chopps {
   1544  1.1  chopps 	volatile unsigned char *acm = gp->g_regkva + ACM_OFFSET;
   1545  1.1  chopps 
   1546  1.1  chopps 	pos->x = acm[ACM_CURSOR_POSITION + 0] +
   1547  1.1  chopps 	    (acm[ACM_CURSOR_POSITION + 1] << 8);
   1548  1.1  chopps 	pos->y = acm[ACM_CURSOR_POSITION + 2] +
   1549  1.1  chopps 	    (acm[ACM_CURSOR_POSITION + 3] << 8);
   1550  1.1  chopps 
   1551  1.1  chopps 	pos->x += xpan;
   1552  1.1  chopps 	pos->y += ypan;
   1553  1.1  chopps 
   1554  1.1  chopps 	return(0);
   1555  1.1  chopps }
   1556  1.1  chopps 
   1557  1.1  chopps int
   1558  1.1  chopps rh_setspritepos (gp, pos)
   1559  1.1  chopps 	struct grf_softc *gp;
   1560  1.1  chopps 	struct grf_position *pos;
   1561  1.1  chopps {
   1562  1.1  chopps 	RZ3SetHWCloc (gp, pos->x, pos->y);
   1563  1.1  chopps 	return(0);
   1564  1.1  chopps }
   1565  1.1  chopps 
   1566  1.1  chopps int
   1567  1.1  chopps rh_getspriteinfo (gp, info)
   1568  1.1  chopps 	struct grf_softc *gp;
   1569  1.1  chopps 	struct grf_spriteinfo *info;
   1570  1.1  chopps {
   1571  1.1  chopps 	volatile unsigned char *ba, *fb;
   1572  1.1  chopps 
   1573  1.1  chopps 	ba = gp->g_regkva;
   1574  1.1  chopps 	fb = gp->g_fbkva;
   1575  1.1  chopps 	if (info->set & GRFSPRSET_ENABLE)
   1576  1.1  chopps 		info->enable = RSeq (ba, SEQ_ID_CURSOR_CONTROL) & 0x01;
   1577  1.1  chopps 	if (info->set & GRFSPRSET_POS)
   1578  1.1  chopps 		rh_getspritepos (gp, &info->pos);
   1579  1.1  chopps 	if (info->set & GRFSPRSET_HOT) {
   1580  1.1  chopps 		info->hot.x = RSeq (ba, SEQ_ID_CURSOR_X_INDEX) & 0x3f;
   1581  1.1  chopps 		info->hot.y = RSeq (ba, SEQ_ID_CURSOR_Y_INDEX) & 0x7f;
   1582  1.1  chopps 	}
   1583  1.1  chopps 	if (info->set & GRFSPRSET_CMAP) {
   1584  1.1  chopps 		struct grf_colormap cmap;
   1585  1.1  chopps 		int index;
   1586  1.1  chopps 		cmap.index = 0;
   1587  1.1  chopps 		cmap.count = 256;
   1588  1.1  chopps 		rh_getcmap (gp, &cmap);
   1589  1.1  chopps 		index = RSeq (ba, SEQ_ID_CURSOR_COLOR0);
   1590  1.1  chopps 		info->cmap.red[0] = cmap.red[index];
   1591  1.1  chopps 		info->cmap.green[0] = cmap.green[index];
   1592  1.1  chopps 		info->cmap.blue[0] = cmap.blue[index];
   1593  1.1  chopps 		index = RSeq (ba, SEQ_ID_CURSOR_COLOR1);
   1594  1.1  chopps 		info->cmap.red[1] = cmap.red[index];
   1595  1.1  chopps 		info->cmap.green[1] = cmap.green[index];
   1596  1.1  chopps 		info->cmap.blue[1] = cmap.blue[index];
   1597  1.1  chopps 	}
   1598  1.1  chopps 	if (info->set & GRFSPRSET_SHAPE) {
   1599  1.1  chopps 		u_char image[128], mask[128];
   1600  1.1  chopps 		volatile u_long *hwp;
   1601  1.1  chopps 		u_char *imp, *mp;
   1602  1.1  chopps 		short row;
   1603  1.1  chopps 
   1604  1.1  chopps 		/* sprite bitmap is WEIRD in this chip.. see grf_rhvar.h
   1605  1.1  chopps 		 * for an explanation. To convert to "our" format, the
   1606  1.1  chopps 		 * following holds:
   1607  1.1  chopps 		 *   col2   = !image & mask
   1608  1.1  chopps 		 *   col1   = image & mask
   1609  1.1  chopps 		 *   transp = !mask
   1610  1.1  chopps 		 * and thus:
   1611  1.1  chopps 		 *   image  = col1
   1612  1.1  chopps 		 *   mask   = col1 | col2
   1613  1.1  chopps 		 * hope I got these bool-eqs right below..
   1614  1.1  chopps 		 */
   1615  1.1  chopps 
   1616  1.1  chopps 		info->size.x = 64;
   1617  1.1  chopps 		info->size.y = 64;
   1618  1.1  chopps 		for (row = 0, hwp = (u_long *)(ba + LM_OFFSET + HWC_MEM_OFF),
   1619  1.1  chopps 		    mp = mask, imp = image;
   1620  1.1  chopps 		    row < 64;
   1621  1.1  chopps 		    row++) {
   1622  1.1  chopps 			u_long bp10, bp20, bp11, bp21;
   1623  1.1  chopps 			bp10 = *hwp++;
   1624  1.1  chopps 			bp20 = *hwp++;
   1625  1.1  chopps 			bp11 = *hwp++;
   1626  1.1  chopps 			bp21 = *hwp++;
   1627  1.1  chopps 			M2I (bp10);
   1628  1.1  chopps 			M2I (bp20);
   1629  1.1  chopps 			M2I (bp11);
   1630  1.1  chopps 			M2I (bp21);
   1631  1.1  chopps 			*imp++ = (~bp10) & bp11;
   1632  1.1  chopps 			*imp++ = (~bp20) & bp21;
   1633  1.1  chopps 			*mp++  = (~bp10) | (bp10 & ~bp11);
   1634  1.1  chopps 			*mp++  = (~bp20) & (bp20 & ~bp21);
   1635  1.1  chopps 		}
   1636  1.1  chopps 		copyout (image, info->image, sizeof (image));
   1637  1.1  chopps 		copyout (mask, info->mask, sizeof (mask));
   1638  1.1  chopps 	}
   1639  1.1  chopps 	return(0);
   1640  1.1  chopps }
   1641  1.1  chopps 
   1642  1.1  chopps int
   1643  1.1  chopps rh_setspriteinfo (gp, info)
   1644  1.1  chopps 	struct grf_softc *gp;
   1645  1.1  chopps 	struct grf_spriteinfo *info;
   1646  1.1  chopps {
   1647  1.1  chopps 	volatile unsigned char *ba, *fb;
   1648  1.1  chopps 	u_char control;
   1649  1.1  chopps 
   1650  1.1  chopps 	ba = gp->g_regkva;
   1651  1.1  chopps 	fb = gp->g_fbkva;
   1652  1.1  chopps 
   1653  1.1  chopps 	if (info->set & GRFSPRSET_SHAPE) {
   1654  1.1  chopps 		/*
   1655  1.1  chopps 		 * For an explanation of these weird actions here, see above
   1656  1.1  chopps 		 * when reading the shape.  We set the shape directly into
   1657  1.1  chopps 		 * the video memory, there's no reason to keep 1k on the
   1658  1.1  chopps 		 * kernel stack just as template
   1659  1.1  chopps 		 */
   1660  1.1  chopps 		u_char *image, *mask;
   1661  1.1  chopps 		volatile u_long *hwp;
   1662  1.1  chopps 		u_char *imp, *mp;
   1663  1.1  chopps 		short row;
   1664  1.1  chopps 
   1665  1.1  chopps 		if (info->size.y > 64)
   1666  1.1  chopps 			info->size.y = 64;
   1667  1.1  chopps 		if (info->size.x > 64)
   1668  1.1  chopps 			info->size.x = 64;
   1669  1.1  chopps 
   1670  1.1  chopps 		if (info->size.x < 32)
   1671  1.1  chopps 			info->size.x = 32;
   1672  1.1  chopps 
   1673  1.1  chopps 		image = malloc(HWC_MEM_SIZE, M_TEMP, M_WAITOK);
   1674  1.1  chopps 		mask  = image + HWC_MEM_SIZE/2;
   1675  1.1  chopps 
   1676  1.1  chopps 		copyin(info->image, image, info->size.y * info->size.x / 8);
   1677  1.1  chopps 		copyin(info->mask, mask, info->size.y * info->size.x / 8);
   1678  1.1  chopps 
   1679  1.1  chopps 		hwp = (u_long *)(ba + LM_OFFSET + HWC_MEM_OFF);
   1680  1.1  chopps 
   1681  1.1  chopps 		/*
   1682  1.1  chopps 		 * setting it is slightly more difficult, because we can't
   1683  1.1  chopps 		 * force the application to not pass a *smaller* than
   1684  1.1  chopps 		 * supported bitmap
   1685  1.1  chopps 		 */
   1686  1.1  chopps 
   1687  1.1  chopps 		for (row = 0, mp = mask, imp = image;
   1688  1.1  chopps 		    row < info->size.y;
   1689  1.1  chopps 		    row++) {
   1690  1.1  chopps 			u_long im1, im2, m1, m2;
   1691  1.1  chopps 
   1692  1.1  chopps 			im1 = *(unsigned long *)imp;
   1693  1.1  chopps 			imp += 4;
   1694  1.1  chopps 			m1  = *(unsigned long *)mp;
   1695  1.1  chopps 			mp  += 4;
   1696  1.1  chopps 			if (info->size.x > 32) {
   1697  1.1  chopps 	      			im2 = *(unsigned long *)imp;
   1698  1.1  chopps 				imp += 4;
   1699  1.1  chopps 				m2  = *(unsigned long *)mp;
   1700  1.1  chopps 				mp  += 4;
   1701  1.1  chopps 			}
   1702  1.1  chopps 			else
   1703  1.1  chopps 				im2 = m2 = 0;
   1704  1.1  chopps 
   1705  1.1  chopps 			M2I(im1);
   1706  1.1  chopps 			M2I(im2);
   1707  1.1  chopps 			M2I(m1);
   1708  1.1  chopps 			M2I(m2);
   1709  1.1  chopps 
   1710  1.1  chopps 			*hwp++ = ~m1;
   1711  1.1  chopps 			*hwp++ = ~m2;
   1712  1.1  chopps 			*hwp++ = m1 & im1;
   1713  1.1  chopps 			*hwp++ = m2 & im2;
   1714  1.1  chopps 		}
   1715  1.1  chopps 		for (; row < 64; row++) {
   1716  1.1  chopps 			*hwp++ = 0xffffffff;
   1717  1.1  chopps 			*hwp++ = 0xffffffff;
   1718  1.1  chopps 			*hwp++ = 0x00000000;
   1719  1.1  chopps 			*hwp++ = 0x00000000;
   1720  1.1  chopps 		}
   1721  1.1  chopps 
   1722  1.1  chopps 		free(image, M_TEMP);
   1723  1.1  chopps 		RZ3SetupHWC(gp, 1, 0, 0, 0, 0);
   1724  1.1  chopps 	}
   1725  1.1  chopps 	if (info->set & GRFSPRSET_CMAP) {
   1726  1.1  chopps 		/* hey cheat a bit here.. XXX */
   1727  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_COLOR0, 0);
   1728  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_COLOR1, 1);
   1729  1.1  chopps 	}
   1730  1.1  chopps 	if (info->set & GRFSPRSET_ENABLE) {
   1731  1.1  chopps 		if (info->enable)
   1732  1.1  chopps 			control = 0x85;
   1733  1.1  chopps 		else
   1734  1.1  chopps 			control = 0;
   1735  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_CONTROL, control);
   1736  1.1  chopps 	}
   1737  1.1  chopps 	if (info->set & GRFSPRSET_POS)
   1738  1.1  chopps 		rh_setspritepos(gp, &info->pos);
   1739  1.1  chopps 	if (info->set & GRFSPRSET_HOT) {
   1740  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_X_INDEX, info->hot.x & 0x3f);
   1741  1.1  chopps 		WSeq(ba, SEQ_ID_CURSOR_Y_INDEX, info->hot.y & 0x7f);
   1742  1.1  chopps 	}
   1743  1.1  chopps 
   1744  1.1  chopps 	return(0);
   1745  1.1  chopps }
   1746  1.1  chopps 
   1747  1.1  chopps int
   1748  1.1  chopps rh_getspritemax (gp, pos)
   1749  1.1  chopps 	struct grf_softc *gp;
   1750  1.1  chopps 	struct grf_position *pos;
   1751  1.1  chopps {
   1752  1.1  chopps 	pos->x = 64;
   1753  1.1  chopps 	pos->y = 64;
   1754  1.1  chopps 
   1755  1.1  chopps 	return(0);
   1756  1.1  chopps }
   1757  1.1  chopps 
   1758  1.1  chopps 
   1759  1.1  chopps int
   1760  1.1  chopps rh_bitblt (gp, bb)
   1761  1.1  chopps 	struct grf_softc *gp;
   1762  1.1  chopps 	struct grf_bitblt *bb;
   1763  1.1  chopps {
   1764  1.1  chopps 	struct MonDef *md = (struct MonDef *)gp->g_data;
   1765  1.1  chopps 	if (md->DEP < 16)
   1766  1.1  chopps 		RZ3BitBlit(gp, bb);
   1767  1.1  chopps 	else
   1768  1.1  chopps 		RZ3BitBlit16(gp, bb);
   1769  1.1  chopps }
   1770  1.1  chopps #endif	/* NGRF */
   1771