Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.4.26.1
      1  1.4.26.1  nathanw /*	$NetBSD: ite_et.c,v 1.4.26.1 2002/02/28 04:06:50 nathanw 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.4.26.1  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34       1.1    veego  */
     35       1.1    veego 
     36       1.4       is #include "opt_amigacons.h"
     37  1.4.26.1  nathanw 
     38  1.4.26.1  nathanw #include <sys/cdefs.h>
     39  1.4.26.1  nathanw __KERNEL_RCSID(0, "$NetBSD: ite_et.c,v 1.4.26.1 2002/02/28 04:06:50 nathanw Exp $");
     40  1.4.26.1  nathanw 
     41       1.1    veego #include "grfet.h"
     42       1.1    veego #if NGRFET > 0
     43       1.1    veego 
     44       1.1    veego #include <sys/param.h>
     45       1.1    veego #include <sys/conf.h>
     46       1.1    veego #include <sys/proc.h>
     47       1.1    veego #include <sys/device.h>
     48       1.1    veego #include <sys/ioctl.h>
     49       1.1    veego #include <sys/tty.h>
     50       1.1    veego #include <sys/systm.h>
     51       1.1    veego #include <dev/cons.h>
     52       1.1    veego #include <machine/cpu.h>
     53       1.1    veego #include <amiga/amiga/device.h>
     54       1.1    veego #include <amiga/dev/grfioctl.h>
     55       1.1    veego #include <amiga/dev/grfvar.h>
     56       1.1    veego #include <amiga/dev/grf_etreg.h>
     57       1.1    veego #include <amiga/dev/itevar.h>
     58       1.1    veego 
     59       1.1    veego #ifdef TSENGCONSOLE
     60       1.1    veego int et_console = 1;
     61       1.1    veego #else
     62       1.1    veego int et_console = 0;
     63       1.1    veego #endif
     64       1.1    veego 
     65  1.4.26.1  nathanw void et_init(struct ite_softc *ip);
     66  1.4.26.1  nathanw void et_cursor(struct ite_softc *ip, int flag);
     67  1.4.26.1  nathanw void et_deinit(struct ite_softc *ip);
     68  1.4.26.1  nathanw void et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
     69  1.4.26.1  nathanw void et_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
     70  1.4.26.1  nathanw void et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
     71       1.2  thorpej static void etbcopy(const void *src, void *dst, size_t len);
     72       1.1    veego 
     73       1.1    veego 
     74       1.1    veego /*
     75       1.1    veego  * Called to determine ite status.  Because the connection between the
     76       1.1    veego  * console & ite in this driver is rather intimate, we return CN_DEAD
     77       1.1    veego  * if the cl_console is not active.
     78       1.1    veego  */
     79       1.1    veego int
     80       1.1    veego grfet_cnprobe(void)
     81       1.1    veego {
     82       1.1    veego 	static int done;
     83       1.1    veego 	int rv;
     84       1.1    veego 
     85       1.1    veego 	if (et_console && (done == 0))
     86       1.1    veego 		rv = CN_INTERNAL;
     87       1.1    veego 	else
     88       1.1    veego 		rv = CN_DEAD;
     89       1.1    veego 
     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 void
     96  1.4.26.1  nathanw grfet_iteinit(struct grf_softc *gp)
     97       1.1    veego {
     98       1.1    veego 	gp->g_iteinit = et_init;
     99       1.1    veego 	gp->g_itedeinit = et_deinit;
    100       1.1    veego 	gp->g_iteclear = et_clear;
    101       1.1    veego 	gp->g_iteputc = et_putc;
    102       1.1    veego 	gp->g_itescroll = et_scroll;
    103       1.1    veego 	gp->g_itecursor = et_cursor;
    104       1.1    veego }
    105       1.1    veego 
    106       1.1    veego 
    107       1.1    veego void
    108  1.4.26.1  nathanw et_init(struct ite_softc *ip)
    109       1.1    veego {
    110       1.1    veego 	struct grfettext_mode *md;
    111       1.1    veego 
    112       1.1    veego 	ip->priv = ip->grf->g_data;
    113       1.1    veego 	md = (struct grfettext_mode *) ip->priv;
    114       1.1    veego 
    115       1.1    veego 	ip->cols = md->cols;
    116       1.1    veego 	ip->rows = md->rows;
    117       1.1    veego }
    118       1.1    veego 
    119       1.1    veego 
    120       1.1    veego void
    121  1.4.26.1  nathanw et_cursor(struct ite_softc *ip, 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.3    veego 		WCrt(ba, CRT_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.4.26.1  nathanw et_deinit(struct ite_softc *ip)
    149       1.1    veego {
    150       1.1    veego 	ip->flags &= ~ITE_INITED;
    151       1.1    veego }
    152       1.1    veego 
    153       1.1    veego 
    154       1.1    veego void
    155  1.4.26.1  nathanw et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    156       1.1    veego {
    157       1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    158       1.1    veego 	unsigned char *fb = ip->grf->g_fbkva;
    159       1.1    veego 	unsigned char attr;
    160       1.1    veego 	unsigned char *cp;
    161       1.1    veego 
    162       1.1    veego 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    163       1.1    veego 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    164       1.1    veego 	if (mode & ATTR_BOLD)   attr |= 0x08;
    165       1.1    veego 	if (mode & ATTR_BLINK)  attr |= 0x80;
    166       1.1    veego 
    167       1.1    veego 	cp = fb + ((dy * ip->cols) + dx);
    168       1.1    veego 	SetTextPlane(ba,0x00);
    169       1.1    veego 	*cp = (unsigned char) c;
    170       1.1    veego 	SetTextPlane(ba,0x01);
    171       1.1    veego 	*cp = (unsigned char) attr;
    172       1.1    veego }
    173       1.1    veego 
    174       1.1    veego 
    175       1.1    veego void
    176  1.4.26.1  nathanw et_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    177       1.1    veego {
    178       1.1    veego 	/* cl_clear and cl_scroll both rely on ite passing arguments
    179       1.1    veego 	 * which describe continuous regions.  For a VT200 terminal,
    180       1.1    veego 	 * this is safe behavior.
    181       1.1    veego 	 */
    182       1.1    veego 	unsigned char *src, *dst;
    183       1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    184       1.1    veego 	int len;
    185       1.1    veego 
    186       1.1    veego 	dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
    187  1.4.26.1  nathanw 	src = dst + (ip->rows*ip->cols);
    188       1.1    veego 	len = w*h;
    189       1.1    veego 
    190       1.1    veego 	SetTextPlane(ba, 0x00);
    191       1.2  thorpej 	etbcopy(src, dst, len);
    192       1.1    veego 	SetTextPlane(ba, 0x01);
    193       1.2  thorpej 	etbcopy(src, dst, len);
    194       1.1    veego }
    195       1.1    veego 
    196       1.1    veego 
    197       1.1    veego void
    198  1.4.26.1  nathanw et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    199       1.1    veego {
    200       1.1    veego 	unsigned char *fb;
    201       1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    202       1.1    veego 
    203       1.1    veego 	fb = ip->grf->g_fbkva + sy * ip->cols;
    204       1.1    veego 	SetTextPlane(ba, 0x00);
    205       1.1    veego 
    206       1.1    veego 	switch (dir) {
    207       1.1    veego 	    case SCROLL_UP:
    208  1.4.26.1  nathanw 		etbcopy(fb, fb - (count * ip->cols),
    209       1.1    veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    210       1.1    veego 		break;
    211       1.1    veego 	    case SCROLL_DOWN:
    212       1.2  thorpej 		etbcopy(fb, fb + (count * ip->cols),
    213       1.1    veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    214       1.1    veego 		break;
    215       1.1    veego 	    case SCROLL_RIGHT:
    216       1.2  thorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    217       1.1    veego 		break;
    218       1.1    veego 	    case SCROLL_LEFT:
    219       1.2  thorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    220       1.1    veego 		break;
    221       1.1    veego 	}
    222       1.1    veego 
    223       1.1    veego 	SetTextPlane(ba, 0x01);
    224       1.1    veego 
    225       1.1    veego 	switch (dir) {
    226       1.1    veego 	    case SCROLL_UP:
    227  1.4.26.1  nathanw 		etbcopy(fb, fb - (count * ip->cols),
    228       1.1    veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    229       1.1    veego 		break;
    230       1.1    veego 	    case SCROLL_DOWN:
    231       1.2  thorpej 		etbcopy(fb, fb + (count * ip->cols),
    232       1.1    veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    233       1.1    veego 		break;
    234       1.1    veego 	    case SCROLL_RIGHT:
    235       1.2  thorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    236       1.1    veego 		break;
    237       1.1    veego 	    case SCROLL_LEFT:
    238       1.2  thorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    239       1.1    veego 		break;
    240       1.1    veego 	}
    241       1.1    veego }
    242       1.2  thorpej 
    243       1.2  thorpej 
    244  1.4.26.1  nathanw static void etbcopy(const void *src, void *dst, size_t len)
    245       1.2  thorpej {
    246       1.2  thorpej 	int i;
    247       1.2  thorpej 
    248       1.2  thorpej 	if (src == dst)
    249       1.2  thorpej 		return;
    250       1.2  thorpej 
    251       1.2  thorpej 	if (src > dst)
    252       1.2  thorpej 		for (i=len; i>0; i--) {
    253       1.2  thorpej 			*((char *)dst)++ = *((char *)src)++;
    254       1.2  thorpej 		}
    255       1.2  thorpej 	else {
    256       1.2  thorpej 		((char *)src) += len;
    257       1.2  thorpej 		((char *)dst) += len;
    258  1.4.26.1  nathanw 
    259       1.2  thorpej 		for (i=len; i>0; i--){
    260       1.2  thorpej 			*--((char *)dst) = *--((char *)src);
    261       1.2  thorpej 		}
    262       1.2  thorpej 	}
    263       1.2  thorpej }
    264       1.2  thorpej 
    265       1.1    veego #endif /* NGRFET */
    266