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