ite_cv3d.c revision 1.4 1 1.4 aymeric /* $NetBSD: ite_cv3d.c,v 1.4 2002/01/26 13:40:57 aymeric 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.4 aymeric #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.4 aymeric void cv3d_ite_init(struct ite_softc *);
64 1.4 aymeric void cv3d_ite_deinit(struct ite_softc *);
65 1.4 aymeric static void cv3d_cursor(struct ite_softc *, int);
66 1.4 aymeric static void cv3d_putc(struct ite_softc *, int, int, int, int);
67 1.4 aymeric static void cv3d_clear(struct ite_softc *, int, int, int, int);
68 1.4 aymeric static void cv3d_scroll(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.4 aymeric grfcv3d_cnprobe(void)
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.4 aymeric grfcv3d_iteinit(struct grf_softc *gp)
102 1.1 veego {
103 1.1 veego gp->g_itecursor = cv3d_cursor;
104 1.1 veego gp->g_iteputc = cv3d_putc;
105 1.1 veego gp->g_iteclear = cv3d_clear;
106 1.1 veego gp->g_itescroll = cv3d_scroll;
107 1.1 veego gp->g_iteinit = cv3d_ite_init;
108 1.1 veego gp->g_itedeinit = cv3d_ite_deinit;
109 1.1 veego }
110 1.1 veego
111 1.1 veego
112 1.1 veego void
113 1.4 aymeric cv3d_ite_deinit(struct ite_softc *ip)
114 1.1 veego {
115 1.1 veego ip->flags &= ~ITE_INITED;
116 1.1 veego }
117 1.1 veego
118 1.1 veego
119 1.1 veego static unsigned short cv3d_rowc[MAXCOLS*(MAXROWS+1)];
120 1.1 veego
121 1.1 veego /*
122 1.1 veego * Console buffer to avoid the slow reading from gfx mem.
123 1.1 veego */
124 1.1 veego
125 1.1 veego static unsigned short *console_buffer;
126 1.1 veego
127 1.1 veego void
128 1.4 aymeric cv3d_ite_init(register struct ite_softc *ip)
129 1.1 veego {
130 1.1 veego struct grfcv3dtext_mode *md;
131 1.1 veego int i;
132 1.1 veego static char first = 1;
133 1.1 veego volatile unsigned short *fb = (volatile unsigned short *)ip->grf->g_fbkva;
134 1.1 veego unsigned short *buffer;
135 1.1 veego
136 1.1 veego
137 1.1 veego ip->priv = ip->grf->g_data;
138 1.1 veego md = (struct grfcv3dtext_mode *) ip->grf->g_data;
139 1.1 veego
140 1.1 veego ip->cols = md->cols;
141 1.1 veego ip->rows = md->rows;
142 1.1 veego
143 1.1 veego /* alloc buffers */
144 1.1 veego
145 1.1 veego #if 0 /* XXX malloc seems not to work in early init :( */
146 1.1 veego if (cv3d_rowc)
147 1.1 veego free(cv3d_rowc, M_DEVBUF);
148 1.4 aymeric
149 1.1 veego /* alloc all in one */
150 1.1 veego cv3d_rowc = malloc(sizeof(short) * (ip->rows + 1) * (ip->cols + 2),
151 1.1 veego M_DEVBUF, M_WAITOK);
152 1.1 veego if (!cv3d_rowc)
153 1.1 veego panic("No buffers for ite_cv3d!");
154 1.1 veego #endif
155 1.4 aymeric
156 1.1 veego console_buffer = cv3d_rowc + ip->rows + 1;
157 1.1 veego
158 1.1 veego
159 1.1 veego for (i = 0; i < ip->rows; i++)
160 1.1 veego cv3d_rowc[i] = i * ip->cols;
161 1.1 veego
162 1.1 veego if (first) {
163 1.1 veego for (i = 0; i < ip->rows * ip->cols; i++)
164 1.1 veego console_buffer[i] = 0x2007;
165 1.1 veego first = 0;
166 1.1 veego } else { /* restore console */
167 1.1 veego buffer = console_buffer;
168 1.1 veego for (i = 0; i < ip->rows * ip->cols; i++) {
169 1.1 veego *fb++ = *buffer++;
170 1.1 veego *fb++;
171 1.1 veego }
172 1.1 veego }
173 1.1 veego }
174 1.1 veego
175 1.1 veego
176 1.1 veego void
177 1.4 aymeric cv3d_cursor(struct ite_softc *ip, int flag)
178 1.1 veego {
179 1.1 veego volatile caddr_t ba = ip->grf->g_regkva;
180 1.1 veego
181 1.1 veego switch (flag) {
182 1.1 veego case DRAW_CURSOR:
183 1.1 veego /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
184 1.1 veego case MOVE_CURSOR:
185 1.1 veego flag = ip->curx + ip->cury * ip->cols;
186 1.1 veego WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
187 1.1 veego WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
188 1.1 veego ip->cursorx = ip->curx;
189 1.1 veego ip->cursory = ip->cury;
190 1.1 veego break;
191 1.1 veego case ERASE_CURSOR:
192 1.1 veego /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
193 1.1 veego case START_CURSOROPT:
194 1.1 veego case END_CURSOROPT:
195 1.1 veego default:
196 1.1 veego break;
197 1.1 veego }
198 1.1 veego }
199 1.1 veego
200 1.1 veego
201 1.1 veego void
202 1.4 aymeric cv3d_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
203 1.1 veego {
204 1.1 veego caddr_t fb = ip->grf->g_fbkva;
205 1.1 veego unsigned char attr;
206 1.1 veego unsigned char *cp;
207 1.1 veego
208 1.1 veego attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
209 1.1 veego if (mode & ATTR_UL) attr = 0x01;
210 1.1 veego if (mode & ATTR_BOLD) attr |= 0x08;
211 1.1 veego if (mode & ATTR_BLINK) attr |= 0x80;
212 1.1 veego
213 1.1 veego cp = fb + ((cv3d_rowc[dy] + dx) << 2); /* *4 */
214 1.1 veego *cp++ = (unsigned char) c;
215 1.1 veego *cp = (unsigned char) attr;
216 1.1 veego
217 1.1 veego cp = (unsigned char *) &console_buffer[cv3d_rowc[dy]+dx];
218 1.1 veego *cp++ = (unsigned char) c;
219 1.1 veego *cp = (unsigned char) attr;
220 1.1 veego }
221 1.1 veego
222 1.1 veego
223 1.1 veego void
224 1.4 aymeric cv3d_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
225 1.1 veego {
226 1.1 veego /* cv3d_clear and cv3d_scroll both rely on ite passing arguments
227 1.1 veego * which describe continuous regions. For a VT200 terminal,
228 1.1 veego * this is safe behavior.
229 1.1 veego */
230 1.1 veego unsigned short *dst;
231 1.1 veego int len;
232 1.1 veego
233 1.1 veego dst = (unsigned short *) (ip->grf->g_fbkva + (((sy * ip->cols) + sx) << 2));
234 1.1 veego
235 1.1 veego for (len = w * h; len > 0 ; len--) {
236 1.1 veego *dst = 0x2007;
237 1.1 veego dst +=2;
238 1.1 veego }
239 1.1 veego
240 1.1 veego dst = &console_buffer[(sy * ip->cols) + sx];
241 1.1 veego for (len = w * h; len > 0 ; len--) {
242 1.1 veego *dst++ = 0x2007;
243 1.1 veego }
244 1.1 veego }
245 1.1 veego
246 1.1 veego void
247 1.4 aymeric cv3d_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
248 1.1 veego {
249 1.1 veego unsigned short *src, *dst, *dst2;
250 1.1 veego int i;
251 1.1 veego int len;
252 1.1 veego
253 1.1 veego src = (unsigned short *)(ip->grf->g_fbkva + (cv3d_rowc[sy] << 2));
254 1.1 veego
255 1.1 veego switch (dir) {
256 1.1 veego case SCROLL_UP:
257 1.1 veego dst = src - ((cv3d_rowc[count])<<1);
258 1.1 veego
259 1.1 veego len = cv3d_rowc[(ip->bottom_margin + 1 - sy)];
260 1.1 veego src = &console_buffer[cv3d_rowc[sy]];
261 1.1 veego
262 1.1 veego if (count > sy) { /* boundary checks */
263 1.1 veego dst2 = console_buffer;
264 1.1 veego dst = (unsigned short *)(ip->grf->g_fbkva);
265 1.1 veego len -= cv3d_rowc[(count - sy)];
266 1.1 veego src += cv3d_rowc[(count - sy)];
267 1.1 veego } else
268 1.1 veego dst2 = &console_buffer[cv3d_rowc[(sy-count)]];
269 1.1 veego
270 1.1 veego bcopy (src, dst2, len << 1);
271 1.1 veego
272 1.1 veego for (i = 0; i < len; i++) {
273 1.1 veego *dst++ = *dst2++;
274 1.1 veego dst++;
275 1.1 veego }
276 1.1 veego break;
277 1.1 veego case SCROLL_DOWN:
278 1.1 veego dst = src + ((cv3d_rowc[count]) << 1);
279 1.1 veego
280 1.1 veego len = cv3d_rowc[(ip->bottom_margin + 1 - (sy + count))];
281 1.1 veego src = &console_buffer[cv3d_rowc[sy]];
282 1.1 veego dst2 = &console_buffer[cv3d_rowc[(sy + count)]];
283 1.1 veego
284 1.1 veego if (len < 0)
285 1.1 veego return; /* do some boundary check */
286 1.1 veego
287 1.1 veego bcopy (src, dst2, len << 1);
288 1.1 veego
289 1.1 veego for (i = 0; i < len; i++) {
290 1.1 veego *dst++ = *dst2++;
291 1.1 veego dst++;
292 1.1 veego }
293 1.1 veego break;
294 1.1 veego case SCROLL_RIGHT:
295 1.1 veego dst = src + ((sx+count)<<1);
296 1.1 veego src = &console_buffer[cv3d_rowc[sy] + sx];
297 1.1 veego len = ip->cols - (sx + count);
298 1.1 veego dst2 = &console_buffer[cv3d_rowc[sy] + sx + count];
299 1.1 veego bcopy (src, dst2, len << 1);
300 1.1 veego
301 1.1 veego for (i = 0; i < len; i++) {
302 1.1 veego *dst++ = *dst2++;
303 1.1 veego dst++;
304 1.1 veego }
305 1.1 veego break;
306 1.1 veego case SCROLL_LEFT:
307 1.1 veego dst = src + ((sx - count)<<1);
308 1.1 veego src = &console_buffer[cv3d_rowc[sy] + sx];
309 1.1 veego len = ip->cols - sx;
310 1.1 veego dst2 = &console_buffer[cv3d_rowc[sy] + sx - count];
311 1.1 veego bcopy (src, dst2, len << 1);
312 1.1 veego
313 1.1 veego for (i = 0; i < len; i++) {
314 1.1 veego *dst++ = *dst2++;
315 1.1 veego dst++;
316 1.1 veego }
317 1.1 veego }
318 1.1 veego }
319 1.1 veego
320 1.1 veego #endif /* NGRFCV3D */
321