Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.1.4.1
      1      1.1  veego /*	$NetBSD: ite_et.c,v 1.1.4.1 1996/05/27 01:12:10 is Exp $	*/
      2      1.1  veego 
      3      1.1  veego /*
      4      1.1  veego  * Copyright (c) 1995 Ezra Story
      5      1.1  veego  * Copyright (c) 1995 Kari Mettinen
      6      1.1  veego  * Copyright (c) 1994 Markus Wild
      7      1.1  veego  * Copyright (c) 1994 Lutz Vieweg
      8      1.1  veego  * All rights reserved.
      9      1.1  veego  *
     10      1.1  veego  * Redistribution and use in source and binary forms, with or without
     11      1.1  veego  * modification, are permitted provided that the following conditions
     12      1.1  veego  * are met:
     13      1.1  veego  * 1. Redistributions of source code must retain the above copyright
     14      1.1  veego  *    notice, this list of conditions and the following disclaimer.
     15      1.1  veego  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  veego  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  veego  *    documentation and/or other materials provided with the distribution.
     18      1.1  veego  * 3. All advertising materials mentioning features or use of this software
     19      1.1  veego  *    must display the following acknowledgement:
     20      1.1  veego  *      This product includes software developed by Lutz Vieweg.
     21      1.1  veego  * 4. The name of the author may not be used to endorse or promote products
     22      1.1  veego  *    derived from this software without specific prior written permission
     23      1.1  veego  *
     24      1.1  veego  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25      1.1  veego  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26      1.1  veego  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27      1.1  veego  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28      1.1  veego  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29      1.1  veego  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30      1.1  veego  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31      1.1  veego  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32      1.1  veego  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33      1.1  veego  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34      1.1  veego  */
     35      1.1  veego 
     36      1.1  veego #include "grfet.h"
     37      1.1  veego #if NGRFET > 0
     38      1.1  veego 
     39      1.1  veego #include <sys/param.h>
     40      1.1  veego #include <sys/conf.h>
     41      1.1  veego #include <sys/proc.h>
     42      1.1  veego #include <sys/device.h>
     43      1.1  veego #include <sys/ioctl.h>
     44      1.1  veego #include <sys/tty.h>
     45      1.1  veego #include <sys/systm.h>
     46      1.1  veego #include <dev/cons.h>
     47      1.1  veego #include <machine/cpu.h>
     48      1.1  veego #include <amiga/amiga/device.h>
     49      1.1  veego #include <amiga/dev/grfioctl.h>
     50      1.1  veego #include <amiga/dev/grfvar.h>
     51      1.1  veego #include <amiga/dev/grf_etreg.h>
     52      1.1  veego #include <amiga/dev/itevar.h>
     53      1.1  veego 
     54      1.1  veego #ifdef TSENGCONSOLE
     55      1.1  veego int et_console = 1;
     56      1.1  veego #else
     57      1.1  veego int et_console = 0;
     58      1.1  veego #endif
     59      1.1  veego 
     60      1.1  veego void et_init __P((struct ite_softc *ip));
     61      1.1  veego void et_cursor __P((struct ite_softc *ip, int flag));
     62      1.1  veego void et_deinit __P((struct ite_softc *ip));
     63      1.1  veego void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
     64      1.1  veego void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
     65      1.1  veego void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
     66      1.1  veego     int dir));
     67  1.1.4.1     is static void etbcopy(const void *src, void *dst, size_t len);
     68      1.1  veego 
     69      1.1  veego 
     70      1.1  veego /*
     71      1.1  veego  * Called to determine ite status.  Because the connection between the
     72      1.1  veego  * console & ite in this driver is rather intimate, we return CN_DEAD
     73      1.1  veego  * if the cl_console is not active.
     74      1.1  veego  */
     75      1.1  veego int
     76      1.1  veego grfet_cnprobe(void)
     77      1.1  veego {
     78      1.1  veego 	static int done;
     79      1.1  veego 	int rv;
     80      1.1  veego 
     81      1.1  veego 	if (et_console && (done == 0))
     82      1.1  veego 		rv = CN_INTERNAL;
     83      1.1  veego 	else
     84      1.1  veego 		rv = CN_DEAD;
     85      1.1  veego 
     86      1.1  veego 	done = 1;
     87      1.1  veego 	return(rv);
     88      1.1  veego }
     89      1.1  veego 
     90      1.1  veego 
     91      1.1  veego void
     92      1.1  veego grfet_iteinit(gp)
     93      1.1  veego 	struct grf_softc *gp;
     94      1.1  veego {
     95      1.1  veego 	gp->g_iteinit = et_init;
     96      1.1  veego 	gp->g_itedeinit = et_deinit;
     97      1.1  veego 	gp->g_iteclear = et_clear;
     98      1.1  veego 	gp->g_iteputc = et_putc;
     99      1.1  veego 	gp->g_itescroll = et_scroll;
    100      1.1  veego 	gp->g_itecursor = et_cursor;
    101      1.1  veego }
    102      1.1  veego 
    103      1.1  veego 
    104      1.1  veego void
    105      1.1  veego et_init(ip)
    106      1.1  veego 	struct ite_softc *ip;
    107      1.1  veego {
    108      1.1  veego 	struct grfettext_mode *md;
    109      1.1  veego 
    110      1.1  veego 	ip->priv = ip->grf->g_data;
    111      1.1  veego 	md = (struct grfettext_mode *) ip->priv;
    112      1.1  veego 
    113      1.1  veego 	ip->cols = md->cols;
    114      1.1  veego 	ip->rows = md->rows;
    115      1.1  veego }
    116      1.1  veego 
    117      1.1  veego 
    118      1.1  veego void
    119      1.1  veego et_cursor(ip, flag)
    120      1.1  veego 	struct ite_softc *ip;
    121      1.1  veego 	int flag;
    122      1.1  veego {
    123      1.1  veego 	volatile u_char *ba = ip->grf->g_regkva;
    124      1.1  veego 
    125      1.1  veego 	switch (flag) {
    126      1.1  veego  	    case DRAW_CURSOR:
    127      1.1  veego 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
    128      1.1  veego 	    case MOVE_CURSOR:
    129      1.1  veego 		flag = ip->curx + ip->cury * ip->cols;
    130      1.1  veego 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
    131      1.1  veego 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff);
    132      1.1  veego 		WCrt(ba, CTR_ID_EXT_START, (flag >> (16-2)) & 0x0c);
    133      1.1  veego 
    134      1.1  veego 		ip->cursorx = ip->curx;
    135      1.1  veego 		ip->cursory = ip->cury;
    136      1.1  veego 		break;
    137      1.1  veego 	    case ERASE_CURSOR:
    138      1.1  veego 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
    139      1.1  veego 	    case START_CURSOROPT:
    140      1.1  veego 	    case END_CURSOROPT:
    141      1.1  veego 	    default:
    142      1.1  veego 		break;
    143      1.1  veego     	}
    144      1.1  veego }
    145      1.1  veego 
    146      1.1  veego 
    147      1.1  veego void
    148      1.1  veego et_deinit(ip)
    149      1.1  veego 	struct ite_softc *ip;
    150      1.1  veego {
    151      1.1  veego 	ip->flags &= ~ITE_INITED;
    152      1.1  veego }
    153      1.1  veego 
    154      1.1  veego 
    155      1.1  veego void
    156      1.1  veego et_putc(ip, c, dy, dx, mode)
    157      1.1  veego 	struct ite_softc *ip;
    158      1.1  veego 	int c;
    159      1.1  veego 	int dy;
    160      1.1  veego 	int dx;
    161      1.1  veego 	int mode;
    162      1.1  veego {
    163      1.1  veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    164      1.1  veego 	unsigned char *fb = ip->grf->g_fbkva;
    165      1.1  veego 	unsigned char attr;
    166      1.1  veego 	unsigned char *cp;
    167      1.1  veego 
    168      1.1  veego 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    169      1.1  veego 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    170      1.1  veego 	if (mode & ATTR_BOLD)   attr |= 0x08;
    171      1.1  veego 	if (mode & ATTR_BLINK)  attr |= 0x80;
    172      1.1  veego 
    173      1.1  veego 	cp = fb + ((dy * ip->cols) + dx);
    174      1.1  veego 	SetTextPlane(ba,0x00);
    175      1.1  veego 	*cp = (unsigned char) c;
    176      1.1  veego 	SetTextPlane(ba,0x01);
    177      1.1  veego 	*cp = (unsigned char) attr;
    178      1.1  veego }
    179      1.1  veego 
    180      1.1  veego 
    181      1.1  veego void
    182      1.1  veego et_clear(ip, sy, sx, h, w)
    183      1.1  veego 	struct ite_softc *ip;
    184      1.1  veego 	int sy;
    185      1.1  veego 	int sx;
    186      1.1  veego 	int h;
    187      1.1  veego 	int w;
    188      1.1  veego {
    189      1.1  veego 	/* cl_clear and cl_scroll both rely on ite passing arguments
    190      1.1  veego 	 * which describe continuous regions.  For a VT200 terminal,
    191      1.1  veego 	 * this is safe behavior.
    192      1.1  veego 	 */
    193      1.1  veego 	unsigned char *src, *dst;
    194      1.1  veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    195      1.1  veego 	int len;
    196      1.1  veego 
    197      1.1  veego 	dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
    198      1.1  veego 	src = dst + (ip->rows*ip->cols);
    199      1.1  veego 	len = w*h;
    200      1.1  veego 
    201      1.1  veego 	SetTextPlane(ba, 0x00);
    202  1.1.4.1     is 	etbcopy(src, dst, len);
    203      1.1  veego 	SetTextPlane(ba, 0x01);
    204  1.1.4.1     is 	etbcopy(src, dst, len);
    205      1.1  veego }
    206      1.1  veego 
    207      1.1  veego 
    208      1.1  veego void
    209      1.1  veego et_scroll(ip, sy, sx, count, dir)
    210      1.1  veego 	struct ite_softc *ip;
    211      1.1  veego 	int sy;
    212      1.1  veego 	int sx;
    213      1.1  veego 	int count;
    214      1.1  veego 	int dir;
    215      1.1  veego {
    216      1.1  veego 	unsigned char *fb;
    217      1.1  veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    218      1.1  veego 
    219      1.1  veego 	fb = ip->grf->g_fbkva + sy * ip->cols;
    220      1.1  veego 	SetTextPlane(ba, 0x00);
    221      1.1  veego 
    222      1.1  veego 	switch (dir) {
    223      1.1  veego 	    case SCROLL_UP:
    224  1.1.4.1     is 		etbcopy(fb, fb - (count * ip->cols),
    225      1.1  veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    226      1.1  veego 		break;
    227      1.1  veego 	    case SCROLL_DOWN:
    228  1.1.4.1     is 		etbcopy(fb, fb + (count * ip->cols),
    229      1.1  veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    230      1.1  veego 		break;
    231      1.1  veego 	    case SCROLL_RIGHT:
    232  1.1.4.1     is 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    233      1.1  veego 		break;
    234      1.1  veego 	    case SCROLL_LEFT:
    235  1.1.4.1     is 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    236      1.1  veego 		break;
    237      1.1  veego 	}
    238      1.1  veego 
    239      1.1  veego 	SetTextPlane(ba, 0x01);
    240      1.1  veego 
    241      1.1  veego 	switch (dir) {
    242      1.1  veego 	    case SCROLL_UP:
    243  1.1.4.1     is 		etbcopy(fb, fb - (count * ip->cols),
    244      1.1  veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    245      1.1  veego 		break;
    246      1.1  veego 	    case SCROLL_DOWN:
    247  1.1.4.1     is 		etbcopy(fb, fb + (count * ip->cols),
    248      1.1  veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    249      1.1  veego 		break;
    250      1.1  veego 	    case SCROLL_RIGHT:
    251  1.1.4.1     is 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    252      1.1  veego 		break;
    253      1.1  veego 	    case SCROLL_LEFT:
    254  1.1.4.1     is 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    255      1.1  veego 		break;
    256      1.1  veego 	}
    257      1.1  veego }
    258  1.1.4.1     is 
    259  1.1.4.1     is 
    260  1.1.4.1     is static void etbcopy(src, dst, len)
    261  1.1.4.1     is 	const void *src;
    262  1.1.4.1     is 	void *dst;
    263  1.1.4.1     is 	size_t len;
    264  1.1.4.1     is {
    265  1.1.4.1     is 	int i;
    266  1.1.4.1     is 
    267  1.1.4.1     is 	if (src == dst)
    268  1.1.4.1     is 		return;
    269  1.1.4.1     is 
    270  1.1.4.1     is 	if (src > dst)
    271  1.1.4.1     is 		for (i=len; i>0; i--) {
    272  1.1.4.1     is 			*((char *)dst)++ = *((char *)src)++;
    273  1.1.4.1     is 		}
    274  1.1.4.1     is 	else {
    275  1.1.4.1     is 		((char *)src) += len;
    276  1.1.4.1     is 		((char *)dst) += len;
    277  1.1.4.1     is 
    278  1.1.4.1     is 		for (i=len; i>0; i--){
    279  1.1.4.1     is 			*--((char *)dst) = *--((char *)src);
    280  1.1.4.1     is 		}
    281  1.1.4.1     is 	}
    282  1.1.4.1     is }
    283  1.1.4.1     is 
    284      1.1  veego #endif /* NGRFET */
    285