xref: /netbsd-src/sys/arch/amiga/dev/ite_et.c (revision 3ba91b05954ec94aa69701aa41726344c411ba89)
1*3ba91b05She /*	$NetBSD: ite_et.c,v 1.12 2007/03/05 20:29:07 he Exp $ */
27212a830Sveego 
37212a830Sveego /*
47212a830Sveego  * Copyright (c) 1995 Ezra Story
57212a830Sveego  * Copyright (c) 1995 Kari Mettinen
67212a830Sveego  * Copyright (c) 1994 Markus Wild
77212a830Sveego  * Copyright (c) 1994 Lutz Vieweg
87212a830Sveego  * All rights reserved.
97212a830Sveego  *
107212a830Sveego  * Redistribution and use in source and binary forms, with or without
117212a830Sveego  * modification, are permitted provided that the following conditions
127212a830Sveego  * are met:
137212a830Sveego  * 1. Redistributions of source code must retain the above copyright
147212a830Sveego  *    notice, this list of conditions and the following disclaimer.
157212a830Sveego  * 2. Redistributions in binary form must reproduce the above copyright
167212a830Sveego  *    notice, this list of conditions and the following disclaimer in the
177212a830Sveego  *    documentation and/or other materials provided with the distribution.
187212a830Sveego  * 3. All advertising materials mentioning features or use of this software
197212a830Sveego  *    must display the following acknowledgement:
207212a830Sveego  *      This product includes software developed by Lutz Vieweg.
217212a830Sveego  * 4. The name of the author may not be used to endorse or promote products
227212a830Sveego  *    derived from this software without specific prior written permission
237212a830Sveego  *
247212a830Sveego  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
257212a830Sveego  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
267212a830Sveego  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
277212a830Sveego  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
287212a830Sveego  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
297212a830Sveego  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
307212a830Sveego  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
317212a830Sveego  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
327212a830Sveego  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
337212a830Sveego  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
347212a830Sveego  */
357212a830Sveego 
36d19d45b8Sis #include "opt_amigacons.h"
371ea4df81Saymeric 
381ea4df81Saymeric #include <sys/cdefs.h>
39*3ba91b05She __KERNEL_RCSID(0, "$NetBSD: ite_et.c,v 1.12 2007/03/05 20:29:07 he Exp $");
401ea4df81Saymeric 
417212a830Sveego #include "grfet.h"
427212a830Sveego #if NGRFET > 0
437212a830Sveego 
447212a830Sveego #include <sys/param.h>
457212a830Sveego #include <sys/conf.h>
467212a830Sveego #include <sys/proc.h>
477212a830Sveego #include <sys/device.h>
487212a830Sveego #include <sys/ioctl.h>
497212a830Sveego #include <sys/tty.h>
507212a830Sveego #include <sys/systm.h>
517212a830Sveego #include <dev/cons.h>
527212a830Sveego #include <machine/cpu.h>
537212a830Sveego #include <amiga/amiga/device.h>
547212a830Sveego #include <amiga/dev/grfioctl.h>
557212a830Sveego #include <amiga/dev/grfvar.h>
567212a830Sveego #include <amiga/dev/grf_etreg.h>
577212a830Sveego #include <amiga/dev/itevar.h>
587212a830Sveego 
597212a830Sveego #ifdef TSENGCONSOLE
607212a830Sveego int et_console = 1;
617212a830Sveego #else
627212a830Sveego int et_console = 0;
637212a830Sveego #endif
647212a830Sveego 
659382c873Saymeric void et_init(struct ite_softc *ip);
669382c873Saymeric void et_cursor(struct ite_softc *ip, int flag);
679382c873Saymeric void et_deinit(struct ite_softc *ip);
689382c873Saymeric void et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
699382c873Saymeric void et_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
709382c873Saymeric void et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
71*3ba91b05She static void etbcopy(const volatile void *src, volatile void *dst, size_t len);
727212a830Sveego 
737212a830Sveego 
747212a830Sveego /*
757212a830Sveego  * Called to determine ite status.  Because the connection between the
767212a830Sveego  * console & ite in this driver is rather intimate, we return CN_DEAD
777212a830Sveego  * if the cl_console is not active.
787212a830Sveego  */
797212a830Sveego int
grfet_cnprobe(void)807212a830Sveego grfet_cnprobe(void)
817212a830Sveego {
827212a830Sveego 	static int done;
837212a830Sveego 	int rv;
847212a830Sveego 
857212a830Sveego 	if (et_console && (done == 0))
867212a830Sveego 		rv = CN_INTERNAL;
877212a830Sveego 	else
887212a830Sveego 		rv = CN_DEAD;
897212a830Sveego 
907212a830Sveego 	done = 1;
917212a830Sveego 	return(rv);
927212a830Sveego }
937212a830Sveego 
947212a830Sveego 
957212a830Sveego void
grfet_iteinit(struct grf_softc * gp)969382c873Saymeric grfet_iteinit(struct grf_softc *gp)
977212a830Sveego {
987212a830Sveego 	gp->g_iteinit = et_init;
997212a830Sveego 	gp->g_itedeinit = et_deinit;
1007212a830Sveego 	gp->g_iteclear = et_clear;
1017212a830Sveego 	gp->g_iteputc = et_putc;
1027212a830Sveego 	gp->g_itescroll = et_scroll;
1037212a830Sveego 	gp->g_itecursor = et_cursor;
1047212a830Sveego }
1057212a830Sveego 
1067212a830Sveego 
1077212a830Sveego void
et_init(struct ite_softc * ip)1089382c873Saymeric et_init(struct ite_softc *ip)
1097212a830Sveego {
1107212a830Sveego 	struct grfettext_mode *md;
1117212a830Sveego 
1127212a830Sveego 	ip->priv = ip->grf->g_data;
1137212a830Sveego 	md = (struct grfettext_mode *) ip->priv;
1147212a830Sveego 
1157212a830Sveego 	ip->cols = md->cols;
1167212a830Sveego 	ip->rows = md->rows;
1177212a830Sveego }
1187212a830Sveego 
1197212a830Sveego 
1207212a830Sveego void
et_cursor(struct ite_softc * ip,int flag)1219382c873Saymeric et_cursor(struct ite_softc *ip, int flag)
1227212a830Sveego {
1237212a830Sveego 	volatile u_char *ba = ip->grf->g_regkva;
1247212a830Sveego 
1257212a830Sveego 	switch (flag) {
1267212a830Sveego  	    case DRAW_CURSOR:
1277212a830Sveego 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
1287212a830Sveego 	    case MOVE_CURSOR:
1297212a830Sveego 		flag = ip->curx + ip->cury * ip->cols;
1307212a830Sveego 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
1317212a830Sveego 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff);
132344b3cf5Sveego 		WCrt(ba, CRT_ID_EXT_START, (flag >> (16-2)) & 0x0c);
1337212a830Sveego 
1347212a830Sveego 		ip->cursorx = ip->curx;
1357212a830Sveego 		ip->cursory = ip->cury;
1367212a830Sveego 		break;
1377212a830Sveego 	    case ERASE_CURSOR:
1387212a830Sveego 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
1397212a830Sveego 	    case START_CURSOROPT:
1407212a830Sveego 	    case END_CURSOROPT:
1417212a830Sveego 	    default:
1427212a830Sveego 		break;
1437212a830Sveego     	}
1447212a830Sveego }
1457212a830Sveego 
1467212a830Sveego 
1477212a830Sveego void
et_deinit(struct ite_softc * ip)1489382c873Saymeric et_deinit(struct ite_softc *ip)
1497212a830Sveego {
1507212a830Sveego 	ip->flags &= ~ITE_INITED;
1517212a830Sveego }
1527212a830Sveego 
1537212a830Sveego 
1547212a830Sveego void
et_putc(struct ite_softc * ip,int c,int dy,int dx,int mode)1559382c873Saymeric et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
1567212a830Sveego {
1577212a830Sveego 	volatile unsigned char *ba = ip->grf->g_regkva;
158*3ba91b05She 	volatile unsigned char *fb = ip->grf->g_fbkva;
1597212a830Sveego 	unsigned char attr;
16063672cdeSis 	volatile unsigned char *cp;
1617212a830Sveego 
1620297f3aeSis 	if (ip->flags & ITE_INGRF)
1630297f3aeSis 		return;
1640297f3aeSis 
1657212a830Sveego 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
1667212a830Sveego 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
1677212a830Sveego 	if (mode & ATTR_BOLD)   attr |= 0x08;
1687212a830Sveego 	if (mode & ATTR_BLINK)  attr |= 0x80;
1697212a830Sveego 
1707212a830Sveego 	cp = fb + ((dy * ip->cols) + dx);
1717212a830Sveego 	SetTextPlane(ba,0x00);
1727212a830Sveego 	*cp = (unsigned char) c;
1737212a830Sveego 	SetTextPlane(ba,0x01);
1747212a830Sveego 	*cp = (unsigned char) attr;
1757212a830Sveego }
1767212a830Sveego 
1777212a830Sveego 
1787212a830Sveego void
et_clear(struct ite_softc * ip,int sy,int sx,int h,int w)1799382c873Saymeric et_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
1807212a830Sveego {
1817212a830Sveego 	/* cl_clear and cl_scroll both rely on ite passing arguments
1827212a830Sveego 	 * which describe continuous regions.  For a VT200 terminal,
1837212a830Sveego 	 * this is safe behavior.
1847212a830Sveego 	 */
185*3ba91b05She 	volatile unsigned char *src, *dst;
1867212a830Sveego 	volatile unsigned char *ba = ip->grf->g_regkva;
1877212a830Sveego 	int len;
1887212a830Sveego 
1890297f3aeSis 	if (ip->flags & ITE_INGRF)
1900297f3aeSis 		return;
1910297f3aeSis 
192*3ba91b05She 	dst = (volatile unsigned char*)ip->grf->g_fbkva + (sy * ip->cols) + sx;
1937212a830Sveego 	src = dst + (ip->rows*ip->cols);
1947212a830Sveego 	len = w*h;
1957212a830Sveego 
1967212a830Sveego 	SetTextPlane(ba, 0x00);
197d498950fSthorpej 	etbcopy(src, dst, len);
1987212a830Sveego 	SetTextPlane(ba, 0x01);
199d498950fSthorpej 	etbcopy(src, dst, len);
2007212a830Sveego }
2017212a830Sveego 
2027212a830Sveego 
2037212a830Sveego void
et_scroll(struct ite_softc * ip,int sy,int sx,int count,int dir)2049382c873Saymeric et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
2057212a830Sveego {
206*3ba91b05She 	volatile unsigned char *fb;
2077212a830Sveego 	volatile unsigned char *ba = ip->grf->g_regkva;
2087212a830Sveego 
2090297f3aeSis 	if (ip->flags & ITE_INGRF)
2100297f3aeSis 		return;
2110297f3aeSis 
212*3ba91b05She 	fb = (volatile unsigned char*)ip->grf->g_fbkva + sy * ip->cols;
2137212a830Sveego 	SetTextPlane(ba, 0x00);
2147212a830Sveego 
2157212a830Sveego 	switch (dir) {
2167212a830Sveego 	    case SCROLL_UP:
217d498950fSthorpej 		etbcopy(fb, fb - (count * ip->cols),
2187212a830Sveego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
2197212a830Sveego 		break;
2207212a830Sveego 	    case SCROLL_DOWN:
221d498950fSthorpej 		etbcopy(fb, fb + (count * ip->cols),
2227212a830Sveego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
2237212a830Sveego 		break;
2247212a830Sveego 	    case SCROLL_RIGHT:
225d498950fSthorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
2267212a830Sveego 		break;
2277212a830Sveego 	    case SCROLL_LEFT:
228d498950fSthorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
2297212a830Sveego 		break;
2307212a830Sveego 	}
2317212a830Sveego 
2327212a830Sveego 	SetTextPlane(ba, 0x01);
2337212a830Sveego 
2347212a830Sveego 	switch (dir) {
2357212a830Sveego 	    case SCROLL_UP:
236d498950fSthorpej 		etbcopy(fb, fb - (count * ip->cols),
2377212a830Sveego 		    (ip->bottom_margin + 1 - sy) * ip->cols);
2387212a830Sveego 		break;
2397212a830Sveego 	    case SCROLL_DOWN:
240d498950fSthorpej 		etbcopy(fb, fb + (count * ip->cols),
2417212a830Sveego 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
2427212a830Sveego 		break;
2437212a830Sveego 	    case SCROLL_RIGHT:
244d498950fSthorpej 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
2457212a830Sveego 		break;
2467212a830Sveego 	    case SCROLL_LEFT:
247d498950fSthorpej 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
2487212a830Sveego 		break;
2497212a830Sveego 	}
2507212a830Sveego }
251d498950fSthorpej 
252d498950fSthorpej 
etbcopy(const volatile void * src,volatile void * dst,size_t len)253*3ba91b05She static void etbcopy(const volatile void *src, volatile void *dst, size_t len)
254d498950fSthorpej {
255d498950fSthorpej 	int i;
256*3ba91b05She 	volatile char *cdst;
257*3ba91b05She 	volatile const char *csrc;
258d498950fSthorpej 
259*3ba91b05She 	cdst = (volatile char*)dst;
260*3ba91b05She 	csrc = (volatile const char*)src;
2619bc6aa01She 
2629bc6aa01She 	if (csrc == cdst)
263d498950fSthorpej 		return;
264d498950fSthorpej 
2659bc6aa01She 	if (csrc > cdst)
266d498950fSthorpej 		for (i=len; i>0; i--) {
2679bc6aa01She 			*cdst++ = *csrc++;
268d498950fSthorpej 		}
269d498950fSthorpej 	else {
2709bc6aa01She 		csrc += len;
2719bc6aa01She 		cdst += len;
272d498950fSthorpej 
273d498950fSthorpej 		for (i=len; i>0; i--){
2749bc6aa01She 			*--cdst = *--csrc;
275d498950fSthorpej 		}
276d498950fSthorpej 	}
277d498950fSthorpej }
278d498950fSthorpej 
2797212a830Sveego #endif /* NGRFET */
280