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