xref: /netbsd/sys/arch/amiga/dev/ite_et.c (revision bf9ec67e)
1 /*	$NetBSD: ite_et.c,v 1.6 2002/01/28 09:57:00 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_et.c,v 1.6 2002/01/28 09:57:00 aymeric Exp $");
40 
41 #include "grfet.h"
42 #if NGRFET > 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_etreg.h>
57 #include <amiga/dev/itevar.h>
58 
59 #ifdef TSENGCONSOLE
60 int et_console = 1;
61 #else
62 int et_console = 0;
63 #endif
64 
65 void et_init(struct ite_softc *ip);
66 void et_cursor(struct ite_softc *ip, int flag);
67 void et_deinit(struct ite_softc *ip);
68 void et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
69 void et_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
70 void et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
71 static void etbcopy(const void *src, void *dst, size_t len);
72 
73 
74 /*
75  * Called to determine ite status.  Because the connection between the
76  * console & ite in this driver is rather intimate, we return CN_DEAD
77  * if the cl_console is not active.
78  */
79 int
80 grfet_cnprobe(void)
81 {
82 	static int done;
83 	int rv;
84 
85 	if (et_console && (done == 0))
86 		rv = CN_INTERNAL;
87 	else
88 		rv = CN_DEAD;
89 
90 	done = 1;
91 	return(rv);
92 }
93 
94 
95 void
96 grfet_iteinit(struct grf_softc *gp)
97 {
98 	gp->g_iteinit = et_init;
99 	gp->g_itedeinit = et_deinit;
100 	gp->g_iteclear = et_clear;
101 	gp->g_iteputc = et_putc;
102 	gp->g_itescroll = et_scroll;
103 	gp->g_itecursor = et_cursor;
104 }
105 
106 
107 void
108 et_init(struct ite_softc *ip)
109 {
110 	struct grfettext_mode *md;
111 
112 	ip->priv = ip->grf->g_data;
113 	md = (struct grfettext_mode *) ip->priv;
114 
115 	ip->cols = md->cols;
116 	ip->rows = md->rows;
117 }
118 
119 
120 void
121 et_cursor(struct ite_softc *ip, int flag)
122 {
123 	volatile u_char *ba = ip->grf->g_regkva;
124 
125 	switch (flag) {
126  	    case DRAW_CURSOR:
127 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
128 	    case MOVE_CURSOR:
129 		flag = ip->curx + ip->cury * ip->cols;
130 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
131 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff);
132 		WCrt(ba, CRT_ID_EXT_START, (flag >> (16-2)) & 0x0c);
133 
134 		ip->cursorx = ip->curx;
135 		ip->cursory = ip->cury;
136 		break;
137 	    case ERASE_CURSOR:
138 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
139 	    case START_CURSOROPT:
140 	    case END_CURSOROPT:
141 	    default:
142 		break;
143     	}
144 }
145 
146 
147 void
148 et_deinit(struct ite_softc *ip)
149 {
150 	ip->flags &= ~ITE_INITED;
151 }
152 
153 
154 void
155 et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
156 {
157 	volatile unsigned char *ba = ip->grf->g_regkva;
158 	unsigned char *fb = ip->grf->g_fbkva;
159 	unsigned char attr;
160 	unsigned char *cp;
161 
162 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
163 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
164 	if (mode & ATTR_BOLD)   attr |= 0x08;
165 	if (mode & ATTR_BLINK)  attr |= 0x80;
166 
167 	cp = fb + ((dy * ip->cols) + dx);
168 	SetTextPlane(ba,0x00);
169 	*cp = (unsigned char) c;
170 	SetTextPlane(ba,0x01);
171 	*cp = (unsigned char) attr;
172 }
173 
174 
175 void
176 et_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
177 {
178 	/* cl_clear and cl_scroll both rely on ite passing arguments
179 	 * which describe continuous regions.  For a VT200 terminal,
180 	 * this is safe behavior.
181 	 */
182 	unsigned char *src, *dst;
183 	volatile unsigned char *ba = ip->grf->g_regkva;
184 	int len;
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 	etbcopy(src, dst, len);
192 	SetTextPlane(ba, 0x01);
193 	etbcopy(src, dst, len);
194 }
195 
196 
197 void
198 et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
199 {
200 	unsigned char *fb;
201 	volatile unsigned char *ba = ip->grf->g_regkva;
202 
203 	fb = ip->grf->g_fbkva + sy * ip->cols;
204 	SetTextPlane(ba, 0x00);
205 
206 	switch (dir) {
207 	    case SCROLL_UP:
208 		etbcopy(fb, fb - (count * ip->cols),
209 		    (ip->bottom_margin + 1 - sy) * ip->cols);
210 		break;
211 	    case SCROLL_DOWN:
212 		etbcopy(fb, fb + (count * ip->cols),
213 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
214 		break;
215 	    case SCROLL_RIGHT:
216 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
217 		break;
218 	    case SCROLL_LEFT:
219 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
220 		break;
221 	}
222 
223 	SetTextPlane(ba, 0x01);
224 
225 	switch (dir) {
226 	    case SCROLL_UP:
227 		etbcopy(fb, fb - (count * ip->cols),
228 		    (ip->bottom_margin + 1 - sy) * ip->cols);
229 		break;
230 	    case SCROLL_DOWN:
231 		etbcopy(fb, fb + (count * ip->cols),
232 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
233 		break;
234 	    case SCROLL_RIGHT:
235 		etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
236 		break;
237 	    case SCROLL_LEFT:
238 		etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
239 		break;
240 	}
241 }
242 
243 
244 static void etbcopy(const void *src, void *dst, size_t len)
245 {
246 	int i;
247 
248 	if (src == dst)
249 		return;
250 
251 	if (src > dst)
252 		for (i=len; i>0; i--) {
253 			*((char *)dst)++ = *((char *)src)++;
254 		}
255 	else {
256 		((char *)src) += len;
257 		((char *)dst) += len;
258 
259 		for (i=len; i>0; i--){
260 			*--((char *)dst) = *--((char *)src);
261 		}
262 	}
263 }
264 
265 #endif /* NGRFET */
266