1 /* $NetBSD: ite_cl.c,v 1.10 2009/03/18 17:06:42 cegger Exp $ */
4 * Copyright (c) 1995 Ezra Story
5 * Copyright (c) 1995 Kari Mettinen
6 * Copyright (c) 1994 Markus Wild
7 * Copyright (c) 1994 Lutz Vieweg
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Lutz Vieweg.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "opt_amigacons.h"
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: ite_cl.c,v 1.10 2009/03/18 17:06:42 cegger Exp $");
44 #include <sys/param.h>
47 #include <sys/device.h>
48 #include <sys/ioctl.h>
50 #include <sys/systm.h>
52 #include <machine/cpu.h>
53 #include <amiga/amiga/device.h>
54 #include <amiga/dev/grfioctl.h>
55 #include <amiga/dev/grfvar.h>
56 #include <amiga/dev/grf_clreg.h>
57 #include <amiga/dev/itevar.h>
65 void cl_init(struct ite_softc
*ip
);
66 void cl_cursor(struct ite_softc
*ip
, int flag
);
67 void cl_deinit(struct ite_softc
*ip
);
68 void cl_putc(struct ite_softc
*ip
, int c
, int dy
, int dx
, int mode
);
69 void cl_clear(struct ite_softc
*ip
, int sy
, int sx
, int h
, int w
);
70 void cl_scroll(struct ite_softc
*ip
, int sy
, int sx
, int count
, int dir
);
74 * Called to determine ite status. Because the connection between the
75 * console & ite in this driver is rather intimate, we return CN_DEAD
76 * if the cl_console is not active.
84 if (cl_console
&& (done
== 0))
94 grfcl_iteinit(struct grf_softc
*gp
)
96 gp
->g_iteinit
= cl_init
;
97 gp
->g_itedeinit
= cl_deinit
;
98 gp
->g_iteclear
= cl_clear
;
99 gp
->g_iteputc
= cl_putc
;
100 gp
->g_itescroll
= cl_scroll
;
101 gp
->g_itecursor
= cl_cursor
;
105 cl_init(struct ite_softc
*ip
)
107 struct grfcltext_mode
*md
;
109 ip
->priv
= ip
->grf
->g_data
;
110 md
= (struct grfcltext_mode
*) ip
->priv
;
118 cl_cursor(struct ite_softc
*ip
, int flag
)
120 volatile u_char
*ba
= ip
->grf
->g_regkva
;
124 /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
126 flag
= ip
->curx
+ ip
->cury
* ip
->cols
;
127 WCrt(ba
, CRT_ID_CURSOR_LOC_LOW
, flag
& 0xff);
128 WCrt(ba
, CRT_ID_CURSOR_LOC_HIGH
, flag
>> 8);
129 ip
->cursorx
= ip
->curx
;
130 ip
->cursory
= ip
->cury
;
133 /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
134 case START_CURSOROPT
:
143 cl_deinit(struct ite_softc
*ip
)
145 ip
->flags
&= ~ITE_INITED
;
150 cl_putc(struct ite_softc
*ip
, int c
, int dy
, int dx
, int mode
)
152 volatile unsigned char *ba
= ip
->grf
->g_regkva
;
153 volatile unsigned char *fb
= ip
->grf
->g_fbkva
;
155 volatile unsigned char *cp
;
157 if (ip
->flags
& ITE_INGRF
)
160 attr
=(unsigned char) ((mode
& ATTR_INV
) ? (0x70) : (0x07));
161 if (mode
& ATTR_UL
) attr
= 0x01; /* ???????? */
162 if (mode
& ATTR_BOLD
) attr
|= 0x08;
163 if (mode
& ATTR_BLINK
) attr
|= 0x80;
165 cp
= fb
+ ((dy
* ip
->cols
) + dx
);
166 SetTextPlane(ba
,0x00);
167 *cp
= (unsigned char) c
;
168 SetTextPlane(ba
,0x01);
169 *cp
= (unsigned char) attr
;
173 cl_clear(struct ite_softc
*ip
, int sy
, int sx
, int h
, int w
)
175 /* cl_clear and cl_scroll both rely on ite passing arguments
176 * which describe continuous regions. For a VT200 terminal,
177 * this is safe behavior.
179 unsigned char *src
, *dst
;
180 volatile unsigned char *ba
= ip
->grf
->g_regkva
;
183 if (ip
->flags
& ITE_INGRF
)
186 dst
= (unsigned char*)__UNVOLATILE(ip
->grf
->g_fbkva
) +
187 (sy
* ip
->cols
) + sx
;
188 src
= dst
+ (ip
->rows
*ip
->cols
);
191 SetTextPlane(ba
, 0x00);
192 memcpy(dst
, src
, len
);
193 SetTextPlane(ba
, 0x01);
194 memcpy(dst
, src
, len
);
198 cl_scroll(struct ite_softc
*ip
, int sy
, int sx
, int count
, int dir
)
201 volatile unsigned char *ba
= ip
->grf
->g_regkva
;
203 if (ip
->flags
& ITE_INGRF
)
206 fb
= (unsigned char*)__UNVOLATILE(ip
->grf
->g_fbkva
) + sy
* ip
->cols
;
207 SetTextPlane(ba
, 0x00);
211 memcpy(fb
- (count
* ip
->cols
), fb
,
212 (ip
->bottom_margin
+ 1 - sy
) * ip
->cols
);
215 memcpy(fb
+ (count
* ip
->cols
), fb
,
216 (ip
->bottom_margin
+ 1 - (sy
+ count
)) * ip
->cols
);
219 memcpy(fb
+sx
+count
, fb
+sx
, ip
->cols
- (sx
+ count
));
222 memcpy(fb
+sx
-count
, fb
+sx
, ip
->cols
- sx
);
226 SetTextPlane(ba
, 0x01);
230 memcpy(fb
- (count
* ip
->cols
), fb
,
231 (ip
->bottom_margin
+ 1 - sy
) * ip
->cols
);
234 memcpy(fb
+ (count
* ip
->cols
), fb
,
235 (ip
->bottom_margin
+ 1 - (sy
+ count
)) * ip
->cols
);
238 memcpy(fb
+sx
+count
, fb
+sx
, ip
->cols
- (sx
+ count
));
241 memcpy(fb
+sx
-count
, fb
+sx
, ip
->cols
- sx
);