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