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