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