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