1 /* $NetBSD: ite_rh.c,v 1.12 2009/03/18 17:06:42 cegger Exp $ */
4 * Copyright (c) 1994 Markus Wild
5 * Copyright (c) 1994 Lutz Vieweg
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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 $");
41 #include <sys/param.h>
44 #include <sys/device.h>
45 #include <sys/ioctl.h>
47 #include <sys/systm.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);
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
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
;
95 rh_init(struct ite_softc
*ip
)
99 #if 0 /* Not in ite_rt.c - DC */
101 ip
->grf
= &grf_softc
[ip
- ite_softc
];
104 ip
->priv
= ip
->grf
->g_data
;
105 md
= (struct MonDef
*) ip
->priv
;
113 rh_cursor(struct ite_softc
*ip
, int flag
)
116 volatile u_char
*ba
= ip
->grf
->g_regkva
;
119 if (flag
== START_CURSOROPT
|| flag
== END_CURSOROPT
)
122 if (flag
== ERASE_CURSOR
) {
125 WCrt (ba
, CRT_ID_CURSOR_START
,
126 RCrt (ba
, CRT_ID_CURSOR_START
) | 0x20);
129 int pos
= ip
->curx
+ ip
->cury
* ip
->cols
;
131 /* make sure to enable cursor */
132 WCrt (ba
, CRT_ID_CURSOR_START
,
133 RCrt (ba
, CRT_ID_CURSOR_START
) & ~0x20);
136 /* and position it */
137 RZ3SetCursorPos (ip
->grf
, pos
);
139 ip
->cursorx
= ip
->curx
;
140 ip
->cursory
= ip
->cury
;
145 #ifdef RETINA_SPEED_HACK
147 screen_up(struct ite_softc
*ip
, int top
, int bottom
, int lines
)
150 /* do some bounds-checking here.. */
154 if (top
+ lines
>= bottom
) {
155 RZ3AlphaErase(ip
->grf
, 0, top
, bottom
- top
, ip
->cols
);
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
);
165 screen_down (struct ite_softc
*ip
, int top
, int bottom
, int lines
)
168 /* do some bounds-checking here.. */
172 if (top
+ lines
>= bottom
) {
173 RZ3AlphaErase(ip
->grf
, 0, top
, bottom
- top
, ip
->cols
);
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 */
184 rh_deinit(struct ite_softc
*ip
)
186 ip
->flags
&= ~ITE_INITED
;
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
;
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
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
);
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
);
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
);
234 } else if (dir
== SCROLL_DOWN
) {
235 #ifdef RETINA_SPEED_HACK
236 screen_down(ip
, sy
, ip
->bottom_margin
, count
);
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
);
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);
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
);