ite_rh.c revision 1.9 1 /* $NetBSD: ite_rh.c,v 1.9 2002/01/26 13:40:57 aymeric 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(struct ite_softc *, int, int, int);
54 static void screen_down(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(void)
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(struct grf_softc *gp)
80 {
81 gp->g_iteinit = rh_init;
82 gp->g_itedeinit = rh_deinit;
83 gp->g_iteclear = rh_clear;
84 gp->g_iteputc = rh_putc;
85 gp->g_itescroll = rh_scroll;
86 gp->g_itecursor = rh_cursor;
87 }
88
89
90 void
91 rh_init(struct ite_softc *ip)
92 {
93 struct MonDef *md;
94
95 #if 0 /* Not in ite_rt.c - DC */
96 if (ip->grf == 0)
97 ip->grf = &grf_softc[ip - ite_softc];
98 #endif
99
100 ip->priv = ip->grf->g_data;
101 md = (struct MonDef *) ip->priv;
102
103 ip->cols = md->TX;
104 ip->rows = md->TY;
105 }
106
107
108 void
109 rh_cursor(struct ite_softc *ip, int flag)
110 {
111 #if 0
112 volatile u_char *ba = ip->grf->g_regkva;
113 #endif
114
115 if (flag == START_CURSOROPT || flag == END_CURSOROPT)
116 return;
117
118 if (flag == ERASE_CURSOR) {
119 #if 0
120 /* disable cursor */
121 WCrt (ba, CRT_ID_CURSOR_START,
122 RCrt (ba, CRT_ID_CURSOR_START) | 0x20);
123 #endif
124 } else {
125 int pos = ip->curx + ip->cury * ip->cols;
126 #if 0
127 /* make sure to enable cursor */
128 WCrt (ba, CRT_ID_CURSOR_START,
129 RCrt (ba, CRT_ID_CURSOR_START) & ~0x20);
130 #endif
131
132 /* and position it */
133 RZ3SetCursorPos (ip->grf, pos);
134
135 ip->cursorx = ip->curx;
136 ip->cursory = ip->cury;
137 }
138 }
139
140
141 #ifdef RETINA_SPEED_HACK
142 static void
143 screen_up(struct ite_softc *ip, int top, int bottom, int lines)
144 {
145
146 /* do some bounds-checking here.. */
147 if (top >= bottom)
148 return;
149
150 if (top + lines >= bottom) {
151 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
152 return;
153 }
154
155 RZ3AlphaCopy(ip->grf, 0, top+lines, 0, top, ip->cols, bottom-top-lines+1);
156 RZ3AlphaErase(ip->grf, 0, bottom - lines + 1, ip->cols, lines);
157 }
158
159
160 static void
161 screen_down (struct ite_softc *ip, int top, int bottom, int lines)
162 {
163
164 /* do some bounds-checking here.. */
165 if (top >= bottom)
166 return;
167
168 if (top + lines >= bottom) {
169 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
170 return;
171 }
172
173 RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
174 RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
175 }
176 #endif /* RETINA_SPEED_HACK */
177
178
179 void
180 rh_deinit(struct ite_softc *ip)
181 {
182 ip->flags &= ~ITE_INITED;
183 }
184
185
186 void
187 rh_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
188 {
189 volatile u_char * fb = ip->grf->g_fbkva;
190 register u_char attr;
191
192 attr = (mode & ATTR_INV) ? 0x21 : 0x10;
193 if (mode & ATTR_UL) attr = 0x01; /* ???????? */
194 if (mode & ATTR_BOLD) attr |= 0x08;
195 if (mode & ATTR_BLINK) attr |= 0x80;
196
197 fb += 4 * (dy * ip->cols + dx);
198 *fb++ = c; *fb = attr;
199 }
200
201
202 void
203 rh_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
204 {
205 RZ3AlphaErase (ip->grf, sx, sy, w, h);
206 }
207
208
209 /*
210 * RETINA_SPEED_HACK code seems to work on some boards and on others
211 * it causes text to smear horizontally
212 */
213 void
214 rh_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
215 {
216 #ifndef RETINA_SPEED_HACK
217 u_long * fb = (u_long *) ip->grf->g_fbkva;
218 #endif
219
220 rh_cursor(ip, ERASE_CURSOR);
221
222 if (dir == SCROLL_UP) {
223 #ifdef RETINA_SPEED_HACK
224 screen_up(ip, sy - count, ip->bottom_margin, count);
225 #else
226 bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
227 4 * (ip->bottom_margin - sy + 1) * ip->cols);
228 rh_clear(ip, ip->bottom_margin + 1 - count, 0, count, ip->cols);
229 #endif
230 } else if (dir == SCROLL_DOWN) {
231 #ifdef RETINA_SPEED_HACK
232 screen_down(ip, sy, ip->bottom_margin, count);
233 #else
234 bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
235 4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
236 rh_clear(ip, sy, 0, count, ip->cols);
237 #endif
238 } else if (dir == SCROLL_RIGHT) {
239 RZ3AlphaCopy(ip->grf, sx, sy, sx + count, sy,
240 ip->cols - (sx + count), 1);
241 RZ3AlphaErase(ip->grf, sx, sy, count, 1);
242 } else {
243 RZ3AlphaCopy(ip->grf, sx + count, sy, sx, sy,
244 ip->cols - (sx + count), 1);
245 RZ3AlphaErase(ip->grf, ip->cols - count, sy, count, 1);
246 }
247 #ifndef RETINA_SPEED_HACK
248 rh_cursor(ip, !ERASE_CURSOR);
249 #endif
250 }
251 #endif /* NGRFRH */
252