Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.10.14.1
      1  1.10.14.1     chap /*	$NetBSD: ite_et.c,v 1.10.14.1 2006/06/19 03:44:01 chap 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.6  aymeric 
     38        1.6  aymeric #include <sys/cdefs.h>
     39  1.10.14.1     chap __KERNEL_RCSID(0, "$NetBSD: ite_et.c,v 1.10.14.1 2006/06/19 03:44:01 chap Exp $");
     40        1.6  aymeric 
     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.5  aymeric void et_init(struct ite_softc *ip);
     66        1.5  aymeric void et_cursor(struct ite_softc *ip, int flag);
     67        1.5  aymeric void et_deinit(struct ite_softc *ip);
     68        1.5  aymeric void et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
     69        1.5  aymeric void et_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
     70        1.5  aymeric 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.5  aymeric 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.5  aymeric 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.5  aymeric 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.5  aymeric 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.5  aymeric 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.8       is 	volatile unsigned char *cp;
    161        1.1    veego 
    162        1.7       is 	if (ip->flags & ITE_INGRF)
    163        1.7       is 		return;
    164        1.7       is 
    165        1.1    veego 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    166        1.1    veego 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
    167        1.1    veego 	if (mode & ATTR_BOLD)   attr |= 0x08;
    168        1.1    veego 	if (mode & ATTR_BLINK)  attr |= 0x80;
    169        1.1    veego 
    170        1.1    veego 	cp = fb + ((dy * ip->cols) + dx);
    171        1.1    veego 	SetTextPlane(ba,0x00);
    172        1.1    veego 	*cp = (unsigned char) c;
    173        1.1    veego 	SetTextPlane(ba,0x01);
    174        1.1    veego 	*cp = (unsigned char) attr;
    175        1.1    veego }
    176        1.1    veego 
    177        1.1    veego 
    178        1.1    veego void
    179        1.5  aymeric et_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    180        1.1    veego {
    181        1.1    veego 	/* cl_clear and cl_scroll both rely on ite passing arguments
    182        1.1    veego 	 * which describe continuous regions.  For a VT200 terminal,
    183        1.1    veego 	 * this is safe behavior.
    184        1.1    veego 	 */
    185        1.1    veego 	unsigned char *src, *dst;
    186        1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    187        1.1    veego 	int len;
    188        1.1    veego 
    189        1.7       is 	if (ip->flags & ITE_INGRF)
    190        1.7       is 		return;
    191        1.7       is 
    192        1.1    veego 	dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
    193        1.5  aymeric 	src = dst + (ip->rows*ip->cols);
    194        1.1    veego 	len = w*h;
    195        1.1    veego 
    196        1.1    veego 	SetTextPlane(ba, 0x00);
    197        1.2  thorpej 	etbcopy(src, dst, len);
    198        1.1    veego 	SetTextPlane(ba, 0x01);
    199        1.2  thorpej 	etbcopy(src, dst, len);
    200        1.1    veego }
    201        1.1    veego 
    202        1.1    veego 
    203        1.1    veego void
    204        1.5  aymeric et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    205        1.1    veego {
    206        1.1    veego 	unsigned char *fb;
    207        1.1    veego 	volatile unsigned char *ba = ip->grf->g_regkva;
    208        1.1    veego 
    209        1.7       is 	if (ip->flags & ITE_INGRF)
    210        1.7       is 		return;
    211        1.7       is 
    212        1.1    veego 	fb = ip->grf->g_fbkva + sy * ip->cols;
    213        1.1    veego 	SetTextPlane(ba, 0x00);
    214        1.1    veego 
    215        1.1    veego 	switch (dir) {
    216        1.1    veego 	    case SCROLL_UP:
    217        1.5  aymeric 		etbcopy(fb, fb - (count * ip->cols),
    218        1.1    veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    219        1.1    veego 		break;
    220        1.1    veego 	    case SCROLL_DOWN:
    221        1.2  thorpej 		etbcopy(fb, fb + (count * ip->cols),
    222        1.1    veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    223        1.1    veego 		break;
    224        1.1    veego 	    case SCROLL_RIGHT:
    225        1.2  thorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    226        1.1    veego 		break;
    227        1.1    veego 	    case SCROLL_LEFT:
    228        1.2  thorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    229        1.1    veego 		break;
    230        1.1    veego 	}
    231        1.1    veego 
    232        1.1    veego 	SetTextPlane(ba, 0x01);
    233        1.1    veego 
    234        1.1    veego 	switch (dir) {
    235        1.1    veego 	    case SCROLL_UP:
    236        1.5  aymeric 		etbcopy(fb, fb - (count * ip->cols),
    237        1.1    veego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
    238        1.1    veego 		break;
    239        1.1    veego 	    case SCROLL_DOWN:
    240        1.2  thorpej 		etbcopy(fb, fb + (count * ip->cols),
    241        1.1    veego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
    242        1.1    veego 		break;
    243        1.1    veego 	    case SCROLL_RIGHT:
    244        1.2  thorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
    245        1.1    veego 		break;
    246        1.1    veego 	    case SCROLL_LEFT:
    247        1.2  thorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
    248        1.1    veego 		break;
    249        1.1    veego 	}
    250        1.1    veego }
    251        1.2  thorpej 
    252        1.2  thorpej 
    253        1.5  aymeric static void etbcopy(const void *src, void *dst, size_t len)
    254        1.2  thorpej {
    255        1.2  thorpej 	int i;
    256  1.10.14.1     chap 	char *cdst;
    257  1.10.14.1     chap 	const char *csrc;
    258        1.2  thorpej 
    259  1.10.14.1     chap 	cdst = (char*)dst;
    260  1.10.14.1     chap 	csrc = (const char*)src;
    261  1.10.14.1     chap 
    262  1.10.14.1     chap 	if (csrc == cdst)
    263        1.2  thorpej 		return;
    264        1.2  thorpej 
    265  1.10.14.1     chap 	if (csrc > cdst)
    266        1.2  thorpej 		for (i=len; i>0; i--) {
    267  1.10.14.1     chap 			*cdst++ = *csrc++;
    268        1.2  thorpej 		}
    269        1.2  thorpej 	else {
    270  1.10.14.1     chap 		csrc += len;
    271  1.10.14.1     chap 		cdst += len;
    272        1.5  aymeric 
    273        1.2  thorpej 		for (i=len; i>0; i--){
    274  1.10.14.1     chap 			*--cdst = *--csrc;
    275        1.2  thorpej 		}
    276        1.2  thorpej 	}
    277        1.2  thorpej }
    278        1.2  thorpej 
    279        1.1    veego #endif /* NGRFET */
    280