xref: /netbsd-src/sys/arch/amiga/dev/ite_et.c (revision 81b108b45f75f89f1e3ffad9fb6f074e771c0935)
1 /*	$NetBSD: ite_et.c,v 1.1 1996/05/19 21:06:00 veego 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 "grfet.h"
37 #if NGRFET > 0
38 
39 #include <sys/param.h>
40 #include <sys/conf.h>
41 #include <sys/proc.h>
42 #include <sys/device.h>
43 #include <sys/ioctl.h>
44 #include <sys/tty.h>
45 #include <sys/systm.h>
46 #include <dev/cons.h>
47 #include <machine/cpu.h>
48 #include <amiga/amiga/device.h>
49 #include <amiga/dev/grfioctl.h>
50 #include <amiga/dev/grfvar.h>
51 #include <amiga/dev/grf_etreg.h>
52 #include <amiga/dev/itevar.h>
53 
54 #ifdef TSENGCONSOLE
55 int et_console = 1;
56 #else
57 int et_console = 0;
58 #endif
59 
60 void et_init __P((struct ite_softc *ip));
61 void et_cursor __P((struct ite_softc *ip, int flag));
62 void et_deinit __P((struct ite_softc *ip));
63 void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
64 void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
65 void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
66     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 grfet_cnprobe(void)
76 {
77 	static int done;
78 	int rv;
79 
80 	if (et_console && (done == 0))
81 		rv = CN_INTERNAL;
82 	else
83 		rv = CN_DEAD;
84 
85 	done = 1;
86 	return(rv);
87 }
88 
89 
90 void
91 grfet_iteinit(gp)
92 	struct grf_softc *gp;
93 {
94 	gp->g_iteinit = et_init;
95 	gp->g_itedeinit = et_deinit;
96 	gp->g_iteclear = et_clear;
97 	gp->g_iteputc = et_putc;
98 	gp->g_itescroll = et_scroll;
99 	gp->g_itecursor = et_cursor;
100 }
101 
102 
103 void
104 et_init(ip)
105 	struct ite_softc *ip;
106 {
107 	struct grfettext_mode *md;
108 
109 	ip->priv = ip->grf->g_data;
110 	md = (struct grfettext_mode *) ip->priv;
111 
112 	ip->cols = md->cols;
113 	ip->rows = md->rows;
114 }
115 
116 
117 void
118 et_cursor(ip, flag)
119 	struct ite_softc *ip;
120 	int flag;
121 {
122 	volatile u_char *ba = ip->grf->g_regkva;
123 
124 	switch (flag) {
125  	    case DRAW_CURSOR:
126 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
127 	    case MOVE_CURSOR:
128 		flag = ip->curx + ip->cury * ip->cols;
129 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
130 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff);
131 		WCrt(ba, CTR_ID_EXT_START, (flag >> (16-2)) & 0x0c);
132 
133 		ip->cursorx = ip->curx;
134 		ip->cursory = ip->cury;
135 		break;
136 	    case ERASE_CURSOR:
137 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
138 	    case START_CURSOROPT:
139 	    case END_CURSOROPT:
140 	    default:
141 		break;
142     	}
143 }
144 
145 
146 void
147 et_deinit(ip)
148 	struct ite_softc *ip;
149 {
150 	ip->flags &= ~ITE_INITED;
151 }
152 
153 
154 void
155 et_putc(ip, c, dy, dx, mode)
156 	struct ite_softc *ip;
157 	int c;
158 	int dy;
159 	int dx;
160 	int mode;
161 {
162 	volatile unsigned char *ba = ip->grf->g_regkva;
163 	unsigned char *fb = ip->grf->g_fbkva;
164 	unsigned char attr;
165 	unsigned char *cp;
166 
167 	attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
168 	if (mode & ATTR_UL)     attr  = 0x01;	/* ???????? */
169 	if (mode & ATTR_BOLD)   attr |= 0x08;
170 	if (mode & ATTR_BLINK)  attr |= 0x80;
171 
172 	cp = fb + ((dy * ip->cols) + dx);
173 	SetTextPlane(ba,0x00);
174 	*cp = (unsigned char) c;
175 	SetTextPlane(ba,0x01);
176 	*cp = (unsigned char) attr;
177 }
178 
179 
180 void
181 et_clear(ip, sy, sx, h, w)
182 	struct ite_softc *ip;
183 	int sy;
184 	int sx;
185 	int h;
186 	int w;
187 {
188 	/* cl_clear and cl_scroll both rely on ite passing arguments
189 	 * which describe continuous regions.  For a VT200 terminal,
190 	 * this is safe behavior.
191 	 */
192 	unsigned char *src, *dst;
193 	volatile unsigned char *ba = ip->grf->g_regkva;
194 	int len;
195 
196 	dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
197 	src = dst + (ip->rows*ip->cols);
198 	len = w*h;
199 
200 	SetTextPlane(ba, 0x00);
201 	bcopy(src, dst, len);
202 	SetTextPlane(ba, 0x01);
203 	bcopy(src, dst, len);
204 }
205 
206 
207 void
208 et_scroll(ip, sy, sx, count, dir)
209 	struct ite_softc *ip;
210 	int sy;
211 	int sx;
212 	int count;
213 	int dir;
214 {
215 	unsigned char *fb;
216 	volatile unsigned char *ba = ip->grf->g_regkva;
217 
218 	fb = ip->grf->g_fbkva + sy * ip->cols;
219 	SetTextPlane(ba, 0x00);
220 
221 	switch (dir) {
222 	    case SCROLL_UP:
223 		bcopy(fb, fb - (count * ip->cols),
224 		    (ip->bottom_margin + 1 - sy) * ip->cols);
225 		break;
226 	    case SCROLL_DOWN:
227 		bcopy(fb, fb + (count * ip->cols),
228 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
229 		break;
230 	    case SCROLL_RIGHT:
231 		bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
232 		break;
233 	    case SCROLL_LEFT:
234 		bcopy(fb+sx, fb+sx-count, ip->cols - sx);
235 		break;
236 	}
237 
238 	SetTextPlane(ba, 0x01);
239 
240 	switch (dir) {
241 	    case SCROLL_UP:
242 		bcopy(fb, fb - (count * ip->cols),
243 		    (ip->bottom_margin + 1 - sy) * ip->cols);
244 		break;
245 	    case SCROLL_DOWN:
246 		bcopy(fb, fb + (count * ip->cols),
247 		    (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
248 		break;
249 	    case SCROLL_RIGHT:
250 		bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
251 		break;
252 	    case SCROLL_LEFT:
253 		bcopy(fb+sx, fb+sx-count, ip->cols - sx);
254 		break;
255 	}
256 }
257 #endif /* NGRFET */
258