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