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