Home | History | Annotate | Line # | Download | only in dev
grf_cv.c revision 1.3.2.2
      1  1.3.2.2  chopps /*	$NetBSD: grf_cv.c,v 1.3.2.2 1995/10/21 15:15:41 chopps Exp $	*/
      2  1.3.2.2  chopps 
      3      1.1  chopps /*
      4      1.1  chopps  * Copyright (c) 1995 Michael Teske
      5      1.1  chopps  * All rights reserved.
      6      1.1  chopps  *
      7      1.1  chopps  * Redistribution and use in source and binary forms, with or without
      8      1.1  chopps  * modification, are permitted provided that the following conditions
      9      1.1  chopps  * are met:
     10      1.1  chopps  * 1. Redistributions of source code must retain the above copyright
     11      1.1  chopps  *    notice, this list of conditions and the following disclaimer.
     12      1.1  chopps  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  chopps  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  chopps  *    documentation and/or other materials provided with the distribution.
     15      1.1  chopps  * 3. All advertising materials mentioning features or use of this software
     16      1.1  chopps  *    must display the following acknowledgement:
     17      1.1  chopps  *      This product includes software developed by Ezra Story, by Kari
     18      1.1  chopps  *      Mettinen and by Bernd Ernesti.
     19      1.1  chopps  * 4. The name of the author may not be used to endorse or promote products
     20      1.1  chopps  *    derived from this software without specific prior written permission
     21      1.1  chopps  *
     22      1.1  chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.1  chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.1  chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.1  chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26      1.1  chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27      1.1  chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28      1.1  chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29      1.1  chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30      1.1  chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31      1.1  chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.1  chopps  */
     33      1.1  chopps #include "grfcv.h"
     34      1.1  chopps #if NGRFCV > 0
     35      1.1  chopps 
     36      1.3  chopps #undef CV64CONSOLE /* DO NOT REMOVE THIS till ite5 is ready */
     37      1.3  chopps 
     38      1.1  chopps /*
     39      1.1  chopps  * Graphics routines for the CyberVision 64 board, using the S3 Trio64.
     40      1.1  chopps  *
     41      1.1  chopps  * Modified for CV64 from
     42      1.1  chopps  * Kari Mettinen's Cirrus driver by Michael Teske 10/95
     43      1.1  chopps  * For questions mail me at teske (at) dice2.desy.de
     44      1.1  chopps  *
     45      1.1  chopps  * Thanks to Tekelec Airtronic for providing me with a S3 Trio64 documentation.
     46      1.1  chopps  * Thanks to Bernd 'the fabulous bug-finder' Ernesti for bringing my messy
     47      1.1  chopps  * source to NetBSD style :)
     48      1.1  chopps  *
     49      1.1  chopps  * TODO:
     50      1.1  chopps  *    Hardware Cursor support
     51      1.1  chopps  *    Blitter support
     52      1.1  chopps  *
     53      1.1  chopps  * BUGS:
     54  1.3.2.1  chopps  *    Xamiag24 and grf_cv can crash when you use fvwm with xterm's, you can
     55  1.3.2.1  chopps  *    avoid this by starting the xterm with '-ah', see the manpage of xterm
     56  1.3.2.1  chopps  *    for more informations about this switch.
     57  1.3.2.1  chopps  *    There is a bug in the Trio64 which produce a small (1 or 2 pixel) white
     58  1.3.2.1  chopps  *    vertical bar on the right side of an 8bit-Screen (only when you use more
     59  1.3.2.1  chopps  *    then 80MHz pixelclock). This has to be fixed in the Xserver.
     60      1.1  chopps  *
     61      1.1  chopps  */
     62      1.1  chopps 
     63      1.1  chopps #include <sys/param.h>
     64      1.1  chopps #include <sys/errno.h>
     65      1.1  chopps #include <sys/ioctl.h>
     66      1.1  chopps #include <sys/device.h>
     67      1.1  chopps #include <sys/malloc.h>
     68      1.1  chopps #include <sys/systm.h>
     69      1.1  chopps #include <machine/cpu.h>
     70      1.1  chopps #include <dev/cons.h>
     71      1.1  chopps #include <amiga/amiga/device.h>
     72      1.1  chopps #include <amiga/dev/grfioctl.h>
     73      1.1  chopps #include <amiga/dev/grfvar.h>
     74      1.1  chopps #include <amiga/dev/grf_cvreg.h>
     75      1.1  chopps #include <amiga/dev/zbusvar.h>
     76      1.1  chopps 
     77      1.1  chopps int cv_mondefok __P((struct grfvideo_mode *));
     78      1.1  chopps void cv_boardinit();
     79      1.1  chopps static unsigned short compute_clock __P((unsigned long));
     80      1.1  chopps int cv_getvmode __P((struct grf_softc *, struct grfvideo_mode *));
     81      1.1  chopps int cv_setvmode __P((struct grf_softc *, unsigned int));
     82      1.1  chopps int cv_setmonitor __P((struct grf_softc *, struct grfvideo_mode *));
     83      1.1  chopps int cv_toggle __P((struct grf_softc *,unsigned short));
     84      1.1  chopps int cv_getcmap __P((struct grf_softc *, struct grf_colormap *));
     85      1.1  chopps int cv_putcmap __P((struct grf_softc *, struct grf_colormap *));
     86      1.1  chopps void cv_off __P((struct grf_softc *));
     87      1.1  chopps int cv_blank __P((struct grf_softc *, int *));
     88      1.1  chopps void cv_inittextmode __P((struct grf_softc *));
     89      1.1  chopps 
     90      1.1  chopps int cv_ioctl __P((register struct grf_softc *gp, int cmd, void *data));
     91      1.1  chopps void grfcvattach __P((struct device *, struct device *, void *));
     92      1.1  chopps int  grfcvprint  __P((void *, char *));
     93      1.1  chopps int  grfcvmatch  __P((struct device *, struct cfdata *, void *));
     94      1.1  chopps void cv_memset __P((unsigned char *, unsigned char, int));
     95      1.1  chopps 
     96      1.3  chopps #ifdef CV64CONSOLE
     97      1.3  chopps extern void grfcv_iteinit __P((struct grf_softc *));
     98      1.3  chopps #endif
     99      1.3  chopps 
    100      1.1  chopps /* Graphics display definitions.
    101      1.1  chopps  * These are filled by 'grfconfig' using GRFIOCSETMON.
    102      1.1  chopps  */
    103      1.1  chopps #define monitor_def_max 8
    104      1.1  chopps static struct grfvideo_mode monitor_def[8] = {
    105      1.1  chopps 	{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}
    106      1.1  chopps };
    107      1.1  chopps static struct grfvideo_mode *monitor_current = &monitor_def[0];
    108      1.1  chopps #define MAXPIXELCLOCK 135000000 /* safety */
    109      1.1  chopps 
    110      1.1  chopps 
    111      1.1  chopps /* Console display definition.
    112      1.1  chopps  *   Default hardcoded text mode.  This grf_cv is set up to
    113      1.1  chopps  *   use one text mode only, and this is it.  You may use
    114      1.1  chopps  *   grfconfig to change the mode after boot.
    115      1.1  chopps  */
    116      1.1  chopps 
    117      1.1  chopps /* Console font */
    118      1.1  chopps #define S3FONT kernel_font_8x8
    119      1.1  chopps #define S3FONTX 8
    120      1.1  chopps #define S3FONTY 8
    121      1.1  chopps extern unsigned char S3FONT[];
    122      1.1  chopps 
    123      1.1  chopps struct grfcvtext_mode cvconsole_mode = {
    124      1.3  chopps 	{255, "", 25000000, 640, 400, 4, 640, 656, 672, 720, 760, 406,
    125      1.1  chopps 	441, 412, 426, 447},
    126      1.1  chopps 	S3FONTX, S3FONTY, 80, 506/S3FONTY, S3FONT, 32, 255
    127      1.1  chopps };
    128      1.1  chopps 
    129      1.1  chopps 
    130      1.1  chopps /* Console colors */
    131      1.1  chopps unsigned char cvconscolors[3][3] = {	/* background, foreground, hilite */
    132      1.1  chopps 	{0,0x40,0x50}, {152,152,152}, {255,255,255}
    133      1.1  chopps };
    134      1.1  chopps 
    135      1.1  chopps unsigned char pass_toggle;	/* passthru status tracker */
    136      1.1  chopps 
    137      1.1  chopps 
    138      1.1  chopps /* Board Address of CV64 */
    139      1.1  chopps 
    140      1.1  chopps static void *cv_boardaddr;
    141      1.1  chopps static int cv_fbsize;
    142      1.1  chopps 
    143      1.1  chopps int
    144      1.1  chopps grfcv_cnprobe()
    145      1.1  chopps {
    146      1.1  chopps 	int rv;
    147      1.1  chopps 	rv = CN_DEAD;
    148      1.2  chopps 	return (rv);
    149      1.1  chopps }
    150      1.1  chopps 
    151      1.1  chopps /* standard driver stuff */
    152      1.1  chopps struct cfdriver grfcvcd = {
    153      1.1  chopps 	NULL, "grfcv", (cfmatch_t)grfcvmatch, grfcvattach,
    154      1.1  chopps 	DV_DULL, sizeof(struct grf_softc), NULL, 0
    155      1.1  chopps };
    156      1.1  chopps static struct cfdata *cfdata;
    157      1.1  chopps 
    158      1.1  chopps 
    159      1.1  chopps /* Reads from the fb must be done at addr + 0x02000000 */
    160      1.1  chopps #define READ_OFFSET 0x02000000
    161      1.1  chopps 
    162      1.1  chopps /*
    163      1.1  chopps  * Get frambuffer memory size.
    164      1.1  chopps  * phase5 didn't provide the bit in CR36,
    165      1.1  chopps  * so we have to do it this way.
    166      1.1  chopps  * Return 0 for 2MB, 1 for 4MB
    167      1.1  chopps  */
    168      1.1  chopps 
    169      1.1  chopps static int
    170      1.1  chopps cv_has_4mb (volatile char *fb)
    171      1.1  chopps {
    172      1.1  chopps 	volatile unsigned long *testfbw, *testfbr;
    173      1.1  chopps 
    174      1.1  chopps 	/* write patterns in memory and test if they can be read */
    175      1.1  chopps 	testfbw = (volatile unsigned long *) fb;
    176      1.1  chopps 	*testfbw = 0x87654321;
    177      1.1  chopps 	testfbr = (volatile unsigned long *)(fb + READ_OFFSET);
    178      1.1  chopps 	if (*testfbr != 0x87654321)
    179      1.2  chopps 		return (0);
    180      1.1  chopps 	/* upper memory region */
    181      1.1  chopps 	testfbw = (volatile unsigned long *)(fb + 0x00200000);
    182      1.1  chopps 	testfbr = (volatile unsigned long *)(fb + 0x00200000 + READ_OFFSET);
    183      1.1  chopps 	*testfbw = 0x87654321;
    184      1.1  chopps 	if (*testfbr != 0x87654321)
    185      1.2  chopps 		return (0);
    186      1.1  chopps 	*testfbw = 0xAAAAAAAA;
    187      1.1  chopps 	if (*testfbr != 0xAAAAAAAA)
    188      1.2  chopps 		return (0);
    189      1.1  chopps 	*testfbw = 0x55555555;
    190      1.1  chopps 	if (*testfbr != 0x55555555)
    191      1.2  chopps 		return (0);
    192      1.2  chopps 	return (1);
    193      1.1  chopps }
    194      1.1  chopps 
    195      1.1  chopps int
    196      1.1  chopps grfcvmatch(pdp, cfp, auxp)
    197      1.1  chopps 	struct device *pdp;
    198      1.1  chopps 	struct cfdata *cfp;
    199      1.1  chopps 	void *auxp;
    200      1.1  chopps {
    201      1.1  chopps 	struct zbus_args *zap;
    202      1.1  chopps 
    203      1.1  chopps 	zap = auxp;
    204      1.1  chopps 
    205      1.1  chopps #ifndef CV64CONSOLE
    206      1.1  chopps 	if (amiga_realconfig == 0)
    207      1.2  chopps 		 return (0);
    208      1.1  chopps #endif
    209      1.1  chopps 
    210      1.1  chopps         /* Lets be Paranoid: Test man and prod id */
    211      1.1  chopps 	if (zap->manid != 8512 || zap->prodid != 34)
    212      1.2  chopps 		return (0);
    213      1.1  chopps 
    214      1.1  chopps 	cv_boardaddr = zap->va;
    215      1.1  chopps 
    216      1.1  chopps #ifdef CV64CONSOLE
    217      1.1  chopps 	if (amiga_realconfig == 0) {
    218      1.1  chopps 		cfdata = cfp;
    219      1.1  chopps 	}
    220      1.1  chopps #endif
    221      1.1  chopps 
    222      1.2  chopps 	return (1);
    223      1.1  chopps }
    224      1.1  chopps 
    225      1.1  chopps void
    226      1.1  chopps grfcvattach(pdp, dp, auxp)
    227      1.1  chopps 	struct device *pdp, *dp;
    228      1.1  chopps 	void *auxp;
    229      1.1  chopps {
    230      1.1  chopps 	static struct grf_softc congrf;
    231      1.1  chopps 	struct zbus_args *zap;
    232      1.1  chopps 	struct grf_softc *gp;
    233      1.1  chopps 	static char attachflag = 0;
    234      1.1  chopps 
    235      1.1  chopps 	zap = auxp;
    236      1.1  chopps 
    237      1.1  chopps 	printf("\n");
    238      1.1  chopps 
    239      1.1  chopps 	/* make sure id's have matched */
    240      1.1  chopps 	if (!cv_boardaddr)
    241      1.1  chopps 		return;
    242      1.1  chopps 
    243      1.1  chopps 	/* do all that messy console/grf stuff */
    244      1.1  chopps 	if (dp == NULL)
    245      1.1  chopps 		gp = &congrf;
    246      1.1  chopps 	else
    247      1.1  chopps 		gp = (struct grf_softc *)dp;
    248      1.1  chopps 
    249      1.1  chopps 	if (dp != NULL && congrf.g_regkva != 0) {
    250      1.1  chopps 		/*
    251      1.1  chopps 		 * inited earlier, just copy (not device struct)
    252      1.1  chopps 		 */
    253      1.1  chopps 		bcopy(&congrf.g_display, &gp->g_display,
    254      1.1  chopps 		    (char *)&gp[1] - (char *)&gp->g_display);
    255      1.1  chopps 	} else {
    256      1.1  chopps 		gp->g_regkva = (volatile caddr_t)cv_boardaddr + READ_OFFSET;
    257      1.1  chopps 		gp->g_fbkva = (volatile caddr_t)cv_boardaddr + 0x01400000;
    258      1.1  chopps 
    259      1.1  chopps 		gp->g_unit = GRF_CV64_UNIT;
    260      1.1  chopps 		gp->g_mode = cv_mode;
    261      1.1  chopps 		gp->g_conpri = grfcv_cnprobe();
    262      1.1  chopps 		gp->g_flags = GF_ALIVE;
    263      1.1  chopps 
    264      1.1  chopps 		/* wakeup the board */
    265      1.1  chopps 		cv_boardinit(gp);
    266      1.1  chopps 
    267      1.1  chopps #ifdef CV64CONSOLE
    268      1.1  chopps 		grfcv_iteinit(gp);
    269      1.1  chopps 		(void)cv_load_mon(gp, &cvconsole_mode);
    270      1.1  chopps #endif
    271      1.1  chopps 	}
    272      1.1  chopps 
    273      1.1  chopps 	/*
    274      1.1  chopps 	 * attach grf (once)
    275      1.1  chopps 	 */
    276      1.1  chopps 	if (amiga_config_found(cfdata, &gp->g_device, gp, grfcvprint)) {
    277      1.1  chopps 		attachflag = 1;
    278      1.1  chopps 		printf("grfcv: CyberVision64 with %dMB being used\n", cv_fbsize/0x100000);
    279      1.1  chopps 	} else {
    280      1.1  chopps 		if (!attachflag)
    281      1.1  chopps 			printf("grfcv unattached!!\n");
    282      1.1  chopps 	}
    283      1.1  chopps }
    284      1.1  chopps 
    285      1.1  chopps int
    286      1.1  chopps grfcvprint(auxp, pnp)
    287      1.1  chopps 	void *auxp;
    288      1.1  chopps 	char *pnp;
    289      1.1  chopps {
    290      1.1  chopps 	if (pnp)
    291      1.1  chopps 		printf("ite at %s: ", pnp);
    292      1.2  chopps 	return (UNCONF);
    293      1.1  chopps }
    294      1.1  chopps 
    295      1.1  chopps 
    296      1.1  chopps /*
    297      1.1  chopps  * Computes M, N, and R values from
    298      1.1  chopps  * given input frequency. It uses a table of
    299      1.1  chopps  * precomputed values, to keep CPU time low.
    300      1.1  chopps  *
    301      1.1  chopps  * The return value consist of:
    302      1.1  chopps  * lower byte:  Bits 4-0: N Divider Value
    303      1.1  chopps  *	        Bits 5-6: R Value          for e.g. SR10 or SR12
    304      1.1  chopps  * higher byte: Bits 0-6: M divider value  for e.g. SR11 or SR13
    305      1.1  chopps  */
    306      1.1  chopps 
    307      1.1  chopps static unsigned short
    308      1.1  chopps compute_clock(freq)
    309      1.1  chopps 	unsigned long freq;
    310      1.1  chopps {
    311      1.1  chopps 
    312      1.1  chopps 	static unsigned char *mnr, *save;	/* M, N + R vals */
    313      1.1  chopps 	unsigned long work_freq, r;
    314      1.1  chopps 	unsigned short erg;
    315      1.1  chopps 	long diff, d2;
    316      1.1  chopps 
    317      1.1  chopps 	/* 0xBEBC20 = 12.5M */
    318      1.1  chopps 	/* 0x080BEFC0 = 135M */
    319      1.1  chopps 	if (freq < 0x00BEBC20 || freq > 0x080BEFC0) {
    320      1.1  chopps 		printf("grfcv: Wrong clock frequency: %dMHz", freq/1000000);
    321      1.1  chopps 		printf("grfcv: Using default frequency: 25MHz");
    322      1.1  chopps 		freq = 0x017D7840;
    323      1.1  chopps 	}
    324      1.1  chopps 
    325      1.1  chopps 	mnr = clocks;	/* there the vals are stored */
    326      1.1  chopps 	d2 = 0x7fffffff;
    327      1.1  chopps 
    328      1.1  chopps 	while (*mnr) {	/* mnr vals are 0-terminated */
    329      1.1  chopps 		work_freq = (0x37EE * (mnr[0] + 2)) / ((mnr[1] & 0x1F) + 2);
    330      1.1  chopps 
    331      1.1  chopps 		r = (mnr[1] >> 5) & 0x03;
    332      1.1  chopps     		if (r != 0)
    333      1.1  chopps 			work_freq=work_freq >> r;	/* r is the freq divider */
    334      1.1  chopps 
    335      1.1  chopps 		work_freq *= 0x3E8;	/* 2nd part of OSC */
    336      1.1  chopps 
    337      1.1  chopps 		diff = abs(freq - work_freq);
    338      1.1  chopps 
    339      1.1  chopps 		if (d2 >= diff) {
    340      1.1  chopps 			d2 = diff;
    341      1.1  chopps 			/* In save are the vals for minimal diff */
    342      1.1  chopps 			save = mnr;
    343      1.1  chopps 		}
    344      1.1  chopps 		mnr += 2;
    345      1.1  chopps 	}
    346      1.1  chopps 	erg = *((unsigned short *)save);
    347      1.1  chopps 
    348      1.1  chopps 	return (erg);
    349      1.1  chopps }
    350      1.1  chopps 
    351      1.1  chopps 
    352      1.1  chopps void
    353      1.1  chopps cv_boardinit(gp)
    354      1.1  chopps 	struct grf_softc *gp;
    355      1.1  chopps {
    356      1.1  chopps 	unsigned char *ba = gp->g_regkva;
    357      1.1  chopps 	unsigned char test;
    358      1.1  chopps 	unsigned int clockpar;
    359      1.1  chopps 	int i;
    360  1.3.2.1  chopps 	struct grfinfo *gi;
    361      1.1  chopps 
    362      1.1  chopps 	/* Reset board */
    363      1.1  chopps 	for (i = 0; i < 6; i++)
    364      1.1  chopps 		cv_write_port (0xff, ba - READ_OFFSET);	/* Clear all bits */
    365      1.1  chopps 
    366      1.1  chopps 	/* Return to operational Mode */
    367      1.1  chopps 	cv_write_port(0x8004, ba - READ_OFFSET);
    368      1.1  chopps 
    369      1.1  chopps 	/* Wakeup Chip */
    370      1.1  chopps 	vgaw(ba, SREG_VIDEO_SUBS_ENABLE, 0x10);
    371      1.1  chopps 	vgaw(ba, SREG_OPTION_SELECT, 0x1);
    372      1.1  chopps 	vgaw(ba, SREG_VIDEO_SUBS_ENABLE, 0x8);
    373      1.1  chopps 
    374      1.1  chopps 	vgaw(ba, GREG_MISC_OUTPUT_W, 0x23);
    375      1.1  chopps 
    376      1.1  chopps 	WCrt(ba, CRT_ID_REGISTER_LOCK_1, 0x48);	/* unlock S3 VGA regs */
    377      1.1  chopps 	WCrt(ba, CRT_ID_REGISTER_LOCK_2, 0xA5);	/* unlock syscontrol */
    378      1.1  chopps 
    379      1.1  chopps 	test = RCrt(ba, CRT_ID_SYSTEM_CONFIG);
    380      1.1  chopps 	test = test | 0x01;	/* enable enhaced register access */
    381      1.1  chopps 	test = test & 0xEF;	/* clear bit 4, 0 wait state */
    382      1.1  chopps 	WCrt(ba, CRT_ID_SYSTEM_CONFIG, test);
    383      1.1  chopps 
    384      1.1  chopps 	/*
    385      1.1  chopps 	 * bit 1=1: enable enhanced mode functions
    386      1.1  chopps 	 * bit 4=1: enable linear adressing
    387      1.1  chopps  	 */
    388      1.1  chopps 	vgaw(ba, ECR_ADV_FUNC_CNTL, 0x11);
    389      1.1  chopps 
    390      1.1  chopps 	/* enable cpu acess, color mode, high 64k page */
    391      1.1  chopps 	vgaw(ba, GREG_MISC_OUTPUT_W, 0x23);
    392      1.1  chopps 
    393      1.1  chopps 	/* Cpu base addr */
    394      1.1  chopps 	WCrt(ba, CRT_ID_EXT_SYS_CNTL_4, 0x0);
    395      1.1  chopps 
    396      1.1  chopps 	/* Reset. This does nothing, but everyone does it:) */
    397      1.1  chopps 	WSeq(ba, SEQ_ID_RESET, 0x3);
    398      1.1  chopps 
    399      1.1  chopps 	WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x1);	/* 8 Dot Clock */
    400      1.1  chopps 	WSeq(ba, SEQ_ID_MAP_MASK, 0xF);		/* Enable write planes */
    401      1.1  chopps 	WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x0);	/* Character Font */
    402      1.1  chopps 
    403      1.1  chopps 	WSeq(ba, SEQ_ID_MEMORY_MODE, 0x2);	/* Complete mem access */
    404      1.1  chopps 
    405      1.1  chopps 	WSeq(ba, SEQ_ID_UNLOCK_EXT, 0x6);	/* Unlock extensions */
    406      1.1  chopps 	test = RSeq(ba, SEQ_ID_BUS_REQ_CNTL);	/* Bus Request */
    407      1.1  chopps 
    408      1.1  chopps 	/* enable 4MB fast Page Mode */
    409      1.1  chopps 	test = test | 1 << 6;
    410      1.1  chopps 	WSeq(ba, SEQ_ID_BUS_REQ_CNTL, test);
    411  1.3.2.1  chopps 	/* faster LUT write */
    412  1.3.2.1  chopps 	WSeq(ba, SEQ_ID_RAMDAC_CNTL, 0x40);
    413      1.1  chopps 
    414      1.1  chopps 	test = RSeq(ba, SEQ_ID_CLKSYN_CNTL_2);	/* Clksyn2 read */
    415      1.1  chopps 
    416      1.1  chopps 	/* immediately Clkload bit clear */
    417      1.1  chopps 	test = test & 0xDF;
    418      1.1  chopps 	WSeq(ba, SEQ_ID_CLKSYN_CNTL_2, test);
    419      1.1  chopps 
    420      1.1  chopps 	clockpar = compute_clock(0x3473BC0);
    421      1.1  chopps 	test = (clockpar & 0xFF00) >> 8;
    422      1.1  chopps 	WSeq(ba, SEQ_ID_MCLK_HI, test);		/* PLL N-Divider Value */
    423      1.1  chopps 
    424      1.1  chopps 	test = clockpar & 0xFF;
    425      1.1  chopps 	WSeq(ba, SEQ_ID_MCLK_LO, test);		/* PLL M-Divider Value */
    426      1.1  chopps 
    427      1.1  chopps 	/* We now load an 25 MHz, 31 kHz, 640x480 standard VGA Mode. */
    428      1.1  chopps 	/* DCLK */
    429      1.1  chopps 	WSeq(ba, SEQ_ID_DCLK_HI, 0x13);
    430      1.1  chopps 	WSeq(ba, SEQ_ID_DCLK_LO, 0x41);
    431      1.1  chopps 
    432      1.1  chopps 	test = RSeq (ba, SEQ_ID_CLKSYN_CNTL_2);
    433      1.1  chopps 	test = test | 0x22;
    434      1.1  chopps 
    435      1.1  chopps 	/* DCLK + MCLK Clock immediate load! */
    436      1.1  chopps 	WSeq(ba,SEQ_ID_CLKSYN_CNTL_2, test);
    437      1.1  chopps 
    438      1.1  chopps 	/* DCLK load */
    439      1.1  chopps 	test = vgar(ba, 0x3cc);
    440      1.1  chopps 	test = test | 0x0c;
    441      1.1  chopps 	vgaw(ba, 0x3c2, test);
    442      1.1  chopps 
    443      1.1  chopps 	/* Clear bit 5 again, prevent further loading. */
    444      1.1  chopps 	WSeq(ba, SEQ_ID_CLKSYN_CNTL_2, 0x2);
    445      1.1  chopps 
    446      1.1  chopps 	WCrt(ba, CRT_ID_HOR_TOTAL, 0x5F);
    447      1.1  chopps 	WCrt(ba, CRT_ID_HOR_DISP_ENA_END, 0x4F);
    448      1.1  chopps 	WCrt(ba, CRT_ID_START_HOR_BLANK, 0x50);
    449      1.1  chopps 	WCrt(ba, CRT_ID_END_HOR_BLANK, 0x82);
    450      1.1  chopps 	WCrt(ba, CRT_ID_START_HOR_RETR, 0x54);
    451      1.1  chopps 	WCrt(ba, CRT_ID_END_HOR_RETR, 0x80);
    452      1.1  chopps 	WCrt(ba, CRT_ID_VER_TOTAL, 0xBF);
    453      1.1  chopps 
    454      1.1  chopps 	WCrt(ba, CRT_ID_OVERFLOW, 0x1F);	/* overflow reg */
    455      1.1  chopps 
    456      1.1  chopps 	WCrt(ba, CRT_ID_PRESET_ROW_SCAN, 0x0);	/* no panning */
    457      1.1  chopps 
    458      1.1  chopps 	WCrt(ba, CRT_ID_MAX_SCAN_LINE, 0x40);	/* vscan */
    459      1.1  chopps 
    460      1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_START, 0x00);
    461      1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_END, 0x00);
    462      1.1  chopps 
    463      1.1  chopps 	/* Display start adress */
    464      1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
    465      1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
    466      1.1  chopps 
    467      1.1  chopps 	/* Cursor location */
    468      1.3  chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
    469      1.1  chopps 	WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
    470      1.1  chopps 
    471      1.1  chopps 	/* Vertical retrace */
    472      1.1  chopps 	WCrt(ba, CRT_ID_START_VER_RETR, 0x9C);
    473      1.1  chopps 	WCrt(ba, CRT_ID_END_VER_RETR, 0x0E);
    474      1.1  chopps 
    475      1.1  chopps 	WCrt(ba, CRT_ID_VER_DISP_ENA_END, 0x8F);
    476      1.1  chopps 	WCrt(ba, CRT_ID_SCREEN_OFFSET, 0x50);
    477      1.1  chopps 
    478      1.1  chopps 	WCrt(ba, CRT_ID_UNDERLINE_LOC, 0x00);
    479      1.1  chopps 
    480      1.1  chopps 	WCrt(ba, CRT_ID_START_VER_BLANK, 0x96);
    481      1.1  chopps 	WCrt(ba, CRT_ID_END_VER_BLANK, 0xB9);
    482      1.1  chopps 
    483      1.1  chopps 	WCrt(ba, CRT_ID_MODE_CONTROL, 0xE3);
    484      1.1  chopps 
    485      1.1  chopps 	WCrt(ba, CRT_ID_LINE_COMPARE, 0xFF);
    486      1.1  chopps 
    487      1.1  chopps 	WCrt(ba, CRT_ID_BACKWAD_COMP_3, 0x10);	/* FIFO enabled */
    488      1.1  chopps 
    489      1.1  chopps 	/* Refresh count 1, High speed text font, enhanced color mode */
    490      1.1  chopps 	WCrt(ba, CRT_ID_MISC_1, 0x35);
    491      1.1  chopps 
    492      1.1  chopps 	/* start fifo position */
    493      1.1  chopps 	WCrt(ba, CRT_ID_DISPLAY_FIFO, 0x5a);
    494      1.1  chopps 
    495      1.1  chopps 	WCrt(ba, CRT_ID_EXT_MEM_CNTL_2, 0x70);
    496      1.1  chopps 
    497      1.1  chopps 	/* address window position */
    498      1.1  chopps 	WCrt(ba, CRT_ID_LAW_POS_LO, 0x40);
    499      1.1  chopps 
    500      1.1  chopps 	/* N Parameter for Display FIFO */
    501      1.1  chopps 	WCrt(ba, CRT_ID_EXT_MEM_CNTL_3, 0xFF);
    502      1.1  chopps 
    503      1.1  chopps 	WGfx(ba, GCT_ID_SET_RESET, 0x0);
    504      1.1  chopps 	WGfx(ba, GCT_ID_ENABLE_SET_RESET, 0x0);
    505      1.1  chopps 	WGfx(ba, GCT_ID_COLOR_COMPARE, 0x0);
    506      1.1  chopps 	WGfx(ba, GCT_ID_DATA_ROTATE, 0x0);
    507      1.1  chopps 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x0);
    508      1.1  chopps 	WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x40);
    509      1.1  chopps 	WGfx(ba, GCT_ID_MISC, 0x01);
    510      1.1  chopps 	WGfx(ba, GCT_ID_COLOR_XCARE, 0x0F);
    511      1.1  chopps 	WGfx(ba, GCT_ID_BITMASK, 0xFF);
    512      1.1  chopps 
    513      1.1  chopps 	/* colors for text mode */
    514      1.1  chopps 	for (i = 0; i <= 0xf; i++)
    515      1.1  chopps 		WAttr (ba, i, i);
    516      1.1  chopps 
    517  1.3.2.1  chopps 	WAttr(ba, ACT_ID_ATTR_MODE_CNTL, 0x41);
    518  1.3.2.1  chopps 	WAttr(ba, ACT_ID_OVERSCAN_COLOR, 0x01);
    519  1.3.2.1  chopps 	WAttr(ba, ACT_ID_COLOR_PLANE_ENA, 0x0F);
    520  1.3.2.1  chopps 	WAttr(ba, ACT_ID_HOR_PEL_PANNING, 0x0);
    521  1.3.2.1  chopps 	WAttr(ba, ACT_ID_COLOR_SELECT, 0x0);
    522      1.1  chopps 
    523      1.1  chopps 	vgaw(ba, VDAC_MASK, 0xFF);	/* DAC Mask */
    524      1.1  chopps 
    525      1.1  chopps 	*((unsigned long *)(ba + ECR_FRGD_COLOR)) = 0xFF;
    526      1.1  chopps 	*((unsigned long *)(ba + ECR_BKGD_COLOR)) = 0;
    527      1.1  chopps 
    528      1.1  chopps 	/* colors initially set to greyscale */
    529      1.1  chopps 
    530      1.1  chopps 	vgaw(ba, VDAC_ADDRESS_W, 0);
    531      1.1  chopps 	for (i = 255; i >= 0 ; i--) {
    532      1.1  chopps 		vgaw(ba, VDAC_DATA, i);
    533      1.1  chopps 		vgaw(ba, VDAC_DATA, i);
    534      1.1  chopps 		vgaw(ba, VDAC_DATA, i);
    535      1.1  chopps 	}
    536      1.1  chopps 
    537      1.1  chopps 	/* GFx hardware cursor off */
    538      1.1  chopps 	WCrt(ba, CRT_ID_HWGC_MODE, 0x00);
    539      1.1  chopps 
    540      1.1  chopps 	/* Set first to 4 MB, so test will work */
    541      1.1  chopps 	WCrt(ba, CRT_ID_LAW_CNTL, 0x13);
    542      1.1  chopps 
    543      1.1  chopps 	/* find *correct* fbsize of z3 board */
    544      1.1  chopps 	if (cv_has_4mb((volatile char *)cv_boardaddr + 0x01400000)) {
    545      1.1  chopps 		cv_fbsize = 1024 * 1024 * 4;
    546      1.1  chopps 		WCrt(ba, CRT_ID_LAW_CNTL, 0x13); /* 4 MB */
    547      1.1  chopps 	} else {
    548      1.1  chopps 		cv_fbsize = 1024 * 1024 * 2;
    549      1.1  chopps 		WCrt(ba, CRT_ID_LAW_CNTL, 0x12); /* 2 MB */
    550      1.1  chopps 	}
    551      1.1  chopps 
    552      1.1  chopps 	/* If I knew what this really does... but it _is_ necessary
    553      1.1  chopps 	to get any gfx on the screen!! Undocumented register? */
    554      1.1  chopps 	WAttr(ba, 0x33, 0);
    555  1.3.2.1  chopps 
    556  1.3.2.1  chopps 	gi = &gp->g_display;
    557  1.3.2.1  chopps 	gi->gd_regaddr	= (caddr_t) kvtop (ba);
    558  1.3.2.1  chopps 	gi->gd_regsize	= 64 * 1024;
    559  1.3.2.1  chopps 	gi->gd_fbaddr	= (caddr_t) kvtop (gp->g_fbkva);
    560  1.3.2.1  chopps 	gi->gd_fbsize	= cv_fbsize;
    561      1.1  chopps }
    562      1.1  chopps 
    563      1.1  chopps 
    564      1.1  chopps int
    565      1.1  chopps cv_getvmode(gp, vm)
    566      1.1  chopps 	struct grf_softc *gp;
    567      1.1  chopps 	struct grfvideo_mode *vm;
    568      1.1  chopps {
    569      1.1  chopps 	struct grfvideo_mode *gv;
    570      1.1  chopps 
    571      1.1  chopps #ifdef CV64CONSOLE
    572      1.1  chopps 	/* Handle grabbing console mode */
    573      1.1  chopps 	if (vm->mode_num == 255) {
    574      1.1  chopps 		bcopy(&cvconsole_mode, vm, sizeof(struct grfvideo_mode));
    575      1.2  chopps 		/* XXX so grfconfig can tell us the correct text dimensions. */
    576      1.1  chopps 		vm->depth = cvconsole_mode.fy;
    577      1.2  chopps 	} else
    578      1.1  chopps #endif
    579      1.2  chopps 	{
    580      1.2  chopps 		if (vm->mode_num == 0)
    581      1.2  chopps 			vm->mode_num = (monitor_current - monitor_def) + 1;
    582      1.2  chopps 		if (vm->mode_num < 1 || vm->mode_num > monitor_def_max)
    583      1.2  chopps 			return (EINVAL);
    584      1.2  chopps 		gv = monitor_def + (vm->mode_num - 1);
    585      1.2  chopps 		if (gv->mode_num == 0)
    586      1.2  chopps 			return (EINVAL);
    587      1.2  chopps 
    588      1.2  chopps 		bcopy(gv, vm, sizeof(struct grfvideo_mode));
    589      1.2  chopps 	}
    590      1.2  chopps 
    591      1.2  chopps 	/* adjust internal values to pixel values */
    592      1.2  chopps 
    593      1.2  chopps 	vm->hblank_start *= 8;
    594      1.2  chopps 	vm->hblank_stop *= 8;
    595      1.2  chopps 	vm->hsync_start *= 8;
    596      1.2  chopps 	vm->hsync_stop *= 8;
    597      1.2  chopps 	vm->htotal *= 8;
    598      1.1  chopps 
    599      1.2  chopps 	return (0);
    600      1.1  chopps }
    601      1.1  chopps 
    602      1.1  chopps 
    603      1.1  chopps int
    604      1.1  chopps cv_setvmode(gp, mode)
    605      1.1  chopps 	struct grf_softc *gp;
    606      1.1  chopps 	unsigned mode;
    607      1.1  chopps {
    608      1.1  chopps 	if (!mode || (mode > monitor_def_max) ||
    609      1.1  chopps 	    monitor_def[mode-1].mode_num == 0)
    610      1.2  chopps 		return (EINVAL);
    611      1.1  chopps 
    612      1.1  chopps 	monitor_current = monitor_def + (mode - 1);
    613      1.1  chopps 
    614      1.2  chopps 	return (0);
    615      1.1  chopps }
    616      1.1  chopps 
    617      1.1  chopps void
    618      1.1  chopps cv_off(gp)
    619      1.1  chopps 	struct grf_softc *gp;
    620      1.1  chopps {
    621      1.1  chopps 	char *ba = gp->g_regkva - READ_OFFSET;
    622      1.1  chopps 
    623      1.1  chopps 	/* we'll put the pass-through on for cc ite and set Full Bandwidth
    624      1.1  chopps 	 * bit on just in case it didn't work...but then it doesn't matter
    625      1.1  chopps 	 * does it? =)
    626      1.1  chopps 	 */
    627      1.1  chopps 	cvscreen(1, ba);
    628      1.1  chopps }
    629      1.1  chopps 
    630      1.1  chopps int
    631      1.1  chopps cv_blank(gp, on)
    632      1.1  chopps 	struct grf_softc *gp;
    633      1.1  chopps 	int *on;
    634      1.1  chopps {
    635      1.1  chopps 	char *ba = gp->g_regkva;
    636      1.1  chopps 
    637      1.2  chopps 	gfx_on_off(*on ? 1 : 0, ba);
    638      1.1  chopps 	return (0);
    639      1.1  chopps }
    640      1.1  chopps 
    641      1.1  chopps 
    642      1.1  chopps /*
    643      1.1  chopps  * Change the mode of the display.
    644      1.1  chopps  * Return a UNIX error number or 0 for success.
    645      1.1  chopps  */
    646      1.1  chopps int
    647      1.1  chopps cv_mode(gp, cmd, arg, a2, a3)
    648      1.1  chopps 	register struct grf_softc *gp;
    649      1.1  chopps 	int cmd;
    650      1.1  chopps 	void *arg;
    651      1.1  chopps 	int a2, a3;
    652      1.1  chopps {
    653      1.1  chopps 	int error;
    654      1.1  chopps 
    655      1.1  chopps 	switch (cmd) {
    656      1.1  chopps 	case GM_GRFON:
    657      1.1  chopps 		error = cv_load_mon (gp,
    658      1.1  chopps 		    (struct grfcvtext_mode *) monitor_current) ? 0 : EINVAL;
    659      1.2  chopps 		return (error);
    660      1.1  chopps 
    661      1.1  chopps 	case GM_GRFOFF:
    662      1.1  chopps #ifndef CV64CONSOLE
    663      1.1  chopps 		cv_off(gp);
    664      1.1  chopps #else
    665      1.1  chopps 		cv_load_mon(gp, &cvconsole_mode);
    666      1.1  chopps #endif
    667      1.2  chopps 		return (0);
    668      1.1  chopps 
    669      1.1  chopps 	case GM_GRFCONFIG:
    670      1.2  chopps 		return (0);
    671      1.1  chopps 
    672      1.1  chopps 	case GM_GRFGETVMODE:
    673      1.2  chopps 		return (cv_getvmode (gp, (struct grfvideo_mode *) arg));
    674      1.1  chopps 
    675      1.1  chopps 	case GM_GRFSETVMODE:
    676      1.1  chopps 		error = cv_setvmode (gp, *(unsigned *) arg);
    677      1.1  chopps 		if (!error && (gp->g_flags & GF_GRFON))
    678      1.1  chopps 			cv_load_mon(gp,
    679      1.1  chopps 			    (struct grfcvtext_mode *) monitor_current);
    680      1.2  chopps 		return (error);
    681      1.1  chopps 
    682      1.1  chopps 	case GM_GRFGETNUMVM:
    683      1.1  chopps 		*(int *)arg = monitor_def_max;
    684      1.2  chopps 		return (0);
    685      1.1  chopps 
    686      1.1  chopps 	case GM_GRFIOCTL:
    687      1.2  chopps 		return (cv_ioctl (gp, (int) arg, (caddr_t) a2));
    688      1.1  chopps 
    689      1.1  chopps 	default:
    690      1.1  chopps 		break;
    691      1.1  chopps 	}
    692      1.1  chopps 
    693      1.2  chopps 	return (EINVAL);
    694      1.1  chopps }
    695      1.1  chopps 
    696      1.1  chopps int
    697      1.1  chopps cv_ioctl (gp, cmd, data)
    698      1.1  chopps 	register struct grf_softc *gp;
    699      1.1  chopps 	int cmd;
    700      1.1  chopps 	void *data;
    701      1.1  chopps {
    702      1.1  chopps 	switch (cmd) {
    703      1.1  chopps 	case GRFIOCGSPRITEPOS:
    704      1.1  chopps 	case GRFIOCSSPRITEPOS:
    705      1.1  chopps 	case GRFIOCSSPRITEINF:
    706      1.1  chopps 	case GRFIOCGSPRITEINF:
    707      1.1  chopps 	case GRFIOCGSPRITEMAX:
    708      1.1  chopps 		break;
    709      1.1  chopps 
    710      1.1  chopps 	case GRFIOCGETCMAP:
    711      1.2  chopps 		return (cv_getcmap (gp, (struct grf_colormap *) data));
    712      1.1  chopps 
    713      1.1  chopps 	case GRFIOCPUTCMAP:
    714      1.2  chopps 		return (cv_putcmap (gp, (struct grf_colormap *) data));
    715      1.1  chopps 
    716      1.1  chopps 	case GRFIOCBITBLT:
    717      1.1  chopps 		break;
    718      1.1  chopps 
    719      1.1  chopps 	case GRFTOGGLE:
    720      1.2  chopps 		return (cv_toggle (gp, 0));
    721      1.1  chopps 
    722      1.1  chopps 	case GRFIOCSETMON:
    723      1.2  chopps 		return (cv_setmonitor (gp, (struct grfvideo_mode *)data));
    724      1.1  chopps 
    725      1.1  chopps 	case GRFIOCBLANK:
    726      1.2  chopps 		return (cv_blank (gp, (int *)data));
    727      1.1  chopps 	}
    728      1.2  chopps 	return (EINVAL);
    729      1.1  chopps }
    730      1.1  chopps 
    731      1.1  chopps int
    732      1.1  chopps cv_setmonitor(gp, gv)
    733      1.1  chopps 	struct grf_softc *gp;
    734      1.1  chopps 	struct grfvideo_mode *gv;
    735      1.1  chopps {
    736      1.1  chopps 	struct grfvideo_mode *md;
    737      1.1  chopps 
    738      1.2  chopps 	if (!cv_mondefok(gv))
    739      1.2  chopps 		return (EINVAL);
    740      1.2  chopps 
    741      1.1  chopps #ifdef CV64CONSOLE
    742      1.1  chopps 	/* handle interactive setting of console mode */
    743      1.2  chopps 	if (gv->mode_num == 255) {
    744      1.1  chopps 		bcopy(gv, &cvconsole_mode.gv, sizeof(struct grfvideo_mode));
    745      1.2  chopps 		cvconsole_mode.gv.hblank_start /= 8;
    746      1.2  chopps 		cvconsole_mode.gv.hblank_stop /= 8;
    747      1.2  chopps 		cvconsole_mode.gv.hsync_start /= 8;
    748      1.2  chopps 		cvconsole_mode.gv.hsync_stop /= 8;
    749      1.2  chopps 		cvconsole_mode.gv.htotal /= 8;
    750      1.1  chopps 		cvconsole_mode.rows = gv->disp_height / cvconsole_mode.fy;
    751      1.1  chopps 		cvconsole_mode.cols = gv->disp_width / cvconsole_mode.fx;
    752      1.1  chopps 		if (!(gp->g_flags & GF_GRFON))
    753      1.1  chopps 			cv_load_mon(gp, &cvconsole_mode);
    754      1.1  chopps 		ite_reinit(gp->g_itedev);
    755      1.2  chopps 		return (0);
    756      1.1  chopps 	}
    757      1.1  chopps #endif
    758      1.1  chopps 
    759      1.2  chopps 	md = monitor_def + (gv->mode_num - 1);
    760      1.2  chopps 	bcopy(gv, md, sizeof(struct grfvideo_mode));
    761      1.1  chopps 
    762      1.2  chopps 	/* adjust pixel oriented values to internal rep. */
    763      1.1  chopps 
    764      1.2  chopps 	md->hblank_start /= 8;
    765      1.2  chopps 	md->hblank_stop /= 8;
    766      1.2  chopps 	md->hsync_start /= 8;
    767      1.2  chopps 	md->hsync_stop /= 8;
    768      1.2  chopps 	md->htotal /= 8;
    769      1.1  chopps 
    770      1.2  chopps 	return (0);
    771      1.1  chopps }
    772      1.1  chopps 
    773      1.1  chopps int
    774      1.1  chopps cv_getcmap(gfp, cmap)
    775      1.1  chopps 	struct grf_softc *gfp;
    776      1.1  chopps 	struct grf_colormap *cmap;
    777      1.1  chopps {
    778      1.1  chopps 	volatile unsigned char *ba;
    779      1.1  chopps 	u_char red[256], green[256], blue[256], *rp, *gp, *bp;
    780      1.1  chopps 	short x;
    781      1.1  chopps 	int error;
    782      1.1  chopps 
    783      1.1  chopps 	if (cmap->count == 0 || cmap->index >= 256)
    784      1.2  chopps 		return (0);
    785      1.1  chopps 
    786      1.1  chopps 	if (cmap->index + cmap->count > 256)
    787      1.1  chopps 		cmap->count = 256 - cmap->index;
    788      1.1  chopps 
    789      1.1  chopps 	ba = gfp->g_regkva;
    790      1.1  chopps 	/* first read colors out of the chip, then copyout to userspace */
    791      1.1  chopps 	vgaw (ba, VDAC_ADDRESS_W, cmap->index);
    792      1.1  chopps 	x = cmap->count - 1;
    793      1.1  chopps 
    794      1.1  chopps 	rp = red + cmap->index;
    795      1.1  chopps 	gp = green + cmap->index;
    796      1.1  chopps 	bp = blue + cmap->index;
    797      1.1  chopps 
    798      1.1  chopps 	do {
    799      1.1  chopps 		*rp++ = vgar (ba, VDAC_DATA) << 2;
    800      1.1  chopps 		*gp++ = vgar (ba, VDAC_DATA) << 2;
    801      1.1  chopps 		*bp++ = vgar (ba, VDAC_DATA) << 2;
    802      1.1  chopps 	} while (x-- > 0);
    803      1.1  chopps 
    804      1.1  chopps 	if (!(error = copyout (red + cmap->index, cmap->red, cmap->count))
    805      1.1  chopps 	    && !(error = copyout (green + cmap->index, cmap->green, cmap->count))
    806      1.1  chopps 	    && !(error = copyout (blue + cmap->index, cmap->blue, cmap->count)))
    807      1.2  chopps 		return (0);
    808      1.1  chopps 
    809      1.2  chopps 	return (error);
    810      1.1  chopps }
    811      1.1  chopps 
    812      1.1  chopps int
    813      1.1  chopps cv_putcmap(gfp, cmap)
    814      1.1  chopps 	struct grf_softc *gfp;
    815      1.1  chopps 	struct grf_colormap *cmap;
    816      1.1  chopps {
    817      1.1  chopps 	volatile unsigned char *ba;
    818      1.1  chopps 	u_char red[256], green[256], blue[256], *rp, *gp, *bp;
    819      1.1  chopps 	short x;
    820      1.1  chopps 	int error;
    821      1.1  chopps 
    822      1.1  chopps 	if (cmap->count == 0 || cmap->index >= 256)
    823      1.2  chopps 		return (0);
    824      1.1  chopps 
    825      1.1  chopps 	if (cmap->index + cmap->count > 256)
    826      1.1  chopps 		cmap->count = 256 - cmap->index;
    827      1.1  chopps 
    828      1.1  chopps 	/* first copy the colors into kernelspace */
    829      1.1  chopps 	if (!(error = copyin (cmap->red, red + cmap->index, cmap->count))
    830      1.1  chopps 	    && !(error = copyin (cmap->green, green + cmap->index, cmap->count))
    831      1.1  chopps 	    && !(error = copyin (cmap->blue, blue + cmap->index, cmap->count))) {
    832      1.1  chopps 		ba = gfp->g_regkva;
    833      1.1  chopps 		vgaw (ba, VDAC_ADDRESS_W, cmap->index);
    834      1.1  chopps 		x = cmap->count - 1;
    835      1.1  chopps 
    836      1.1  chopps 		rp = red + cmap->index;
    837      1.1  chopps 		gp = green + cmap->index;
    838      1.1  chopps 		bp = blue + cmap->index;
    839      1.1  chopps 
    840      1.1  chopps 		do {
    841      1.1  chopps 			vgaw (ba, VDAC_DATA, *rp++ >> 2);
    842      1.1  chopps 			vgaw (ba, VDAC_DATA, *gp++ >> 2);
    843      1.1  chopps 			vgaw (ba, VDAC_DATA, *bp++ >> 2);
    844      1.1  chopps 		} while (x-- > 0);
    845      1.2  chopps 		return (0);
    846      1.2  chopps 	} else
    847      1.2  chopps 		return (error);
    848      1.1  chopps }
    849      1.1  chopps 
    850      1.1  chopps 
    851      1.1  chopps int
    852      1.1  chopps cv_toggle(gp,wopp)
    853      1.1  chopps 	struct grf_softc *gp;
    854      1.1  chopps 	unsigned short wopp; /* don't need that one yet, ill */
    855      1.1  chopps {
    856      1.1  chopps 	volatile unsigned char *ba;
    857      1.1  chopps 
    858      1.3  chopps 	ba = gp->g_regkva - READ_OFFSET;
    859      1.1  chopps 
    860      1.1  chopps 	if (pass_toggle) {
    861      1.1  chopps 		cvscreen(0, ba);
    862      1.1  chopps 	} else {
    863  1.3.2.1  chopps 		cvscreen(1, ba);
    864      1.1  chopps 	}
    865      1.2  chopps 	return (0);
    866      1.1  chopps }
    867      1.1  chopps 
    868      1.1  chopps 
    869      1.1  chopps int
    870      1.2  chopps cv_mondefok(gv)
    871      1.2  chopps 	struct grfvideo_mode *gv;
    872      1.1  chopps {
    873      1.2  chopps 	unsigned long maxpix;
    874      1.2  chopps 
    875      1.2  chopps 	if (gv->mode_num < 1 || gv->mode_num > monitor_def_max)
    876      1.2  chopps 		if (gv->mode_num != 255 || gv->depth != 4)
    877      1.2  chopps 			return (0);
    878      1.1  chopps 
    879      1.2  chopps 	switch(gv->depth) {
    880      1.1  chopps 	   case 1:
    881      1.1  chopps 	   case 4:
    882      1.3  chopps 		/* Remove this comment when ite5 is ready */
    883      1.2  chopps 		/* if (gv->mode_num != 255) */
    884      1.2  chopps 			return (0);
    885      1.1  chopps 	   case 8:
    886      1.2  chopps 		maxpix = MAXPIXELCLOCK;
    887      1.2  chopps 		break;
    888      1.1  chopps 	   case 15:
    889      1.1  chopps 	   case 16:
    890      1.2  chopps 		maxpix = MAXPIXELCLOCK - 55000000;
    891      1.2  chopps 		break;
    892      1.1  chopps 	   case 24:
    893      1.2  chopps 		maxpix = MAXPIXELCLOCK - 85000000;
    894      1.2  chopps 		break;
    895      1.1  chopps 	   default:
    896      1.2  chopps 		return (0);
    897      1.1  chopps 	}
    898      1.2  chopps 
    899      1.2  chopps 	if (gv->pixel_clock > maxpix)
    900      1.2  chopps 		return (0);
    901      1.2  chopps 	return (1);
    902      1.1  chopps }
    903      1.1  chopps 
    904      1.1  chopps int
    905      1.1  chopps cv_load_mon(gp, md)
    906      1.1  chopps 	struct grf_softc *gp;
    907      1.1  chopps 	struct grfcvtext_mode *md;
    908      1.1  chopps {
    909      1.1  chopps 	struct grfvideo_mode *gv;
    910      1.1  chopps 	struct grfinfo *gi;
    911      1.1  chopps 	volatile unsigned char *ba;
    912      1.1  chopps 	volatile unsigned char *fb;
    913      1.1  chopps 	unsigned short mnr;
    914      1.2  chopps 	unsigned short HT, HDE, HBS, HBE, HSS, HSE, VDE, VBS, VBE, VSS,
    915      1.2  chopps 		VSE, VT;
    916      1.1  chopps 	char LACE, DBLSCAN, TEXT;
    917      1.1  chopps 	int uplim, lowlim;
    918  1.3.2.1  chopps 	int cr33, sr15, sr18, clock_mode, test;
    919  1.3.2.1  chopps 	int m, n, clock;	/* For calc'ing display FIFO */
    920      1.1  chopps 
    921      1.1  chopps 	/* identity */
    922      1.1  chopps 	gv = &md->gv;
    923      1.1  chopps 	TEXT = (gv->depth == 4);
    924      1.1  chopps 
    925      1.1  chopps 	if (!cv_mondefok(gv)) {
    926      1.1  chopps 		printf("mondef not ok\n");
    927      1.2  chopps 		return (0);
    928      1.1  chopps 	}
    929      1.1  chopps 	ba = gp->g_regkva;
    930      1.1  chopps 	fb = gp->g_fbkva;
    931      1.1  chopps 
    932      1.3  chopps 	/* turn gfx off, don't mess up the display */
    933      1.3  chopps 	gfx_on_off(1, ba);
    934      1.3  chopps 
    935      1.2  chopps 	/* provide all needed information in grf device-independant locations */
    936      1.1  chopps 	gp->g_data		= (caddr_t) gv;
    937      1.1  chopps 	gi = &gp->g_display;
    938      1.1  chopps 	gi->gd_colors		= 1 << gv->depth;
    939      1.1  chopps 	gi->gd_planes		= gv->depth;
    940      1.1  chopps 	gi->gd_fbwidth		= gv->disp_width;
    941      1.1  chopps 	gi->gd_fbheight		= gv->disp_height;
    942      1.1  chopps 	gi->gd_fbx		= 0;
    943      1.1  chopps 	gi->gd_fby		= 0;
    944      1.1  chopps 	if (TEXT) {
    945      1.1  chopps 		gi->gd_dwidth	= md->fx * md->cols;
    946      1.1  chopps 		gi->gd_dheight	= md->fy * md->rows;
    947      1.1  chopps 	} else {
    948      1.1  chopps 		gi->gd_dwidth	= gv->disp_width;
    949      1.1  chopps 		gi->gd_dheight	= gv->disp_height;
    950      1.1  chopps 	}
    951      1.1  chopps 	gi->gd_dx		= 0;
    952      1.1  chopps 	gi->gd_dy		= 0;
    953      1.1  chopps 
    954      1.1  chopps 	/* get display mode parameters */
    955      1.1  chopps 
    956      1.1  chopps 	HBS = gv->hblank_start;
    957      1.1  chopps 	HBE = gv->hblank_stop;
    958      1.1  chopps 	HSS = gv->hsync_start;
    959      1.1  chopps 	HSE = gv->hsync_stop;
    960      1.1  chopps 	HT  = gv->htotal;
    961      1.1  chopps 	VBS = gv->vblank_start;
    962      1.1  chopps 	VSS = gv->vsync_start;
    963      1.1  chopps 	VSE = gv->vsync_stop;
    964      1.1  chopps 	VBE = gv->vblank_stop;
    965      1.1  chopps 	VT  = gv->vtotal;
    966      1.1  chopps 
    967      1.1  chopps 	if (TEXT)
    968      1.1  chopps 		HDE = ((gv->disp_width + md->fx - 1) / md->fx) - 1;
    969      1.1  chopps 	else
    970      1.1  chopps 		HDE = (gv->disp_width + 3) / 8 - 1; /*HBS;*/
    971      1.1  chopps 	VDE = gv->disp_height - 1;
    972      1.1  chopps 
    973      1.1  chopps 	/* figure out whether lace or dblscan is needed */
    974      1.1  chopps 
    975      1.1  chopps 	uplim = gv->disp_height + (gv->disp_height / 4);
    976      1.1  chopps 	lowlim = gv->disp_height - (gv->disp_height / 4);
    977      1.1  chopps 	LACE = (((VT * 2) > lowlim) && ((VT * 2) < uplim)) ? 1 : 0;
    978      1.1  chopps 	DBLSCAN = (((VT / 2) > lowlim) && ((VT / 2) < uplim)) ? 1 : 0;
    979      1.1  chopps 
    980      1.1  chopps 	/* adjustments */
    981      1.1  chopps 
    982      1.1  chopps 	if (LACE)
    983      1.1  chopps 		VDE /= 2;
    984      1.1  chopps 
    985      1.1  chopps 	WSeq(ba, SEQ_ID_MEMORY_MODE, (TEXT || (gv->depth == 1)) ? 0x06 : 0x0e);
    986      1.1  chopps 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
    987      1.1  chopps 	WSeq(ba, SEQ_ID_MAP_MASK, (gv->depth == 1) ? 0x01 : 0xff);
    988      1.1  chopps 	WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
    989      1.1  chopps 
    990      1.1  chopps 	/* Set clock */
    991      1.1  chopps 
    992      1.1  chopps 	switch (gv->depth) {
    993      1.1  chopps 	   case 15:
    994      1.1  chopps 	   case 16:
    995      1.1  chopps 		mnr = compute_clock(gv->pixel_clock * 2);
    996      1.1  chopps 		break;
    997      1.1  chopps 	   case 24:
    998      1.1  chopps 		mnr = compute_clock(gv->pixel_clock * 3);
    999      1.1  chopps 		break;
   1000      1.1  chopps 	   default:
   1001      1.1  chopps 		mnr = compute_clock(gv->pixel_clock);
   1002      1.1  chopps 		break;
   1003      1.1  chopps 	}
   1004      1.1  chopps 
   1005      1.1  chopps 	WSeq(ba, SEQ_ID_DCLK_HI, ((mnr & 0xFF00) >> 8) );
   1006      1.1  chopps 	WSeq(ba, SEQ_ID_DCLK_LO, (mnr & 0xFF));
   1007      1.1  chopps 
   1008      1.1  chopps 	/* load display parameters into board */
   1009      1.1  chopps 
   1010      1.1  chopps 	WCrt(ba, CRT_ID_EXT_HOR_OVF,
   1011      1.1  chopps 	   ((HT & 0x100) ? 0x01 : 0x00) |
   1012      1.1  chopps 	   ((HDE & 0x100) ? 0x02 : 0x00) |
   1013      1.1  chopps 	   ((HBS & 0x100) ? 0x04 : 0x00) |
   1014      1.3  chopps 	/* ((HBE & 0x40) ? 0x08 : 0x00) | */  /* Later... */
   1015      1.1  chopps 	   ((HSS & 0x100) ? 0x10 : 0x00) |
   1016      1.3  chopps 	/* ((HSE & 0x20) ? 0x20 : 0x00) | */
   1017      1.1  chopps 	   (((HT-5) & 0x100) ? 0x40 : 0x00) );
   1018      1.1  chopps 
   1019      1.1  chopps 	WCrt(ba, CRT_ID_EXT_VER_OVF,
   1020      1.1  chopps 	    0x40 |	/* Line compare */
   1021      1.1  chopps 	    ((VT  & 0x400) ? 0x01 : 0x00) |
   1022      1.1  chopps 	    ((VDE & 0x400) ? 0x02 : 0x00) |
   1023      1.1  chopps 	    ((VBS & 0x400) ? 0x04 : 0x00) |
   1024      1.1  chopps 	    ((VSS & 0x400) ? 0x10 : 0x00) );
   1025      1.1  chopps 
   1026      1.1  chopps 	WCrt(ba, CRT_ID_HOR_TOTAL, HT);
   1027      1.1  chopps 	WCrt(ba, CRT_ID_DISPLAY_FIFO, HT - 5);
   1028      1.1  chopps 
   1029      1.1  chopps 	WCrt(ba, CRT_ID_HOR_DISP_ENA_END, ((HDE >= HBS) ? (HBS - 1) : HDE));
   1030      1.1  chopps 	WCrt(ba, CRT_ID_START_HOR_BLANK, HBS);
   1031      1.1  chopps 	WCrt(ba, CRT_ID_END_HOR_BLANK, ((HBE & 0x1f) | 0x80));
   1032      1.1  chopps 	WCrt(ba, CRT_ID_START_HOR_RETR, HSS);
   1033      1.1  chopps 	WCrt(ba, CRT_ID_END_HOR_RETR,
   1034      1.1  chopps 	    (HSE & 0x1f) |
   1035      1.1  chopps 	    ((HBE & 0x20) ? 0x80 : 0x00) );
   1036      1.1  chopps 	WCrt(ba, CRT_ID_VER_TOTAL, VT);
   1037      1.1  chopps 	WCrt(ba, CRT_ID_OVERFLOW,
   1038      1.1  chopps 	    0x10 |
   1039      1.1  chopps 	    ((VT  & 0x100) ? 0x01 : 0x00) |
   1040      1.1  chopps 	    ((VDE & 0x100) ? 0x02 : 0x00) |
   1041      1.1  chopps 	    ((VSS & 0x100) ? 0x04 : 0x00) |
   1042      1.1  chopps 	    ((VBS & 0x100) ? 0x08 : 0x00) |
   1043      1.1  chopps 	    ((VT  & 0x200) ? 0x20 : 0x00) |
   1044      1.1  chopps 	    ((VDE & 0x200) ? 0x40 : 0x00) |
   1045      1.1  chopps 	    ((VSS & 0x200) ? 0x80 : 0x00) );
   1046      1.1  chopps 
   1047      1.1  chopps 	WCrt(ba, CRT_ID_MAX_SCAN_LINE,
   1048      1.1  chopps 	    0x40 |  /* TEXT ? 0x00 ??? */
   1049      1.1  chopps 	    (DBLSCAN ? 0x80 : 0x00) |
   1050      1.1  chopps 	    ((VBS & 0x200) ? 0x20 : 0x00) |
   1051      1.1  chopps 	    (TEXT ? ((md->fy - 1) & 0x1f) : 0x00));
   1052      1.1  chopps 
   1053      1.1  chopps 	WCrt(ba, CRT_ID_MODE_CONTROL,
   1054      1.1  chopps 	    ((TEXT || (gv->depth == 1)) ? 0xc3 : 0xe3));
   1055      1.1  chopps 
   1056      1.1  chopps 	/* text cursor */
   1057      1.1  chopps 
   1058      1.1  chopps 	if (TEXT) {
   1059      1.1  chopps #if 1
   1060      1.1  chopps 		WCrt(ba, CRT_ID_CURSOR_START, (md->fy & 0x1f) - 2);
   1061      1.1  chopps 		WCrt(ba, CRT_ID_CURSOR_END, (md->fy & 0x1f) - 1);
   1062      1.1  chopps #else
   1063      1.1  chopps 		WCrt(ba, CRT_ID_CURSOR_START, 0x00);
   1064      1.1  chopps 		WCrt(ba, CRT_ID_CURSOR_END, md->fy & 0x1f);
   1065      1.1  chopps #endif
   1066      1.1  chopps 		WCrt(ba, CRT_ID_UNDERLINE_LOC, (md->fy - 1) & 0x1f);
   1067      1.1  chopps 
   1068      1.1  chopps 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
   1069      1.1  chopps 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
   1070      1.1  chopps 	}
   1071      1.1  chopps 
   1072      1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
   1073      1.1  chopps 	WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
   1074      1.1  chopps 
   1075      1.1  chopps 	WCrt(ba, CRT_ID_START_VER_RETR, VSS);
   1076      1.1  chopps 	WCrt(ba, CRT_ID_END_VER_RETR, (VSE & 0x0f));
   1077      1.1  chopps 	WCrt(ba, CRT_ID_VER_DISP_ENA_END, VDE);
   1078      1.1  chopps 	WCrt(ba, CRT_ID_START_VER_BLANK, VBS);
   1079      1.1  chopps 	WCrt(ba, CRT_ID_END_VER_BLANK, VBE);
   1080      1.1  chopps 
   1081      1.1  chopps 	WCrt(ba, CRT_ID_LINE_COMPARE, 0xff);
   1082      1.1  chopps 	WCrt(ba, CRT_ID_LACE_RETR_START, HT / 2);
   1083      1.1  chopps 	WCrt(ba, CRT_ID_LACE_CONTROL, (LACE ? 0x20 : 0x00));
   1084      1.1  chopps 
   1085      1.1  chopps 	WGfx(ba, GCT_ID_GRAPHICS_MODE,
   1086      1.1  chopps 	    ((TEXT || (gv->depth == 1)) ? 0x00 : 0x40));
   1087      1.1  chopps 	WGfx(ba, GCT_ID_MISC, (TEXT ? 0x04 : 0x01));
   1088      1.1  chopps 
   1089      1.1  chopps 	WSeq (ba, SEQ_ID_MEMORY_MODE,
   1090      1.1  chopps 	    ((TEXT || (gv->depth == 1)) ? 0x6 : 0x02));
   1091      1.1  chopps 
   1092      1.1  chopps 	vgaw(ba, VDAC_MASK, 0xff);
   1093      1.1  chopps 
   1094  1.3.2.1  chopps 	sr15 = RSeq(ba, SEQ_ID_CLKSYN_CNTL_2);
   1095  1.3.2.1  chopps 	sr15 &= 0xef;
   1096  1.3.2.1  chopps 	sr18 = RSeq(ba, SEQ_ID_RAMDAC_CNTL);
   1097  1.3.2.1  chopps 	sr18 &= 0x7f;
   1098  1.3.2.1  chopps 	cr33 = RCrt(ba, CRT_ID_BACKWAD_COMP_2);
   1099  1.3.2.1  chopps 	cr33 &= 0xdf;
   1100  1.3.2.1  chopps 	clock_mode = 0x00;
   1101      1.1  chopps 
   1102      1.1  chopps 	test = RCrt(ba, CRT_ID_EXT_MISC_CNTL_2);
   1103  1.3.2.1  chopps 	test &= 0xd;
   1104      1.1  chopps 
   1105      1.1  chopps 	switch (gv->depth) {
   1106      1.1  chopps 	   case 1:
   1107      1.1  chopps 	   case 4: /* text */
   1108      1.1  chopps 		HDE = gv->disp_width / 16;
   1109      1.1  chopps 		break;
   1110      1.1  chopps 	   case 8:
   1111  1.3.2.1  chopps 		if (gv->pixel_clock > 80000000) {
   1112  1.3.2.1  chopps 			clock_mode = 0x10 | 0x02;
   1113  1.3.2.1  chopps 			sr15 |= 0x10;
   1114  1.3.2.1  chopps 			sr18 |= 0x80;
   1115  1.3.2.1  chopps 			cr33 |= 0x20;
   1116  1.3.2.1  chopps 		}
   1117      1.1  chopps 		HDE = gv->disp_width / 8;
   1118      1.1  chopps 		break;
   1119      1.1  chopps 	   case 15:
   1120  1.3.2.1  chopps 		clock_mode = 0x30;
   1121      1.1  chopps 		HDE = gv->disp_width / 4;
   1122      1.1  chopps 		break;
   1123      1.1  chopps 	   case 16:
   1124  1.3.2.1  chopps 		clock_mode = 0x50;
   1125      1.1  chopps 		HDE = gv->disp_width / 4;
   1126      1.1  chopps 		break;
   1127      1.1  chopps 	   case 24:
   1128  1.3.2.1  chopps 		clock_mode = 0xd0;
   1129      1.1  chopps 		HDE = (gv->disp_width / 8) * 3;
   1130      1.1  chopps 		break;
   1131      1.1  chopps 	}
   1132      1.1  chopps 
   1133  1.3.2.1  chopps 	WCrt(ba, CRT_ID_EXT_MISC_CNTL_2, clock_mode | test);
   1134  1.3.2.1  chopps 	WSeq(ba, SEQ_ID_CLKSYN_CNTL_2, sr15);
   1135  1.3.2.1  chopps 	WSeq(ba, SEQ_ID_RAMDAC_CNTL, sr18);
   1136  1.3.2.1  chopps 	WCrt(ba, CRT_ID_BACKWAD_COMP_2, cr33);
   1137  1.3.2.1  chopps 	WCrt(ba, CRT_ID_SCREEN_OFFSET, HDE);
   1138      1.1  chopps 
   1139      1.1  chopps 	test = RCrt(ba, CRT_ID_EXT_SYS_CNTL_2);
   1140      1.1  chopps 	/* HDE Overflow in bits 4-5 */
   1141      1.1  chopps 	test |= (HDE >> 4) & 0x30;
   1142      1.1  chopps 	WCrt(ba, CRT_ID_EXT_SYS_CNTL_2, test);
   1143      1.1  chopps 
   1144      1.1  chopps 	delay(100000);
   1145      1.1  chopps 	WAttr(ba, ACT_ID_ATTR_MODE_CNTL, (TEXT ? 0x0a : 0x41));
   1146      1.1  chopps 	delay(100000);
   1147      1.1  chopps 	WAttr(ba, ACT_ID_COLOR_PLANE_ENA,
   1148      1.1  chopps 	    (gv->depth == 1) ? 0x01 : 0x0f);
   1149      1.1  chopps 	delay(100000);
   1150      1.1  chopps 
   1151  1.3.2.1  chopps 	/*
   1152  1.3.2.1  chopps 	 * Calc. display fifo m and n parameters
   1153  1.3.2.1  chopps 	 * Dont't ask me what the hell these values mean.
   1154      1.1  chopps 	 */
   1155      1.1  chopps 
   1156  1.3.2.1  chopps 	n = 0xff;
   1157  1.3.2.1  chopps 	if (gv->depth < 9)
   1158  1.3.2.1  chopps 		clock = gv->pixel_clock / 500000.0;
   1159  1.3.2.1  chopps 	else if (gv->depth == 15)
   1160  1.3.2.1  chopps 		clock = gv->pixel_clock / 250000.0;
   1161  1.3.2.1  chopps 	else
   1162  1.3.2.1  chopps 		clock = (gv->pixel_clock * (gv->depth / 8)) / 500000.0;
   1163  1.3.2.1  chopps 
   1164  1.3.2.1  chopps 	m = ((int)((55 * .72 + 16.867) * 89.736 / (clock + 39) - 21.1543) / 2) - 1;
   1165  1.3.2.1  chopps 
   1166  1.3.2.1  chopps 	if (m > 31)
   1167  1.3.2.1  chopps 		m = 31;
   1168  1.3.2.1  chopps 	else if (m <= 0) {
   1169  1.3.2.1  chopps 		m = 0;
   1170  1.3.2.1  chopps 		n = 16;
   1171  1.3.2.1  chopps 	}
   1172      1.1  chopps 
   1173  1.3.2.1  chopps 	m = m << 3;
   1174  1.3.2.1  chopps 	WCrt(ba, CRT_ID_EXT_MEM_CNTL_2, m);
   1175  1.3.2.1  chopps 	WCrt(ba, CRT_ID_EXT_MEM_CNTL_3, n);
   1176      1.1  chopps 	delay(10000);
   1177      1.1  chopps 
   1178      1.3  chopps 	/* text initialization */
   1179      1.3  chopps 
   1180      1.3  chopps 	if (TEXT) {
   1181      1.3  chopps 		cv_inittextmode(gp);
   1182      1.3  chopps 	}
   1183      1.3  chopps 
   1184      1.1  chopps 	/* Some kind of Magic */
   1185      1.1  chopps 	WAttr(ba, 0x33, 0);
   1186      1.1  chopps 
   1187      1.1  chopps 	/* turn gfx on again */
   1188      1.1  chopps 	gfx_on_off(0, ba);
   1189      1.1  chopps 
   1190      1.1  chopps 	/* Pass-through */
   1191      1.3  chopps 	cvscreen(0, ba - READ_OFFSET);
   1192      1.1  chopps 
   1193      1.2  chopps 	return (1);
   1194      1.1  chopps }
   1195      1.1  chopps 
   1196      1.1  chopps void
   1197      1.1  chopps cv_inittextmode(gp)
   1198      1.1  chopps 	struct grf_softc *gp;
   1199      1.1  chopps {
   1200      1.1  chopps 	struct grfcvtext_mode *tm = (struct grfcvtext_mode *)gp->g_data;
   1201      1.1  chopps 	volatile unsigned char *ba = gp->g_regkva;
   1202      1.1  chopps 	unsigned char *fb = gp->g_fbkva;
   1203      1.1  chopps 	unsigned char *c, *f, y;
   1204      1.1  chopps 	unsigned short z;
   1205      1.1  chopps 
   1206      1.1  chopps 
   1207      1.1  chopps 	/* load text font into beginning of display memory.
   1208      1.2  chopps 	 * Each character cell is 32 bytes long (enough for 4 planes)
   1209      1.1  chopps 	 */
   1210      1.1  chopps 
   1211      1.1  chopps 	SetTextPlane(ba, 0x02);
   1212      1.2  chopps 	cv_memset(fb, 0, 256 * 32);
   1213      1.2  chopps 	c = (unsigned char *) (fb) + (32 * tm->fdstart);
   1214      1.1  chopps 	f = tm->fdata;
   1215      1.2  chopps 	for (z = tm->fdstart; z <= tm->fdend; z++, c += (32 - tm->fy))
   1216      1.2  chopps 		for (y = 0; y < tm->fy; y++)
   1217      1.1  chopps 			*c++ = *f++;
   1218      1.1  chopps 
   1219      1.1  chopps 	/* clear out text/attr planes (three screens worth) */
   1220      1.1  chopps 
   1221      1.1  chopps 	SetTextPlane(ba, 0x01);
   1222      1.2  chopps 	cv_memset(fb, 0x07, tm->cols * tm->rows * 3);
   1223      1.1  chopps 	SetTextPlane(ba, 0x00);
   1224      1.2  chopps 	cv_memset(fb, 0x20, tm->cols * tm->rows * 3);
   1225      1.1  chopps 
   1226      1.1  chopps 	/* print out a little init msg */
   1227      1.1  chopps 
   1228      1.1  chopps 	c = (unsigned char *)(fb) + (tm->cols-16);
   1229      1.1  chopps 	strcpy(c, "CV64");
   1230      1.1  chopps 	c[6] = 0x20;
   1231      1.1  chopps 
   1232      1.1  chopps 	/* set colors (B&W) */
   1233      1.1  chopps 
   1234      1.1  chopps 	vgaw(ba, VDAC_ADDRESS_W, 0);
   1235      1.1  chopps 	for (z=0; z<256; z++) {
   1236      1.1  chopps 		unsigned char r, g, b;
   1237      1.1  chopps 
   1238      1.1  chopps 		y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
   1239      1.1  chopps 
   1240      1.1  chopps 		r = cvconscolors[y][0];
   1241      1.1  chopps 		g = cvconscolors[y][1];
   1242      1.1  chopps 		b = cvconscolors[y][2];
   1243      1.1  chopps 		vgaw(ba, VDAC_DATA, r >> 2);
   1244      1.1  chopps 		vgaw(ba, VDAC_DATA, g >> 2);
   1245      1.1  chopps 		vgaw(ba, VDAC_DATA, b >> 2);
   1246      1.1  chopps 	}
   1247      1.1  chopps }
   1248      1.1  chopps 
   1249      1.1  chopps void
   1250      1.1  chopps cv_memset(d, c, l)
   1251      1.1  chopps 	unsigned char *d;
   1252      1.1  chopps 	unsigned char c;
   1253      1.1  chopps 	int l;
   1254      1.1  chopps {
   1255      1.1  chopps 	for(; l > 0; l--)
   1256      1.1  chopps 		*d++ = c;
   1257      1.1  chopps }
   1258      1.1  chopps 
   1259      1.1  chopps #endif  /* NGRFCV */
   1260