ite_cl.c revision 1.5 1 1.5 aymeric /* $NetBSD: ite_cl.c,v 1.5 2002/01/26 13:40:57 aymeric 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.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.5 aymeric void cl_init(struct ite_softc *ip);
62 1.5 aymeric void cl_cursor(struct ite_softc *ip, int flag);
63 1.5 aymeric void cl_deinit(struct ite_softc *ip);
64 1.5 aymeric void cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
65 1.5 aymeric void cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
66 1.5 aymeric void cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
67 1.1 chopps
68 1.1 chopps
69 1.1 chopps /*
70 1.1 chopps * Called to determine ite status. Because the connection between the
71 1.1 chopps * console & ite in this driver is rather intimate, we return CN_DEAD
72 1.1 chopps * if the cl_console is not active.
73 1.1 chopps */
74 1.1 chopps int
75 1.1 chopps grfcl_cnprobe(void)
76 1.1 chopps {
77 1.1 chopps static int done;
78 1.1 chopps int rv;
79 1.1 chopps
80 1.1 chopps if (cl_console && (done == 0))
81 1.1 chopps rv = CN_INTERNAL;
82 1.1 chopps else
83 1.1 chopps rv = CN_DEAD;
84 1.1 chopps
85 1.1 chopps done = 1;
86 1.1 chopps return(rv);
87 1.1 chopps }
88 1.1 chopps
89 1.1 chopps void
90 1.5 aymeric grfcl_iteinit(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.5 aymeric cl_init(struct ite_softc *ip)
102 1.1 chopps {
103 1.1 chopps struct grfcltext_mode *md;
104 1.1 chopps
105 1.1 chopps ip->priv = ip->grf->g_data;
106 1.1 chopps md = (struct grfcltext_mode *) ip->priv;
107 1.1 chopps
108 1.1 chopps ip->cols = md->cols;
109 1.1 chopps ip->rows = md->rows;
110 1.1 chopps }
111 1.1 chopps
112 1.1 chopps
113 1.1 chopps void
114 1.5 aymeric cl_cursor(struct ite_softc *ip, int flag)
115 1.1 chopps {
116 1.1 chopps volatile u_char *ba = ip->grf->g_regkva;
117 1.1 chopps
118 1.1 chopps switch (flag) {
119 1.1 chopps case DRAW_CURSOR:
120 1.1 chopps /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
121 1.1 chopps case MOVE_CURSOR:
122 1.1 chopps flag = ip->curx + ip->cury * ip->cols;
123 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
124 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
125 1.1 chopps ip->cursorx = ip->curx;
126 1.1 chopps ip->cursory = ip->cury;
127 1.1 chopps break;
128 1.1 chopps case ERASE_CURSOR:
129 1.1 chopps /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
130 1.1 chopps case START_CURSOROPT:
131 1.1 chopps case END_CURSOROPT:
132 1.1 chopps default:
133 1.1 chopps break;
134 1.1 chopps }
135 1.1 chopps }
136 1.1 chopps
137 1.1 chopps
138 1.1 chopps void
139 1.5 aymeric cl_deinit(struct ite_softc *ip)
140 1.1 chopps {
141 1.1 chopps ip->flags &= ~ITE_INITED;
142 1.1 chopps }
143 1.1 chopps
144 1.1 chopps
145 1.1 chopps void
146 1.5 aymeric cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
147 1.1 chopps {
148 1.1 chopps volatile unsigned char *ba = ip->grf->g_regkva;
149 1.1 chopps unsigned char *fb = ip->grf->g_fbkva;
150 1.1 chopps unsigned char attr;
151 1.1 chopps unsigned char *cp;
152 1.1 chopps
153 1.4 is if (ip->flags & ITE_INGRF)
154 1.4 is return;
155 1.4 is
156 1.1 chopps attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
157 1.1 chopps if (mode & ATTR_UL) attr = 0x01; /* ???????? */
158 1.1 chopps if (mode & ATTR_BOLD) attr |= 0x08;
159 1.1 chopps if (mode & ATTR_BLINK) attr |= 0x80;
160 1.1 chopps
161 1.1 chopps cp = fb + ((dy * ip->cols) + dx);
162 1.1 chopps SetTextPlane(ba,0x00);
163 1.1 chopps *cp = (unsigned char) c;
164 1.1 chopps SetTextPlane(ba,0x01);
165 1.1 chopps *cp = (unsigned char) attr;
166 1.1 chopps }
167 1.1 chopps
168 1.1 chopps void
169 1.5 aymeric cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
170 1.1 chopps {
171 1.1 chopps /* cl_clear and cl_scroll both rely on ite passing arguments
172 1.1 chopps * which describe continuous regions. For a VT200 terminal,
173 1.1 chopps * this is safe behavior.
174 1.1 chopps */
175 1.1 chopps unsigned char *src, *dst;
176 1.1 chopps volatile unsigned char *ba = ip->grf->g_regkva;
177 1.1 chopps int len;
178 1.1 chopps
179 1.4 is if (ip->flags & ITE_INGRF)
180 1.4 is return;
181 1.4 is
182 1.1 chopps dst = ip->grf->g_fbkva + (sy * ip->cols) + sx;
183 1.5 aymeric src = dst + (ip->rows*ip->cols);
184 1.1 chopps len = w*h;
185 1.1 chopps
186 1.1 chopps SetTextPlane(ba, 0x00);
187 1.1 chopps bcopy(src, dst, len);
188 1.1 chopps SetTextPlane(ba, 0x01);
189 1.1 chopps bcopy(src, dst, len);
190 1.1 chopps }
191 1.1 chopps
192 1.1 chopps void
193 1.5 aymeric cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
194 1.1 chopps {
195 1.1 chopps unsigned char *fb;
196 1.1 chopps volatile unsigned char *ba = ip->grf->g_regkva;
197 1.4 is
198 1.4 is if (ip->flags & ITE_INGRF)
199 1.4 is return;
200 1.1 chopps
201 1.1 chopps fb = ip->grf->g_fbkva + sy * ip->cols;
202 1.1 chopps SetTextPlane(ba, 0x00);
203 1.1 chopps
204 1.1 chopps switch (dir) {
205 1.1 chopps case SCROLL_UP:
206 1.5 aymeric bcopy(fb, fb - (count * ip->cols),
207 1.1 chopps (ip->bottom_margin + 1 - sy) * ip->cols);
208 1.1 chopps break;
209 1.1 chopps case SCROLL_DOWN:
210 1.1 chopps bcopy(fb, fb + (count * ip->cols),
211 1.1 chopps (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
212 1.1 chopps break;
213 1.1 chopps case SCROLL_RIGHT:
214 1.1 chopps bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
215 1.1 chopps break;
216 1.1 chopps case SCROLL_LEFT:
217 1.1 chopps bcopy(fb+sx, fb+sx-count, ip->cols - sx);
218 1.1 chopps break;
219 1.1 chopps }
220 1.1 chopps
221 1.1 chopps SetTextPlane(ba, 0x01);
222 1.1 chopps
223 1.1 chopps switch (dir) {
224 1.1 chopps case SCROLL_UP:
225 1.5 aymeric bcopy(fb, fb - (count * ip->cols),
226 1.1 chopps (ip->bottom_margin + 1 - sy) * ip->cols);
227 1.1 chopps break;
228 1.1 chopps case SCROLL_DOWN:
229 1.1 chopps bcopy(fb, fb + (count * ip->cols),
230 1.1 chopps (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
231 1.1 chopps break;
232 1.1 chopps case SCROLL_RIGHT:
233 1.1 chopps bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count));
234 1.1 chopps break;
235 1.1 chopps case SCROLL_LEFT:
236 1.1 chopps bcopy(fb+sx, fb+sx-count, ip->cols - sx);
237 1.1 chopps break;
238 1.1 chopps }
239 1.1 chopps }
240 1.1 chopps #endif /* NGRFCL */
241