xref: /netbsd/sys/arch/amiga/dev/ite_rh.c (revision 6550d01e)
1 /*	$NetBSD: ite_rh.c,v 1.13 2009/10/26 19:16:54 cegger 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 
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: ite_rh.c,v 1.13 2009/10/26 19:16:54 cegger Exp $");
37 
38 #include "grfrh.h"
39 #if NGRFRH > 0
40 
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>
55 
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
60 
61 /*
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.
66  */
67 int
68 grfrh_cnprobe(void)
69 {
70 	static int done;
71 	int rv;
72 
73 	if (done == 0)
74 		rv = CN_INTERNAL;
75 	else
76 		rv = CN_NORMAL;
77 	done = 1;
78 	return(rv);
79 }
80 
81 
82 void
83 grfrh_iteinit(struct grf_softc *gp)
84 {
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;
91 }
92 
93 
94 void
95 rh_init(struct ite_softc *ip)
96 {
97 	struct MonDef *md;
98 
99 #if 0 /* Not in ite_rt.c - DC */
100 	if (ip->grf == 0)
101 		ip->grf = &grf_softc[ip - ite_softc];
102 #endif
103 
104 	ip->priv = ip->grf->g_data;
105 	md = (struct MonDef *) ip->priv;
106 
107 	ip->cols = md->TX;
108 	ip->rows = md->TY;
109 }
110 
111 
112 void
113 rh_cursor(struct ite_softc *ip, 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(struct ite_softc *ip, int top, int bottom, int lines)
148 {
149 
150 	/* do some bounds-checking here.. */
151 	if (top >= bottom)
152 		return;
153 
154 	if (top + lines >= bottom) {
155 		RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
156 		return;
157 	}
158 
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);
161 }
162 
163 
164 static void
165 screen_down (struct ite_softc *ip, int top, int bottom, int lines)
166 {
167 
168 	/* do some bounds-checking here.. */
169 	if (top >= bottom)
170 		return;
171 
172 	if (top + lines >= bottom) {
173 		RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
174 		return;
175 	}
176 
177 	RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
178 	RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
179 }
180 #endif	/* RETINA_SPEED_HACK */
181 
182 
183 void
184 rh_deinit(struct ite_softc *ip)
185 {
186 	ip->flags &= ~ITE_INITED;
187 }
188 
189 
190 void
191 rh_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
192 {
193 	volatile u_char * fb = ip->grf->g_fbkva;
194 	register u_char attr;
195 
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;
200 
201 	fb += 4 * (dy * ip->cols + dx);
202 	*fb++ = c; *fb = attr;
203 }
204 
205 
206 void
207 rh_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
208 {
209 	RZ3AlphaErase (ip->grf, sx, sy, w, h);
210 }
211 
212 
213 /*
214  * RETINA_SPEED_HACK code seems to work on some boards and on others
215  * it causes text to smear horizontally
216  */
217 void
218 rh_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
219 {
220 #ifndef	RETINA_SPEED_HACK
221 	u_long *fb = (u_long *)__UNVOLATILE(ip->grf->g_fbkva);
222 #endif
223 
224 	rh_cursor(ip, ERASE_CURSOR);
225 
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);
250 	}
251 #ifndef	RETINA_SPEED_HACK
252 	rh_cursor(ip, !ERASE_CURSOR);
253 #endif
254 }
255 #endif /* NGRFRH */
256