xref: /netbsd/sys/arch/amiga/dev/ite_cl.c (revision bf9ec67e)
1 /*	$NetBSD: ite_cl.c,v 1.6 2002/01/28 09:56:59 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 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: ite_cl.c,v 1.6 2002/01/28 09:56:59 aymeric Exp $");
40 
41 #include "grfcl.h"
42 #if NGRFCL > 0
43 
44 #include <sys/param.h>
45 #include <sys/conf.h>
46 #include <sys/proc.h>
47 #include <sys/device.h>
48 #include <sys/ioctl.h>
49 #include <sys/tty.h>
50 #include <sys/systm.h>
51 #include <dev/cons.h>
52 #include <machine/cpu.h>
53 #include <amiga/amiga/device.h>
54 #include <amiga/dev/grfioctl.h>
55 #include <amiga/dev/grfvar.h>
56 #include <amiga/dev/grf_clreg.h>
57 #include <amiga/dev/itevar.h>
58 
59 #ifdef CL5426CONSOLE
60 int cl_console = 1;
61 #else
62 int cl_console = 0;
63 #endif
64 
65 void cl_init(struct ite_softc *ip);
66 void cl_cursor(struct ite_softc *ip, int flag);
67 void cl_deinit(struct ite_softc *ip);
68 void cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
69 void cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
70 void cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
71 
72 
73 /*
74  * Called to determine ite status.  Because the connection between the
75  * console & ite in this driver is rather intimate, we return CN_DEAD
76  * if the cl_console is not active.
77  */
78 int
79 grfcl_cnprobe(void)
80 {
81 	static int done;
82 	int rv;
83 
84 	if (cl_console && (done == 0))
85 		rv = CN_INTERNAL;
86 	else
87 		rv = CN_DEAD;
88 
89 	done = 1;
90 	return(rv);
91 }
92 
93 void
94 grfcl_iteinit(struct grf_softc *gp)
95 {
96 	gp->g_iteinit = cl_init;
97 	gp->g_itedeinit = cl_deinit;
98 	gp->g_iteclear = cl_clear;
99 	gp->g_iteputc = cl_putc;
100 	gp->g_itescroll = cl_scroll;
101 	gp->g_itecursor = cl_cursor;
102 }
103 
104 void
105 cl_init(struct ite_softc *ip)
106 {
107 	struct grfcltext_mode *md;
108 
109 	ip->priv = ip->grf->g_data;
110 	md = (struct grfcltext_mode *) ip->priv;
111 
112 	ip->cols = md->cols;
113 	ip->rows = md->rows;
114 }
115 
116 
117 void
118 cl_cursor(struct ite_softc *ip, int flag)
119 {
120 	volatile u_char *ba = ip->grf->g_regkva;
121 
122     	switch (flag) {
123     	case DRAW_CURSOR:
124     	    	/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
125     	case MOVE_CURSOR:
126     	    	flag = ip->curx + ip->cury * ip->cols;
127     	    	WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
128     	    	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
129 		ip->cursorx = ip->curx;
130 		ip->cursory = ip->cury;
131     	    	break;
132     	case ERASE_CURSOR:
133     	    	/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
134     	case START_CURSOROPT:
135     	case END_CURSOROPT:
136     	default:
137     	    	break;
138     	}
139 }
140 
141 
142 void
143 cl_deinit(struct ite_softc *ip)
144 {
145 	ip->flags &= ~ITE_INITED;
146 }
147 
148 
149 void
150 cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
151 {
152 	volatile unsigned char *ba = ip->grf->g_regkva;
153 	unsigned char *fb = ip->grf->g_fbkva;
154 	unsigned char attr;
155 	unsigned char *cp;
156 
157 	if (ip->flags & ITE_INGRF)
158 		return;
159 
160 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
161 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
162 	if (mode & ATTR_BOLD)   attr |= 0x08;
163 	if (mode & ATTR_BLINK)  attr |= 0x80;
164 
165 	cp = fb + ((dy * ip->cols) + dx);
166 	SetTextPlane(ba,0x00);
167 	*cp = (unsigned char) c;
168 	SetTextPlane(ba,0x01);
169 	*cp = (unsigned char) attr;
170 }
171 
172 void
173 cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
174 {
175     	/* cl_clear and cl_scroll both rely on ite passing arguments
176          * which describe continuous regions.  For a VT200 terminal,
177          * this is safe behavior.
178          */
179     	unsigned char *src, *dst;
180     	volatile unsigned char *ba = ip->grf->g_regkva;
181     	int len;
182 
183 	if (ip->flags & ITE_INGRF)
184 		return;
185 
186     	dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
187     	src = dst + (ip->rows*ip->cols);
188     	len = w*h;
189 
190     	SetTextPlane(ba, 0x00);
191     	bcopy(src, dst, len);
192     	SetTextPlane(ba, 0x01);
193     	bcopy(src, dst, len);
194 }
195 
196 void
197 cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
198 {
199     	unsigned char *fb;
200     	volatile unsigned char *ba = ip->grf->g_regkva;
201 
202 	if (ip->flags & ITE_INGRF)
203 		return;
204 
205     	fb = ip->grf->g_fbkva + sy * ip->cols;
206     	SetTextPlane(ba, 0x00);
207 
208     	switch (dir) {
209     	case SCROLL_UP:
210     	    	bcopy(fb, fb - (count * ip->cols),
211     	    	    (ip->bottom_margin + 1 - sy) * ip->cols);
212     	    	break;
213     	case SCROLL_DOWN:
214     	    	bcopy(fb, fb + (count * ip->cols),
215     	    	    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
216     	    	break;
217     	case SCROLL_RIGHT:
218     	    	bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
219     	    	break;
220     	case SCROLL_LEFT:
221     	    	bcopy(fb+sx, fb+sx-count, ip->cols - sx);
222     	    	break;
223     	}
224 
225     	SetTextPlane(ba, 0x01);
226 
227     	switch (dir) {
228     	case SCROLL_UP:
229     	    	bcopy(fb, fb - (count * ip->cols),
230     	    	    (ip->bottom_margin + 1 - sy) * ip->cols);
231     	    	break;
232     	case SCROLL_DOWN:
233     	    	bcopy(fb, fb + (count * ip->cols),
234     	    	    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
235     	    	break;
236     	case SCROLL_RIGHT:
237     	    	bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
238     	    	break;
239     	case SCROLL_LEFT:
240     	    	bcopy(fb+sx, fb+sx-count, ip->cols - sx);
241     	    	break;
242     	}
243 }
244 #endif /* NGRFCL */
245