Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.5
      1  1.5  aymeric /*	$NetBSD: ite_et.c,v 1.5 2002/01/26 13:40:57 aymeric 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.5  aymeric  * 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.1    veego #include "grfet.h"
     38  1.1    veego #if NGRFET > 0
     39  1.1    veego 
     40  1.1    veego #include <sys/param.h>
     41  1.1    veego #include <sys/conf.h>
     42  1.1    veego #include <sys/proc.h>
     43  1.1    veego #include <sys/device.h>
     44  1.1    veego #include <sys/ioctl.h>
     45  1.1    veego #include <sys/tty.h>
     46  1.1    veego #include <sys/systm.h>
     47  1.1    veego #include <dev/cons.h>
     48  1.1    veego #include <machine/cpu.h>
     49  1.1    veego #include <amiga/amiga/device.h>
     50  1.1    veego #include <amiga/dev/grfioctl.h>
     51  1.1    veego #include <amiga/dev/grfvar.h>
     52  1.1    veego #include <amiga/dev/grf_etreg.h>
     53  1.1    veego #include <amiga/dev/itevar.h>
     54  1.1    veego 
     55  1.1    veego #ifdef TSENGCONSOLE
     56  1.1    veego int et_console = 1;
     57  1.1    veego #else
     58  1.1    veego int et_console = 0;
     59  1.1    veego #endif
     60  1.1    veego 
     61  1.5  aymeric void et_init(struct ite_softc *ip);
     62  1.5  aymeric void et_cursor(struct ite_softc *ip, int flag);
     63  1.5  aymeric void et_deinit(struct ite_softc *ip);
     64  1.5  aymeric void et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
     65  1.5  aymeric void et_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
     66  1.5  aymeric void et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
     67  1.2  thorpej 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.5  aymeric grfet_iteinit(struct grf_softc *gp)
     93  1.1    veego {
     94  1.1    veego 	gp->g_iteinit = et_init;
     95  1.1    veego 	gp->g_itedeinit = et_deinit;
     96  1.1    veego 	gp->g_iteclear = et_clear;
     97  1.1    veego 	gp->g_iteputc = et_putc;
     98  1.1    veego 	gp->g_itescroll = et_scroll;
     99  1.1    veego 	gp->g_itecursor = et_cursor;
    100  1.1    veego }
    101  1.1    veego 
    102  1.1    veego 
    103  1.1    veego void
    104  1.5  aymeric et_init(struct ite_softc *ip)
    105  1.1    veego {
    106  1.1    veego 	struct grfettext_mode *md;
    107  1.1    veego 
    108  1.1    veego 	ip->priv = ip->grf->g_data;
    109  1.1    veego 	md = (struct grfettext_mode *) ip->priv;
    110  1.1    veego 
    111  1.1    veego 	ip->cols = md->cols;
    112  1.1    veego 	ip->rows = md->rows;
    113  1.1    veego }
    114  1.1    veego 
    115  1.1    veego 
    116  1.1    veego void
    117  1.5  aymeric et_cursor(struct ite_softc *ip, int flag)
    118  1.1    veego {
    119  1.1    veego 	volatile u_char *ba = ip->grf->g_regkva;
    120  1.1    veego 
    121  1.1    veego 	switch (flag) {
    122  1.1    veego  	    case DRAW_CURSOR:
    123  1.1    veego 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
    124  1.1    veego 	    case MOVE_CURSOR:
    125  1.1    veego 		flag = ip->curx + ip->cury * ip->cols;
    126  1.1    veego 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
    127  1.1    veego 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff);
    128  1.3    veego 		WCrt(ba, CRT_ID_EXT_START, (flag >> (16-2)) & 0x0c);
    129  1.1    veego 
    130  1.1    veego 		ip->cursorx = ip->curx;
    131  1.1    veego 		ip->cursory = ip->cury;
    132  1.1    veego 		break;
    133  1.1    veego 	    case ERASE_CURSOR:
    134  1.1    veego 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
    135  1.1    veego 	    case START_CURSOROPT:
    136  1.1    veego 	    case END_CURSOROPT:
    137  1.1    veego 	    default:
    138  1.1    veego 		break;
    139  1.1    veego     	}
    140  1.1    veego }
    141  1.1    veego 
    142  1.1    veego 
    143  1.1    veego void
    144  1.5  aymeric et_deinit(struct ite_softc *ip)
    145  1.1    veego {
    146  1.1    veego 	ip->flags &= ~ITE_INITED;
    147  1.1    veego }
    148  1.1    veego 
    149  1.1    veego 
    150  1.1    veego void
    151  1.5  aymeric et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    152  1.1    veego {
    153  1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    154  1.1    veego 	unsigned char *fb = ip->grf->g_fbkva;
    155  1.1    veego 	unsigned char attr;
    156  1.1    veego 	unsigned char *cp;
    157  1.1    veego 
    158  1.1    veego 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    159  1.1    veego 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    160  1.1    veego 	if (mode & ATTR_BOLD)   attr |= 0x08;
    161  1.1    veego 	if (mode & ATTR_BLINK)  attr |= 0x80;
    162  1.1    veego 
    163  1.1    veego 	cp = fb + ((dy * ip->cols) + dx);
    164  1.1    veego 	SetTextPlane(ba,0x00);
    165  1.1    veego 	*cp = (unsigned char) c;
    166  1.1    veego 	SetTextPlane(ba,0x01);
    167  1.1    veego 	*cp = (unsigned char) attr;
    168  1.1    veego }
    169  1.1    veego 
    170  1.1    veego 
    171  1.1    veego void
    172  1.5  aymeric et_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    173  1.1    veego {
    174  1.1    veego 	/* cl_clear and cl_scroll both rely on ite passing arguments
    175  1.1    veego 	 * which describe continuous regions.  For a VT200 terminal,
    176  1.1    veego 	 * this is safe behavior.
    177  1.1    veego 	 */
    178  1.1    veego 	unsigned char *src, *dst;
    179  1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    180  1.1    veego 	int len;
    181  1.1    veego 
    182  1.1    veego 	dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
    183  1.5  aymeric 	src = dst + (ip->rows*ip->cols);
    184  1.1    veego 	len = w*h;
    185  1.1    veego 
    186  1.1    veego 	SetTextPlane(ba, 0x00);
    187  1.2  thorpej 	etbcopy(src, dst, len);
    188  1.1    veego 	SetTextPlane(ba, 0x01);
    189  1.2  thorpej 	etbcopy(src, dst, len);
    190  1.1    veego }
    191  1.1    veego 
    192  1.1    veego 
    193  1.1    veego void
    194  1.5  aymeric et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    195  1.1    veego {
    196  1.1    veego 	unsigned char *fb;
    197  1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    198  1.1    veego 
    199  1.1    veego 	fb = ip->grf->g_fbkva + sy * ip->cols;
    200  1.1    veego 	SetTextPlane(ba, 0x00);
    201  1.1    veego 
    202  1.1    veego 	switch (dir) {
    203  1.1    veego 	    case SCROLL_UP:
    204  1.5  aymeric 		etbcopy(fb, fb - (count * ip->cols),
    205  1.1    veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    206  1.1    veego 		break;
    207  1.1    veego 	    case SCROLL_DOWN:
    208  1.2  thorpej 		etbcopy(fb, fb + (count * ip->cols),
    209  1.1    veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    210  1.1    veego 		break;
    211  1.1    veego 	    case SCROLL_RIGHT:
    212  1.2  thorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    213  1.1    veego 		break;
    214  1.1    veego 	    case SCROLL_LEFT:
    215  1.2  thorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    216  1.1    veego 		break;
    217  1.1    veego 	}
    218  1.1    veego 
    219  1.1    veego 	SetTextPlane(ba, 0x01);
    220  1.1    veego 
    221  1.1    veego 	switch (dir) {
    222  1.1    veego 	    case SCROLL_UP:
    223  1.5  aymeric 		etbcopy(fb, fb - (count * ip->cols),
    224  1.1    veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    225  1.1    veego 		break;
    226  1.1    veego 	    case SCROLL_DOWN:
    227  1.2  thorpej 		etbcopy(fb, fb + (count * ip->cols),
    228  1.1    veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    229  1.1    veego 		break;
    230  1.1    veego 	    case SCROLL_RIGHT:
    231  1.2  thorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    232  1.1    veego 		break;
    233  1.1    veego 	    case SCROLL_LEFT:
    234  1.2  thorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    235  1.1    veego 		break;
    236  1.1    veego 	}
    237  1.1    veego }
    238  1.2  thorpej 
    239  1.2  thorpej 
    240  1.5  aymeric static void etbcopy(const void *src, void *dst, size_t len)
    241  1.2  thorpej {
    242  1.2  thorpej 	int i;
    243  1.2  thorpej 
    244  1.2  thorpej 	if (src == dst)
    245  1.2  thorpej 		return;
    246  1.2  thorpej 
    247  1.2  thorpej 	if (src > dst)
    248  1.2  thorpej 		for (i=len; i>0; i--) {
    249  1.2  thorpej 			*((char *)dst)++ = *((char *)src)++;
    250  1.2  thorpej 		}
    251  1.2  thorpej 	else {
    252  1.2  thorpej 		((char *)src) += len;
    253  1.2  thorpej 		((char *)dst) += len;
    254  1.5  aymeric 
    255  1.2  thorpej 		for (i=len; i>0; i--){
    256  1.2  thorpej 			*--((char *)dst) = *--((char *)src);
    257  1.2  thorpej 		}
    258  1.2  thorpej 	}
    259  1.2  thorpej }
    260  1.2  thorpej 
    261  1.1    veego #endif /* NGRFET */
    262