Home | History | Annotate | Line # | Download | only in dev
ite_rt.c revision 1.21
      1  1.21  christos /*	$NetBSD: ite_rt.c,v 1.21 2007/03/04 05:59:23 christos Exp $ */
      2   1.5    chopps 
      3  1.12    chopps /*
      4  1.12    chopps  * Copyright (c) 1993 Markus Wild
      5  1.12    chopps  * Copyright (c) 1993 Lutz Vieweg
      6  1.12    chopps  * All rights reserved.
      7  1.12    chopps  *
      8  1.12    chopps  * Redistribution and use in source and binary forms, with or without
      9  1.12    chopps  * modification, are permitted provided that the following conditions
     10  1.12    chopps  * are met:
     11  1.12    chopps  * 1. Redistributions of source code must retain the above copyright
     12  1.12    chopps  *    notice, this list of conditions and the following disclaimer.
     13  1.12    chopps  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.12    chopps  *    notice, this list of conditions and the following disclaimer in the
     15  1.12    chopps  *    documentation and/or other materials provided with the distribution.
     16  1.12    chopps  * 3. All advertising materials mentioning features or use of this software
     17  1.12    chopps  *    must display the following acknowledgement:
     18  1.12    chopps  *      This product includes software developed by Lutz Vieweg.
     19  1.12    chopps  * 4. The name of the author may not be used to endorse or promote products
     20  1.12    chopps  *    derived from this software without specific prior written permission
     21  1.12    chopps  *
     22  1.12    chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.12    chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.12    chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.12    chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.12    chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.12    chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.12    chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.12    chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.12    chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.12    chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.12    chopps  */
     33  1.18   aymeric 
     34  1.18   aymeric #include <sys/cdefs.h>
     35  1.21  christos __KERNEL_RCSID(0, "$NetBSD: ite_rt.c,v 1.21 2007/03/04 05:59:23 christos Exp $");
     36  1.18   aymeric 
     37  1.10    chopps #include "grfrt.h"
     38  1.10    chopps #if NGRFRT > 0
     39  1.10    chopps 
     40   1.6    chopps #include <sys/param.h>
     41   1.6    chopps #include <sys/conf.h>
     42   1.6    chopps #include <sys/proc.h>
     43   1.9    chopps #include <sys/device.h>
     44   1.6    chopps #include <sys/ioctl.h>
     45   1.6    chopps #include <sys/tty.h>
     46   1.6    chopps #include <sys/systm.h>
     47   1.7    chopps #include <dev/cons.h>
     48   1.9    chopps #include <machine/cpu.h>
     49   1.9    chopps #include <amiga/amiga/device.h>
     50   1.6    chopps #include <amiga/dev/itevar.h>
     51   1.6    chopps #include <amiga/dev/grfioctl.h>
     52   1.6    chopps #include <amiga/dev/grfvar.h>
     53   1.6    chopps #include <amiga/dev/grf_rtreg.h>
     54   1.7    chopps 
     55   1.8    chopps int retina_console = 1;
     56   1.7    chopps 
     57  1.17   aymeric void retina_cursor(struct ite_softc *, int);
     58  1.17   aymeric void retina_scroll(struct ite_softc *, int, int, int, int);
     59  1.17   aymeric void retina_deinit(struct ite_softc *);
     60  1.17   aymeric void retina_clear(struct ite_softc *, int, int, int, int);
     61  1.17   aymeric void retina_putc(struct ite_softc *, int, int, int, int);
     62  1.17   aymeric void retina_init(struct ite_softc *);
     63   1.9    chopps 
     64  1.16     veego #ifdef RETINA_SPEED_HACK
     65  1.17   aymeric static void screen_up(struct ite_softc *, int, int, int);
     66  1.17   aymeric static void screen_down(struct ite_softc *, int, int, int);
     67  1.16     veego #endif
     68  1.16     veego 
     69   1.7    chopps /*
     70   1.9    chopps  * this function is called from grf_rt to init the grf_softc->g_conpri
     71   1.9    chopps  * field each time a retina is attached.
     72   1.7    chopps  */
     73   1.7    chopps int
     74  1.17   aymeric grfrt_cnprobe(void)
     75   1.7    chopps {
     76   1.9    chopps 	static int done;
     77   1.9    chopps 	int rv;
     78   1.9    chopps 
     79   1.9    chopps 	if (retina_console && done == 0)
     80   1.9    chopps 		rv = CN_INTERNAL;
     81   1.9    chopps 	else
     82   1.9    chopps 		rv = CN_NORMAL;
     83   1.9    chopps 	done = 1;
     84   1.9    chopps 	return(rv);
     85   1.7    chopps }
     86   1.1        mw 
     87  1.17   aymeric /*
     88   1.9    chopps  * init the required fields in the grf_softc struct for a
     89   1.9    chopps  * grf to function as an ite.
     90   1.9    chopps  */
     91   1.9    chopps void
     92  1.17   aymeric grfrt_iteinit(struct grf_softc *gp)
     93   1.1        mw {
     94   1.9    chopps 	gp->g_iteinit = retina_init;
     95   1.9    chopps 	gp->g_itedeinit = retina_deinit;
     96   1.9    chopps 	gp->g_iteclear = retina_clear;
     97   1.9    chopps 	gp->g_iteputc = retina_putc;
     98   1.9    chopps 	gp->g_itescroll = retina_scroll;
     99   1.9    chopps 	gp->g_itecursor = retina_cursor;
    100   1.9    chopps }
    101   1.1        mw 
    102  1.16     veego 
    103   1.9    chopps void
    104  1.17   aymeric retina_init(struct ite_softc *ip)
    105   1.9    chopps {
    106   1.9    chopps 	struct MonDef *md;
    107   1.1        mw 
    108   1.9    chopps 	ip->priv = ip->grf->g_data;
    109   1.9    chopps 	md = (struct MonDef *) ip->priv;
    110  1.17   aymeric 
    111   1.9    chopps 	ip->cols = md->TX;
    112   1.9    chopps 	ip->rows = md->TY;
    113   1.1        mw }
    114   1.1        mw 
    115   1.1        mw 
    116  1.16     veego void
    117  1.17   aymeric retina_cursor(struct ite_softc *ip, int flag)
    118   1.1        mw {
    119  1.21  christos       volatile void *ba = ip->grf->g_regkva;
    120  1.17   aymeric 
    121   1.1        mw       if (flag == ERASE_CURSOR)
    122   1.1        mw         {
    123   1.1        mw 	  /* disable cursor */
    124   1.1        mw           WCrt (ba, CRT_ID_CURSOR_START, RCrt (ba, CRT_ID_CURSOR_START) | 0x20);
    125   1.1        mw         }
    126   1.1        mw       else
    127   1.1        mw 	{
    128   1.1        mw 	  int pos = ip->curx + ip->cury * ip->cols;
    129   1.1        mw 
    130   1.1        mw 	  /* make sure to enable cursor */
    131   1.1        mw           WCrt (ba, CRT_ID_CURSOR_START, RCrt (ba, CRT_ID_CURSOR_START) & ~0x20);
    132   1.1        mw 
    133   1.1        mw 	  /* and position it */
    134   1.1        mw 	  WCrt (ba, CRT_ID_CURSOR_LOC_HIGH, (u_char) (pos >> 8));
    135   1.1        mw 	  WCrt (ba, CRT_ID_CURSOR_LOC_LOW,  (u_char) pos);
    136   1.1        mw 
    137   1.1        mw 	  ip->cursorx = ip->curx;
    138   1.1        mw 	  ip->cursory = ip->cury;
    139   1.1        mw 	}
    140   1.1        mw }
    141   1.1        mw 
    142   1.1        mw 
    143   1.1        mw 
    144  1.16     veego #ifdef	RETINA_SPEED_HACK
    145  1.16     veego static void
    146  1.17   aymeric screen_up(struct ite_softc *ip, int top, int bottom, int lines)
    147  1.17   aymeric {
    148  1.21  christos 	volatile void *ba = ip->grf->g_regkva;
    149  1.21  christos 	volatile void *fb = ip->grf->g_fbkva;
    150   1.1        mw 	const struct MonDef * md = (struct MonDef *) ip->priv;
    151   1.1        mw 
    152   1.1        mw 	/* do some bounds-checking here.. */
    153   1.1        mw 	if (top >= bottom)
    154   1.1        mw 	  return;
    155  1.17   aymeric 
    156   1.1        mw 	if (top + lines >= bottom)
    157   1.1        mw 	  {
    158   1.1        mw 	    retina_clear (ip, top, 0, bottom - top, ip->cols);
    159   1.1        mw 	    return;
    160   1.1        mw 	  }
    161   1.1        mw 
    162   1.1        mw 	/* the trick here is to use a feature of the NCR chip. It can
    163   1.1        mw 	   optimize data access in various read/write modes. One of
    164   1.1        mw 	   the modes is able to read/write from/to different zones.
    165   1.1        mw 
    166   1.1        mw 	   Thus, by setting the read-offset to lineN, and the write-offset
    167   1.1        mw 	   to line0, we just cause read/write cycles for all characters
    168   1.1        mw 	   up to the last line, and have the chip transfer the data. The
    169   1.1        mw 	   `addqb' are the cheapest way to cause read/write cycles (DONT
    170   1.1        mw 	   use `tas' on the Amiga!), their results are completely ignored
    171   1.1        mw 	   by the NCR chip, it just replicates what it just read. */
    172  1.17   aymeric 
    173   1.1        mw 		/* write to primary, read from secondary */
    174  1.16     veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    175  1.17   aymeric 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0 );
    176   1.1        mw 		/* clear extended chain4 mode */
    177  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    178  1.17   aymeric 
    179   1.1        mw 		/* set write mode 1, "[...] data in the read latches is written
    180   1.1        mw 		   to memory during CPU memory write cycles. [...]" */
    181  1.16     veego 	WGfx (ba, GCT_ID_GRAPHICS_MODE,
    182  1.17   aymeric 		(RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    183  1.17   aymeric 
    184   1.1        mw 	{
    185  1.17   aymeric 		/* write to line TOP */
    186   1.1        mw 		long toploc = top * (md->TX / 16);
    187  1.17   aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, ((unsigned char)toploc));
    188  1.17   aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, ((unsigned char)(toploc >> 8)));
    189   1.1        mw 	}
    190   1.1        mw 	{
    191   1.1        mw 		/* read from line TOP + LINES */
    192   1.1        mw 		long fromloc = (top+lines) * (md->TX / 16);
    193  1.17   aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, ((unsigned char)fromloc)) ;
    194  1.17   aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, ((unsigned char)(fromloc >> 8))) ;
    195   1.1        mw 	}
    196   1.1        mw 	{
    197  1.21  christos 		void *p = (void *)fb;
    198   1.1        mw 		/* transfer all characters but LINES lines, unroll by 16 */
    199   1.1        mw 		short x = (1 + bottom - (top + lines)) * (md->TX / 16) - 1;
    200   1.1        mw 		do {
    201  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    202  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    203  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    204  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    205  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    206  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    207  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    208  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    209  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    210  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    211  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    212  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    213  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    214  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    215  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    216  1.20     perry 			__asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    217   1.1        mw 		} while (x--);
    218   1.1        mw 	}
    219  1.17   aymeric 
    220   1.1        mw 		/* reset to default values */
    221  1.17   aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, 0);
    222  1.17   aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, 0);
    223  1.17   aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, 0);
    224  1.17   aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, 0);
    225   1.1        mw 		/* write mode 0 */
    226  1.16     veego 	WGfx (ba, GCT_ID_GRAPHICS_MODE,
    227  1.16     veego 		(RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    228   1.1        mw 		/* extended chain4 enable */
    229  1.16     veego 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR,
    230  1.17   aymeric 		RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    231   1.1        mw 		/* read/write to primary on A0, secondary on B0 */
    232  1.16     veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    233  1.16     veego 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0x40);
    234  1.16     veego 
    235  1.16     veego 
    236   1.1        mw 	/* fill the free lines with spaces */
    237  1.16     veego 
    238   1.1        mw 	{  /* feed latches with value */
    239   1.1        mw 		unsigned short * f = (unsigned short *) fb;
    240  1.16     veego 
    241   1.1        mw 		f += (1 + bottom - lines) * md->TX * 2;
    242   1.1        mw 		*f = 0x2010;
    243   1.1        mw 	}
    244  1.16     veego 
    245   1.1        mw 	   /* clear extended chain4 mode */
    246  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    247   1.1        mw 	   /* set write mode 1, "[...] data in the read latches is written
    248   1.1        mw 	      to memory during CPU memory write cycles. [...]" */
    249  1.17   aymeric 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    250  1.16     veego 
    251   1.1        mw 	{
    252   1.1        mw 		unsigned long * p = (unsigned long *) fb;
    253   1.1        mw 		short x = (lines * (md->TX/16)) - 1;
    254   1.1        mw 		const unsigned long dummyval = 0;
    255  1.16     veego 
    256   1.1        mw 		p += (1 + bottom - lines) * (md->TX/4);
    257  1.16     veego 
    258   1.1        mw 		do {
    259   1.1        mw 			*p++ = dummyval;
    260   1.1        mw 			*p++ = dummyval;
    261   1.1        mw 			*p++ = dummyval;
    262   1.1        mw 			*p++ = dummyval;
    263   1.1        mw 		} while (x--);
    264   1.1        mw 	}
    265  1.16     veego 
    266   1.1        mw 	   /* write mode 0 */
    267   1.1        mw 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    268   1.1        mw 	   /* extended chain4 enable */
    269  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR , RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    270   1.1        mw };
    271   1.1        mw 
    272  1.16     veego 
    273  1.16     veego static void
    274  1.17   aymeric screen_down(struct ite_softc *ip, int top, int bottom, int lines)
    275  1.16     veego {
    276  1.21  christos 	volatile void *ba = ip->grf->g_regkva;
    277  1.21  christos 	volatile void *fb = ip->grf->g_fbkva;
    278   1.1        mw 	const struct MonDef * md = (struct MonDef *) ip->priv;
    279   1.1        mw 
    280   1.1        mw 	/* do some bounds-checking here.. */
    281   1.1        mw 	if (top >= bottom)
    282   1.1        mw 	  return;
    283  1.17   aymeric 
    284   1.1        mw 	if (top + lines >= bottom)
    285   1.1        mw 	  {
    286   1.1        mw 	    retina_clear (ip, top, 0, bottom - top, ip->cols);
    287   1.1        mw 	    return;
    288   1.1        mw 	  }
    289   1.1        mw 
    290   1.1        mw 	/* see screen_up() for explanation of chip-tricks */
    291   1.1        mw 
    292   1.1        mw 		/* write to primary, read from secondary */
    293  1.16     veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    294  1.17   aymeric 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0 );
    295   1.1        mw 		/* clear extended chain4 mode */
    296  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    297  1.16     veego 
    298   1.1        mw 		/* set write mode 1, "[...] data in the read latches is written
    299   1.1        mw 		   to memory during CPU memory write cycles. [...]" */
    300  1.17   aymeric 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    301  1.16     veego 
    302   1.1        mw 	{
    303  1.17   aymeric 		/* write to line TOP + LINES */
    304   1.1        mw 		long toloc = (top + lines) * (md->TX / 16);
    305  1.17   aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, ((unsigned char)toloc));
    306  1.17   aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, ((unsigned char)(toloc >> 8)));
    307   1.1        mw 	}
    308   1.1        mw 	{
    309   1.1        mw 		/* read from line TOP */
    310   1.1        mw 		long fromloc = top * (md->TX / 16);
    311  1.17   aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, ((unsigned char)fromloc));
    312  1.17   aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, ((unsigned char)(fromloc >> 8))) ;
    313   1.1        mw 	}
    314  1.16     veego 
    315   1.1        mw 	{
    316  1.21  christos 		void *p = (void *)fb;
    317   1.1        mw 		short x = (1 + bottom - (top + lines)) * (md->TX / 16) - 1;
    318   1.1        mw 		p += (1 + bottom - (top + lines)) * md->TX;
    319   1.1        mw 		do {
    320  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    321  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    322  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    323  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    324  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    325  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    326  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    327  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    328  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    329  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    330  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    331  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    332  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    333  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    334  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    335  1.20     perry 			__asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    336   1.1        mw 		} while (x--);
    337   1.1        mw 	}
    338  1.16     veego 
    339  1.17   aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, 0);
    340  1.17   aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, 0);
    341  1.17   aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, 0);
    342  1.17   aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, 0);
    343  1.16     veego 
    344   1.1        mw 		/* write mode 0 */
    345  1.16     veego 	WGfx (ba, GCT_ID_GRAPHICS_MODE,
    346  1.16     veego 		(RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    347   1.1        mw 		/* extended chain4 enable */
    348  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR , RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    349   1.1        mw 		/* read/write to primary on A0, secondary on B0 */
    350  1.16     veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    351  1.17   aymeric 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0x40 );
    352  1.16     veego 
    353   1.1        mw 	/* fill the free lines with spaces */
    354  1.16     veego 
    355   1.1        mw 	{  /* feed latches with value */
    356   1.1        mw 		unsigned short * f = (unsigned short *) fb;
    357  1.16     veego 
    358   1.1        mw 		f += top * md->TX * 2;
    359   1.1        mw 		*f = 0x2010;
    360   1.1        mw 	}
    361  1.16     veego 
    362   1.1        mw 	   /* clear extended chain4 mode */
    363  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    364   1.1        mw 	   /* set write mode 1, "[...] data in the read latches is written
    365   1.1        mw 	      to memory during CPU memory write cycles. [...]" */
    366  1.17   aymeric 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    367  1.16     veego 
    368   1.1        mw 	{
    369   1.1        mw 		unsigned long * p = (unsigned long *) fb;
    370   1.1        mw 		short x = (lines * (md->TX/16)) - 1;
    371   1.1        mw 		const unsigned long dummyval = 0;
    372  1.16     veego 
    373   1.1        mw 		p += top * (md->TX/4);
    374  1.16     veego 
    375   1.1        mw 		do {
    376   1.1        mw 			*p++ = dummyval;
    377   1.1        mw 			*p++ = dummyval;
    378   1.1        mw 			*p++ = dummyval;
    379   1.1        mw 			*p++ = dummyval;
    380   1.1        mw 		} while (x--);
    381   1.1        mw 	}
    382  1.16     veego 
    383   1.1        mw 	   /* write mode 0 */
    384   1.1        mw 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    385   1.1        mw 	   /* extended chain4 enable */
    386  1.17   aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR , RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    387   1.1        mw };
    388  1.16     veego #endif	/* RETINA_SPEED_HACK */
    389  1.16     veego 
    390   1.1        mw 
    391  1.16     veego void
    392  1.17   aymeric retina_deinit(struct ite_softc *ip)
    393   1.1        mw {
    394  1.16     veego 	ip->flags &= ~ITE_INITED;
    395   1.1        mw }
    396   1.1        mw 
    397   1.1        mw 
    398  1.16     veego void
    399  1.17   aymeric retina_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    400   1.1        mw {
    401  1.21  christos 	volatile void *fb = ip->grf->g_fbkva;
    402   1.1        mw 	register u_char attr;
    403  1.16     veego 
    404   1.1        mw 	attr = (mode & ATTR_INV) ? 0x21 : 0x10;
    405   1.1        mw 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    406   1.1        mw 	if (mode & ATTR_BOLD)   attr |= 0x08;
    407   1.1        mw 	if (mode & ATTR_BLINK)	attr |= 0x80;
    408  1.16     veego 
    409   1.1        mw 	fb += 4 * (dy * ip->cols + dx);
    410   1.1        mw 	*fb++ = c; *fb = attr;
    411   1.1        mw }
    412   1.1        mw 
    413  1.16     veego 
    414  1.16     veego void
    415  1.17   aymeric retina_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    416   1.1        mw {
    417   1.1        mw 	u_short * fb = (u_short *) ip->grf->g_fbkva;
    418   1.1        mw 	short x;
    419   1.1        mw 	const u_short fillval = 0x2010;
    420  1.16     veego 
    421   1.1        mw 	/* could probably be optimized just like the scrolling functions !! */
    422   1.1        mw 	fb += 2 * (sy * ip->cols + sx);
    423   1.1        mw 	while (h--)
    424   1.1        mw 	  {
    425   1.1        mw 	    for (x = 2 * (w - 1); x >= 0; x -= 2)
    426   1.1        mw 	      fb[x] = fillval;
    427   1.1        mw 	    fb += 2 * ip->cols;
    428   1.1        mw 	  }
    429   1.1        mw }
    430   1.1        mw 
    431  1.16     veego 
    432  1.13    chopps /*
    433  1.13    chopps  * RETINA_SPEED_HACK code seems to work on some boards and on others
    434  1.13    chopps  * it causes text to smear horizontally
    435  1.13    chopps  */
    436  1.13    chopps void
    437  1.17   aymeric retina_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    438   1.1        mw {
    439  1.21  christos 	volatile void *ba;
    440  1.13    chopps 	u_long *fb;
    441  1.13    chopps 
    442  1.13    chopps 	ba = ip->grf->g_regkva;
    443  1.13    chopps 	fb = (u_long *)ip->grf->g_fbkva;
    444  1.16     veego 
    445  1.13    chopps 	retina_cursor(ip, ERASE_CURSOR);
    446  1.13    chopps 
    447  1.13    chopps 	if (dir == SCROLL_UP) {
    448  1.13    chopps #ifdef	RETINA_SPEED_HACK
    449  1.13    chopps 		screen_up(ip, sy - count, ip->bottom_margin, count);
    450  1.13    chopps #else
    451  1.13    chopps 		bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
    452  1.13    chopps 		    4 * (ip->bottom_margin - sy + 1) * ip->cols);
    453  1.13    chopps 		retina_clear(ip, ip->bottom_margin + 1 - count, 0, count,
    454  1.13    chopps 		    ip->cols);
    455  1.13    chopps #endif
    456  1.13    chopps 	} else if (dir == SCROLL_DOWN) {
    457  1.13    chopps #ifdef	RETINA_SPEED_HACK
    458  1.13    chopps 		screen_down(ip, sy, ip->bottom_margin, count);
    459  1.13    chopps #else
    460  1.13    chopps 		bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
    461  1.13    chopps 		    4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
    462  1.13    chopps 		retina_clear(ip, sy, 0, count, ip->cols);
    463  1.14    chopps #endif
    464  1.13    chopps 	} else if (dir == SCROLL_RIGHT) {
    465  1.13    chopps 		bcopy(fb + sx + sy * ip->cols, fb + sx + sy * ip->cols + count,
    466  1.13    chopps 		    4 * (ip->cols - (sx + count)));
    467  1.13    chopps 		retina_clear(ip, sy, sx, 1, count);
    468  1.13    chopps 	} else {
    469  1.13    chopps 		bcopy(fb + sx + sy * ip->cols, fb + sx - count + sy * ip->cols,
    470  1.13    chopps 		    4 * (ip->cols - sx));
    471  1.13    chopps 		retina_clear(ip, sy, ip->cols - count, 1, count);
    472  1.13    chopps 	}
    473  1.13    chopps #ifndef	RETINA_SPEED_HACK
    474  1.13    chopps 	retina_cursor(ip, !ERASE_CURSOR);
    475  1.13    chopps #endif
    476   1.1        mw }
    477  1.10    chopps 
    478  1.10    chopps #endif /* NGRFRT */
    479