ite_et.c revision 1.3.2.2 1 1.3.2.2 veego /* $NetBSD: ite_et.c,v 1.3.2.2 1997/03/05 22:50:42 veego Exp $ */
2 1.3.2.2 veego
3 1.3.2.2 veego /*
4 1.3.2.2 veego * Copyright (c) 1995 Ezra Story
5 1.3.2.2 veego * Copyright (c) 1995 Kari Mettinen
6 1.3.2.2 veego * Copyright (c) 1994 Markus Wild
7 1.3.2.2 veego * Copyright (c) 1994 Lutz Vieweg
8 1.3.2.2 veego * All rights reserved.
9 1.3.2.2 veego *
10 1.3.2.2 veego * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 veego * modification, are permitted provided that the following conditions
12 1.3.2.2 veego * are met:
13 1.3.2.2 veego * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 veego * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 veego * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 veego * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 veego * documentation and/or other materials provided with the distribution.
18 1.3.2.2 veego * 3. All advertising materials mentioning features or use of this software
19 1.3.2.2 veego * must display the following acknowledgement:
20 1.3.2.2 veego * This product includes software developed by Lutz Vieweg.
21 1.3.2.2 veego * 4. The name of the author may not be used to endorse or promote products
22 1.3.2.2 veego * derived from this software without specific prior written permission
23 1.3.2.2 veego *
24 1.3.2.2 veego * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 1.3.2.2 veego * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.3.2.2 veego * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.3.2.2 veego * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.3.2.2 veego * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.3.2.2 veego * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.3.2.2 veego * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.3.2.2 veego * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.3.2.2 veego * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.3.2.2 veego * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.3.2.2 veego */
35 1.3.2.2 veego
36 1.3.2.2 veego #include "grfet.h"
37 1.3.2.2 veego #if NGRFET > 0
38 1.3.2.2 veego
39 1.3.2.2 veego #include <sys/param.h>
40 1.3.2.2 veego #include <sys/conf.h>
41 1.3.2.2 veego #include <sys/proc.h>
42 1.3.2.2 veego #include <sys/device.h>
43 1.3.2.2 veego #include <sys/ioctl.h>
44 1.3.2.2 veego #include <sys/tty.h>
45 1.3.2.2 veego #include <sys/systm.h>
46 1.3.2.2 veego #include <dev/cons.h>
47 1.3.2.2 veego #include <machine/cpu.h>
48 1.3.2.2 veego #include <amiga/amiga/device.h>
49 1.3.2.2 veego #include <amiga/dev/grfioctl.h>
50 1.3.2.2 veego #include <amiga/dev/grfvar.h>
51 1.3.2.2 veego #include <amiga/dev/grf_etreg.h>
52 1.3.2.2 veego #include <amiga/dev/itevar.h>
53 1.3.2.2 veego
54 1.3.2.2 veego #ifdef TSENGCONSOLE
55 1.3.2.2 veego int et_console = 1;
56 1.3.2.2 veego #else
57 1.3.2.2 veego int et_console = 0;
58 1.3.2.2 veego #endif
59 1.3.2.2 veego
60 1.3.2.2 veego void et_init __P((struct ite_softc *ip));
61 1.3.2.2 veego void et_cursor __P((struct ite_softc *ip, int flag));
62 1.3.2.2 veego void et_deinit __P((struct ite_softc *ip));
63 1.3.2.2 veego void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
64 1.3.2.2 veego void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
65 1.3.2.2 veego void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
66 1.3.2.2 veego int dir));
67 1.3.2.2 veego static void etbcopy(const void *src, void *dst, size_t len);
68 1.3.2.2 veego
69 1.3.2.2 veego
70 1.3.2.2 veego /*
71 1.3.2.2 veego * Called to determine ite status. Because the connection between the
72 1.3.2.2 veego * console & ite in this driver is rather intimate, we return CN_DEAD
73 1.3.2.2 veego * if the cl_console is not active.
74 1.3.2.2 veego */
75 1.3.2.2 veego int
76 1.3.2.2 veego grfet_cnprobe(void)
77 1.3.2.2 veego {
78 1.3.2.2 veego static int done;
79 1.3.2.2 veego int rv;
80 1.3.2.2 veego
81 1.3.2.2 veego if (et_console && (done == 0))
82 1.3.2.2 veego rv = CN_INTERNAL;
83 1.3.2.2 veego else
84 1.3.2.2 veego rv = CN_DEAD;
85 1.3.2.2 veego
86 1.3.2.2 veego done = 1;
87 1.3.2.2 veego return(rv);
88 1.3.2.2 veego }
89 1.3.2.2 veego
90 1.3.2.2 veego
91 1.3.2.2 veego void
92 1.3.2.2 veego grfet_iteinit(gp)
93 1.3.2.2 veego struct grf_softc *gp;
94 1.3.2.2 veego {
95 1.3.2.2 veego gp->g_iteinit = et_init;
96 1.3.2.2 veego gp->g_itedeinit = et_deinit;
97 1.3.2.2 veego gp->g_iteclear = et_clear;
98 1.3.2.2 veego gp->g_iteputc = et_putc;
99 1.3.2.2 veego gp->g_itescroll = et_scroll;
100 1.3.2.2 veego gp->g_itecursor = et_cursor;
101 1.3.2.2 veego }
102 1.3.2.2 veego
103 1.3.2.2 veego
104 1.3.2.2 veego void
105 1.3.2.2 veego et_init(ip)
106 1.3.2.2 veego struct ite_softc *ip;
107 1.3.2.2 veego {
108 1.3.2.2 veego struct grfettext_mode *md;
109 1.3.2.2 veego
110 1.3.2.2 veego ip->priv = ip->grf->g_data;
111 1.3.2.2 veego md = (struct grfettext_mode *) ip->priv;
112 1.3.2.2 veego
113 1.3.2.2 veego ip->cols = md->cols;
114 1.3.2.2 veego ip->rows = md->rows;
115 1.3.2.2 veego }
116 1.3.2.2 veego
117 1.3.2.2 veego
118 1.3.2.2 veego void
119 1.3.2.2 veego et_cursor(ip, flag)
120 1.3.2.2 veego struct ite_softc *ip;
121 1.3.2.2 veego int flag;
122 1.3.2.2 veego {
123 1.3.2.2 veego volatile u_char *ba = ip->grf->g_regkva;
124 1.3.2.2 veego
125 1.3.2.2 veego switch (flag) {
126 1.3.2.2 veego case DRAW_CURSOR:
127 1.3.2.2 veego /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
128 1.3.2.2 veego case MOVE_CURSOR:
129 1.3.2.2 veego flag = ip->curx + ip->cury * ip->cols;
130 1.3.2.2 veego WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
131 1.3.2.2 veego WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff);
132 1.3.2.2 veego WCrt(ba, CRT_ID_EXT_START, (flag >> (16-2)) & 0x0c);
133 1.3.2.2 veego
134 1.3.2.2 veego ip->cursorx = ip->curx;
135 1.3.2.2 veego ip->cursory = ip->cury;
136 1.3.2.2 veego break;
137 1.3.2.2 veego case ERASE_CURSOR:
138 1.3.2.2 veego /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
139 1.3.2.2 veego case START_CURSOROPT:
140 1.3.2.2 veego case END_CURSOROPT:
141 1.3.2.2 veego default:
142 1.3.2.2 veego break;
143 1.3.2.2 veego }
144 1.3.2.2 veego }
145 1.3.2.2 veego
146 1.3.2.2 veego
147 1.3.2.2 veego void
148 1.3.2.2 veego et_deinit(ip)
149 1.3.2.2 veego struct ite_softc *ip;
150 1.3.2.2 veego {
151 1.3.2.2 veego ip->flags &= ~ITE_INITED;
152 1.3.2.2 veego }
153 1.3.2.2 veego
154 1.3.2.2 veego
155 1.3.2.2 veego void
156 1.3.2.2 veego et_putc(ip, c, dy, dx, mode)
157 1.3.2.2 veego struct ite_softc *ip;
158 1.3.2.2 veego int c;
159 1.3.2.2 veego int dy;
160 1.3.2.2 veego int dx;
161 1.3.2.2 veego int mode;
162 1.3.2.2 veego {
163 1.3.2.2 veego volatile unsigned char *ba = ip->grf->g_regkva;
164 1.3.2.2 veego unsigned char *fb = ip->grf->g_fbkva;
165 1.3.2.2 veego unsigned char attr;
166 1.3.2.2 veego unsigned char *cp;
167 1.3.2.2 veego
168 1.3.2.2 veego attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
169 1.3.2.2 veego if (mode & ATTR_UL) attr = 0x01; /* ???????? */
170 1.3.2.2 veego if (mode & ATTR_BOLD) attr |= 0x08;
171 1.3.2.2 veego if (mode & ATTR_BLINK) attr |= 0x80;
172 1.3.2.2 veego
173 1.3.2.2 veego cp = fb + ((dy * ip->cols) + dx);
174 1.3.2.2 veego SetTextPlane(ba,0x00);
175 1.3.2.2 veego *cp = (unsigned char) c;
176 1.3.2.2 veego SetTextPlane(ba,0x01);
177 1.3.2.2 veego *cp = (unsigned char) attr;
178 1.3.2.2 veego }
179 1.3.2.2 veego
180 1.3.2.2 veego
181 1.3.2.2 veego void
182 1.3.2.2 veego et_clear(ip, sy, sx, h, w)
183 1.3.2.2 veego struct ite_softc *ip;
184 1.3.2.2 veego int sy;
185 1.3.2.2 veego int sx;
186 1.3.2.2 veego int h;
187 1.3.2.2 veego int w;
188 1.3.2.2 veego {
189 1.3.2.2 veego /* cl_clear and cl_scroll both rely on ite passing arguments
190 1.3.2.2 veego * which describe continuous regions. For a VT200 terminal,
191 1.3.2.2 veego * this is safe behavior.
192 1.3.2.2 veego */
193 1.3.2.2 veego unsigned char *src, *dst;
194 1.3.2.2 veego volatile unsigned char *ba = ip->grf->g_regkva;
195 1.3.2.2 veego int len;
196 1.3.2.2 veego
197 1.3.2.2 veego dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
198 1.3.2.2 veego src = dst + (ip->rows*ip->cols);
199 1.3.2.2 veego len = w*h;
200 1.3.2.2 veego
201 1.3.2.2 veego SetTextPlane(ba, 0x00);
202 1.3.2.2 veego etbcopy(src, dst, len);
203 1.3.2.2 veego SetTextPlane(ba, 0x01);
204 1.3.2.2 veego etbcopy(src, dst, len);
205 1.3.2.2 veego }
206 1.3.2.2 veego
207 1.3.2.2 veego
208 1.3.2.2 veego void
209 1.3.2.2 veego et_scroll(ip, sy, sx, count, dir)
210 1.3.2.2 veego struct ite_softc *ip;
211 1.3.2.2 veego int sy;
212 1.3.2.2 veego int sx;
213 1.3.2.2 veego int count;
214 1.3.2.2 veego int dir;
215 1.3.2.2 veego {
216 1.3.2.2 veego unsigned char *fb;
217 1.3.2.2 veego volatile unsigned char *ba = ip->grf->g_regkva;
218 1.3.2.2 veego
219 1.3.2.2 veego fb = ip->grf->g_fbkva + sy * ip->cols;
220 1.3.2.2 veego SetTextPlane(ba, 0x00);
221 1.3.2.2 veego
222 1.3.2.2 veego switch (dir) {
223 1.3.2.2 veego case SCROLL_UP:
224 1.3.2.2 veego etbcopy(fb, fb - (count * ip->cols),
225 1.3.2.2 veego (ip->bottom_margin + 1 - sy) * ip->cols);
226 1.3.2.2 veego break;
227 1.3.2.2 veego case SCROLL_DOWN:
228 1.3.2.2 veego etbcopy(fb, fb + (count * ip->cols),
229 1.3.2.2 veego (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
230 1.3.2.2 veego break;
231 1.3.2.2 veego case SCROLL_RIGHT:
232 1.3.2.2 veego etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
233 1.3.2.2 veego break;
234 1.3.2.2 veego case SCROLL_LEFT:
235 1.3.2.2 veego etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
236 1.3.2.2 veego break;
237 1.3.2.2 veego }
238 1.3.2.2 veego
239 1.3.2.2 veego SetTextPlane(ba, 0x01);
240 1.3.2.2 veego
241 1.3.2.2 veego switch (dir) {
242 1.3.2.2 veego case SCROLL_UP:
243 1.3.2.2 veego etbcopy(fb, fb - (count * ip->cols),
244 1.3.2.2 veego (ip->bottom_margin + 1 - sy) * ip->cols);
245 1.3.2.2 veego break;
246 1.3.2.2 veego case SCROLL_DOWN:
247 1.3.2.2 veego etbcopy(fb, fb + (count * ip->cols),
248 1.3.2.2 veego (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
249 1.3.2.2 veego break;
250 1.3.2.2 veego case SCROLL_RIGHT:
251 1.3.2.2 veego etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
252 1.3.2.2 veego break;
253 1.3.2.2 veego case SCROLL_LEFT:
254 1.3.2.2 veego etbcopy(fb+sx, fb+sx-count, ip->cols - sx);
255 1.3.2.2 veego break;
256 1.3.2.2 veego }
257 1.3.2.2 veego }
258 1.3.2.2 veego
259 1.3.2.2 veego
260 1.3.2.2 veego static void etbcopy(src, dst, len)
261 1.3.2.2 veego const void *src;
262 1.3.2.2 veego void *dst;
263 1.3.2.2 veego size_t len;
264 1.3.2.2 veego {
265 1.3.2.2 veego int i;
266 1.3.2.2 veego
267 1.3.2.2 veego if (src == dst)
268 1.3.2.2 veego return;
269 1.3.2.2 veego
270 1.3.2.2 veego if (src > dst)
271 1.3.2.2 veego for (i=len; i>0; i--) {
272 1.3.2.2 veego *((char *)dst)++ = *((char *)src)++;
273 1.3.2.2 veego }
274 1.3.2.2 veego else {
275 1.3.2.2 veego ((char *)src) += len;
276 1.3.2.2 veego ((char *)dst) += len;
277 1.3.2.2 veego
278 1.3.2.2 veego for (i=len; i>0; i--){
279 1.3.2.2 veego *--((char *)dst) = *--((char *)src);
280 1.3.2.2 veego }
281 1.3.2.2 veego }
282 1.3.2.2 veego }
283 1.3.2.2 veego
284 1.3.2.2 veego #endif /* NGRFET */
285