Home | History | Annotate | Line # | Download | only in dev
ite_rh.c revision 1.6
      1 /*	$NetBSD: ite_rh.c,v 1.6 1996/04/21 21:12:00 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 static void screen_up __P((struct ite_softc *, int, int, int));
     52 static void screen_down __P((struct ite_softc *, int, int, int));
     53 
     54 /*
     55  * grfrh_cnprobe is called when the console is being initialized
     56  * i.e. very early.  grfconfig() has been called, so this implies
     57  * that rt_init() was called.  If we are functioning rh_inited
     58  * will be true.
     59  */
     60 int
     61 grfrh_cnprobe()
     62 {
     63 	static int done;
     64 	int rv;
     65 
     66 	if (done == 0)
     67 		rv = CN_INTERNAL;
     68 	else
     69 		rv = CN_NORMAL;
     70 	done = 1;
     71 	return(rv);
     72 }
     73 
     74 void
     75 grfrh_iteinit(gp)
     76 	struct grf_softc *gp;
     77 {
     78 	gp->g_iteinit = rh_init;
     79 	gp->g_itedeinit = rh_deinit;
     80 	gp->g_iteclear = rh_clear;
     81 	gp->g_iteputc = rh_putc;
     82 	gp->g_itescroll = rh_scroll;
     83 	gp->g_itecursor = rh_cursor;
     84 }
     85 
     86 void
     87 rh_init(ip)
     88 	struct ite_softc *ip;
     89 {
     90 	struct MonDef *md;
     91 
     92 #if 0 /* Not in ite_rt.c - DC */
     93 	if (ip->grf == 0)
     94 		ip->grf = &grf_softc[ip - ite_softc];
     95 #endif
     96 
     97 	ip->priv = ip->grf->g_data;
     98 	md = (struct MonDef *) ip->priv;
     99 
    100 	ip->cols = md->TX;
    101 	ip->rows = md->TY;
    102 }
    103 
    104 
    105 void
    106 rh_cursor(ip, flag)
    107 	struct ite_softc *ip;
    108 	int flag;
    109 {
    110 #if 0
    111 	volatile u_char *ba = ip->grf->g_regkva;
    112 #endif
    113 
    114 	if (flag == START_CURSOROPT || flag == END_CURSOROPT)
    115 		return;
    116 
    117 	if (flag == ERASE_CURSOR) {
    118 #if 0
    119 		/* disable cursor */
    120 		WCrt (ba, CRT_ID_CURSOR_START,
    121 		    RCrt (ba, CRT_ID_CURSOR_START) | 0x20);
    122 #endif
    123 	} else {
    124 		int pos = ip->curx + ip->cury * ip->cols;
    125 #if 0
    126 		/* make sure to enable cursor */
    127 		WCrt (ba, CRT_ID_CURSOR_START,
    128 		    RCrt (ba, CRT_ID_CURSOR_START) & ~0x20);
    129 #endif
    130 
    131 		/* and position it */
    132 		RZ3SetCursorPos (ip->grf, pos);
    133 
    134 		ip->cursorx = ip->curx;
    135 		ip->cursory = ip->cury;
    136 	}
    137 }
    138 
    139 
    140 
    141 static void
    142 screen_up(ip, top, bottom, lines)
    143 	struct ite_softc *ip;
    144 	int top;
    145 	int bottom;
    146 	int lines;
    147 {
    148 
    149 	/* do some bounds-checking here.. */
    150 	if (top >= bottom)
    151 		return;
    152 
    153 	if (top + lines >= bottom) {
    154 		RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
    155 		return;
    156 	}
    157 
    158 	RZ3AlphaCopy(ip->grf, 0, top+lines, 0, top, ip->cols, bottom-top-lines+1);
    159 	RZ3AlphaErase(ip->grf, 0, bottom - lines + 1, ip->cols, lines);
    160 }
    161 
    162 static void
    163 screen_down (ip, top, bottom, lines)
    164 	struct ite_softc *ip;
    165 	int top;
    166 	int bottom;
    167 	int lines;
    168 {
    169 
    170 	/* do some bounds-checking here.. */
    171 	if (top >= bottom)
    172 		return;
    173 
    174 	if (top + lines >= bottom) {
    175 		RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
    176 		return;
    177 	}
    178 
    179 	RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
    180 	RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
    181 }
    182 
    183 void
    184 rh_deinit(ip)
    185 	struct ite_softc *ip;
    186 {
    187 	ip->flags &= ~ITE_INITED;
    188 }
    189 
    190 
    191 void
    192 rh_putc(ip, c, dy, dx, mode)
    193 	struct ite_softc *ip;
    194 	int c;
    195 	int dy;
    196 	int dx;
    197 	int mode;
    198 {
    199 	volatile u_char * fb = ip->grf->g_fbkva;
    200 	register u_char attr;
    201 
    202 	attr = (mode & ATTR_INV) ? 0x21 : 0x10;
    203 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    204 	if (mode & ATTR_BOLD)   attr |= 0x08;
    205 	if (mode & ATTR_BLINK)  attr |= 0x80;
    206 
    207 	fb += 4 * (dy * ip->cols + dx);
    208 	*fb++ = c; *fb = attr;
    209 }
    210 
    211 void
    212 rh_clear(ip, sy, sx, h, w)
    213 	struct ite_softc *ip;
    214 	int sy;
    215 	int sx;
    216 	int h;
    217 	int w;
    218 {
    219 	RZ3AlphaErase (ip->grf, sx, sy, w, h);
    220 }
    221 
    222 /*
    223  * RETINA_SPEED_HACK code seems to work on some boards and on others
    224  * it causes text to smear horizontally
    225  */
    226 void
    227 rh_scroll(ip, sy, sx, count, dir)
    228 	struct ite_softc *ip;
    229 	int sy;
    230 	int sx;
    231 	int count;
    232 	int dir;
    233 {
    234 #ifndef	RETINA_SPEED_HACK
    235 	u_long * fb = (u_long *) ip->grf->g_fbkva;
    236 #endif
    237 
    238 	rh_cursor(ip, ERASE_CURSOR);
    239 
    240 	if (dir == SCROLL_UP) {
    241 #ifdef	RETINA_SPEED_HACK
    242 		screen_up(ip, sy - count, ip->bottom_margin, count);
    243 #else
    244 		bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
    245 		    4 * (ip->bottom_margin - sy + 1) * ip->cols);
    246 		rh_clear(ip, ip->bottom_margin + 1 - count, 0, count, ip->cols);
    247 #endif
    248 	} else if (dir == SCROLL_DOWN) {
    249 #ifdef	RETINA_SPEED_HACK
    250 		screen_down(ip, sy, ip->bottom_margin, count);
    251 #else
    252 		bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
    253 		    4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
    254 		rh_clear(ip, sy, 0, count, ip->cols);
    255 #endif
    256 	} else if (dir == SCROLL_RIGHT) {
    257 		RZ3AlphaCopy(ip->grf, sx, sy, sx + count, sy,
    258 		    ip->cols - (sx + count), 1);
    259 		RZ3AlphaErase(ip->grf, sx, sy, count, 1);
    260 	} else {
    261 		RZ3AlphaCopy(ip->grf, sx + count, sy, sx, sy,
    262 		    ip->cols - (sx + count), 1);
    263 		RZ3AlphaErase(ip->grf, ip->cols - count, sy, count, 1);
    264 	}
    265 #ifndef	RETINA_SPEED_HACK
    266 	retina_cursor(ip, !ERASE_CURSOR);
    267 #endif
    268 }
    269 #endif /* NGRFRH */
    270