ite_cv3d.c revision 1.3 1 /* $NetBSD: ite_cv3d.c,v 1.3 1999/03/25 23:20:00 is Exp $ */
2
3 /*
4 * Copyright (c) 1995 Michael Teske
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christian E. Hopps,
18 * Ezra Story, Kari Mettinen, Markus Wild, Lutz Vieweg
19 * and Michael Teske.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /*
36 * This code is based on ite_cl.c and ite_rh.c by
37 * Ezra Story, Kari Mettinen, Markus Wild, Lutz Vieweg.
38 */
39
40 #include "opt_amigacons.h"
41 #include "grfcv3d.h"
42 #if NGRFCV3D > 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 <sys/queue.h>
52 #include <sys/termios.h>
53 #include <sys/malloc.h>
54 #include <dev/cons.h>
55 #include <machine/cpu.h>
56 #include <amiga/dev/itevar.h>
57 #include <amiga/dev/iteioctl.h>
58 #include <amiga/amiga/device.h>
59 #include <amiga/dev/grfioctl.h>
60 #include <amiga/dev/grfvar.h>
61 #include <amiga/dev/grf_cv3dreg.h>
62
63 void cv3d_ite_init __P((struct ite_softc *));
64 void cv3d_ite_deinit __P((struct ite_softc *));
65 static void cv3d_cursor __P((struct ite_softc *, int));
66 static void cv3d_putc __P((struct ite_softc *, int, int, int, int));
67 static void cv3d_clear __P((struct ite_softc *, int, int, int, int));
68 static void cv3d_scroll __P((struct ite_softc *, int, int, int, int));
69
70 /*
71 * called from grf_cv3d to return console priority
72 */
73 int
74 grfcv3d_cnprobe()
75 {
76 static int done;
77 int rv;
78
79 if (done == 0)
80 #ifdef CV3DCONSOLE
81 rv = CN_INTERNAL;
82 #else
83 rv = CN_DEAD;
84 #endif
85 else
86 #ifdef CV3DCONSOLE
87 rv = CN_NORMAL;
88 #else
89 rv = CN_DEAD;
90 #endif
91 done = 1;
92 return(rv);
93 }
94
95
96 /*
97 * called from grf_cv3d to init ite portion of
98 * grf_softc struct
99 */
100 void
101 grfcv3d_iteinit(gp)
102 struct grf_softc *gp;
103 {
104 gp->g_itecursor = cv3d_cursor;
105 gp->g_iteputc = cv3d_putc;
106 gp->g_iteclear = cv3d_clear;
107 gp->g_itescroll = cv3d_scroll;
108 gp->g_iteinit = cv3d_ite_init;
109 gp->g_itedeinit = cv3d_ite_deinit;
110 }
111
112
113 void
114 cv3d_ite_deinit(ip)
115 struct ite_softc *ip;
116 {
117 ip->flags &= ~ITE_INITED;
118 }
119
120
121 static unsigned short cv3d_rowc[MAXCOLS*(MAXROWS+1)];
122
123 /*
124 * Console buffer to avoid the slow reading from gfx mem.
125 */
126
127 static unsigned short *console_buffer;
128
129 void
130 cv3d_ite_init(ip)
131 register struct ite_softc *ip;
132 {
133 struct grfcv3dtext_mode *md;
134 int i;
135 static char first = 1;
136 volatile unsigned short *fb = (volatile unsigned short *)ip->grf->g_fbkva;
137 unsigned short *buffer;
138
139
140 ip->priv = ip->grf->g_data;
141 md = (struct grfcv3dtext_mode *) ip->grf->g_data;
142
143 ip->cols = md->cols;
144 ip->rows = md->rows;
145
146 /* alloc buffers */
147
148 #if 0 /* XXX malloc seems not to work in early init :( */
149 if (cv3d_rowc)
150 free(cv3d_rowc, M_DEVBUF);
151
152 /* alloc all in one */
153 cv3d_rowc = malloc(sizeof(short) * (ip->rows + 1) * (ip->cols + 2),
154 M_DEVBUF, M_WAITOK);
155 if (!cv3d_rowc)
156 panic("No buffers for ite_cv3d!");
157 #endif
158
159 console_buffer = cv3d_rowc + ip->rows + 1;
160
161
162 for (i = 0; i < ip->rows; i++)
163 cv3d_rowc[i] = i * ip->cols;
164
165 if (first) {
166 for (i = 0; i < ip->rows * ip->cols; i++)
167 console_buffer[i] = 0x2007;
168 first = 0;
169 } else { /* restore console */
170 buffer = console_buffer;
171 for (i = 0; i < ip->rows * ip->cols; i++) {
172 *fb++ = *buffer++;
173 *fb++;
174 }
175 }
176 }
177
178
179 void
180 cv3d_cursor(ip, flag)
181 struct ite_softc *ip;
182 int flag;
183 {
184 volatile caddr_t ba = ip->grf->g_regkva;
185
186 switch (flag) {
187 case DRAW_CURSOR:
188 /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
189 case MOVE_CURSOR:
190 flag = ip->curx + ip->cury * ip->cols;
191 WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
192 WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
193 ip->cursorx = ip->curx;
194 ip->cursory = ip->cury;
195 break;
196 case ERASE_CURSOR:
197 /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
198 case START_CURSOROPT:
199 case END_CURSOROPT:
200 default:
201 break;
202 }
203 }
204
205
206 void
207 cv3d_putc(ip, c, dy, dx, mode)
208 struct ite_softc *ip;
209 int c;
210 int dy;
211 int dx;
212 int mode;
213 {
214 caddr_t fb = ip->grf->g_fbkva;
215 unsigned char attr;
216 unsigned char *cp;
217
218 attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
219 if (mode & ATTR_UL) attr = 0x01;
220 if (mode & ATTR_BOLD) attr |= 0x08;
221 if (mode & ATTR_BLINK) attr |= 0x80;
222
223 cp = fb + ((cv3d_rowc[dy] + dx) << 2); /* *4 */
224 *cp++ = (unsigned char) c;
225 *cp = (unsigned char) attr;
226
227 cp = (unsigned char *) &console_buffer[cv3d_rowc[dy]+dx];
228 *cp++ = (unsigned char) c;
229 *cp = (unsigned char) attr;
230 }
231
232
233 void
234 cv3d_clear(ip, sy, sx, h, w)
235 struct ite_softc *ip;
236 int sy;
237 int sx;
238 int h;
239 int w;
240 {
241 /* cv3d_clear and cv3d_scroll both rely on ite passing arguments
242 * which describe continuous regions. For a VT200 terminal,
243 * this is safe behavior.
244 */
245 unsigned short *dst;
246 int len;
247
248 dst = (unsigned short *) (ip->grf->g_fbkva + (((sy * ip->cols) + sx) << 2));
249
250 for (len = w * h; len > 0 ; len--) {
251 *dst = 0x2007;
252 dst +=2;
253 }
254
255 dst = &console_buffer[(sy * ip->cols) + sx];
256 for (len = w * h; len > 0 ; len--) {
257 *dst++ = 0x2007;
258 }
259 }
260
261 void
262 cv3d_scroll(ip, sy, sx, count, dir)
263 struct ite_softc *ip;
264 int sy;
265 int sx;
266 int count;
267 int dir;
268 {
269 unsigned short *src, *dst, *dst2;
270 int i;
271 int len;
272
273 src = (unsigned short *)(ip->grf->g_fbkva + (cv3d_rowc[sy] << 2));
274
275 switch (dir) {
276 case SCROLL_UP:
277 dst = src - ((cv3d_rowc[count])<<1);
278
279 len = cv3d_rowc[(ip->bottom_margin + 1 - sy)];
280 src = &console_buffer[cv3d_rowc[sy]];
281
282 if (count > sy) { /* boundary checks */
283 dst2 = console_buffer;
284 dst = (unsigned short *)(ip->grf->g_fbkva);
285 len -= cv3d_rowc[(count - sy)];
286 src += cv3d_rowc[(count - sy)];
287 } else
288 dst2 = &console_buffer[cv3d_rowc[(sy-count)]];
289
290 bcopy (src, dst2, len << 1);
291
292 for (i = 0; i < len; i++) {
293 *dst++ = *dst2++;
294 dst++;
295 }
296 break;
297 case SCROLL_DOWN:
298 dst = src + ((cv3d_rowc[count]) << 1);
299
300 len = cv3d_rowc[(ip->bottom_margin + 1 - (sy + count))];
301 src = &console_buffer[cv3d_rowc[sy]];
302 dst2 = &console_buffer[cv3d_rowc[(sy + count)]];
303
304 if (len < 0)
305 return; /* do some boundary check */
306
307 bcopy (src, dst2, len << 1);
308
309 for (i = 0; i < len; i++) {
310 *dst++ = *dst2++;
311 dst++;
312 }
313 break;
314 case SCROLL_RIGHT:
315 dst = src + ((sx+count)<<1);
316 src = &console_buffer[cv3d_rowc[sy] + sx];
317 len = ip->cols - (sx + count);
318 dst2 = &console_buffer[cv3d_rowc[sy] + sx + count];
319 bcopy (src, dst2, len << 1);
320
321 for (i = 0; i < len; i++) {
322 *dst++ = *dst2++;
323 dst++;
324 }
325 break;
326 case SCROLL_LEFT:
327 dst = src + ((sx - count)<<1);
328 src = &console_buffer[cv3d_rowc[sy] + sx];
329 len = ip->cols - sx;
330 dst2 = &console_buffer[cv3d_rowc[sy] + sx - count];
331 bcopy (src, dst2, len << 1);
332
333 for (i = 0; i < len; i++) {
334 *dst++ = *dst2++;
335 dst++;
336 }
337 }
338 }
339
340 #endif /* NGRFCV3D */
341