ite_cl.c revision 1.3 1 /* $NetBSD: ite_cl.c,v 1.3 1999/03/25 23:20:00 is 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 "grfcl.h"
38 #if NGRFCL > 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_clreg.h>
53 #include <amiga/dev/itevar.h>
54
55 #ifdef CL5426CONSOLE
56 int cl_console = 1;
57 #else
58 int cl_console = 0;
59 #endif
60
61 void cl_init __P((struct ite_softc *ip));
62 void cl_cursor __P((struct ite_softc *ip, int flag));
63 void cl_deinit __P((struct ite_softc *ip));
64 void cl_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
65 void cl_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
66 void cl_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
67 int dir));
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 grfcl_cnprobe(void)
77 {
78 static int done;
79 int rv;
80
81 if (cl_console && (done == 0))
82 rv = CN_INTERNAL;
83 else
84 rv = CN_DEAD;
85
86 done = 1;
87 return(rv);
88 }
89
90 void
91 grfcl_iteinit(gp)
92 struct grf_softc *gp;
93 {
94 gp->g_iteinit = cl_init;
95 gp->g_itedeinit = cl_deinit;
96 gp->g_iteclear = cl_clear;
97 gp->g_iteputc = cl_putc;
98 gp->g_itescroll = cl_scroll;
99 gp->g_itecursor = cl_cursor;
100 }
101
102 void
103 cl_init(ip)
104 struct ite_softc *ip;
105 {
106 struct grfcltext_mode *md;
107
108 ip->priv = ip->grf->g_data;
109 md = (struct grfcltext_mode *) ip->priv;
110
111 ip->cols = md->cols;
112 ip->rows = md->rows;
113 }
114
115
116 void
117 cl_cursor(ip, flag)
118 struct ite_softc *ip;
119 int flag;
120 {
121 volatile u_char *ba = ip->grf->g_regkva;
122
123 switch (flag) {
124 case DRAW_CURSOR:
125 /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
126 case MOVE_CURSOR:
127 flag = ip->curx + ip->cury * ip->cols;
128 WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
129 WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
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 cl_deinit(ip)
145 struct ite_softc *ip;
146 {
147 ip->flags &= ~ITE_INITED;
148 }
149
150
151 void
152 cl_putc(ip, c, dy, dx, mode)
153 struct ite_softc *ip;
154 int c;
155 int dy;
156 int dx;
157 int mode;
158 {
159 volatile unsigned char *ba = ip->grf->g_regkva;
160 unsigned char *fb = ip->grf->g_fbkva;
161 unsigned char attr;
162 unsigned char *cp;
163
164 attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
165 if (mode & ATTR_UL) attr = 0x01; /* ???????? */
166 if (mode & ATTR_BOLD) attr |= 0x08;
167 if (mode & ATTR_BLINK) attr |= 0x80;
168
169 cp = fb + ((dy * ip->cols) + dx);
170 SetTextPlane(ba,0x00);
171 *cp = (unsigned char) c;
172 SetTextPlane(ba,0x01);
173 *cp = (unsigned char) attr;
174 }
175
176 void
177 cl_clear(ip, sy, sx, h, w)
178 struct ite_softc *ip;
179 int sy;
180 int sx;
181 int h;
182 int w;
183 {
184 /* cl_clear and cl_scroll both rely on ite passing arguments
185 * which describe continuous regions. For a VT200 terminal,
186 * this is safe behavior.
187 */
188 unsigned char *src, *dst;
189 volatile unsigned char *ba = ip->grf->g_regkva;
190 int len;
191
192 dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
193 src = dst + (ip->rows*ip->cols);
194 len = w*h;
195
196 SetTextPlane(ba, 0x00);
197 bcopy(src, dst, len);
198 SetTextPlane(ba, 0x01);
199 bcopy(src, dst, len);
200 }
201
202 void
203 cl_scroll(ip, sy, sx, count, dir)
204 struct ite_softc *ip;
205 int sy;
206 int sx;
207 int count;
208 int dir;
209 {
210 unsigned char *fb;
211 volatile unsigned char *ba = ip->grf->g_regkva;
212
213 fb = ip->grf->g_fbkva + sy * ip->cols;
214 SetTextPlane(ba, 0x00);
215
216 switch (dir) {
217 case SCROLL_UP:
218 bcopy(fb, fb - (count * ip->cols),
219 (ip->bottom_margin + 1 - sy) * ip->cols);
220 break;
221 case SCROLL_DOWN:
222 bcopy(fb, fb + (count * ip->cols),
223 (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
224 break;
225 case SCROLL_RIGHT:
226 bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
227 break;
228 case SCROLL_LEFT:
229 bcopy(fb+sx, fb+sx-count, ip->cols - sx);
230 break;
231 }
232
233 SetTextPlane(ba, 0x01);
234
235 switch (dir) {
236 case SCROLL_UP:
237 bcopy(fb, fb - (count * ip->cols),
238 (ip->bottom_margin + 1 - sy) * ip->cols);
239 break;
240 case SCROLL_DOWN:
241 bcopy(fb, fb + (count * ip->cols),
242 (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
243 break;
244 case SCROLL_RIGHT:
245 bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
246 break;
247 case SCROLL_LEFT:
248 bcopy(fb+sx, fb+sx-count, ip->cols - sx);
249 break;
250 }
251 }
252 #endif /* NGRFCL */
253