ite_cl.c revision 1.9.58.1 1 1.9.58.1 jym /* $NetBSD: ite_cl.c,v 1.9.58.1 2009/05/13 17:16:10 jym 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.5 aymeric * 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.6 aymeric
38 1.6 aymeric #include <sys/cdefs.h>
39 1.9.58.1 jym __KERNEL_RCSID(0, "$NetBSD: ite_cl.c,v 1.9.58.1 2009/05/13 17:16:10 jym Exp $");
40 1.6 aymeric
41 1.1 chopps #include "grfcl.h"
42 1.1 chopps #if NGRFCL > 0
43 1.1 chopps
44 1.1 chopps #include <sys/param.h>
45 1.1 chopps #include <sys/conf.h>
46 1.1 chopps #include <sys/proc.h>
47 1.1 chopps #include <sys/device.h>
48 1.1 chopps #include <sys/ioctl.h>
49 1.1 chopps #include <sys/tty.h>
50 1.1 chopps #include <sys/systm.h>
51 1.1 chopps #include <dev/cons.h>
52 1.1 chopps #include <machine/cpu.h>
53 1.1 chopps #include <amiga/amiga/device.h>
54 1.1 chopps #include <amiga/dev/grfioctl.h>
55 1.1 chopps #include <amiga/dev/grfvar.h>
56 1.1 chopps #include <amiga/dev/grf_clreg.h>
57 1.1 chopps #include <amiga/dev/itevar.h>
58 1.1 chopps
59 1.1 chopps #ifdef CL5426CONSOLE
60 1.1 chopps int cl_console = 1;
61 1.1 chopps #else
62 1.1 chopps int cl_console = 0;
63 1.1 chopps #endif
64 1.1 chopps
65 1.5 aymeric void cl_init(struct ite_softc *ip);
66 1.5 aymeric void cl_cursor(struct ite_softc *ip, int flag);
67 1.5 aymeric void cl_deinit(struct ite_softc *ip);
68 1.5 aymeric void cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
69 1.5 aymeric void cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
70 1.5 aymeric void cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
71 1.1 chopps
72 1.1 chopps
73 1.1 chopps /*
74 1.1 chopps * Called to determine ite status. Because the connection between the
75 1.1 chopps * console & ite in this driver is rather intimate, we return CN_DEAD
76 1.1 chopps * if the cl_console is not active.
77 1.1 chopps */
78 1.1 chopps int
79 1.1 chopps grfcl_cnprobe(void)
80 1.1 chopps {
81 1.1 chopps static int done;
82 1.1 chopps int rv;
83 1.1 chopps
84 1.1 chopps if (cl_console && (done == 0))
85 1.1 chopps rv = CN_INTERNAL;
86 1.1 chopps else
87 1.1 chopps rv = CN_DEAD;
88 1.1 chopps
89 1.1 chopps done = 1;
90 1.1 chopps return(rv);
91 1.1 chopps }
92 1.1 chopps
93 1.1 chopps void
94 1.5 aymeric grfcl_iteinit(struct grf_softc *gp)
95 1.1 chopps {
96 1.1 chopps gp->g_iteinit = cl_init;
97 1.1 chopps gp->g_itedeinit = cl_deinit;
98 1.1 chopps gp->g_iteclear = cl_clear;
99 1.1 chopps gp->g_iteputc = cl_putc;
100 1.1 chopps gp->g_itescroll = cl_scroll;
101 1.1 chopps gp->g_itecursor = cl_cursor;
102 1.1 chopps }
103 1.1 chopps
104 1.1 chopps void
105 1.5 aymeric cl_init(struct ite_softc *ip)
106 1.1 chopps {
107 1.1 chopps struct grfcltext_mode *md;
108 1.1 chopps
109 1.1 chopps ip->priv = ip->grf->g_data;
110 1.1 chopps md = (struct grfcltext_mode *) ip->priv;
111 1.1 chopps
112 1.1 chopps ip->cols = md->cols;
113 1.1 chopps ip->rows = md->rows;
114 1.1 chopps }
115 1.1 chopps
116 1.1 chopps
117 1.1 chopps void
118 1.5 aymeric cl_cursor(struct ite_softc *ip, int flag)
119 1.1 chopps {
120 1.1 chopps volatile u_char *ba = ip->grf->g_regkva;
121 1.1 chopps
122 1.1 chopps switch (flag) {
123 1.1 chopps case DRAW_CURSOR:
124 1.1 chopps /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
125 1.1 chopps case MOVE_CURSOR:
126 1.1 chopps flag = ip->curx + ip->cury * ip->cols;
127 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
128 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
129 1.1 chopps ip->cursorx = ip->curx;
130 1.1 chopps ip->cursory = ip->cury;
131 1.1 chopps break;
132 1.1 chopps case ERASE_CURSOR:
133 1.1 chopps /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
134 1.1 chopps case START_CURSOROPT:
135 1.1 chopps case END_CURSOROPT:
136 1.1 chopps default:
137 1.1 chopps break;
138 1.1 chopps }
139 1.1 chopps }
140 1.1 chopps
141 1.1 chopps
142 1.1 chopps void
143 1.5 aymeric cl_deinit(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.5 aymeric cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
151 1.1 chopps {
152 1.1 chopps volatile unsigned char *ba = ip->grf->g_regkva;
153 1.9 he volatile unsigned char *fb = ip->grf->g_fbkva;
154 1.1 chopps unsigned char attr;
155 1.7 mhitch volatile unsigned char *cp;
156 1.1 chopps
157 1.4 is if (ip->flags & ITE_INGRF)
158 1.4 is return;
159 1.4 is
160 1.1 chopps attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
161 1.1 chopps if (mode & ATTR_UL) attr = 0x01; /* ???????? */
162 1.1 chopps if (mode & ATTR_BOLD) attr |= 0x08;
163 1.1 chopps if (mode & ATTR_BLINK) attr |= 0x80;
164 1.1 chopps
165 1.1 chopps cp = fb + ((dy * ip->cols) + dx);
166 1.1 chopps SetTextPlane(ba,0x00);
167 1.1 chopps *cp = (unsigned char) c;
168 1.1 chopps SetTextPlane(ba,0x01);
169 1.1 chopps *cp = (unsigned char) attr;
170 1.1 chopps }
171 1.1 chopps
172 1.1 chopps void
173 1.5 aymeric cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
174 1.1 chopps {
175 1.1 chopps /* cl_clear and cl_scroll both rely on ite passing arguments
176 1.1 chopps * which describe continuous regions. For a VT200 terminal,
177 1.1 chopps * this is safe behavior.
178 1.1 chopps */
179 1.1 chopps unsigned char *src, *dst;
180 1.1 chopps volatile unsigned char *ba = ip->grf->g_regkva;
181 1.1 chopps int len;
182 1.1 chopps
183 1.4 is if (ip->flags & ITE_INGRF)
184 1.4 is return;
185 1.4 is
186 1.9 he dst = (unsigned char*)__UNVOLATILE(ip->grf->g_fbkva) +
187 1.9 he (sy * ip->cols) + sx;
188 1.5 aymeric src = dst + (ip->rows*ip->cols);
189 1.1 chopps len = w*h;
190 1.1 chopps
191 1.1 chopps SetTextPlane(ba, 0x00);
192 1.9.58.1 jym memcpy( dst, src, len);
193 1.1 chopps SetTextPlane(ba, 0x01);
194 1.9.58.1 jym memcpy( dst, src, len);
195 1.1 chopps }
196 1.1 chopps
197 1.1 chopps void
198 1.5 aymeric cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
199 1.1 chopps {
200 1.1 chopps unsigned char *fb;
201 1.1 chopps volatile unsigned char *ba = ip->grf->g_regkva;
202 1.4 is
203 1.4 is if (ip->flags & ITE_INGRF)
204 1.4 is return;
205 1.1 chopps
206 1.9 he fb = (unsigned char*)__UNVOLATILE(ip->grf->g_fbkva) + sy * ip->cols;
207 1.1 chopps SetTextPlane(ba, 0x00);
208 1.1 chopps
209 1.1 chopps switch (dir) {
210 1.1 chopps case SCROLL_UP:
211 1.9.58.1 jym memcpy( fb - (count * ip->cols), fb,
212 1.1 chopps (ip->bottom_margin + 1 - sy) * ip->cols);
213 1.1 chopps break;
214 1.1 chopps case SCROLL_DOWN:
215 1.9.58.1 jym memcpy( fb + (count * ip->cols), fb,
216 1.1 chopps (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
217 1.1 chopps break;
218 1.1 chopps case SCROLL_RIGHT:
219 1.9.58.1 jym memcpy( fb+sx+count, fb+sx, ip->cols - (sx + count));
220 1.1 chopps break;
221 1.1 chopps case SCROLL_LEFT:
222 1.9.58.1 jym memcpy( fb+sx-count, fb+sx, ip->cols - sx);
223 1.1 chopps break;
224 1.1 chopps }
225 1.1 chopps
226 1.1 chopps SetTextPlane(ba, 0x01);
227 1.1 chopps
228 1.1 chopps switch (dir) {
229 1.1 chopps case SCROLL_UP:
230 1.9.58.1 jym memcpy( fb - (count * ip->cols), fb,
231 1.1 chopps (ip->bottom_margin + 1 - sy) * ip->cols);
232 1.1 chopps break;
233 1.1 chopps case SCROLL_DOWN:
234 1.9.58.1 jym memcpy( fb + (count * ip->cols), fb,
235 1.1 chopps (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
236 1.1 chopps break;
237 1.1 chopps case SCROLL_RIGHT:
238 1.9.58.1 jym memcpy( fb+sx+count, fb+sx, ip->cols - (sx + count));
239 1.1 chopps break;
240 1.1 chopps case SCROLL_LEFT:
241 1.9.58.1 jym memcpy( fb+sx-count, fb+sx, ip->cols - sx);
242 1.1 chopps break;
243 1.1 chopps }
244 1.1 chopps }
245 1.1 chopps #endif /* NGRFCL */
246