Home | History | Annotate | Line # | Download | only in dev
ite_rh.c revision 1.10.32.1
      1  1.10.32.1     yamt /*	$NetBSD: ite_rh.c,v 1.10.32.1 2007/09/03 14:22:54 yamt Exp $ */
      2        1.1   chopps 
      3        1.4   chopps /*
      4        1.4   chopps  * Copyright (c) 1994 Markus Wild
      5        1.4   chopps  * Copyright (c) 1994 Lutz Vieweg
      6        1.4   chopps  * All rights reserved.
      7        1.4   chopps  *
      8        1.4   chopps  * Redistribution and use in source and binary forms, with or without
      9        1.4   chopps  * modification, are permitted provided that the following conditions
     10        1.4   chopps  * are met:
     11        1.4   chopps  * 1. Redistributions of source code must retain the above copyright
     12        1.4   chopps  *    notice, this list of conditions and the following disclaimer.
     13        1.4   chopps  * 2. Redistributions in binary form must reproduce the above copyright
     14        1.4   chopps  *    notice, this list of conditions and the following disclaimer in the
     15        1.4   chopps  *    documentation and/or other materials provided with the distribution.
     16        1.4   chopps  * 3. All advertising materials mentioning features or use of this software
     17        1.4   chopps  *    must display the following acknowledgement:
     18        1.4   chopps  *      This product includes software developed by Lutz Vieweg.
     19        1.4   chopps  * 4. The name of the author may not be used to endorse or promote products
     20        1.4   chopps  *    derived from this software without specific prior written permission
     21        1.4   chopps  *
     22        1.4   chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23        1.4   chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24        1.4   chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25        1.4   chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26        1.4   chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27        1.4   chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28        1.4   chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29        1.4   chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30        1.4   chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31        1.4   chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32        1.4   chopps  */
     33        1.8       is #include "opt_retina.h"
     34       1.10  aymeric 
     35       1.10  aymeric #include <sys/cdefs.h>
     36  1.10.32.1     yamt __KERNEL_RCSID(0, "$NetBSD: ite_rh.c,v 1.10.32.1 2007/09/03 14:22:54 yamt Exp $");
     37       1.10  aymeric 
     38        1.2   chopps #include "grfrh.h"
     39        1.2   chopps #if NGRFRH > 0
     40        1.1   chopps 
     41        1.1   chopps #include <sys/param.h>
     42        1.1   chopps #include <sys/conf.h>
     43        1.1   chopps #include <sys/proc.h>
     44        1.1   chopps #include <sys/device.h>
     45        1.1   chopps #include <sys/ioctl.h>
     46        1.1   chopps #include <sys/tty.h>
     47        1.1   chopps #include <sys/systm.h>
     48        1.1   chopps #include <dev/cons.h>
     49        1.1   chopps #include <machine/cpu.h>
     50        1.1   chopps #include <amiga/amiga/device.h>
     51        1.1   chopps #include <amiga/dev/grfioctl.h>
     52        1.1   chopps #include <amiga/dev/grfvar.h>
     53        1.1   chopps #include <amiga/dev/grf_rhreg.h>
     54        1.1   chopps #include <amiga/dev/itevar.h>
     55        1.1   chopps 
     56        1.7    veego #ifdef	RETINA_SPEED_HACK
     57        1.9  aymeric static void screen_up(struct ite_softc *, int, int, int);
     58        1.9  aymeric static void screen_down(struct ite_softc *, int, int, int);
     59        1.7    veego #endif
     60        1.1   chopps 
     61        1.1   chopps /*
     62        1.1   chopps  * grfrh_cnprobe is called when the console is being initialized
     63        1.1   chopps  * i.e. very early.  grfconfig() has been called, so this implies
     64        1.1   chopps  * that rt_init() was called.  If we are functioning rh_inited
     65        1.1   chopps  * will be true.
     66        1.1   chopps  */
     67        1.1   chopps int
     68        1.9  aymeric grfrh_cnprobe(void)
     69        1.1   chopps {
     70        1.1   chopps 	static int done;
     71        1.1   chopps 	int rv;
     72        1.1   chopps 
     73        1.1   chopps 	if (done == 0)
     74        1.1   chopps 		rv = CN_INTERNAL;
     75        1.1   chopps 	else
     76        1.1   chopps 		rv = CN_NORMAL;
     77        1.1   chopps 	done = 1;
     78        1.1   chopps 	return(rv);
     79        1.1   chopps }
     80        1.1   chopps 
     81        1.7    veego 
     82        1.1   chopps void
     83        1.9  aymeric grfrh_iteinit(struct grf_softc *gp)
     84        1.1   chopps {
     85        1.1   chopps 	gp->g_iteinit = rh_init;
     86        1.1   chopps 	gp->g_itedeinit = rh_deinit;
     87        1.1   chopps 	gp->g_iteclear = rh_clear;
     88        1.1   chopps 	gp->g_iteputc = rh_putc;
     89        1.1   chopps 	gp->g_itescroll = rh_scroll;
     90        1.1   chopps 	gp->g_itecursor = rh_cursor;
     91        1.1   chopps }
     92        1.1   chopps 
     93        1.7    veego 
     94        1.1   chopps void
     95        1.9  aymeric rh_init(struct ite_softc *ip)
     96        1.1   chopps {
     97        1.1   chopps 	struct MonDef *md;
     98        1.1   chopps 
     99        1.1   chopps #if 0 /* Not in ite_rt.c - DC */
    100        1.1   chopps 	if (ip->grf == 0)
    101        1.1   chopps 		ip->grf = &grf_softc[ip - ite_softc];
    102        1.1   chopps #endif
    103        1.1   chopps 
    104        1.1   chopps 	ip->priv = ip->grf->g_data;
    105        1.1   chopps 	md = (struct MonDef *) ip->priv;
    106        1.1   chopps 
    107        1.1   chopps 	ip->cols = md->TX;
    108        1.1   chopps 	ip->rows = md->TY;
    109        1.1   chopps }
    110        1.1   chopps 
    111        1.1   chopps 
    112        1.1   chopps void
    113        1.9  aymeric rh_cursor(struct ite_softc *ip, int flag)
    114        1.1   chopps {
    115        1.6    veego #if 0
    116        1.1   chopps 	volatile u_char *ba = ip->grf->g_regkva;
    117        1.6    veego #endif
    118        1.1   chopps 
    119        1.1   chopps 	if (flag == START_CURSOROPT || flag == END_CURSOROPT)
    120        1.1   chopps 		return;
    121        1.1   chopps 
    122        1.1   chopps 	if (flag == ERASE_CURSOR) {
    123        1.1   chopps #if 0
    124        1.1   chopps 		/* disable cursor */
    125        1.1   chopps 		WCrt (ba, CRT_ID_CURSOR_START,
    126        1.1   chopps 		    RCrt (ba, CRT_ID_CURSOR_START) | 0x20);
    127        1.1   chopps #endif
    128        1.1   chopps 	} else {
    129        1.1   chopps 		int pos = ip->curx + ip->cury * ip->cols;
    130        1.1   chopps #if 0
    131        1.1   chopps 		/* make sure to enable cursor */
    132        1.1   chopps 		WCrt (ba, CRT_ID_CURSOR_START,
    133        1.1   chopps 		    RCrt (ba, CRT_ID_CURSOR_START) & ~0x20);
    134        1.1   chopps #endif
    135        1.1   chopps 
    136        1.1   chopps 		/* and position it */
    137        1.1   chopps 		RZ3SetCursorPos (ip->grf, pos);
    138        1.1   chopps 
    139        1.1   chopps 		ip->cursorx = ip->curx;
    140        1.1   chopps 		ip->cursory = ip->cury;
    141        1.1   chopps 	}
    142        1.1   chopps }
    143        1.1   chopps 
    144        1.1   chopps 
    145        1.7    veego #ifdef	RETINA_SPEED_HACK
    146        1.1   chopps static void
    147        1.9  aymeric screen_up(struct ite_softc *ip, int top, int bottom, int lines)
    148        1.1   chopps {
    149        1.1   chopps 
    150        1.1   chopps 	/* do some bounds-checking here.. */
    151        1.1   chopps 	if (top >= bottom)
    152        1.1   chopps 		return;
    153        1.1   chopps 
    154        1.1   chopps 	if (top + lines >= bottom) {
    155        1.1   chopps 		RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
    156        1.1   chopps 		return;
    157        1.1   chopps 	}
    158        1.1   chopps 
    159        1.1   chopps 	RZ3AlphaCopy(ip->grf, 0, top+lines, 0, top, ip->cols, bottom-top-lines+1);
    160        1.1   chopps 	RZ3AlphaErase(ip->grf, 0, bottom - lines + 1, ip->cols, lines);
    161        1.1   chopps }
    162        1.1   chopps 
    163        1.7    veego 
    164        1.1   chopps static void
    165        1.9  aymeric screen_down (struct ite_softc *ip, int top, int bottom, int lines)
    166        1.1   chopps {
    167        1.1   chopps 
    168        1.1   chopps 	/* do some bounds-checking here.. */
    169        1.1   chopps 	if (top >= bottom)
    170        1.1   chopps 		return;
    171        1.1   chopps 
    172        1.1   chopps 	if (top + lines >= bottom) {
    173        1.1   chopps 		RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
    174        1.1   chopps 		return;
    175        1.1   chopps 	}
    176        1.1   chopps 
    177        1.1   chopps 	RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
    178        1.1   chopps 	RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
    179        1.1   chopps }
    180        1.7    veego #endif	/* RETINA_SPEED_HACK */
    181        1.7    veego 
    182        1.1   chopps 
    183        1.1   chopps void
    184        1.9  aymeric rh_deinit(struct ite_softc *ip)
    185        1.1   chopps {
    186        1.1   chopps 	ip->flags &= ~ITE_INITED;
    187        1.1   chopps }
    188        1.1   chopps 
    189        1.1   chopps 
    190        1.1   chopps void
    191        1.9  aymeric rh_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    192        1.1   chopps {
    193        1.1   chopps 	volatile u_char * fb = ip->grf->g_fbkva;
    194        1.1   chopps 	register u_char attr;
    195        1.1   chopps 
    196        1.1   chopps 	attr = (mode & ATTR_INV) ? 0x21 : 0x10;
    197        1.1   chopps 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    198        1.1   chopps 	if (mode & ATTR_BOLD)   attr |= 0x08;
    199        1.1   chopps 	if (mode & ATTR_BLINK)  attr |= 0x80;
    200        1.1   chopps 
    201        1.1   chopps 	fb += 4 * (dy * ip->cols + dx);
    202        1.1   chopps 	*fb++ = c; *fb = attr;
    203        1.1   chopps }
    204        1.1   chopps 
    205        1.7    veego 
    206        1.1   chopps void
    207        1.9  aymeric rh_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    208        1.1   chopps {
    209        1.1   chopps 	RZ3AlphaErase (ip->grf, sx, sy, w, h);
    210        1.1   chopps }
    211        1.1   chopps 
    212        1.7    veego 
    213        1.5   chopps /*
    214        1.5   chopps  * RETINA_SPEED_HACK code seems to work on some boards and on others
    215        1.5   chopps  * it causes text to smear horizontally
    216        1.5   chopps  */
    217        1.1   chopps void
    218        1.9  aymeric rh_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    219        1.1   chopps {
    220        1.6    veego #ifndef	RETINA_SPEED_HACK
    221  1.10.32.1     yamt 	u_long *fb = (u_long *)__UNVOLATILE(ip->grf->g_fbkva);
    222        1.6    veego #endif
    223        1.1   chopps 
    224        1.1   chopps 	rh_cursor(ip, ERASE_CURSOR);
    225        1.1   chopps 
    226        1.1   chopps 	if (dir == SCROLL_UP) {
    227        1.5   chopps #ifdef	RETINA_SPEED_HACK
    228        1.1   chopps 		screen_up(ip, sy - count, ip->bottom_margin, count);
    229        1.5   chopps #else
    230        1.5   chopps 		bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
    231        1.5   chopps 		    4 * (ip->bottom_margin - sy + 1) * ip->cols);
    232        1.5   chopps 		rh_clear(ip, ip->bottom_margin + 1 - count, 0, count, ip->cols);
    233        1.5   chopps #endif
    234        1.1   chopps 	} else if (dir == SCROLL_DOWN) {
    235        1.5   chopps #ifdef	RETINA_SPEED_HACK
    236        1.1   chopps 		screen_down(ip, sy, ip->bottom_margin, count);
    237        1.5   chopps #else
    238        1.5   chopps 		bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
    239        1.5   chopps 		    4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
    240        1.5   chopps 		rh_clear(ip, sy, 0, count, ip->cols);
    241        1.5   chopps #endif
    242        1.1   chopps 	} else if (dir == SCROLL_RIGHT) {
    243        1.1   chopps 		RZ3AlphaCopy(ip->grf, sx, sy, sx + count, sy,
    244        1.1   chopps 		    ip->cols - (sx + count), 1);
    245        1.1   chopps 		RZ3AlphaErase(ip->grf, sx, sy, count, 1);
    246        1.1   chopps 	} else {
    247        1.1   chopps 		RZ3AlphaCopy(ip->grf, sx + count, sy, sx, sy,
    248        1.1   chopps 		    ip->cols - (sx + count), 1);
    249        1.1   chopps 		RZ3AlphaErase(ip->grf, ip->cols - count, sy, count, 1);
    250        1.1   chopps 	}
    251        1.5   chopps #ifndef	RETINA_SPEED_HACK
    252        1.7    veego 	rh_cursor(ip, !ERASE_CURSOR);
    253        1.5   chopps #endif
    254        1.1   chopps }
    255        1.2   chopps #endif /* NGRFRH */
    256