Home | History | Annotate | Line # | Download | only in dev
grf_rt.c revision 1.18
      1  1.18     cgd /*	$NetBSD: grf_rt.c,v 1.18 1994/10/26 02:03:16 cgd Exp $	*/
      2   1.6  chopps 
      3  1.15  chopps #include "grfrt.h"
      4  1.15  chopps #if NGRFRT > 0
      5   1.1      mw 
      6   1.1      mw /* Graphics routines for the Retina board,
      7   1.1      mw    using the NCR 77C22E+ VGA controller. */
      8   1.1      mw 
      9   1.4      mw #include <sys/param.h>
     10   1.4      mw #include <sys/errno.h>
     11   1.4      mw #include <sys/ioctl.h>
     12  1.11  chopps #include <sys/device.h>
     13  1.11  chopps #include <machine/cpu.h>
     14  1.11  chopps #include <amiga/amiga/device.h>
     15  1.11  chopps #include <amiga/dev/ztwobusvar.h>
     16   1.7  chopps #include <amiga/dev/grfioctl.h>
     17   1.7  chopps #include <amiga/dev/grfvar.h>
     18   1.7  chopps #include <amiga/dev/grf_rtreg.h>
     19   1.1      mw 
     20  1.11  chopps /*
     21  1.11  chopps  * marked true early so that retina_cnprobe() can tell if we are alive.
     22  1.11  chopps  */
     23  1.11  chopps int retina_inited;
     24   1.8  chopps 
     25   1.8  chopps 
     26   1.1      mw /* NOTE: this driver for the MacroSystem Retina board was only possible,
     27   1.1      mw          because MacroSystem provided information about the pecularities
     28   1.1      mw          of the board. THANKS! Competition in Europe among gfx board
     29   1.1      mw          manufacturers is rather tough, so Lutz Vieweg, who wrote the
     30   1.1      mw          initial driver, has made an agreement with MS not to document
     31   1.1      mw          the driver source (see also his Copyright disclaimer below).
     32   1.1      mw          -> ALL comments after
     33   1.1      mw 	 -> "/* -------------- START OF CODE -------------- * /"
     34   1.1      mw 	 -> have been added by myself (mw) from studying the publically
     35   1.1      mw 	 -> available "NCR 77C22E+" Data Manual
     36   1.1      mw 
     37   1.1      mw 	 Lutz' original driver source (without any of my comments) is
     38   1.1      mw 	 available on request. */
     39   1.1      mw 
     40   1.1      mw 
     41   1.1      mw /* This code offers low-level routines to access the Retina graphics-board
     42   1.1      mw    manufactured by MS MacroSystem GmbH from within NetBSD for the Amiga.
     43   1.1      mw    No warranties for any kind of function at all - this code may crash
     44   1.1      mw    your hardware and scratch your harddisk.
     45   1.1      mw    Use at your own risk.
     46   1.1      mw    Freely distributable.
     47   1.1      mw 
     48   1.1      mw    Written by Lutz Vieweg 07/93
     49   1.1      mw 
     50   1.1      mw    Thanks to MacroSystem for providing me with the neccessary information
     51   1.1      mw    to create theese routines. The sparse documentation of this code
     52   1.1      mw    results from the agreements between MS and me.
     53   1.1      mw */
     54   1.1      mw 
     55   1.9  chopps extern unsigned char kernel_font_8x8_width, kernel_font_8x8_height;
     56   1.9  chopps extern unsigned char kernel_font_8x8_lo, kernel_font_8x8_hi;
     57   1.9  chopps extern unsigned char kernel_font_8x8[];
     58   1.1      mw 
     59   1.1      mw 
     60   1.1      mw #define MDF_DBL 1
     61   1.1      mw #define MDF_LACE 2
     62   1.1      mw #define MDF_CLKDIV2 4
     63   1.1      mw 
     64   1.1      mw 
     65   1.1      mw /* standard-palette definition */
     66   1.1      mw 
     67   1.1      mw unsigned char NCRStdPalette[16*3] = {
     68   1.1      mw /*   R   G   B  */
     69   1.1      mw 	  0,  0,  0,
     70   1.1      mw 	192,192,192,
     71   1.1      mw 	128,  0,  0,
     72   1.1      mw 	  0,128,  0,
     73   1.1      mw 	  0,  0,128,
     74   1.1      mw 	128,128,  0,
     75   1.1      mw 	  0,128,128,
     76   1.1      mw 	128,  0,128,
     77   1.1      mw 	 64, 64, 64, /* the higher 8 colors have more intensity for  */
     78   1.1      mw 	255,255,255, /* compatibility with standard attributes       */
     79   1.1      mw 	255,  0,  0,
     80   1.1      mw 	  0,255,  0,
     81   1.1      mw 	  0,  0,255,
     82   1.1      mw 	255,255,  0,
     83   1.1      mw 	  0,255,255,
     84   1.1      mw 	255,  0,255
     85   1.1      mw };
     86   1.1      mw 
     87   1.1      mw 
     88   1.1      mw /* The following structures are examples for monitor-definitions. To make one
     89   1.1      mw    of your own, first use "DefineMonitor" and create the 8-bit monitor-mode of
     90   1.1      mw    your dreams. Then save it, and make a structure from the values provided in
     91   1.1      mw    the file DefineMonitor stored - the labels in the comment above the
     92   1.1      mw    structure definition show where to put what value.
     93   1.1      mw 
     94   1.1      mw    Then you'll need to adapt your monitor-definition to the font you want to
     95   1.1      mw    use. Be FX the width of the font, then the following modifications have to
     96   1.1      mw    be applied to your values:
     97   1.1      mw 
     98   1.1      mw    HBS = (HBS * 4) / FX
     99   1.1      mw    HSS = (HSS * 4) / FX
    100   1.1      mw    HSE = (HSE * 4) / FX
    101   1.1      mw    HBE = (HBE * 4) / FX
    102   1.1      mw    HT  = (HT  * 4) / FX
    103   1.1      mw 
    104   1.1      mw    Make sure your maximum width (MW) and height (MH) are even multiples of
    105   1.1      mw    the fonts' width and height.
    106   1.1      mw */
    107   1.1      mw 
    108   1.1      mw #if 0
    109   1.1      mw /* horizontal 31.5 kHz */
    110   1.1      mw 
    111   1.1      mw /*                                      FQ     FLG    MW   MH   HBS HSS HSE HBE  HT  VBS  VSS  VSE  VBE   VT  */
    112   1.1      mw    struct MonDef MON_640_512_60  = { 50000000,  28,  640, 512,   81, 86, 93, 98, 95, 513, 513, 521, 535, 535,
    113   1.1      mw    /* Depth,           PAL, TX,  TY,    XY,FontX, FontY,    FontData,  FLo,  Fhi */
    114   1.9  chopps           4, NCRStdPalette, 80,  64,  5120,    8,     8, kernel_font_8x8,   32,  255};
    115   1.1      mw 
    116   1.4      mw  struct MonDef MON_640_480_62_G  = { 50000000,   4,  640, 480,  161,171,184,196,195, 481, 484, 492, 502, 502,
    117   1.9  chopps           8, NCRStdPalette,640,480,  5120,    8,     8, kernel_font_8x8,   32,  255};
    118   1.4      mw /* Enter higher values here ^   ^ for panning! */
    119   1.4      mw 
    120   1.1      mw /* horizontal 38kHz */
    121   1.1      mw 
    122   1.1      mw    struct MonDef MON_768_600_60  = { 75000000,  28,  768, 600,   97, 99,107,120,117, 601, 615, 625, 638, 638,
    123   1.9  chopps           4, NCRStdPalette, 96,  75,  7200,    8,     8, kernel_font_8x8,   32,  255};
    124   1.1      mw 
    125   1.1      mw /* horizontal 64kHz */
    126   1.1      mw 
    127   1.1      mw    struct MonDef MON_768_600_80  = { 50000000, 24,  768, 600,   97,104,112,122,119, 601, 606, 616, 628, 628,
    128   1.9  chopps           4, NCRStdPalette, 96,  75,  7200,    8,     8, kernel_font_8x8,   32,  255};
    129   1.1      mw 
    130   1.1      mw    struct MonDef MON_1024_768_80 = { 90000000, 24, 1024, 768,  129,130,141,172,169, 769, 770, 783, 804, 804,
    131   1.9  chopps           4, NCRStdPalette,128,  96, 12288,    8,     8, kernel_font_8x8,   32,  255};
    132   1.4      mw 
    133   1.4      mw /*                                     FQ     FLG    MW   MH   HBS HSS HSE HBE  HT  VBS  VSS  VSE  VBE   VT  */
    134   1.4      mw  struct MonDef MON_1024_768_80_G = { 90000000, 0,  1024, 768,  257,258,280,344,343, 769, 770, 783, 804, 804,
    135   1.9  chopps           8, NCRStdPalette, 1024, 768, 12288,    8,     8, kernel_font_8x8,   32,  255};
    136   1.1      mw 
    137   1.1      mw    struct MonDef MON_1024_1024_59= { 90000000, 24, 1024,1024,  129,130,141,173,170,1025,1059,1076,1087,1087,
    138   1.9  chopps           4, NCRStdPalette,128, 128, 16384,    8,     8, kernel_font_8x8,   32,  255};
    139   1.1      mw 
    140   1.1      mw /* WARNING: THE FOLLOWING MONITOR MODES EXCEED THE 90-MHz LIMIT THE PROCESSOR
    141   1.1      mw             HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
    142   1.1      mw             MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)!     */
    143   1.1      mw 
    144   1.1      mw    struct MonDef MON_1280_1024_60= {110000000,  24, 1280,1024,  161,162,176,211,208,1025,1026,1043,1073,1073,
    145   1.9  chopps           4, NCRStdPalette,160, 128, 20480,    8,     8, kernel_font_8x8,   32,  255};
    146   1.1      mw 
    147   1.4      mw  struct MonDef MON_1280_1024_60_G= {110000000,   0, 1280,1024,  321,322,349,422,421,1025,1026,1043,1073,1073,
    148   1.9  chopps           8, NCRStdPalette,1280,1024, 20480,    8,     8, kernel_font_8x8,   32,  255};
    149   1.4      mw 
    150   1.1      mw /* horizontal 75kHz */
    151   1.1      mw 
    152   1.1      mw    struct MonDef MON_1280_1024_69= {120000000,  24, 1280,1024,  161,162,175,200,197,1025,1026,1043,1073,1073,
    153   1.9  chopps           4, NCRStdPalette,160, 128, 20480,    8,     8, kernel_font_8x8,   32,  255};
    154   1.1      mw 
    155   1.1      mw #else
    156   1.1      mw 
    157   1.1      mw struct MonDef monitor_defs[] = {
    158   1.1      mw /* horizontal 31.5 kHz */
    159   1.1      mw 
    160   1.1      mw    { 50000000,  28,  640, 512,   81, 86, 93, 98, 95, 513, 513, 521, 535, 535,
    161   1.9  chopps           4, NCRStdPalette, 80,  64,  5120,    8,     8, kernel_font_8x8,   32,  255},
    162   1.1      mw 
    163   1.1      mw /* horizontal 38kHz */
    164   1.1      mw 
    165   1.1      mw    { 75000000,  28,  768, 600,   97, 99,107,120,117, 601, 615, 625, 638, 638,
    166   1.9  chopps           4, NCRStdPalette, 96,  75,  7200,    8,     8, kernel_font_8x8,   32,  255},
    167   1.1      mw 
    168   1.1      mw /* horizontal 64kHz */
    169   1.1      mw 
    170   1.1      mw    { 50000000, 24,  768, 600,   97,104,112,122,119, 601, 606, 616, 628, 628,
    171   1.9  chopps           4, NCRStdPalette, 96,  75,  7200,    8,     8, kernel_font_8x8,   32,  255},
    172   1.4      mw 
    173   1.1      mw    { 90000000, 24, 1024, 768,  129,130,141,172,169, 769, 770, 783, 804, 804,
    174   1.9  chopps           4, NCRStdPalette,128,  96, 12288,    8,     8, kernel_font_8x8,   32,  255},
    175   1.1      mw 
    176   1.4      mw    /* GFX modes */
    177   1.2      mw 
    178   1.4      mw /* horizontal 31.5 kHz */
    179   1.2      mw 
    180   1.4      mw    { 50000000,   4,  640, 480,  161,171,184,196,195, 481, 484, 492, 502, 502,
    181   1.9  chopps           8, NCRStdPalette,640, 480,  5120,    8,     8, kernel_font_8x8,   32,  255},
    182   1.2      mw 
    183   1.4      mw /* horizontal 64kHz */
    184   1.2      mw 
    185   1.4      mw    { 90000000, 0,  1024, 768,  257,258,280,344,343, 769, 770, 783, 804, 804,
    186   1.9  chopps           8, NCRStdPalette, 1024, 768, 12288,    8,     8, kernel_font_8x8,   32,  255},
    187   1.1      mw 
    188   1.1      mw /* WARNING: THE FOLLOWING MONITOR MODES EXCEED THE 90-MHz LIMIT THE PROCESSOR
    189   1.1      mw             HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
    190   1.1      mw             MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)!     */
    191   1.1      mw 
    192   1.4      mw    {110000000,   0, 1280,1024,  321,322,349,422,421,1025,1026,1043,1073,1073,
    193   1.9  chopps           8, NCRStdPalette,1280,1024, 20480,    8,     8, kernel_font_8x8,   32,  255},
    194   1.1      mw };
    195   1.1      mw 
    196   1.1      mw static const char *monitor_descr[] = {
    197   1.1      mw   "80x64 (640x512) 31.5kHz",
    198   1.1      mw   "96x75 (768x600) 38kHz",
    199   1.1      mw   "96x75 (768x600) 64kHz",
    200   1.1      mw   "128x96 (1024x768) 64kHz",
    201   1.4      mw 
    202   1.4      mw   "GFX (640x480) 31.5kHz",
    203   1.4      mw   "GFX (1024x768) 64kHz",
    204   1.4      mw   "GFX (1280x1024) 64kHz ***EXCEEDS CHIP LIMIT!!!***",
    205   1.1      mw };
    206   1.1      mw 
    207   1.1      mw int retina_mon_max = sizeof (monitor_defs)/sizeof (monitor_defs[0]);
    208   1.1      mw 
    209   1.1      mw /* patchable */
    210  1.17  chopps int retina_default_mon = 0;
    211  1.17  chopps int retina_default_gfx = 4;
    212   1.1      mw 
    213   1.1      mw #endif
    214   1.1      mw 
    215   1.1      mw 
    216   1.1      mw static struct MonDef *current_mon;
    217   1.1      mw 
    218   1.1      mw /* -------------- START OF CODE -------------- */
    219   1.1      mw 
    220   1.1      mw 
    221   1.1      mw static const long FQTab[16] =
    222   1.1      mw { 25175000,  28322000,  36000000,  65000000,
    223   1.1      mw   44900000,  50000000,  80000000,  75000000,
    224   1.1      mw   56644000,  63000000,  72000000, 130000000,
    225   1.1      mw   90000000, 100000000, 110000000, 120000000 };
    226   1.1      mw 
    227   1.1      mw 
    228   1.1      mw /*--------------------------------------------------*/
    229   1.1      mw /*--------------------------------------------------*/
    230   1.1      mw 
    231   1.1      mw #if 0
    232   1.1      mw static struct MonDef *default_monitor = &DEFAULT_MONDEF;
    233   1.1      mw #endif
    234   1.1      mw 
    235  1.11  chopps /*
    236  1.11  chopps  * used to query the retina to see if its alive (?)
    237  1.11  chopps  */
    238  1.11  chopps int
    239  1.11  chopps retina_alive(mdp)
    240  1.11  chopps 	struct MonDef *mdp;
    241  1.11  chopps {
    242  1.11  chopps 	short clksel;
    243  1.11  chopps 
    244  1.11  chopps 	for (clksel = 15; clksel; clksel--) {
    245  1.11  chopps 		if (FQTab[clksel] == mdp->FQ)
    246  1.11  chopps 			break;
    247  1.11  chopps 	}
    248  1.11  chopps 	if (clksel < 0)
    249  1.11  chopps 		return(0);
    250  1.11  chopps 	if (mdp->DEP != 4)
    251  1.11  chopps 		return(1);
    252  1.11  chopps 	if (mdp->FX == 4 || (mdp->FX >= 7 && mdp->FX <= 16))
    253  1.11  chopps 		return(1);
    254  1.11  chopps 	return(0);
    255  1.11  chopps }
    256   1.1      mw 
    257  1.11  chopps static int
    258  1.11  chopps rt_load_mon(gp, md)
    259  1.11  chopps 	struct grf_softc *gp;
    260  1.11  chopps 	struct MonDef *md;
    261   1.1      mw {
    262   1.1      mw 	struct grfinfo *gi = &gp->g_display;
    263   1.1      mw 	volatile unsigned char *ba;
    264   1.1      mw 	volatile unsigned char *fb;
    265   1.1      mw 	short FW, clksel, HDE, VDE;
    266   1.1      mw 
    267   1.1      mw 	for (clksel = 15; clksel; clksel--) {
    268   1.1      mw 		if (FQTab[clksel] == md->FQ) break;
    269   1.1      mw 	}
    270  1.11  chopps 	if (clksel < 0)
    271  1.11  chopps 		return(0);
    272   1.1      mw 
    273   1.1      mw 	ba = gp->g_regkva;;
    274   1.1      mw 	fb = gp->g_fbkva;
    275   1.4      mw 
    276   1.4      mw 	FW = 0;
    277   1.4      mw 	if (md->DEP == 4) {
    278   1.4      mw 		switch (md->FX) {
    279   1.4      mw 		case 4:
    280   1.4      mw 			FW = 0;
    281   1.4      mw 			break;
    282   1.4      mw 		case 7:
    283   1.4      mw 			FW = 1;
    284   1.4      mw 			break;
    285   1.4      mw 		case 8:
    286   1.4      mw 			FW = 2;
    287   1.4      mw 			break;
    288   1.4      mw 		case 9:
    289   1.4      mw 			FW = 3;
    290   1.4      mw 			break;
    291   1.4      mw 		case 10:
    292   1.4      mw 			FW = 4;
    293   1.4      mw 			break;
    294   1.4      mw 		case 11:
    295   1.4      mw 			FW = 5;
    296   1.4      mw 			break;
    297   1.4      mw 		case 12:
    298   1.4      mw 			FW = 6;
    299   1.4      mw 			break;
    300   1.4      mw 		case 13:
    301   1.4      mw 			FW = 7;
    302   1.4      mw 			break;
    303   1.4      mw 		case 14:
    304   1.4      mw 			FW = 8;
    305   1.4      mw 			break;
    306   1.4      mw 		case 15:
    307   1.4      mw 			FW = 9;
    308   1.4      mw 			break;
    309   1.4      mw 		case 16:
    310   1.4      mw 			FW = 11;
    311   1.4      mw 			break;
    312   1.4      mw 		default:
    313  1.11  chopps 			return(0);
    314   1.4      mw 			break;
    315   1.4      mw 		};
    316   1.4      mw 	}
    317   1.1      mw 
    318   1.4      mw         if (md->DEP == 4) HDE = (md->MW+md->FX-1)/md->FX;
    319   1.4      mw         else              HDE = (md->MW+3)/4;
    320   1.1      mw 	VDE = md->MH-1;
    321   1.1      mw 
    322   1.1      mw 	/* hmm... */
    323   1.1      mw 	fb[0x8000] = 0;
    324   1.1      mw 
    325   1.2      mw 		/* enable extension registers */
    326   1.2      mw 	WSeq (ba, SEQ_ID_EXTENDED_ENABLE,	0x05);
    327   1.2      mw 
    328   1.2      mw #if 0
    329   1.1      mw 	/* program the clock oscillator */
    330   1.1      mw 	vgaw (ba, GREG_MISC_OUTPUT_W, 0xe3 | ((clksel & 3) * 0x04));
    331   1.1      mw 	vgaw (ba, GREG_FEATURE_CONTROL_W, 0x00);
    332   1.1      mw 
    333   1.1      mw 	/* XXXX according to the NCR specs, this register should be set to 1
    334   1.1      mw 	   XXXX before doing the MISC_OUTPUT setting and CLOCKING_MODE
    335   1.1      mw 	   XXXX setting. */
    336   1.1      mw 	WSeq (ba, SEQ_ID_RESET, 		0x03);
    337   1.1      mw 
    338   1.1      mw 	WSeq (ba, SEQ_ID_CLOCKING_MODE, 	0x01 | ((md->FLG & MDF_CLKDIV2)/ MDF_CLKDIV2 * 8));
    339   1.1      mw 	WSeq (ba, SEQ_ID_MAP_MASK, 		0x0f);
    340   1.1      mw 	WSeq (ba, SEQ_ID_CHAR_MAP_SELECT, 	0x00);
    341   1.1      mw 		/* odd/even write select + extended memory */
    342   1.1      mw 	WSeq (ba, SEQ_ID_MEMORY_MODE, 	0x06);
    343   1.1      mw 	/* XXXX I think this order of setting RESET is wrong... */
    344   1.1      mw 	WSeq (ba, SEQ_ID_RESET, 		0x01);
    345   1.1      mw 	WSeq (ba, SEQ_ID_RESET, 		0x03);
    346   1.2      mw #else
    347   1.2      mw 	WSeq (ba, SEQ_ID_RESET, 		0x01);
    348   1.2      mw 
    349   1.2      mw 		/* set font width + rest of clocks */
    350   1.2      mw 	WSeq (ba, SEQ_ID_EXT_CLOCK_MODE,	0x30 | (FW & 0x0f) | ((clksel & 4) / 4 * 0x40) );
    351   1.2      mw 		/* another clock bit, plus hw stuff */
    352   1.2      mw 	WSeq (ba, SEQ_ID_MISC_FEATURE_SEL,	0xf4 | (clksel & 8) );
    353   1.2      mw 
    354   1.2      mw 	/* program the clock oscillator */
    355   1.2      mw 	vgaw (ba, GREG_MISC_OUTPUT_W, 		0xe3 | ((clksel & 3) * 0x04));
    356   1.2      mw 	vgaw (ba, GREG_FEATURE_CONTROL_W, 	0x00);
    357   1.2      mw 
    358   1.2      mw 	WSeq (ba, SEQ_ID_CLOCKING_MODE, 	0x01 | ((md->FLG & MDF_CLKDIV2)/ MDF_CLKDIV2 * 8));
    359   1.2      mw 	WSeq (ba, SEQ_ID_MAP_MASK, 		0x0f);
    360   1.2      mw 	WSeq (ba, SEQ_ID_CHAR_MAP_SELECT, 	0x00);
    361   1.2      mw 		/* odd/even write select + extended memory */
    362   1.2      mw 	WSeq (ba, SEQ_ID_MEMORY_MODE, 		0x06);
    363   1.2      mw 	WSeq (ba, SEQ_ID_RESET, 		0x03);
    364   1.2      mw #endif
    365   1.1      mw 
    366   1.1      mw 		/* monochrome cursor */
    367   1.1      mw 	WSeq (ba, SEQ_ID_CURSOR_CONTROL,	0x00);
    368   1.1      mw 		/* bank0 */
    369   1.1      mw 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI,	0x00);
    370   1.1      mw 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO,	0x00);
    371   1.4      mw 	WSeq (ba, SEQ_ID_DISP_OFF_HI , 		0x00);
    372   1.4      mw 	WSeq (ba, SEQ_ID_DISP_OFF_LO , 		0x00);
    373   1.1      mw 		/* bank0 */
    374   1.1      mw 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI,	0x00);
    375   1.1      mw 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO,	0x00);
    376   1.1      mw 		/* 1M-chips + ena SEC + ena EMem + rw PrimA0/rw Sec/B0 */
    377   1.1      mw 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,	0x3 | 0x4 | 0x10 | 0x40);
    378   1.2      mw #if 0
    379   1.1      mw 		/* set font width + rest of clocks */
    380   1.1      mw 	WSeq (ba, SEQ_ID_EXT_CLOCK_MODE,	0x30 | (FW & 0x0f) | ((clksel & 4) / 4 * 0x40) );
    381   1.2      mw #endif
    382   1.4      mw 	if (md->DEP == 4) {
    383   1.4      mw 			/* no ext-chain4 + no host-addr-bit-16 */
    384   1.4      mw 		WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR,	0x00);
    385   1.4      mw 			/* no packed/nibble + no 256bit gfx format */
    386   1.4      mw 		WSeq (ba, SEQ_ID_EXT_PIXEL_CNTL,	0x00);
    387   1.4      mw 	}
    388   1.4      mw 	else {
    389   1.4      mw 		WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR,	0x02);
    390   1.4      mw 			/* 256bit gfx format */
    391   1.4      mw 		WSeq (ba, SEQ_ID_EXT_PIXEL_CNTL,	0x01);
    392   1.4      mw 	}
    393   1.1      mw 		/* AT-interface */
    394   1.1      mw 	WSeq (ba, SEQ_ID_BUS_WIDTH_FEEDB,	0x06);
    395   1.1      mw 		/* see fg/bg color expansion */
    396   1.1      mw 	WSeq (ba, SEQ_ID_COLOR_EXP_WFG,		0x01);
    397   1.1      mw 	WSeq (ba, SEQ_ID_COLOR_EXP_WBG,		0x00);
    398   1.1      mw 	WSeq (ba, SEQ_ID_EXT_RW_CONTROL,	0x00);
    399   1.2      mw #if 0
    400   1.1      mw 		/* another clock bit, plus hw stuff */
    401   1.1      mw 	WSeq (ba, SEQ_ID_MISC_FEATURE_SEL,	0xf4 | (clksel & 8) );
    402   1.2      mw #endif
    403   1.1      mw 		/* don't tristate PCLK and PIX */
    404   1.1      mw 	WSeq (ba, SEQ_ID_COLOR_KEY_CNTL,	0x40 );
    405   1.1      mw 		/* reset CRC circuit */
    406   1.1      mw 	WSeq (ba, SEQ_ID_CRC_CONTROL,		0x00 );
    407   1.1      mw 		/* set RAS/CAS swap */
    408   1.1      mw 	WSeq (ba, SEQ_ID_PERF_SELECT,		0x20);
    409   1.1      mw 
    410   1.1      mw 	WCrt (ba, CRT_ID_END_VER_RETR,		(md->VSE & 0xf ) | 0x20);
    411   1.1      mw 	WCrt (ba, CRT_ID_HOR_TOTAL,		md->HT   & 0xff);
    412   1.1      mw 	WCrt (ba, CRT_ID_HOR_DISP_ENA_END,	(HDE-1)  & 0xff);
    413   1.1      mw 	WCrt (ba, CRT_ID_START_HOR_BLANK,	md->HBS  & 0xff);
    414   1.1      mw 	WCrt (ba, CRT_ID_END_HOR_BLANK,		(md->HBE & 0x1f) | 0x80);
    415   1.1      mw 
    416   1.1      mw 	WCrt (ba, CRT_ID_START_HOR_RETR,	md->HSS  & 0xff);
    417   1.1      mw 	WCrt (ba, CRT_ID_END_HOR_RETR,		(md->HSE & 0x1f) | ((md->HBE & 0x20)/ 0x20 * 0x80));
    418   1.1      mw 	WCrt (ba, CRT_ID_VER_TOTAL,		(md->VT  & 0xff));
    419   1.1      mw 	WCrt (ba, CRT_ID_OVERFLOW,		(( (md->VSS  & 0x200) / 0x200 * 0x80)
    420   1.1      mw 						 | ((VDE     & 0x200) / 0x200 * 0x40)
    421   1.1      mw 						 | ((md->VT  & 0x200) / 0x200 * 0x20)
    422   1.1      mw 						 | 				0x10
    423   1.1      mw 						 | ((md->VBS & 0x100) / 0x100 * 8   )
    424   1.1      mw 						 | ((md->VSS & 0x100) / 0x100 * 4   )
    425   1.1      mw 						 | ((VDE     & 0x100) / 0x100 * 2   )
    426   1.1      mw 						 | ((md->VT  & 0x100) / 0x100       )));
    427   1.1      mw 	WCrt (ba, CRT_ID_PRESET_ROW_SCAN,	0x00);
    428   1.1      mw 
    429   1.4      mw 	if (md->DEP == 4) {
    430   1.4      mw 		WCrt (ba, CRT_ID_MAX_SCAN_LINE, 	((  (md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
    431   1.4      mw 							 | 				   0x40
    432   1.4      mw 							 | ((md->VBS & 0x200)/0x200	 * 0x20)
    433   1.4      mw 							 | ((md->FY-1) 			 & 0x1f)));
    434   1.4      mw 	}
    435   1.4      mw 	else {
    436   1.4      mw 		WCrt (ba, CRT_ID_MAX_SCAN_LINE, 	((  (md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
    437   1.4      mw 							 | 				   0x40
    438   1.4      mw 							 | ((md->VBS & 0x200)/0x200	 * 0x20)
    439   1.4      mw 							 | (0	 			 & 0x1f)));
    440   1.4      mw 	}
    441   1.1      mw 
    442   1.1      mw 	WCrt (ba, CRT_ID_CURSOR_START,		(md->FY & 0x1f) - 2);
    443   1.1      mw 	WCrt (ba, CRT_ID_CURSOR_END,		(md->FY & 0x1f) - 1);
    444   1.1      mw 
    445   1.1      mw 	WCrt (ba, CRT_ID_START_ADDR_HIGH,	0x00);
    446   1.1      mw 	WCrt (ba, CRT_ID_START_ADDR_LOW,	0x00);
    447   1.1      mw 
    448   1.1      mw 	WCrt (ba, CRT_ID_CURSOR_LOC_HIGH,	0x00);
    449   1.1      mw 	WCrt (ba, CRT_ID_CURSOR_LOC_LOW,	0x00);
    450   1.1      mw 
    451   1.1      mw 	WCrt (ba, CRT_ID_START_VER_RETR,	md->VSS    & 0xff);
    452   1.1      mw 	WCrt (ba, CRT_ID_END_VER_RETR,		(md->VSE   & 0x0f) | 0x80 | 0x20);
    453   1.1      mw 	WCrt (ba, CRT_ID_VER_DISP_ENA_END,	VDE        & 0xff);
    454   1.4      mw 	if (md->DEP == 4)
    455   1.4      mw 		WCrt (ba, CRT_ID_OFFSET,	(HDE / 2)  & 0xff);
    456   1.4      mw 	else
    457   1.4      mw 		WCrt (ba, CRT_ID_OFFSET,	(md->TX / 8)  & 0xff);
    458   1.4      mw 
    459   1.1      mw 	WCrt (ba, CRT_ID_UNDERLINE_LOC,		(md->FY-1) & 0x1f);
    460   1.1      mw 	WCrt (ba, CRT_ID_START_VER_BLANK,	md->VBS    & 0xff);
    461   1.1      mw 	WCrt (ba, CRT_ID_END_VER_BLANK,		md->VBE    & 0xff);
    462   1.1      mw 		/* byte mode + wrap + select row scan counter + cms */
    463   1.1      mw 	WCrt (ba, CRT_ID_MODE_CONTROL,		0xe3);
    464   1.1      mw 	WCrt (ba, CRT_ID_LINE_COMPARE,		0xff);
    465   1.1      mw 
    466   1.1      mw 		/* enable extended end bits + those bits */
    467   1.1      mw 	WCrt (ba, CRT_ID_EXT_HOR_TIMING1,	(           				 0x20
    468   1.1      mw 						 | ((md->FLG & MDF_LACE)  / MDF_LACE   * 0x10)
    469   1.1      mw 						 | ((md->HT  & 0x100) / 0x100          * 0x01)
    470   1.1      mw 						 | (((HDE-1) & 0x100) / 0x100 	       * 0x02)
    471   1.1      mw 						 | ((md->HBS & 0x100) / 0x100 	       * 0x04)
    472   1.1      mw 						 | ((md->HSS & 0x100) / 0x100 	       * 0x08)));
    473   1.1      mw 
    474   1.4      mw 	if (md->DEP == 4)
    475   1.4      mw 		WCrt (ba, CRT_ID_EXT_START_ADDR,	(((HDE / 2) & 0x100)/0x100 * 16));
    476   1.4      mw 	else
    477   1.4      mw 		WCrt (ba, CRT_ID_EXT_START_ADDR,	(((md->TX / 8) & 0x100)/0x100 * 16));
    478   1.1      mw 
    479   1.1      mw 	WCrt (ba, CRT_ID_EXT_HOR_TIMING2, 	(  ((md->HT  & 0x200)/ 0x200  	       * 0x01)
    480   1.1      mw 						 | (((HDE-1) & 0x200)/ 0x200 	       * 0x02)
    481   1.1      mw 						 | ((md->HBS & 0x200)/ 0x200 	       * 0x04)
    482   1.1      mw 						 | ((md->HSS & 0x200)/ 0x200 	       * 0x08)
    483   1.1      mw 						 | ((md->HBE & 0xc0) / 0x40  	       * 0x10)
    484   1.1      mw 						 | ((md->HSE & 0x60) / 0x20  	       * 0x40)));
    485   1.1      mw 
    486   1.1      mw 	WCrt (ba, CRT_ID_EXT_VER_TIMING,	(  ((md->VSE & 0x10) / 0x10  	       * 0x80)
    487   1.1      mw 						 | ((md->VBE & 0x300)/ 0x100 	       * 0x20)
    488   1.1      mw 						 |				         0x10
    489   1.1      mw 						 | ((md->VSS & 0x400)/ 0x400 	       * 0x08)
    490   1.1      mw 						 | ((md->VBS & 0x400)/ 0x400 	       * 0x04)
    491   1.1      mw 						 | ((VDE     & 0x400)/ 0x400 	       * 0x02)
    492   1.1      mw 						 | ((md->VT  & 0x400)/ 0x400           * 0x01)));
    493   1.1      mw 
    494   1.1      mw 	WGfx (ba, GCT_ID_SET_RESET,		0x00);
    495   1.1      mw 	WGfx (ba, GCT_ID_ENABLE_SET_RESET,	0x00);
    496   1.1      mw 	WGfx (ba, GCT_ID_COLOR_COMPARE,		0x00);
    497   1.1      mw 	WGfx (ba, GCT_ID_DATA_ROTATE,		0x00);
    498   1.1      mw 	WGfx (ba, GCT_ID_READ_MAP_SELECT,	0x00);
    499   1.4      mw 	WGfx (ba, GCT_ID_GRAPHICS_MODE,		0x00);
    500   1.4      mw 	if (md->DEP == 4)
    501   1.4      mw 		WGfx (ba, GCT_ID_MISC,			0x04);
    502   1.4      mw 	else
    503   1.4      mw 		WGfx (ba, GCT_ID_MISC,			0x05);
    504   1.1      mw 	WGfx (ba, GCT_ID_COLOR_XCARE,		0xff);
    505   1.1      mw 	WGfx (ba, GCT_ID_BITMASK,		0xff);
    506   1.1      mw 
    507   1.1      mw 	/* reset the Attribute Controller flipflop */
    508   1.1      mw 	vgar (ba, GREG_STATUS1_R);
    509   1.1      mw 	WAttr (ba, ACT_ID_PALETTE0,		0x00);
    510   1.1      mw 	WAttr (ba, ACT_ID_PALETTE1,		0x01);
    511   1.1      mw 	WAttr (ba, ACT_ID_PALETTE2,		0x02);
    512   1.1      mw 	WAttr (ba, ACT_ID_PALETTE3,		0x03);
    513   1.1      mw 	WAttr (ba, ACT_ID_PALETTE4,		0x04);
    514   1.1      mw 	WAttr (ba, ACT_ID_PALETTE5,		0x05);
    515   1.1      mw 	WAttr (ba, ACT_ID_PALETTE6,		0x06);
    516   1.1      mw 	WAttr (ba, ACT_ID_PALETTE7,		0x07);
    517   1.1      mw 	WAttr (ba, ACT_ID_PALETTE8,		0x08);
    518   1.1      mw 	WAttr (ba, ACT_ID_PALETTE9,		0x09);
    519   1.1      mw 	WAttr (ba, ACT_ID_PALETTE10,		0x0a);
    520   1.1      mw 	WAttr (ba, ACT_ID_PALETTE11,		0x0b);
    521   1.1      mw 	WAttr (ba, ACT_ID_PALETTE12,		0x0c);
    522   1.1      mw 	WAttr (ba, ACT_ID_PALETTE13,		0x0d);
    523   1.1      mw 	WAttr (ba, ACT_ID_PALETTE14,		0x0e);
    524   1.1      mw 	WAttr (ba, ACT_ID_PALETTE15,		0x0f);
    525   1.1      mw 
    526   1.1      mw 	vgar (ba, GREG_STATUS1_R);
    527   1.4      mw 	if (md->DEP == 4)
    528   1.4      mw 		WAttr (ba, ACT_ID_ATTR_MODE_CNTL,	0x08);
    529   1.4      mw 	else
    530   1.4      mw 		WAttr (ba, ACT_ID_ATTR_MODE_CNTL,	0x09);
    531   1.1      mw 
    532   1.1      mw 	WAttr (ba, ACT_ID_OVERSCAN_COLOR,	0x00);
    533   1.1      mw 	WAttr (ba, ACT_ID_COLOR_PLANE_ENA,	0x0f);
    534   1.1      mw 	WAttr (ba, ACT_ID_HOR_PEL_PANNING,	0x00);
    535   1.1      mw 	WAttr (ba, ACT_ID_COLOR_SELECT,	0x00);
    536   1.1      mw 
    537   1.1      mw 	vgar (ba, GREG_STATUS1_R);
    538   1.1      mw 		/* I have *NO* idea what strobing reg-0x20 might do... */
    539   1.1      mw 	vgaw (ba, ACT_ADDRESS_W, 0x20);
    540   1.1      mw 
    541   1.4      mw 	if (md->DEP == 4)
    542   1.4      mw 		WCrt (ba, CRT_ID_MAX_SCAN_LINE,	( ((md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
    543   1.1      mw 						|	                          0x40
    544   1.1      mw 						| ((md->VBS & 0x200)/0x200	* 0x20)
    545   1.4      mw 						| ((md->FY-1) 			& 0x1f)));
    546   1.4      mw 	else
    547   1.4      mw 		WCrt (ba, CRT_ID_MAX_SCAN_LINE,	( ((md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
    548   1.4      mw 						|	                          0x40
    549   1.4      mw 						| ((md->VBS & 0x200)/0x200	* 0x20)
    550   1.4      mw 						| (0	 			& 0x1f)));
    551   1.4      mw 
    552   1.1      mw 
    553   1.1      mw 	/* not it's time for guessing... */
    554   1.1      mw 
    555   1.1      mw 	vgaw (ba, VDAC_REG_D, 	   0x02);
    556   1.1      mw 
    557   1.1      mw 		/* if this does what I think it does, it selects DAC
    558   1.1      mw 		   register 0, and writes the palette in subsequent
    559   1.1      mw 		   registers, thus it works similar to the WD33C93
    560   1.1      mw 		   select/data mechanism */
    561   1.1      mw 	vgaw (ba, VDAC_REG_SELECT, 0x00);
    562   1.1      mw 
    563   1.1      mw 	{
    564   1.1      mw 
    565   1.1      mw 		short x = 15;
    566   1.1      mw 		const unsigned char * col = md->PAL;
    567   1.1      mw 		do {
    568   1.1      mw 
    569   1.1      mw 			vgaw (ba, VDAC_REG_DATA, *col++);
    570   1.1      mw 			vgaw (ba, VDAC_REG_DATA, *col++);
    571   1.1      mw 			vgaw (ba, VDAC_REG_DATA, *col++);
    572   1.1      mw 
    573   1.1      mw 
    574   1.1      mw 		} while (x--);
    575   1.4      mw 
    576   1.4      mw 		if (md->DEP != 4) {
    577   1.4      mw 			short x = 256-17;
    578   1.4      mw 			unsigned char col = 16;
    579   1.4      mw 			do {
    580   1.4      mw 
    581   1.4      mw 				vgaw(ba, VDAC_REG_DATA, col);
    582   1.4      mw 				vgaw(ba, VDAC_REG_DATA, col);
    583   1.4      mw 				vgaw(ba, VDAC_REG_DATA, col);
    584   1.4      mw 				col++;
    585   1.4      mw 
    586   1.4      mw 			} while (x--);
    587   1.4      mw 		}
    588   1.1      mw 	}
    589   1.1      mw 
    590   1.1      mw 
    591   1.1      mw 	/* now load the font into maps 2 (and 3 for fonts wider than 8 pixels) */
    592   1.4      mw 	if (md->DEP == 4) {
    593   1.1      mw 
    594   1.1      mw 		/* first set the whole font memory to a test-pattern, so we
    595   1.1      mw 		   can see if something that shouldn't be drawn IS drawn.. */
    596   1.1      mw 		{
    597   1.5  chopps 			volatile unsigned char * c = fb;
    598   1.1      mw 			long x;
    599   1.1      mw 			Map(2);
    600   1.1      mw 
    601   1.1      mw 			for (x = 0; x < 65536; x++) {
    602   1.1      mw 				*c++ = (x & 1)? 0xaa : 0x55;
    603   1.1      mw 			}
    604   1.1      mw 		}
    605   1.1      mw 
    606   1.1      mw 		{
    607   1.5  chopps 			volatile unsigned char * c = fb;
    608   1.1      mw 			long x;
    609   1.1      mw 			Map(3);
    610   1.1      mw 
    611   1.1      mw 			for (x = 0; x < 65536; x++) {
    612   1.1      mw 				*c++ = (x & 1)? 0xaa : 0x55;
    613   1.1      mw 			}
    614   1.1      mw 		}
    615   1.1      mw 
    616   1.1      mw 		{
    617   1.1      mw 		  /* ok, now position at first defined character, and
    618   1.1      mw 		     copy over the images */
    619   1.5  chopps 		  volatile unsigned char * c = fb + md->FLo * 32;
    620   1.1      mw 		  const unsigned char * f = md->FData;
    621   1.1      mw 		  unsigned short z;
    622   1.1      mw 
    623   1.1      mw 		  Map(2);
    624   1.1      mw 		  for (z = md->FLo; z <= md->FHi; z++) {
    625   1.1      mw 
    626   1.1      mw 			short y = md->FY-1;
    627   1.1      mw 			if (md->FX > 8){
    628   1.1      mw 				do {
    629   1.1      mw 					*c++ = *f;
    630   1.1      mw 					f += 2;
    631   1.1      mw 				} while (y--);
    632   1.1      mw 			}
    633   1.1      mw 			else {
    634   1.1      mw 				do {
    635   1.1      mw 					*c++ = *f++;
    636   1.1      mw 				} while (y--);
    637   1.1      mw 			}
    638   1.1      mw 
    639   1.1      mw 			c += 32-md->FY;
    640   1.1      mw 
    641   1.1      mw 		  }
    642   1.1      mw 
    643   1.1      mw 		  if (md->FX > 8) {
    644   1.1      mw 			unsigned short z;
    645   1.1      mw 
    646   1.1      mw 			Map(3);
    647   1.1      mw 			c = fb + md->FLo*32;
    648   1.1      mw 			f = md->FData+1;
    649   1.1      mw 			for (z = md->FLo; z <= md->FHi; z++) {
    650   1.1      mw 
    651   1.1      mw 				short y = md->FY-1;
    652   1.1      mw 				do {
    653   1.1      mw 					*c++ = *f;
    654   1.1      mw 					f += 2;
    655   1.1      mw 				} while (y--);
    656   1.1      mw 
    657   1.1      mw 				c += 32-md->FY;
    658   1.1      mw 
    659   1.1      mw 			}
    660   1.1      mw 		  }
    661   1.1      mw 		}
    662   1.1      mw 
    663   1.1      mw 	}
    664   1.1      mw 
    665   1.1      mw 		/* select map 0 */
    666   1.1      mw 	WGfx (ba, GCT_ID_READ_MAP_SELECT,	0);
    667   1.4      mw 	if (md->DEP == 4)
    668   1.4      mw 			/* allow writes into maps 0 and 1 */
    669   1.4      mw 		WSeq (ba, SEQ_ID_MAP_MASK,		3);
    670   1.4      mw 	else
    671   1.4      mw 			/* allow writes into all maps */
    672   1.4      mw 		WSeq (ba, SEQ_ID_MAP_MASK,		0x0f);
    673   1.4      mw 
    674   1.1      mw 		/* select extended chain4 addressing:
    675   1.1      mw 		    !A0/!A1	map 0	character to be displayed
    676   1.1      mw 		    !A1/ A1	map 1	attribute of that character
    677   1.1      mw 		     A0/!A1	map 2	not used (masked out, ignored)
    678   1.1      mw 		     A0/ A1 	map 3	not used (masked out, ignored) */
    679   1.1      mw 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR,	RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    680   1.1      mw 
    681   1.4      mw 	if (md->DEP == 4) {
    682   1.1      mw 		/* position in display memory */
    683   1.1      mw 		unsigned short * c = (unsigned short *) fb;
    684   1.1      mw 
    685   1.1      mw 		/* fill with blank, white on black */
    686   1.1      mw 		const unsigned short fill_val = 0x2010;
    687   1.1      mw 		short x = md->XY;
    688   1.1      mw 		do {
    689   1.1      mw 			*c = fill_val;
    690  1.11  chopps 			c += 2; } while (x--);
    691   1.1      mw 
    692   1.1      mw 		/* I won't comment this :-)) */
    693   1.1      mw 		c = (unsigned short *) fb;
    694   1.1      mw 		c += (md->TX-6)*2;
    695   1.1      mw 		{
    696   1.1      mw 		  unsigned short init_msg[6] = {0x520a, 0x450b, 0x540c, 0x490d, 0x4e0e, 0x410f};
    697   1.1      mw 		  unsigned short * f = init_msg;
    698   1.1      mw 		  x = 5;
    699   1.1      mw 		  do {
    700   1.1      mw 			*c = *f++;
    701   1.1      mw 			c += 2;
    702   1.1      mw 	 	  } while (x--);
    703   1.1      mw 	 	}
    704   1.1      mw 	}
    705   1.4      mw 	else if (md->DEP == 8) {
    706   1.4      mw 		/* could clear the gfx screen here, but that's what the X server does anyway */
    707   1.4      mw 	        ;
    708   1.4      mw 	}
    709   1.1      mw 
    710  1.13  chopps 	gp->g_data	= (caddr_t)md;
    711  1.16  chopps 	gi->gd_regaddr  = (caddr_t)ztwopa(ba);
    712   1.3      mw 	gi->gd_regsize  = 64*1024;
    713   1.1      mw 
    714  1.16  chopps 	gi->gd_fbaddr   = (caddr_t)ztwopa(fb);
    715   1.4      mw #ifdef BANKEDDEVPAGER
    716   1.4      mw 	gi->gd_fbsize	= 4*1024*1024;  /* XXX */
    717   1.4      mw 	gi->gd_bank_size = 64*1024;
    718   1.4      mw #else
    719   1.1      mw 	gi->gd_fbsize   = 64*1024;	/* larger, but that's whats mappable */
    720   1.4      mw #endif
    721   1.1      mw 
    722   1.1      mw 	gi->gd_colors   = 1 << md->DEP;
    723   1.1      mw 	gi->gd_planes   = md->DEP;
    724   1.1      mw 
    725   1.1      mw 	gi->gd_fbwidth  = md->MW;
    726   1.1      mw 	gi->gd_fbheight = md->MH;
    727   1.1      mw 	gi->gd_fbx	= 0;
    728   1.1      mw 	gi->gd_fby	= 0;
    729   1.1      mw 	gi->gd_dwidth   = md->TX * md->FX;
    730   1.1      mw 	gi->gd_dheight  = md->TY * md->FY;
    731   1.1      mw 	gi->gd_dx	= 0;
    732   1.1      mw 	gi->gd_dy	= 0;
    733   1.1      mw 
    734   1.1      mw 	/* initialized, works, return 1 */
    735  1.11  chopps 	return(1);
    736   1.1      mw }
    737   1.1      mw 
    738  1.11  chopps int rt_mode __P((struct grf_softc *, int, void *, int , int));
    739  1.11  chopps 
    740  1.11  chopps void grfrtattach __P((struct device *, struct device *, void *));
    741  1.11  chopps int grfrtprint __P((void *, char *));
    742  1.11  chopps int grfrtmatch __P((struct device *, struct cfdata *, void *));
    743  1.11  chopps 
    744  1.11  chopps struct cfdriver grfrtcd = {
    745  1.11  chopps 	NULL, "grfrt", grfrtmatch, grfrtattach,
    746  1.11  chopps 	DV_DULL, sizeof(struct grf_softc), NULL, 0 };
    747  1.11  chopps 
    748  1.11  chopps /*
    749  1.11  chopps  * only used in console init
    750  1.11  chopps  */
    751  1.11  chopps static struct cfdata *cfdata;
    752  1.11  chopps 
    753  1.11  chopps /*
    754  1.11  chopps  * we make sure to only init things once.  this is somewhat
    755  1.11  chopps  * tricky regarding the console.
    756  1.11  chopps  */
    757  1.11  chopps int
    758  1.11  chopps grfrtmatch(pdp, cfp, auxp)
    759  1.11  chopps 	struct device *pdp;
    760  1.11  chopps 	struct cfdata *cfp;
    761  1.11  chopps 	void *auxp;
    762   1.1      mw {
    763  1.12  chopps #ifdef RETINACONSOLE
    764  1.11  chopps 	static int rtconunit = -1;
    765  1.12  chopps #endif
    766  1.11  chopps 	struct ztwobus_args *zap;
    767  1.11  chopps 
    768  1.11  chopps 	zap = auxp;
    769  1.11  chopps 
    770  1.11  chopps 	/*
    771  1.11  chopps 	 * allow only one retina console
    772  1.11  chopps 	 */
    773  1.12  chopps 	if (amiga_realconfig == 0)
    774  1.12  chopps #ifdef RETINACONSOLE
    775  1.12  chopps 		if (rtconunit != -1)
    776  1.12  chopps #endif
    777  1.12  chopps 			return(0);
    778  1.11  chopps 	/*
    779  1.11  chopps 	 * check that this is a retina board.
    780  1.11  chopps 	 */
    781  1.11  chopps 	if (zap->manid != 18260 || zap->prodid != 6)
    782  1.11  chopps 		return(0);
    783  1.11  chopps 
    784  1.14  chopps #ifdef RETINACONSOLE
    785  1.11  chopps 	if (amiga_realconfig == 0 || rtconunit != cfp->cf_unit) {
    786  1.14  chopps #endif
    787  1.11  chopps 		if ((unsigned)retina_default_mon >= retina_mon_max ||
    788  1.11  chopps 		    monitor_defs[retina_default_mon].DEP == 8)
    789  1.11  chopps 			retina_default_mon = 0;
    790  1.11  chopps 
    791  1.11  chopps 		current_mon = monitor_defs + retina_default_mon;
    792  1.11  chopps 		if (retina_alive(current_mon) == 0)
    793  1.11  chopps 			return(0);
    794  1.14  chopps #ifdef RETINACONSOLE
    795  1.11  chopps 		if (amiga_realconfig == 0) {
    796  1.11  chopps 			rtconunit = cfp->cf_unit;
    797  1.11  chopps 			cfdata = cfp;
    798  1.11  chopps 		}
    799  1.11  chopps 	}
    800  1.14  chopps #endif
    801  1.11  chopps 	return(1);
    802  1.11  chopps }
    803   1.1      mw 
    804  1.11  chopps /*
    805  1.11  chopps  * attach to the grfbus (ztwobus)
    806  1.11  chopps  */
    807  1.11  chopps void
    808  1.11  chopps grfrtattach(pdp, dp, auxp)
    809  1.11  chopps 	struct device *pdp, *dp;
    810  1.11  chopps 	void *auxp;
    811  1.11  chopps {
    812  1.11  chopps 	static struct grf_softc congrf;
    813  1.11  chopps 	static int coninited;
    814  1.11  chopps 	struct ztwobus_args *zap;
    815  1.11  chopps 	struct grf_softc *gp;
    816  1.11  chopps 
    817  1.11  chopps 	zap = auxp;
    818  1.11  chopps 
    819  1.11  chopps 	if (dp == NULL)
    820  1.11  chopps 		gp = &congrf;
    821  1.11  chopps 	else
    822  1.11  chopps 		gp = (struct grf_softc *)dp;
    823  1.11  chopps 
    824  1.11  chopps 	if (dp != NULL && congrf.g_regkva != 0) {
    825  1.11  chopps 		/*
    826  1.11  chopps 		 * we inited earlier just copy the info
    827  1.11  chopps 		 * take care not to copy the device struct though.
    828  1.11  chopps 		 */
    829  1.11  chopps 		bcopy(&congrf.g_display, &gp->g_display,
    830  1.11  chopps 		    (char *)&gp[1] - (char *)&gp->g_display);
    831  1.11  chopps 	} else {
    832  1.11  chopps 		gp->g_regkva = (volatile caddr_t)zap->va;
    833  1.11  chopps 		gp->g_fbkva = (volatile caddr_t)zap->va + 64 * 1024;
    834  1.11  chopps 		gp->g_unit = GRF_RETINAII_UNIT;
    835  1.14  chopps 		gp->g_flags = GF_ALIVE;
    836  1.11  chopps 		gp->g_mode = rt_mode;
    837  1.11  chopps 		gp->g_conpri = grfrt_cnprobe();
    838  1.11  chopps 		grfrt_iteinit(gp);
    839  1.11  chopps 		(void)rt_load_mon(gp, current_mon);
    840  1.11  chopps 	}
    841  1.11  chopps 	if (dp != NULL)
    842  1.11  chopps 		printf("\n");
    843  1.11  chopps 	/*
    844  1.11  chopps 	 * attach grf
    845  1.11  chopps 	 */
    846  1.11  chopps 	amiga_config_found(cfdata, &gp->g_device, gp, grfrtprint);
    847  1.11  chopps }
    848  1.11  chopps 
    849  1.11  chopps int
    850  1.11  chopps grfrtprint(auxp, pnp)
    851  1.11  chopps 	void *auxp;
    852  1.11  chopps 	char *pnp;
    853  1.11  chopps {
    854  1.11  chopps 	if (pnp)
    855  1.11  chopps 		printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
    856  1.11  chopps 			pnp);
    857  1.11  chopps 	return(UNCONF);
    858   1.1      mw }
    859   1.1      mw 
    860   1.1      mw static int
    861   1.1      mw rt_getvmode (gp, vm)
    862   1.1      mw      struct grf_softc *gp;
    863   1.1      mw      struct grfvideo_mode *vm;
    864   1.1      mw {
    865   1.1      mw   struct MonDef *md;
    866   1.1      mw 
    867   1.1      mw   if (vm->mode_num && vm->mode_num > retina_mon_max)
    868   1.1      mw     return EINVAL;
    869   1.1      mw 
    870   1.1      mw   if (! vm->mode_num)
    871   1.1      mw     vm->mode_num = (current_mon - monitor_defs) + 1;
    872   1.1      mw 
    873   1.1      mw   md = monitor_defs + (vm->mode_num - 1);
    874   1.1      mw   strncpy (vm->mode_descr, monitor_descr + (vm->mode_num - 1),
    875   1.1      mw 	   sizeof (vm->mode_descr));
    876   1.1      mw   vm->pixel_clock  = md->FQ;
    877   1.1      mw   vm->disp_width   = md->MW;
    878   1.1      mw   vm->disp_height  = md->MH;
    879   1.1      mw   vm->depth        = md->DEP;
    880   1.1      mw   vm->hblank_start = md->HBS;
    881   1.1      mw   vm->hblank_stop  = md->HBE;
    882   1.1      mw   vm->hsync_start  = md->HSS;
    883   1.1      mw   vm->hsync_stop   = md->HSE;
    884   1.1      mw   vm->htotal       = md->HT;
    885   1.1      mw   vm->vblank_start = md->VBS;
    886   1.1      mw   vm->vblank_stop  = md->VBE;
    887   1.1      mw   vm->vsync_start  = md->VSS;
    888   1.1      mw   vm->vsync_stop   = md->VSE;
    889   1.1      mw   vm->vtotal       = md->VT;
    890   1.1      mw 
    891   1.1      mw   return 0;
    892   1.1      mw }
    893   1.1      mw 
    894   1.1      mw 
    895   1.1      mw static int
    896   1.4      mw rt_setvmode (gp, mode, txtonly)
    897   1.1      mw      struct grf_softc *gp;
    898   1.1      mw      unsigned mode;
    899   1.4      mw      int txtonly;
    900   1.1      mw {
    901   1.1      mw   struct MonDef *md;
    902   1.4      mw   int error;
    903   1.1      mw 
    904   1.1      mw   if (!mode || mode > retina_mon_max)
    905   1.1      mw     return EINVAL;
    906   1.1      mw 
    907   1.4      mw   if (txtonly && monitor_defs[mode-1].DEP == 8)
    908   1.4      mw     return EINVAL;
    909   1.4      mw 
    910   1.1      mw   current_mon = monitor_defs + (mode - 1);
    911   1.4      mw 
    912   1.4      mw   error = rt_load_mon (gp, current_mon) ? 0 : EINVAL;
    913   1.4      mw 
    914   1.4      mw   return error;
    915   1.1      mw }
    916   1.1      mw 
    917   1.1      mw 
    918   1.1      mw /*
    919   1.1      mw  * Change the mode of the display.
    920   1.1      mw  * Return a UNIX error number or 0 for success.
    921   1.1      mw  */
    922  1.11  chopps int
    923   1.4      mw rt_mode(gp, cmd, arg, a2, a3)
    924  1.11  chopps 	struct grf_softc *gp;
    925   1.1      mw 	int cmd;
    926   1.1      mw 	void *arg;
    927   1.4      mw 	int a2, a3;
    928   1.1      mw {
    929   1.1      mw   /* implement these later... */
    930   1.1      mw 
    931   1.1      mw   switch (cmd)
    932   1.1      mw     {
    933   1.1      mw     case GM_GRFON:
    934   1.4      mw       rt_setvmode (gp, retina_default_gfx + 1, 0);
    935   1.1      mw       return 0;
    936   1.1      mw 
    937   1.1      mw     case GM_GRFOFF:
    938   1.4      mw       rt_setvmode (gp, retina_default_mon + 1, 0);
    939   1.1      mw       return 0;
    940   1.1      mw 
    941   1.1      mw     case GM_GRFCONFIG:
    942   1.1      mw       return 0;
    943   1.1      mw 
    944   1.1      mw     case GM_GRFGETVMODE:
    945   1.1      mw       return rt_getvmode (gp, (struct grfvideo_mode *) arg);
    946   1.1      mw 
    947   1.1      mw     case GM_GRFSETVMODE:
    948   1.4      mw       return rt_setvmode (gp, *(unsigned *) arg, 1);
    949   1.1      mw 
    950   1.1      mw     case GM_GRFGETNUMVM:
    951   1.1      mw       *(int *)arg = retina_mon_max;
    952   1.1      mw       return 0;
    953   1.1      mw 
    954   1.4      mw #ifdef BANKEDDEVPAGER
    955   1.4      mw     case GM_GRFGETBANK:
    956   1.4      mw       *(int *)arg = rt_getbank (gp, a2, a3);
    957   1.4      mw       return 0;
    958   1.4      mw 
    959   1.4      mw     case GM_GRFGETCURBANK:
    960   1.4      mw       *(int *)arg = rt_getcurbank (gp);
    961   1.4      mw       return 0;
    962   1.4      mw 
    963   1.4      mw     case GM_GRFSETBANK:
    964   1.4      mw       return rt_setbank (gp, arg);
    965   1.4      mw #endif
    966   1.4      mw     case GM_GRFIOCTL:
    967   1.4      mw       return rt_ioctl (gp, arg, a2);
    968   1.4      mw 
    969   1.1      mw     default:
    970   1.1      mw       break;
    971   1.1      mw     }
    972   1.1      mw 
    973   1.1      mw   return EINVAL;
    974   1.1      mw }
    975   1.4      mw 
    976   1.4      mw int
    977   1.4      mw rt_ioctl (gp, cmd, data)
    978   1.4      mw 	register struct grf_softc *gp;
    979   1.4      mw 	int cmd;
    980   1.4      mw 	void *data;
    981   1.4      mw {
    982   1.4      mw   switch (cmd)
    983   1.4      mw     {
    984   1.4      mw     case GRFIOCGSPRITEPOS:
    985   1.4      mw       return rt_getspritepos (gp, (struct grf_position *) data);
    986   1.4      mw 
    987   1.4      mw     case GRFIOCSSPRITEPOS:
    988   1.4      mw       return rt_setspritepos (gp, (struct grf_position *) data);
    989   1.4      mw 
    990   1.4      mw     case GRFIOCSSPRITEINF:
    991   1.4      mw       return rt_setspriteinfo (gp, (struct grf_spriteinfo *) data);
    992   1.4      mw 
    993   1.4      mw     case GRFIOCGSPRITEINF:
    994   1.4      mw       return rt_getspriteinfo (gp, (struct grf_spriteinfo *) data);
    995   1.4      mw 
    996   1.4      mw     case GRFIOCGSPRITEMAX:
    997   1.4      mw       return rt_getspritemax (gp, (struct grf_position *) data);
    998   1.4      mw 
    999   1.4      mw     case GRFIOCGETCMAP:
   1000   1.4      mw       return rt_getcmap (gp, (struct grf_colormap *) data);
   1001   1.4      mw 
   1002   1.4      mw     case GRFIOCPUTCMAP:
   1003   1.4      mw       return rt_putcmap (gp, (struct grf_colormap *) data);
   1004   1.4      mw 
   1005   1.4      mw     case GRFIOCBITBLT:
   1006   1.4      mw       return rt_bitblt (gp, (struct grf_bitblt *) data);
   1007   1.4      mw     }
   1008   1.4      mw 
   1009   1.4      mw   return EINVAL;
   1010   1.4      mw }
   1011   1.4      mw 
   1012   1.4      mw #ifdef BANKEDDEVPAGER
   1013   1.4      mw 
   1014   1.4      mw /* Retina banks can overlap. Don't use this information (yet?), and
   1015   1.4      mw    only switch 64k sized banks. */
   1016   1.4      mw 
   1017   1.4      mw int
   1018   1.4      mw rt_getbank (gp, offs, prot)
   1019   1.4      mw      struct grf_softc *gp;
   1020   1.4      mw      off_t offs;
   1021   1.4      mw      int prot;
   1022   1.4      mw {
   1023   1.4      mw   /* XXX */
   1024   1.4      mw   if (offs <  0 || offs >= 4*1024*1024)
   1025   1.4      mw     return -1;
   1026   1.4      mw   else
   1027   1.4      mw     return offs >> 16;
   1028   1.4      mw }
   1029   1.4      mw 
   1030   1.4      mw int
   1031   1.4      mw rt_getcurbank (gp)
   1032   1.4      mw      struct grf_softc *gp;
   1033   1.4      mw {
   1034   1.4      mw   struct grfinfo *gi = &gp->g_display;
   1035   1.4      mw   volatile unsigned char *ba;
   1036   1.4      mw   int bank;
   1037   1.4      mw 
   1038   1.4      mw   ba = gp->g_regkva;
   1039   1.4      mw   bank = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO) | (RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI) << 8);
   1040   1.4      mw 
   1041   1.4      mw   /* bank register is multiple of 64 byte, make this multiple of 64k */
   1042   1.4      mw   bank >>= 10;
   1043   1.4      mw   return bank;
   1044   1.4      mw }
   1045   1.4      mw 
   1046   1.4      mw int
   1047   1.4      mw rt_setbank (gp, bank)
   1048   1.4      mw      struct grf_softc *gp;
   1049   1.4      mw      int bank;
   1050   1.4      mw {
   1051   1.4      mw   volatile unsigned char *ba;
   1052   1.4      mw 
   1053   1.4      mw   ba = gp->g_regkva;
   1054   1.4      mw   /* bank register is multiple of 64 byte, make this multiple of 64k */
   1055   1.4      mw   bank <<= 10;
   1056   1.4      mw   WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, (unsigned char) bank);
   1057   1.4      mw   bank >>= 8;
   1058   1.4      mw   WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, (unsigned char) bank);
   1059   1.4      mw 
   1060   1.4      mw   return 0;
   1061   1.4      mw }
   1062   1.4      mw 
   1063   1.4      mw #endif
   1064   1.4      mw 
   1065   1.4      mw int
   1066   1.4      mw rt_getcmap (gfp, cmap)
   1067   1.4      mw      struct grf_softc *gfp;
   1068   1.4      mw      struct grf_colormap *cmap;
   1069   1.4      mw {
   1070   1.4      mw   volatile unsigned char *ba;
   1071   1.4      mw   u_char red[256], green[256], blue[256], *rp, *gp, *bp;
   1072   1.4      mw   short x;
   1073   1.4      mw   int error;
   1074   1.4      mw 
   1075   1.4      mw   if (cmap->count == 0 || cmap->index >= 256)
   1076   1.4      mw     return 0;
   1077   1.4      mw 
   1078   1.4      mw   if (cmap->index + cmap->count > 256)
   1079   1.4      mw     cmap->count = 256 - cmap->index;
   1080   1.4      mw 
   1081   1.4      mw   ba = gfp->g_regkva;
   1082   1.4      mw   /* first read colors out of the chip, then copyout to userspace */
   1083   1.4      mw   vgaw (ba, VDAC_REG_SELECT, cmap->index);
   1084   1.4      mw   x = cmap->count - 1;
   1085   1.4      mw   rp = red + cmap->index;
   1086   1.4      mw   gp = green + cmap->index;
   1087   1.4      mw   bp = blue + cmap->index;
   1088   1.4      mw   do
   1089   1.4      mw     {
   1090   1.4      mw       *rp++ = vgar (ba, VDAC_REG_DATA);
   1091   1.4      mw       *gp++ = vgar (ba, VDAC_REG_DATA);
   1092   1.4      mw       *bp++ = vgar (ba, VDAC_REG_DATA);
   1093   1.4      mw     }
   1094   1.4      mw   while (x--);
   1095   1.4      mw 
   1096   1.4      mw   if (!(error = copyout (red + cmap->index, cmap->red, cmap->count))
   1097   1.4      mw       && !(error = copyout (green + cmap->index, cmap->green, cmap->count))
   1098   1.4      mw       && !(error = copyout (blue + cmap->index, cmap->blue, cmap->count)))
   1099   1.4      mw     return 0;
   1100   1.4      mw 
   1101   1.4      mw   return error;
   1102   1.4      mw }
   1103   1.4      mw 
   1104   1.4      mw int
   1105   1.4      mw rt_putcmap (gfp, cmap)
   1106   1.4      mw      struct grf_softc *gfp;
   1107   1.4      mw      struct grf_colormap *cmap;
   1108   1.4      mw {
   1109   1.4      mw   volatile unsigned char *ba;
   1110   1.4      mw   u_char red[256], green[256], blue[256], *rp, *gp, *bp;
   1111   1.4      mw   short x;
   1112   1.4      mw   int error;
   1113   1.4      mw 
   1114   1.4      mw   if (cmap->count == 0 || cmap->index >= 256)
   1115   1.4      mw     return 0;
   1116   1.4      mw 
   1117   1.4      mw   if (cmap->index + cmap->count > 256)
   1118   1.4      mw     cmap->count = 256 - cmap->index;
   1119   1.4      mw 
   1120   1.4      mw   /* first copy the colors into kernelspace */
   1121   1.4      mw   if (!(error = copyin (cmap->red, red + cmap->index, cmap->count))
   1122   1.4      mw       && !(error = copyin (cmap->green, green + cmap->index, cmap->count))
   1123   1.4      mw       && !(error = copyin (cmap->blue, blue + cmap->index, cmap->count)))
   1124   1.4      mw     {
   1125   1.4      mw       ba = gfp->g_regkva;
   1126   1.4      mw       vgaw (ba, VDAC_REG_SELECT, cmap->index);
   1127   1.4      mw       x = cmap->count - 1;
   1128   1.4      mw       rp = red + cmap->index;
   1129   1.4      mw       gp = green + cmap->index;
   1130   1.4      mw       bp = blue + cmap->index;
   1131   1.4      mw       do
   1132   1.4      mw 	{
   1133   1.4      mw 	  vgaw (ba, VDAC_REG_DATA, *rp++);
   1134   1.4      mw 	  vgaw (ba, VDAC_REG_DATA, *gp++);
   1135   1.4      mw 	  vgaw (ba, VDAC_REG_DATA, *bp++);
   1136   1.4      mw 	}
   1137   1.4      mw       while (x--);
   1138   1.4      mw       return 0;
   1139   1.4      mw     }
   1140   1.4      mw   else
   1141   1.4      mw     return error;
   1142   1.4      mw }
   1143   1.4      mw 
   1144   1.4      mw int
   1145   1.4      mw rt_getspritepos (gp, pos)
   1146   1.4      mw      struct grf_softc *gp;
   1147   1.4      mw      struct grf_position *pos;
   1148   1.4      mw {
   1149   1.4      mw   volatile unsigned char *ba;
   1150   1.4      mw 
   1151   1.4      mw   ba = gp->g_regkva;
   1152   1.4      mw   pos->x = vgar (ba, SEQ_ID_CURSOR_X_LOC_LO) | (vgar (ba, SEQ_ID_CURSOR_X_LOC_HI) << 8);
   1153   1.4      mw   pos->y = vgar (ba, SEQ_ID_CURSOR_Y_LOC_LO) | (vgar (ba, SEQ_ID_CURSOR_Y_LOC_HI) << 8);
   1154   1.4      mw   return 0;
   1155   1.4      mw }
   1156   1.4      mw 
   1157   1.4      mw int
   1158   1.4      mw rt_setspritepos (gp, pos)
   1159   1.4      mw      struct grf_softc *gp;
   1160   1.4      mw      struct grf_position *pos;
   1161   1.4      mw {
   1162   1.4      mw   volatile unsigned char *ba;
   1163   1.4      mw 
   1164   1.4      mw   ba = gp->g_regkva;
   1165   1.4      mw   vgaw (ba, SEQ_ID_CURSOR_X_LOC_LO, pos->x & 0xff);
   1166   1.4      mw   vgaw (ba, SEQ_ID_CURSOR_X_LOC_HI, (pos->x >> 8) & 0x07);
   1167   1.4      mw   vgaw (ba, SEQ_ID_CURSOR_Y_LOC_LO, pos->y & 0xff);
   1168   1.4      mw   vgaw (ba, SEQ_ID_CURSOR_Y_LOC_HI, (pos->y >> 8) & 0x07);
   1169   1.4      mw   return 0;
   1170   1.4      mw }
   1171   1.4      mw 
   1172   1.4      mw /* assume an at least 2M retina (XXX), sprite is last in memory.
   1173   1.4      mw    According to the bogus docs, the cursor can be at most 128 lines
   1174   1.4      mw    in height, and the x-hostspot can be placed at most at pos 31,
   1175   1.4      mw    this gives width of a long */
   1176   1.4      mw #define SPRITE_ADDR (2*1024*1024 - 128*4)
   1177   1.4      mw 
   1178   1.4      mw int
   1179   1.4      mw rt_getspriteinfo (gp, info)
   1180   1.4      mw      struct grf_softc *gp;
   1181   1.4      mw      struct grf_spriteinfo *info;
   1182   1.4      mw {
   1183   1.4      mw   volatile unsigned char *ba, *fb;
   1184   1.4      mw 
   1185   1.4      mw   ba = gp->g_regkva;
   1186   1.4      mw   fb = gp->g_fbkva;
   1187   1.4      mw   if (info->set & GRFSPRSET_ENABLE)
   1188   1.4      mw     info->enable = vgar (ba, SEQ_ID_CURSOR_CONTROL) & 0x01;
   1189   1.4      mw   if (info->set & GRFSPRSET_POS)
   1190   1.4      mw     rt_getspritepos (gp, &info->pos);
   1191   1.4      mw   if (info->set & GRFSPRSET_HOT)
   1192   1.4      mw     {
   1193   1.4      mw       info->hot.x = vgar (ba, SEQ_ID_CURSOR_X_INDEX) & 0x1f;
   1194   1.4      mw       info->hot.y = vgar (ba, SEQ_ID_CURSOR_Y_INDEX) & 0x7f;
   1195   1.4      mw     }
   1196   1.4      mw   if (info->set & GRFSPRSET_CMAP)
   1197   1.4      mw     {
   1198   1.4      mw       struct grf_colormap cmap;
   1199   1.4      mw       int index;
   1200   1.4      mw       cmap.index = 0;
   1201   1.4      mw       cmap.count = 256;
   1202   1.4      mw       rt_getcmap (gp, &cmap);
   1203   1.4      mw       index = vgar (ba, SEQ_ID_CURSOR_COLOR0);
   1204   1.4      mw       info->cmap.red[0] = cmap.red[index];
   1205   1.4      mw       info->cmap.green[0] = cmap.green[index];
   1206   1.4      mw       info->cmap.blue[0] = cmap.blue[index];
   1207   1.4      mw       index = vgar (ba, SEQ_ID_CURSOR_COLOR1);
   1208   1.4      mw       info->cmap.red[1] = cmap.red[index];
   1209   1.4      mw       info->cmap.green[1] = cmap.green[index];
   1210   1.4      mw       info->cmap.blue[1] = cmap.blue[index];
   1211   1.4      mw     }
   1212   1.4      mw   if (info->set & GRFSPRSET_SHAPE)
   1213   1.4      mw     {
   1214   1.4      mw       int saved_bank_lo = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO);
   1215   1.4      mw       int saved_bank_hi = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI);
   1216   1.4      mw       int last_bank = SPRITE_ADDR >> 6;
   1217   1.4      mw       int last_bank_lo = last_bank & 0xff;
   1218   1.4      mw       int last_bank_hi = last_bank >> 8;
   1219   1.4      mw       u_char mask;
   1220   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, last_bank_lo);
   1221   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, last_bank_hi);
   1222   1.4      mw       copyout (fb, info->image, 128*4);
   1223   1.4      mw       mask = RSeq (ba, SEQ_ID_CURSOR_PIXELMASK);
   1224   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, saved_bank_lo);
   1225   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, saved_bank_hi);
   1226   1.4      mw       copyout (&mask, info->mask, 1);
   1227   1.4      mw       info->size.x = 32; /* ??? */
   1228   1.4      mw       info->size.y = (RSeq (ba, SEQ_ID_CURSOR_CONTROL) & 6) << 4;
   1229   1.4      mw     }
   1230   1.4      mw 
   1231   1.4      mw }
   1232   1.4      mw 
   1233   1.4      mw int
   1234   1.4      mw rt_setspriteinfo (gp, info)
   1235   1.4      mw      struct grf_softc *gp;
   1236   1.4      mw      struct grf_spriteinfo *info;
   1237   1.4      mw {
   1238   1.4      mw   volatile unsigned char *ba, *fb;
   1239   1.4      mw   u_char control;
   1240   1.4      mw 
   1241   1.4      mw   ba = gp->g_regkva;
   1242   1.4      mw   fb = gp->g_fbkva;
   1243   1.4      mw   control = vgar (ba, SEQ_ID_CURSOR_CONTROL);
   1244   1.4      mw   if (info->set & GRFSPRSET_ENABLE)
   1245   1.4      mw     {
   1246   1.4      mw       if (info->enable)
   1247   1.4      mw 	control |= 1;
   1248   1.4      mw       else
   1249   1.4      mw 	control &= ~1;
   1250   1.4      mw       vgaw (ba, SEQ_ID_CURSOR_CONTROL, control);
   1251   1.4      mw     }
   1252   1.4      mw   if (info->set & GRFSPRSET_POS)
   1253   1.4      mw     rt_setspritepos (gp, &info->pos);
   1254   1.4      mw   if (info->set & GRFSPRSET_HOT)
   1255   1.4      mw     {
   1256   1.4      mw       vgaw (ba, SEQ_ID_CURSOR_X_INDEX, info->hot.x & 0x1f);
   1257   1.4      mw       vgaw (ba, SEQ_ID_CURSOR_Y_INDEX, info->hot.y & 0x7f);
   1258   1.4      mw     }
   1259   1.4      mw   if (info->set & GRFSPRSET_CMAP)
   1260   1.4      mw     {
   1261   1.4      mw       /* hey cheat a bit here.. XXX */
   1262   1.4      mw       vgaw (ba, SEQ_ID_CURSOR_COLOR0, 0);
   1263   1.4      mw       vgaw (ba, SEQ_ID_CURSOR_COLOR1, 1);
   1264   1.4      mw     }
   1265   1.4      mw   if (info->set & GRFSPRSET_SHAPE)
   1266   1.4      mw     {
   1267   1.4      mw       int saved_bank_lo = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO);
   1268   1.4      mw       int saved_bank_hi = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI);
   1269   1.4      mw       int last_bank = SPRITE_ADDR >> 6;
   1270   1.4      mw       int last_bank_lo = last_bank & 0xff;
   1271   1.4      mw       int last_bank_hi = last_bank >> 8;
   1272   1.4      mw       u_char mask;
   1273   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, last_bank_lo);
   1274   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, last_bank_hi);
   1275   1.4      mw       copyin (info->image, fb, 128*4);
   1276   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, saved_bank_lo);
   1277   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, saved_bank_hi);
   1278   1.4      mw       copyin (info->mask, &mask, 1);
   1279   1.4      mw       WSeq (ba, SEQ_ID_CURSOR_PIXELMASK, mask);
   1280   1.4      mw       /* info->size.x = 32; *//* ??? */
   1281   1.4      mw 
   1282   1.4      mw       info->size.y = (RSeq (ba, SEQ_ID_CURSOR_CONTROL) & 6) << 4;
   1283   1.4      mw       control = (control & ~6) | ((info->size.y >> 4) & 6);
   1284   1.4      mw       vgaw (ba, SEQ_ID_CURSOR_CONTROL, control);
   1285   1.4      mw 
   1286   1.4      mw       /* sick intel bull-addressing.. */
   1287   1.4      mw       WSeq (ba, SEQ_ID_CURSOR_STORE_LO, SPRITE_ADDR & 0x0f);
   1288   1.4      mw       WSeq (ba, SEQ_ID_CURSOR_STORE_HI, 0);
   1289   1.4      mw       WSeq (ba, SEQ_ID_CURSOR_ST_OFF_LO, (SPRITE_ADDR >> 4) & 0xff);
   1290   1.4      mw       WSeq (ba, SEQ_ID_CURSOR_ST_OFF_HI, ((SPRITE_ADDR >> 4) >> 8) & 0xff);
   1291   1.4      mw     }
   1292   1.4      mw 
   1293   1.4      mw   return 0;
   1294   1.4      mw }
   1295   1.4      mw 
   1296   1.4      mw int
   1297   1.4      mw rt_getspritemax (gp, pos)
   1298   1.4      mw      struct grf_softc *gp;
   1299   1.4      mw      struct grf_position *pos;
   1300   1.4      mw {
   1301   1.4      mw   pos->x = 32;
   1302   1.4      mw   pos->y = 128;
   1303   1.4      mw 
   1304   1.4      mw   return 0;
   1305   1.4      mw }
   1306   1.4      mw 
   1307   1.4      mw 
   1308   1.4      mw /*
   1309   1.4      mw  * !!! THIS AREA UNDER CONSTRUCTION !!!
   1310   1.4      mw  */
   1311   1.4      mw 
   1312   1.4      mw int
   1313   1.4      mw rt_bitblt (gp, bb)
   1314   1.4      mw      struct grf_softc *gp;
   1315   1.4      mw      struct grf_bitblt *bb;
   1316   1.4      mw {
   1317   1.4      mw   return EINVAL;
   1318   1.4      mw 
   1319   1.4      mw 
   1320   1.4      mw #if 0
   1321   1.4      mw   volatile unsigned char *ba, *fb;
   1322   1.4      mw   u_char control;
   1323   1.4      mw   u_char saved_bank_lo;
   1324   1.4      mw   u_char saved_bank_hi;
   1325   1.4      mw   u_char src_bank_lo, src_bank_hi;
   1326   1.4      mw   u_char dst_bank_lo, dst_bank_hi;
   1327   1.4      mw   u_long src_offset, dst_offset;
   1328   1.4      mw   u_short src_bank, dst_bank;
   1329   1.4      mw   u_char *srcp, *dstp;
   1330   1.4      mw   short x, y;
   1331   1.4      mw   u_long tot;
   1332   1.4      mw 
   1333   1.4      mw   ba = gp->g_regkva;
   1334   1.4      mw   fb = gp->g_fbkva;
   1335   1.4      mw 
   1336   1.4      mw   saved_bank_lo = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO);
   1337   1.4      mw   saved_bank_hi = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI);
   1338   1.4      mw 
   1339   1.4      mw   /* for now, only GRFBBcopy is supported, and only for depth 8. No
   1340   1.4      mw      clipping is performed, either... */
   1341   1.4      mw 
   1342   1.4      mw   if (bb->op != GRFBBcopy && gp->g_display.gd_planes != 8)
   1343   1.4      mw     return EINVAL;
   1344   1.4      mw 
   1345   1.4      mw   src_offset = op->src_x + op->src_y * gp->g_display.gd_fbwidth;
   1346   1.4      mw   dst_offset = op->dst_x + op->dst_y * gp->g_display.gd_fbwidth;
   1347   1.4      mw   tot = op->w * op->h;
   1348   1.4      mw 
   1349   1.4      mw   /* set write mode 1, "[...] data in the read latches is written
   1350   1.4      mw      to memory during CPU memory write cycles. [...]" */
   1351   1.4      mw   WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
   1352   1.4      mw   /* write to primary, read from secondary */
   1353   1.4      mw   WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA, (RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0 );
   1354   1.4      mw 
   1355   1.4      mw   if (src_offset < dst_offset)
   1356   1.4      mw     {
   1357   1.4      mw       /* start at end */
   1358   1.4      mw       src_offset += tot;
   1359   1.4      mw       dst_offset += tot;
   1360   1.4      mw     }
   1361   1.4      mw 
   1362   1.4      mw   src_bank_lo = (src_offset >> 6) & 0xff;
   1363   1.4      mw   src_bank_hi = (src_offset >> 14) & 0xff;
   1364   1.4      mw   dst_bank_lo = (dst_offset >> 6) & 0xff;
   1365   1.4      mw   dst_bank_hi = (dst_offset >> 14) & 0xff;
   1366   1.4      mw 
   1367   1.4      mw   while (tot)
   1368   1.4      mw     {
   1369   1.4      mw       WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, src_bank_lo);
   1370   1.4      mw       WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, src_bank_hi);
   1371   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, dst_bank_lo);
   1372   1.4      mw       WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, dst_bank_hi);
   1373   1.4      mw 
   1374   1.4      mw       if (src_offset < dst_offset)
   1375   1.4      mw 	{
   1376   1.4      mw 
   1377   1.4      mw 
   1378   1.4      mw 	}
   1379   1.4      mw       else
   1380   1.4      mw 	{
   1381   1.4      mw 
   1382   1.4      mw 	}
   1383   1.4      mw     }
   1384   1.4      mw 
   1385   1.4      mw 
   1386   1.4      mw #endif
   1387   1.4      mw }
   1388   1.4      mw 
   1389   1.1      mw 
   1390   1.1      mw #endif	/* NGRF */
   1391