Home | History | Annotate | Line # | Download | only in dev
ite_cv3d.c revision 1.4
      1 /*	$NetBSD: ite_cv3d.c,v 1.4 2002/01/26 13:40:57 aymeric Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995 Michael Teske
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Christian E. Hopps,
     18  *      Ezra Story, Kari Mettinen, Markus Wild, Lutz Vieweg
     19  *      and Michael Teske.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * This code is based on ite_cl.c and ite_rh.c by
     37  * Ezra Story, Kari Mettinen, Markus Wild, Lutz Vieweg.
     38  */
     39 
     40 #include "opt_amigacons.h"
     41 #include "grfcv3d.h"
     42 #if NGRFCV3D > 0
     43 
     44 #include <sys/param.h>
     45 #include <sys/conf.h>
     46 #include <sys/proc.h>
     47 #include <sys/device.h>
     48 #include <sys/ioctl.h>
     49 #include <sys/tty.h>
     50 #include <sys/systm.h>
     51 #include <sys/queue.h>
     52 #include <sys/termios.h>
     53 #include <sys/malloc.h>
     54 #include <dev/cons.h>
     55 #include <machine/cpu.h>
     56 #include <amiga/dev/itevar.h>
     57 #include <amiga/dev/iteioctl.h>
     58 #include <amiga/amiga/device.h>
     59 #include <amiga/dev/grfioctl.h>
     60 #include <amiga/dev/grfvar.h>
     61 #include <amiga/dev/grf_cv3dreg.h>
     62 
     63 void cv3d_ite_init(struct ite_softc *);
     64 void cv3d_ite_deinit(struct ite_softc *);
     65 static void cv3d_cursor(struct ite_softc *, int);
     66 static void cv3d_putc(struct ite_softc *, int, int, int, int);
     67 static void cv3d_clear(struct ite_softc *, int, int, int, int);
     68 static void cv3d_scroll(struct ite_softc *, int, int, int, int);
     69 
     70 /*
     71  * called from grf_cv3d to return console priority
     72  */
     73 int
     74 grfcv3d_cnprobe(void)
     75 {
     76 	static int done;
     77 	int rv;
     78 
     79 	if (done == 0)
     80 #ifdef CV3DCONSOLE
     81 		rv = CN_INTERNAL;
     82 #else
     83 		rv = CN_DEAD;
     84 #endif
     85 	else
     86 #ifdef CV3DCONSOLE
     87 		rv = CN_NORMAL;
     88 #else
     89 		rv = CN_DEAD;
     90 #endif
     91 	done = 1;
     92 	return(rv);
     93 }
     94 
     95 
     96 /*
     97  * called from grf_cv3d to init ite portion of
     98  * grf_softc struct
     99  */
    100 void
    101 grfcv3d_iteinit(struct grf_softc *gp)
    102 {
    103 	gp->g_itecursor = cv3d_cursor;
    104 	gp->g_iteputc = cv3d_putc;
    105 	gp->g_iteclear = cv3d_clear;
    106 	gp->g_itescroll = cv3d_scroll;
    107 	gp->g_iteinit = cv3d_ite_init;
    108 	gp->g_itedeinit = cv3d_ite_deinit;
    109 }
    110 
    111 
    112 void
    113 cv3d_ite_deinit(struct ite_softc *ip)
    114 {
    115 	ip->flags &= ~ITE_INITED;
    116 }
    117 
    118 
    119 static unsigned short cv3d_rowc[MAXCOLS*(MAXROWS+1)];
    120 
    121 /*
    122  * Console buffer to avoid the slow reading from gfx mem.
    123  */
    124 
    125 static unsigned short *console_buffer;
    126 
    127 void
    128 cv3d_ite_init(register struct ite_softc *ip)
    129 {
    130 	struct grfcv3dtext_mode *md;
    131 	int i;
    132 	static char first = 1;
    133 	volatile unsigned short *fb = (volatile unsigned short *)ip->grf->g_fbkva;
    134 	unsigned short *buffer;
    135 
    136 
    137 	ip->priv = ip->grf->g_data;
    138 	md = (struct grfcv3dtext_mode *) ip->grf->g_data;
    139 
    140 	ip->cols = md->cols;
    141 	ip->rows = md->rows;
    142 
    143 	/* alloc buffers */
    144 
    145 #if 0  /* XXX malloc seems not to work in early init :( */
    146 	if (cv3d_rowc)
    147 		free(cv3d_rowc, M_DEVBUF);
    148 
    149 	/* alloc all in one */
    150 	cv3d_rowc = malloc(sizeof(short) * (ip->rows + 1) * (ip->cols + 2),
    151 		M_DEVBUF, M_WAITOK);
    152 	if (!cv3d_rowc)
    153 		panic("No buffers for ite_cv3d!");
    154 #endif
    155 
    156 	console_buffer = cv3d_rowc + ip->rows + 1;
    157 
    158 
    159 	for (i = 0; i < ip->rows; i++)
    160 		cv3d_rowc[i] = i * ip->cols;
    161 
    162 	if (first) {
    163 		for (i = 0; i < ip->rows * ip->cols; i++)
    164 			console_buffer[i] = 0x2007;
    165 		first = 0;
    166 	} else { /* restore console */
    167 		buffer = console_buffer;
    168 		for (i = 0; i < ip->rows * ip->cols; i++) {
    169 			*fb++ = *buffer++;
    170 			*fb++;
    171 		}
    172 	}
    173 }
    174 
    175 
    176 void
    177 cv3d_cursor(struct ite_softc *ip, int flag)
    178 {
    179 	volatile caddr_t ba = ip->grf->g_regkva;
    180 
    181 	switch (flag) {
    182 	    case DRAW_CURSOR:
    183 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
    184 	    case MOVE_CURSOR:
    185 		flag = ip->curx + ip->cury * ip->cols;
    186 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
    187 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
    188 		ip->cursorx = ip->curx;
    189 		ip->cursory = ip->cury;
    190 		break;
    191 	    case ERASE_CURSOR:
    192 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
    193 	    case START_CURSOROPT:
    194 	    case END_CURSOROPT:
    195 	    default:
    196 		break;
    197 	}
    198 }
    199 
    200 
    201 void
    202 cv3d_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    203 {
    204 	caddr_t fb = ip->grf->g_fbkva;
    205 	unsigned char attr;
    206 	unsigned char *cp;
    207 
    208 	attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    209 	if (mode & ATTR_UL)     attr  = 0x01;
    210 	if (mode & ATTR_BOLD)   attr |= 0x08;
    211 	if (mode & ATTR_BLINK)  attr |= 0x80;
    212 
    213 	cp = fb + ((cv3d_rowc[dy] + dx) << 2); /* *4 */
    214 	*cp++ = (unsigned char) c;
    215 	*cp = (unsigned char) attr;
    216 
    217 	cp = (unsigned char *) &console_buffer[cv3d_rowc[dy]+dx];
    218 	*cp++ = (unsigned char) c;
    219 	*cp = (unsigned char) attr;
    220 }
    221 
    222 
    223 void
    224 cv3d_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    225 {
    226 	/* cv3d_clear and cv3d_scroll both rely on ite passing arguments
    227 	 * which describe continuous regions.  For a VT200 terminal,
    228 	 * this is safe behavior.
    229 	 */
    230 	unsigned short  *dst;
    231 	int len;
    232 
    233 	dst = (unsigned short *) (ip->grf->g_fbkva + (((sy * ip->cols) + sx) << 2));
    234 
    235 	for (len = w * h; len > 0 ; len--) {
    236 		*dst = 0x2007;
    237 		dst +=2;
    238 	}
    239 
    240 	dst = &console_buffer[(sy * ip->cols) + sx];
    241 	for (len = w * h; len > 0 ; len--) {
    242 		*dst++ = 0x2007;
    243 	}
    244 }
    245 
    246 void
    247 cv3d_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    248 {
    249 	unsigned short *src, *dst, *dst2;
    250 	int i;
    251 	int len;
    252 
    253 	src = (unsigned short *)(ip->grf->g_fbkva + (cv3d_rowc[sy] << 2));
    254 
    255 	switch (dir) {
    256 	    case SCROLL_UP:
    257 		dst = src - ((cv3d_rowc[count])<<1);
    258 
    259 		len = cv3d_rowc[(ip->bottom_margin + 1 - sy)];
    260 		src = &console_buffer[cv3d_rowc[sy]];
    261 
    262 		if (count > sy) { /* boundary checks */
    263 			dst2 = console_buffer;
    264 			dst = (unsigned short *)(ip->grf->g_fbkva);
    265 			len -= cv3d_rowc[(count - sy)];
    266 			src += cv3d_rowc[(count - sy)];
    267 		} else
    268 			dst2 = &console_buffer[cv3d_rowc[(sy-count)]];
    269 
    270 		bcopy (src, dst2, len << 1);
    271 
    272 		for (i = 0; i < len; i++) {
    273 			*dst++ = *dst2++;
    274 			dst++;
    275 		}
    276 		break;
    277 	    case SCROLL_DOWN:
    278 		dst = src + ((cv3d_rowc[count]) << 1);
    279 
    280 		len = cv3d_rowc[(ip->bottom_margin + 1 - (sy + count))];
    281 		src = &console_buffer[cv3d_rowc[sy]];
    282 		dst2 = &console_buffer[cv3d_rowc[(sy + count)]];
    283 
    284 		if (len < 0)
    285 			return;  /* do some boundary check */
    286 
    287 		bcopy (src, dst2, len << 1);
    288 
    289 		for (i = 0; i < len; i++) {
    290 			*dst++ = *dst2++;
    291 			dst++;
    292 		}
    293 		break;
    294 	    case SCROLL_RIGHT:
    295 		dst = src + ((sx+count)<<1);
    296 		src = &console_buffer[cv3d_rowc[sy] + sx];
    297 		len = ip->cols - (sx + count);
    298 		dst2 = &console_buffer[cv3d_rowc[sy] + sx + count];
    299 		bcopy (src, dst2, len << 1);
    300 
    301 		for (i = 0; i < len; i++) {
    302 			*dst++ = *dst2++;
    303 			dst++;
    304 		}
    305 		break;
    306 	    case SCROLL_LEFT:
    307 		dst = src + ((sx - count)<<1);
    308 		src = &console_buffer[cv3d_rowc[sy] + sx];
    309 		len = ip->cols - sx;
    310 		dst2 = &console_buffer[cv3d_rowc[sy] + sx - count];
    311 		bcopy (src, dst2, len << 1);
    312 
    313 		for (i = 0; i < len; i++) {
    314 			*dst++ = *dst2++;
    315 			dst++;
    316 		}
    317 	}
    318 }
    319 
    320 #endif /* NGRFCV3D */
    321