Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / amiga / dev / ite_rh.c
blobb54ba09e9eff025ffc13631594d2a0783a436b40
1 /* $NetBSD: ite_rh.c,v 1.12 2009/03/18 17:06:42 cegger Exp $ */
3 /*
4 * Copyright (c) 1994 Markus Wild
5 * Copyright (c) 1994 Lutz Vieweg
6 * All rights reserved.
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
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.
33 #include "opt_retina.h"
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: ite_rh.c,v 1.12 2009/03/18 17:06:42 cegger Exp $");
38 #include "grfrh.h"
39 #if NGRFRH > 0
41 #include <sys/param.h>
42 #include <sys/conf.h>
43 #include <sys/proc.h>
44 #include <sys/device.h>
45 #include <sys/ioctl.h>
46 #include <sys/tty.h>
47 #include <sys/systm.h>
48 #include <dev/cons.h>
49 #include <machine/cpu.h>
50 #include <amiga/amiga/device.h>
51 #include <amiga/dev/grfioctl.h>
52 #include <amiga/dev/grfvar.h>
53 #include <amiga/dev/grf_rhreg.h>
54 #include <amiga/dev/itevar.h>
56 #ifdef RETINA_SPEED_HACK
57 static void screen_up(struct ite_softc *, int, int, int);
58 static void screen_down(struct ite_softc *, int, int, int);
59 #endif
62 * grfrh_cnprobe is called when the console is being initialized
63 * i.e. very early. grfconfig() has been called, so this implies
64 * that rt_init() was called. If we are functioning rh_inited
65 * will be true.
67 int
68 grfrh_cnprobe(void)
70 static int done;
71 int rv;
73 if (done == 0)
74 rv = CN_INTERNAL;
75 else
76 rv = CN_NORMAL;
77 done = 1;
78 return(rv);
82 void
83 grfrh_iteinit(struct grf_softc *gp)
85 gp->g_iteinit = rh_init;
86 gp->g_itedeinit = rh_deinit;
87 gp->g_iteclear = rh_clear;
88 gp->g_iteputc = rh_putc;
89 gp->g_itescroll = rh_scroll;
90 gp->g_itecursor = rh_cursor;
94 void
95 rh_init(struct ite_softc *ip)
97 struct MonDef *md;
99 #if 0 /* Not in ite_rt.c - DC */
100 if (ip->grf == 0)
101 ip->grf = &grf_softc[ip - ite_softc];
102 #endif
104 ip->priv = ip->grf->g_data;
105 md = (struct MonDef *) ip->priv;
107 ip->cols = md->TX;
108 ip->rows = md->TY;
112 void
113 rh_cursor(struct ite_softc *ip, int flag)
115 #if 0
116 volatile u_char *ba = ip->grf->g_regkva;
117 #endif
119 if (flag == START_CURSOROPT || flag == END_CURSOROPT)
120 return;
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
136 /* and position it */
137 RZ3SetCursorPos (ip->grf, pos);
139 ip->cursorx = ip->curx;
140 ip->cursory = ip->cury;
145 #ifdef RETINA_SPEED_HACK
146 static void
147 screen_up(struct ite_softc *ip, int top, int bottom, int lines)
150 /* do some bounds-checking here.. */
151 if (top >= bottom)
152 return;
154 if (top + lines >= bottom) {
155 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
156 return;
159 RZ3AlphaCopy(ip->grf, 0, top+lines, 0, top, ip->cols, bottom-top-lines+1);
160 RZ3AlphaErase(ip->grf, 0, bottom - lines + 1, ip->cols, lines);
164 static void
165 screen_down (struct ite_softc *ip, int top, int bottom, int lines)
168 /* do some bounds-checking here.. */
169 if (top >= bottom)
170 return;
172 if (top + lines >= bottom) {
173 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
174 return;
177 RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
178 RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
180 #endif /* RETINA_SPEED_HACK */
183 void
184 rh_deinit(struct ite_softc *ip)
186 ip->flags &= ~ITE_INITED;
190 void
191 rh_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
193 volatile u_char * fb = ip->grf->g_fbkva;
194 register u_char attr;
196 attr = (mode & ATTR_INV) ? 0x21 : 0x10;
197 if (mode & ATTR_UL) attr = 0x01; /* ???????? */
198 if (mode & ATTR_BOLD) attr |= 0x08;
199 if (mode & ATTR_BLINK) attr |= 0x80;
201 fb += 4 * (dy * ip->cols + dx);
202 *fb++ = c; *fb = attr;
206 void
207 rh_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
209 RZ3AlphaErase (ip->grf, sx, sy, w, h);
214 * RETINA_SPEED_HACK code seems to work on some boards and on others
215 * it causes text to smear horizontally
217 void
218 rh_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
220 #ifndef RETINA_SPEED_HACK
221 u_long *fb = (u_long *)__UNVOLATILE(ip->grf->g_fbkva);
222 #endif
224 rh_cursor(ip, ERASE_CURSOR);
226 if (dir == SCROLL_UP) {
227 #ifdef RETINA_SPEED_HACK
228 screen_up(ip, sy - count, ip->bottom_margin, count);
229 #else
230 memcpy(fb + (sy - count) * ip->cols, fb + sy * ip->cols,
231 4 * (ip->bottom_margin - sy + 1) * ip->cols);
232 rh_clear(ip, ip->bottom_margin + 1 - count, 0, count, ip->cols);
233 #endif
234 } else if (dir == SCROLL_DOWN) {
235 #ifdef RETINA_SPEED_HACK
236 screen_down(ip, sy, ip->bottom_margin, count);
237 #else
238 memcpy(fb + (sy + count) * ip->cols, fb + sy * ip->cols,
239 4 * (ip->bottom_margin - sy - count + 1) * ip->cols);
240 rh_clear(ip, sy, 0, count, ip->cols);
241 #endif
242 } else if (dir == SCROLL_RIGHT) {
243 RZ3AlphaCopy(ip->grf, sx, sy, sx + count, sy,
244 ip->cols - (sx + count), 1);
245 RZ3AlphaErase(ip->grf, sx, sy, count, 1);
246 } else {
247 RZ3AlphaCopy(ip->grf, sx + count, sy, sx, sy,
248 ip->cols - (sx + count), 1);
249 RZ3AlphaErase(ip->grf, ip->cols - count, sy, count, 1);
251 #ifndef RETINA_SPEED_HACK
252 rh_cursor(ip, !ERASE_CURSOR);
253 #endif
255 #endif /* NGRFRH */