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