ite_rh.c revision 1.8 1 /* $NetBSD: ite_rh.c,v 1.8 1999/03/25 23:19:59 is Exp $ */
2
3 /*
4 * Copyright (c) 1994 Markus Wild
5 * Copyright (c) 1994 Lutz Vieweg
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Lutz Vieweg.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 #include "opt_retina.h"
34 #include "grfrh.h"
35 #if NGRFRH > 0
36
37 #include <sys/param.h>
38 #include <sys/conf.h>
39 #include <sys/proc.h>
40 #include <sys/device.h>
41 #include <sys/ioctl.h>
42 #include <sys/tty.h>
43 #include <sys/systm.h>
44 #include <dev/cons.h>
45 #include <machine/cpu.h>
46 #include <amiga/amiga/device.h>
47 #include <amiga/dev/grfioctl.h>
48 #include <amiga/dev/grfvar.h>
49 #include <amiga/dev/grf_rhreg.h>
50 #include <amiga/dev/itevar.h>
51
52 #ifdef RETINA_SPEED_HACK
53 static void screen_up __P((struct ite_softc *, int, int, int));
54 static void screen_down __P((struct ite_softc *, int, int, int));
55 #endif
56
57 /*
58 * grfrh_cnprobe is called when the console is being initialized
59 * i.e. very early. grfconfig() has been called, so this implies
60 * that rt_init() was called. If we are functioning rh_inited
61 * will be true.
62 */
63 int
64 grfrh_cnprobe()
65 {
66 static int done;
67 int rv;
68
69 if (done == 0)
70 rv = CN_INTERNAL;
71 else
72 rv = CN_NORMAL;
73 done = 1;
74 return(rv);
75 }
76
77
78 void
79 grfrh_iteinit(gp)
80 struct grf_softc *gp;
81 {
82 gp->g_iteinit = rh_init;
83 gp->g_itedeinit = rh_deinit;
84 gp->g_iteclear = rh_clear;
85 gp->g_iteputc = rh_putc;
86 gp->g_itescroll = rh_scroll;
87 gp->g_itecursor = rh_cursor;
88 }
89
90
91 void
92 rh_init(ip)
93 struct ite_softc *ip;
94 {
95 struct MonDef *md;
96
97 #if 0 /* Not in ite_rt.c - DC */
98 if (ip->grf == 0)
99 ip->grf = &grf_softc[ip - ite_softc];
100 #endif
101
102 ip->priv = ip->grf->g_data;
103 md = (struct MonDef *) ip->priv;
104
105 ip->cols = md->TX;
106 ip->rows = md->TY;
107 }
108
109
110 void
111 rh_cursor(ip, flag)
112 struct ite_softc *ip;
113 int flag;
114 {
115 #if 0
116 volatile u_char *ba = ip->grf->g_regkva;
117 #endif
118
119 if (flag == START_CURSOROPT || flag == END_CURSOROPT)
120 return;
121
122 if (flag == ERASE_CURSOR) {
123 #if 0
124 /* disable cursor */
125 WCrt (ba, CRT_ID_CURSOR_START,
126 RCrt (ba, CRT_ID_CURSOR_START) | 0x20);
127 #endif
128 } else {
129 int pos = ip->curx + ip->cury * ip->cols;
130 #if 0
131 /* make sure to enable cursor */
132 WCrt (ba, CRT_ID_CURSOR_START,
133 RCrt (ba, CRT_ID_CURSOR_START) & ~0x20);
134 #endif
135
136 /* and position it */
137 RZ3SetCursorPos (ip->grf, pos);
138
139 ip->cursorx = ip->curx;
140 ip->cursory = ip->cury;
141 }
142 }
143
144
145 #ifdef RETINA_SPEED_HACK
146 static void
147 screen_up(ip, top, bottom, lines)
148 struct ite_softc *ip;
149 int top;
150 int bottom;
151 int lines;
152 {
153
154 /* do some bounds-checking here.. */
155 if (top >= bottom)
156 return;
157
158 if (top + lines >= bottom) {
159 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
160 return;
161 }
162
163 RZ3AlphaCopy(ip->grf, 0, top+lines, 0, top, ip->cols, bottom-top-lines+1);
164 RZ3AlphaErase(ip->grf, 0, bottom - lines + 1, ip->cols, lines);
165 }
166
167
168 static void
169 screen_down (ip, top, bottom, lines)
170 struct ite_softc *ip;
171 int top;
172 int bottom;
173 int lines;
174 {
175
176 /* do some bounds-checking here.. */
177 if (top >= bottom)
178 return;
179
180 if (top + lines >= bottom) {
181 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
182 return;
183 }
184
185 RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
186 RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
187 }
188 #endif /* RETINA_SPEED_HACK */
189
190
191 void
192 rh_deinit(ip)
193 struct ite_softc *ip;
194 {
195 ip->flags &= ~ITE_INITED;
196 }
197
198
199 void
200 rh_putc(ip, c, dy, dx, mode)
201 struct ite_softc *ip;
202 int c;
203 int dy;
204 int dx;
205 int mode;
206 {
207 volatile u_char * fb = ip->grf->g_fbkva;
208 register u_char attr;
209
210 attr = (mode & ATTR_INV) ? 0x21 : 0x10;
211 if (mode & ATTR_UL) attr = 0x01; /* ???????? */
212 if (mode & ATTR_BOLD) attr |= 0x08;
213 if (mode & ATTR_BLINK) attr |= 0x80;
214
215 fb += 4 * (dy * ip->cols + dx);
216 *fb++ = c; *fb = attr;
217 }
218
219
220 void
221 rh_clear(ip, sy, sx, h, w)
222 struct ite_softc *ip;
223 int sy;
224 int sx;
225 int h;
226 int w;
227 {
228 RZ3AlphaErase (ip->grf, sx, sy, w, h);
229 }
230
231
232 /*
233 * RETINA_SPEED_HACK code seems to work on some boards and on others
234 * it causes text to smear horizontally
235 */
236 void
237 rh_scroll(ip, sy, sx, count, dir)
238 struct ite_softc *ip;
239 int sy;
240 int sx;
241 int count;
242 int dir;
243 {
244 #ifndef RETINA_SPEED_HACK
245 u_long * fb = (u_long *) ip->grf->g_fbkva;
246 #endif
247
248 rh_cursor(ip, ERASE_CURSOR);
249
250 if (dir == SCROLL_UP) {
251 #ifdef RETINA_SPEED_HACK
252 screen_up(ip, sy - count, ip->bottom_margin, count);
253 #else
254 bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
255 4 * (ip->bottom_margin - sy + 1) * ip->cols);
256 rh_clear(ip, ip->bottom_margin + 1 - count, 0, count, ip->cols);
257 #endif
258 } else if (dir == SCROLL_DOWN) {
259 #ifdef RETINA_SPEED_HACK
260 screen_down(ip, sy, ip->bottom_margin, count);
261 #else
262 bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
263 4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
264 rh_clear(ip, sy, 0, count, ip->cols);
265 #endif
266 } else if (dir == SCROLL_RIGHT) {
267 RZ3AlphaCopy(ip->grf, sx, sy, sx + count, sy,
268 ip->cols - (sx + count), 1);
269 RZ3AlphaErase(ip->grf, sx, sy, count, 1);
270 } else {
271 RZ3AlphaCopy(ip->grf, sx + count, sy, sx, sy,
272 ip->cols - (sx + count), 1);
273 RZ3AlphaErase(ip->grf, ip->cols - count, sy, count, 1);
274 }
275 #ifndef RETINA_SPEED_HACK
276 rh_cursor(ip, !ERASE_CURSOR);
277 #endif
278 }
279 #endif /* NGRFRH */
280