ite_cl.c revision 1.1 1
2 /*
3 * Copyright (c) 1995 Ezra Story
4 * Copyright (c) 1995 Kari Mettinen
5 * Copyright (c) 1994 Markus Wild
6 * Copyright (c) 1994 Lutz Vieweg
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Lutz Vieweg.
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 #include "grfcl.h"
36 #if NGRFCL > 0
37
38 #include <sys/param.h>
39 #include <sys/conf.h>
40 #include <sys/proc.h>
41 #include <sys/device.h>
42 #include <sys/ioctl.h>
43 #include <sys/tty.h>
44 #include <sys/systm.h>
45 #include <dev/cons.h>
46 #include <machine/cpu.h>
47 #include <amiga/amiga/device.h>
48 #include <amiga/dev/grfioctl.h>
49 #include <amiga/dev/grfvar.h>
50 #include <amiga/dev/grf_clreg.h>
51 #include <amiga/dev/itevar.h>
52
53 #ifdef CL5426CONSOLE
54 int cl_console = 1;
55 #else
56 int cl_console = 0;
57 #endif
58
59 void cl_init __P((struct ite_softc *ip));
60 void cl_cursor __P((struct ite_softc *ip, int flag));
61 void cl_deinit __P((struct ite_softc *ip));
62 void cl_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
63 void cl_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
64 void cl_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
65 int dir));
66
67
68 /*
69 * Called to determine ite status. Because the connection between the
70 * console & ite in this driver is rather intimate, we return CN_DEAD
71 * if the cl_console is not active.
72 */
73 int
74 grfcl_cnprobe(void)
75 {
76 static int done;
77 int rv;
78
79 if (cl_console && (done == 0))
80 rv = CN_INTERNAL;
81 else
82 rv = CN_DEAD;
83
84 done = 1;
85 return(rv);
86 }
87
88 void
89 grfcl_iteinit(gp)
90 struct grf_softc *gp;
91 {
92 gp->g_iteinit = cl_init;
93 gp->g_itedeinit = cl_deinit;
94 gp->g_iteclear = cl_clear;
95 gp->g_iteputc = cl_putc;
96 gp->g_itescroll = cl_scroll;
97 gp->g_itecursor = cl_cursor;
98 }
99
100 void
101 cl_init(ip)
102 struct ite_softc *ip;
103 {
104 struct grfcltext_mode *md;
105
106 ip->priv = ip->grf->g_data;
107 md = (struct grfcltext_mode *) ip->priv;
108
109 ip->cols = md->cols;
110 ip->rows = md->rows;
111 }
112
113
114 void
115 cl_cursor(ip, flag)
116 struct ite_softc *ip;
117 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);
128 ip->cursorx = ip->curx;
129 ip->cursory = ip->cury;
130 break;
131 case ERASE_CURSOR:
132 /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
133 case START_CURSOROPT:
134 case END_CURSOROPT:
135 default:
136 break;
137 }
138 }
139
140
141 void
142 cl_deinit(ip)
143 struct ite_softc *ip;
144 {
145 ip->flags &= ~ITE_INITED;
146 }
147
148
149 void
150 cl_putc(ip, c, dy, dx, mode)
151 struct ite_softc *ip;
152 int c;
153 int dy;
154 int dx;
155 int mode;
156 {
157 volatile unsigned char *ba = ip->grf->g_regkva;
158 unsigned char *fb = ip->grf->g_fbkva;
159 unsigned char attr;
160 unsigned char *cp;
161
162 attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
163 if (mode & ATTR_UL) attr = 0x01; /* ???????? */
164 if (mode & ATTR_BOLD) attr |= 0x08;
165 if (mode & ATTR_BLINK) attr |= 0x80;
166
167 cp = fb + ((dy * ip->cols) + dx);
168 SetTextPlane(ba,0x00);
169 *cp = (unsigned char) c;
170 SetTextPlane(ba,0x01);
171 *cp = (unsigned char) attr;
172 }
173
174 void
175 cl_clear(ip, sy, sx, h, w)
176 struct ite_softc *ip;
177 int sy;
178 int sx;
179 int h;
180 int w;
181 {
182 /* cl_clear and cl_scroll both rely on ite passing arguments
183 * which describe continuous regions. For a VT200 terminal,
184 * this is safe behavior.
185 */
186 unsigned char *src, *dst;
187 volatile unsigned char *ba = ip->grf->g_regkva;
188 int len;
189
190 dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
191 src = dst + (ip->rows*ip->cols);
192 len = w*h;
193
194 SetTextPlane(ba, 0x00);
195 bcopy(src, dst, len);
196 SetTextPlane(ba, 0x01);
197 bcopy(src, dst, len);
198 }
199
200 void
201 cl_scroll(ip, sy, sx, count, dir)
202 struct ite_softc *ip;
203 int sy;
204 int sx;
205 int count;
206 int dir;
207 {
208 unsigned char *fb;
209 volatile unsigned char *ba = ip->grf->g_regkva;
210
211 fb = ip->grf->g_fbkva + sy * ip->cols;
212 SetTextPlane(ba, 0x00);
213
214 switch (dir) {
215 case SCROLL_UP:
216 bcopy(fb, fb - (count * ip->cols),
217 (ip->bottom_margin + 1 - sy) * ip->cols);
218 break;
219 case SCROLL_DOWN:
220 bcopy(fb, fb + (count * ip->cols),
221 (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
222 break;
223 case SCROLL_RIGHT:
224 bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
225 break;
226 case SCROLL_LEFT:
227 bcopy(fb+sx, fb+sx-count, ip->cols - sx);
228 break;
229 }
230
231 SetTextPlane(ba, 0x01);
232
233 switch (dir) {
234 case SCROLL_UP:
235 bcopy(fb, fb - (count * ip->cols),
236 (ip->bottom_margin + 1 - sy) * ip->cols);
237 break;
238 case SCROLL_DOWN:
239 bcopy(fb, fb + (count * ip->cols),
240 (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
241 break;
242 case SCROLL_RIGHT:
243 bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
244 break;
245 case SCROLL_LEFT:
246 bcopy(fb+sx, fb+sx-count, ip->cols - sx);
247 break;
248 }
249 }
250 #endif /* NGRFCL */
251