Home | History | Annotate | Line # | Download | only in dev
ite_rt.c revision 1.18
      1  1.18  aymeric /*	$NetBSD: ite_rt.c,v 1.18 2002/01/28 09:57:00 aymeric 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.18  aymeric __KERNEL_RCSID(0, "$NetBSD: ite_rt.c,v 1.18 2002/01/28 09:57:00 aymeric 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.15    veego       volatile caddr_t 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.15    veego 	volatile caddr_t ba = ip->grf->g_regkva;
    149  1.15    veego 	volatile caddr_t fb = ip->grf->g_fbkva;
    150   1.1       mw 	const struct MonDef * md = (struct MonDef *) ip->priv;
    151   1.3       mw #ifdef BANKEDDEVPAGER
    152   1.3       mw 	int bank;
    153   1.3       mw #endif
    154   1.1       mw 
    155   1.1       mw 	/* do some bounds-checking here.. */
    156   1.1       mw 	if (top >= bottom)
    157   1.1       mw 	  return;
    158  1.17  aymeric 
    159   1.1       mw 	if (top + lines >= bottom)
    160   1.1       mw 	  {
    161   1.1       mw 	    retina_clear (ip, top, 0, bottom - top, ip->cols);
    162   1.1       mw 	    return;
    163   1.1       mw 	  }
    164   1.1       mw 
    165   1.1       mw 
    166   1.3       mw #ifdef BANKEDDEVPAGER
    167   1.3       mw 	/* make sure to save/restore active bank (and if it's only
    168   1.3       mw 	   for tests of the feature in text-mode..) */
    169  1.17  aymeric 	bank = (RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO)
    170   1.3       mw 		| (RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI) << 8));
    171   1.3       mw #endif
    172   1.3       mw 
    173   1.1       mw 	/* the trick here is to use a feature of the NCR chip. It can
    174   1.1       mw 	   optimize data access in various read/write modes. One of
    175   1.1       mw 	   the modes is able to read/write from/to different zones.
    176   1.1       mw 
    177   1.1       mw 	   Thus, by setting the read-offset to lineN, and the write-offset
    178   1.1       mw 	   to line0, we just cause read/write cycles for all characters
    179   1.1       mw 	   up to the last line, and have the chip transfer the data. The
    180   1.1       mw 	   `addqb' are the cheapest way to cause read/write cycles (DONT
    181   1.1       mw 	   use `tas' on the Amiga!), their results are completely ignored
    182   1.1       mw 	   by the NCR chip, it just replicates what it just read. */
    183  1.17  aymeric 
    184   1.1       mw 		/* write to primary, read from secondary */
    185  1.16    veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    186  1.17  aymeric 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0 );
    187   1.1       mw 		/* clear extended chain4 mode */
    188  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    189  1.17  aymeric 
    190   1.1       mw 		/* set write mode 1, "[...] data in the read latches is written
    191   1.1       mw 		   to memory during CPU memory write cycles. [...]" */
    192  1.16    veego 	WGfx (ba, GCT_ID_GRAPHICS_MODE,
    193  1.17  aymeric 		(RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    194  1.17  aymeric 
    195   1.1       mw 	{
    196  1.17  aymeric 		/* write to line TOP */
    197   1.1       mw 		long toploc = top * (md->TX / 16);
    198  1.17  aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, ((unsigned char)toploc));
    199  1.17  aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, ((unsigned char)(toploc >> 8)));
    200   1.1       mw 	}
    201   1.1       mw 	{
    202   1.1       mw 		/* read from line TOP + LINES */
    203   1.1       mw 		long fromloc = (top+lines) * (md->TX / 16);
    204  1.17  aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, ((unsigned char)fromloc)) ;
    205  1.17  aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, ((unsigned char)(fromloc >> 8))) ;
    206   1.1       mw 	}
    207   1.1       mw 	{
    208  1.15    veego 		caddr_t p = (caddr_t)fb;
    209   1.1       mw 		/* transfer all characters but LINES lines, unroll by 16 */
    210   1.1       mw 		short x = (1 + bottom - (top + lines)) * (md->TX / 16) - 1;
    211   1.1       mw 		do {
    212  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    213  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    214  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    215  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    216  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    217  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    218  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    219  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    220  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    221  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    222  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    223  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    224  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    225  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    226  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    227  1.17  aymeric 			asm volatile("addqb #1,%0@+" : "=a" (p) : "0" (p));
    228   1.1       mw 		} while (x--);
    229   1.1       mw 	}
    230  1.17  aymeric 
    231   1.1       mw 		/* reset to default values */
    232  1.17  aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, 0);
    233  1.17  aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, 0);
    234  1.17  aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, 0);
    235  1.17  aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, 0);
    236   1.1       mw 		/* write mode 0 */
    237  1.16    veego 	WGfx (ba, GCT_ID_GRAPHICS_MODE,
    238  1.16    veego 		(RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    239   1.1       mw 		/* extended chain4 enable */
    240  1.16    veego 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR,
    241  1.17  aymeric 		RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    242   1.1       mw 		/* read/write to primary on A0, secondary on B0 */
    243  1.16    veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    244  1.16    veego 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0x40);
    245  1.16    veego 
    246  1.16    veego 
    247   1.1       mw 	/* fill the free lines with spaces */
    248  1.16    veego 
    249   1.1       mw 	{  /* feed latches with value */
    250   1.1       mw 		unsigned short * f = (unsigned short *) fb;
    251  1.16    veego 
    252   1.1       mw 		f += (1 + bottom - lines) * md->TX * 2;
    253   1.1       mw 		*f = 0x2010;
    254   1.1       mw 	}
    255  1.16    veego 
    256   1.1       mw 	   /* clear extended chain4 mode */
    257  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    258   1.1       mw 	   /* set write mode 1, "[...] data in the read latches is written
    259   1.1       mw 	      to memory during CPU memory write cycles. [...]" */
    260  1.17  aymeric 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    261  1.16    veego 
    262   1.1       mw 	{
    263   1.1       mw 		unsigned long * p = (unsigned long *) fb;
    264   1.1       mw 		short x = (lines * (md->TX/16)) - 1;
    265   1.1       mw 		const unsigned long dummyval = 0;
    266  1.16    veego 
    267   1.1       mw 		p += (1 + bottom - lines) * (md->TX/4);
    268  1.16    veego 
    269   1.1       mw 		do {
    270   1.1       mw 			*p++ = dummyval;
    271   1.1       mw 			*p++ = dummyval;
    272   1.1       mw 			*p++ = dummyval;
    273   1.1       mw 			*p++ = dummyval;
    274   1.1       mw 		} while (x--);
    275   1.1       mw 	}
    276  1.16    veego 
    277   1.1       mw 	   /* write mode 0 */
    278   1.1       mw 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    279   1.1       mw 	   /* extended chain4 enable */
    280  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR , RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    281   1.3       mw 
    282   1.3       mw #ifdef BANKEDDEVPAGER
    283   1.3       mw 	/* restore former bank */
    284   1.3       mw 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, (unsigned char) bank);
    285   1.3       mw 	bank >>= 8;
    286   1.3       mw 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, (unsigned char) bank);
    287   1.3       mw #endif
    288   1.1       mw };
    289   1.1       mw 
    290  1.16    veego 
    291  1.16    veego static void
    292  1.17  aymeric screen_down(struct ite_softc *ip, int top, int bottom, int lines)
    293  1.16    veego {
    294  1.15    veego 	volatile caddr_t ba = ip->grf->g_regkva;
    295  1.15    veego 	volatile caddr_t fb = ip->grf->g_fbkva;
    296   1.1       mw 	const struct MonDef * md = (struct MonDef *) ip->priv;
    297   1.3       mw #ifdef BANKEDDEVPAGER
    298   1.3       mw 	int bank;
    299   1.3       mw #endif
    300   1.1       mw 
    301   1.1       mw 	/* do some bounds-checking here.. */
    302   1.1       mw 	if (top >= bottom)
    303   1.1       mw 	  return;
    304  1.17  aymeric 
    305   1.1       mw 	if (top + lines >= bottom)
    306   1.1       mw 	  {
    307   1.1       mw 	    retina_clear (ip, top, 0, bottom - top, ip->cols);
    308   1.1       mw 	    return;
    309   1.1       mw 	  }
    310   1.1       mw 
    311   1.3       mw #ifdef BANKEDDEVPAGER
    312   1.3       mw 	/* make sure to save/restore active bank (and if it's only
    313   1.3       mw 	   for tests of the feature in text-mode..) */
    314  1.17  aymeric 	bank = (RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO)
    315   1.3       mw 		| (RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI) << 8));
    316   1.3       mw #endif
    317   1.1       mw 	/* see screen_up() for explanation of chip-tricks */
    318   1.1       mw 
    319   1.1       mw 		/* write to primary, read from secondary */
    320  1.16    veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    321  1.17  aymeric 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0 );
    322   1.1       mw 		/* clear extended chain4 mode */
    323  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    324  1.16    veego 
    325   1.1       mw 		/* set write mode 1, "[...] data in the read latches is written
    326   1.1       mw 		   to memory during CPU memory write cycles. [...]" */
    327  1.17  aymeric 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    328  1.16    veego 
    329   1.1       mw 	{
    330  1.17  aymeric 		/* write to line TOP + LINES */
    331   1.1       mw 		long toloc = (top + lines) * (md->TX / 16);
    332  1.17  aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, ((unsigned char)toloc));
    333  1.17  aymeric 		WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, ((unsigned char)(toloc >> 8)));
    334   1.1       mw 	}
    335   1.1       mw 	{
    336   1.1       mw 		/* read from line TOP */
    337   1.1       mw 		long fromloc = top * (md->TX / 16);
    338  1.17  aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, ((unsigned char)fromloc));
    339  1.17  aymeric 		WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, ((unsigned char)(fromloc >> 8))) ;
    340   1.1       mw 	}
    341  1.16    veego 
    342   1.1       mw 	{
    343  1.15    veego 		caddr_t p = (caddr_t)fb;
    344   1.1       mw 		short x = (1 + bottom - (top + lines)) * (md->TX / 16) - 1;
    345   1.1       mw 		p += (1 + bottom - (top + lines)) * md->TX;
    346   1.1       mw 		do {
    347  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    348  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    349  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    350  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    351  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    352  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    353  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    354  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    355  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    356  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    357  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    358  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    359  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    360  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    361  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    362  1.17  aymeric 			asm volatile("addqb #1,%0@-" : "=a" (p) : "0" (p));
    363   1.1       mw 		} while (x--);
    364   1.1       mw 	}
    365  1.16    veego 
    366  1.17  aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, 0);
    367  1.17  aymeric 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, 0);
    368  1.17  aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, 0);
    369  1.17  aymeric 	WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, 0);
    370  1.16    veego 
    371   1.1       mw 		/* write mode 0 */
    372  1.16    veego 	WGfx (ba, GCT_ID_GRAPHICS_MODE,
    373  1.16    veego 		(RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    374   1.1       mw 		/* extended chain4 enable */
    375  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR , RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    376   1.1       mw 		/* read/write to primary on A0, secondary on B0 */
    377  1.16    veego 	WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA,
    378  1.17  aymeric 		(RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0x40 );
    379  1.16    veego 
    380   1.1       mw 	/* fill the free lines with spaces */
    381  1.16    veego 
    382   1.1       mw 	{  /* feed latches with value */
    383   1.1       mw 		unsigned short * f = (unsigned short *) fb;
    384  1.16    veego 
    385   1.1       mw 		f += top * md->TX * 2;
    386   1.1       mw 		*f = 0x2010;
    387   1.1       mw 	}
    388  1.16    veego 
    389   1.1       mw 	   /* clear extended chain4 mode */
    390  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) & ~0x02);
    391   1.1       mw 	   /* set write mode 1, "[...] data in the read latches is written
    392   1.1       mw 	      to memory during CPU memory write cycles. [...]" */
    393  1.17  aymeric 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
    394  1.16    veego 
    395   1.1       mw 	{
    396   1.1       mw 		unsigned long * p = (unsigned long *) fb;
    397   1.1       mw 		short x = (lines * (md->TX/16)) - 1;
    398   1.1       mw 		const unsigned long dummyval = 0;
    399  1.16    veego 
    400   1.1       mw 		p += top * (md->TX/4);
    401  1.16    veego 
    402   1.1       mw 		do {
    403   1.1       mw 			*p++ = dummyval;
    404   1.1       mw 			*p++ = dummyval;
    405   1.1       mw 			*p++ = dummyval;
    406   1.1       mw 			*p++ = dummyval;
    407   1.1       mw 		} while (x--);
    408   1.1       mw 	}
    409  1.16    veego 
    410   1.1       mw 	   /* write mode 0 */
    411   1.1       mw 	WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 0);
    412   1.1       mw 	   /* extended chain4 enable */
    413  1.17  aymeric 	WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR , RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
    414  1.16    veego 
    415   1.3       mw #ifdef BANKEDDEVPAGER
    416   1.3       mw 	/* restore former bank */
    417   1.3       mw 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, (unsigned char) bank);
    418   1.3       mw 	bank >>= 8;
    419   1.3       mw 	WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, (unsigned char) bank);
    420   1.3       mw #endif
    421   1.1       mw };
    422  1.16    veego #endif	/* RETINA_SPEED_HACK */
    423  1.16    veego 
    424   1.1       mw 
    425  1.16    veego void
    426  1.17  aymeric retina_deinit(struct ite_softc *ip)
    427   1.1       mw {
    428  1.16    veego 	ip->flags &= ~ITE_INITED;
    429   1.1       mw }
    430   1.1       mw 
    431   1.1       mw 
    432  1.16    veego void
    433  1.17  aymeric retina_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    434   1.1       mw {
    435  1.15    veego 	volatile caddr_t fb = ip->grf->g_fbkva;
    436   1.1       mw 	register u_char attr;
    437  1.16    veego 
    438   1.1       mw 	attr = (mode & ATTR_INV) ? 0x21 : 0x10;
    439   1.1       mw 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    440   1.1       mw 	if (mode & ATTR_BOLD)   attr |= 0x08;
    441   1.1       mw 	if (mode & ATTR_BLINK)	attr |= 0x80;
    442  1.16    veego 
    443   1.1       mw 	fb += 4 * (dy * ip->cols + dx);
    444   1.1       mw 	*fb++ = c; *fb = attr;
    445   1.1       mw }
    446   1.1       mw 
    447  1.16    veego 
    448  1.16    veego void
    449  1.17  aymeric retina_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    450   1.1       mw {
    451   1.1       mw 	u_short * fb = (u_short *) ip->grf->g_fbkva;
    452   1.1       mw 	short x;
    453   1.1       mw 	const u_short fillval = 0x2010;
    454  1.16    veego 
    455   1.1       mw 	/* could probably be optimized just like the scrolling functions !! */
    456   1.1       mw 	fb += 2 * (sy * ip->cols + sx);
    457   1.1       mw 	while (h--)
    458   1.1       mw 	  {
    459   1.1       mw 	    for (x = 2 * (w - 1); x >= 0; x -= 2)
    460   1.1       mw 	      fb[x] = fillval;
    461   1.1       mw 	    fb += 2 * ip->cols;
    462   1.1       mw 	  }
    463   1.1       mw }
    464   1.1       mw 
    465  1.16    veego 
    466  1.13   chopps /*
    467  1.13   chopps  * RETINA_SPEED_HACK code seems to work on some boards and on others
    468  1.13   chopps  * it causes text to smear horizontally
    469  1.13   chopps  */
    470  1.13   chopps void
    471  1.17  aymeric retina_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    472   1.1       mw {
    473  1.15    veego 	volatile caddr_t ba;
    474  1.13   chopps 	u_long *fb;
    475  1.13   chopps 
    476  1.13   chopps 	ba = ip->grf->g_regkva;
    477  1.13   chopps 	fb = (u_long *)ip->grf->g_fbkva;
    478  1.16    veego 
    479  1.13   chopps 	retina_cursor(ip, ERASE_CURSOR);
    480  1.13   chopps 
    481  1.13   chopps 	if (dir == SCROLL_UP) {
    482  1.13   chopps #ifdef	RETINA_SPEED_HACK
    483  1.13   chopps 		screen_up(ip, sy - count, ip->bottom_margin, count);
    484  1.13   chopps #else
    485  1.13   chopps 		bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
    486  1.13   chopps 		    4 * (ip->bottom_margin - sy + 1) * ip->cols);
    487  1.13   chopps 		retina_clear(ip, ip->bottom_margin + 1 - count, 0, count,
    488  1.13   chopps 		    ip->cols);
    489  1.13   chopps #endif
    490  1.13   chopps 	} else if (dir == SCROLL_DOWN) {
    491  1.13   chopps #ifdef	RETINA_SPEED_HACK
    492  1.13   chopps 		screen_down(ip, sy, ip->bottom_margin, count);
    493  1.13   chopps #else
    494  1.13   chopps 		bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
    495  1.13   chopps 		    4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
    496  1.13   chopps 		retina_clear(ip, sy, 0, count, ip->cols);
    497  1.14   chopps #endif
    498  1.13   chopps 	} else if (dir == SCROLL_RIGHT) {
    499  1.13   chopps 		bcopy(fb + sx + sy * ip->cols, fb + sx + sy * ip->cols + count,
    500  1.13   chopps 		    4 * (ip->cols - (sx + count)));
    501  1.13   chopps 		retina_clear(ip, sy, sx, 1, count);
    502  1.13   chopps 	} else {
    503  1.13   chopps 		bcopy(fb + sx + sy * ip->cols, fb + sx - count + sy * ip->cols,
    504  1.13   chopps 		    4 * (ip->cols - sx));
    505  1.13   chopps 		retina_clear(ip, sy, ip->cols - count, 1, count);
    506  1.13   chopps 	}
    507  1.13   chopps #ifndef	RETINA_SPEED_HACK
    508  1.13   chopps 	retina_cursor(ip, !ERASE_CURSOR);
    509  1.13   chopps #endif
    510   1.1       mw }
    511  1.10   chopps 
    512  1.10   chopps #endif /* NGRFRT */
    513