1 /* $NetBSD: wsemul_dumb.c,v 1.13 2006/10/12 01:32:06 christos Exp $ */
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: wsemul_dumb.c,v 1.13 2006/10/12 01:32:06 christos Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/malloc.h>
40 #include <sys/fcntl.h>
42 #include <dev/wscons/wsconsio.h>
43 #include <dev/wscons/wsdisplayvar.h>
44 #include <dev/wscons/wsemulvar.h>
45 #include <dev/wscons/ascii.h>
47 void *wsemul_dumb_cnattach(const struct wsscreen_descr
*, void *,
49 void *wsemul_dumb_attach(int console
, const struct wsscreen_descr
*,
50 void *, int, int, void *, long);
51 void wsemul_dumb_output(void *cookie
, const u_char
*data
, u_int count
, int);
52 int wsemul_dumb_translate(void *cookie
, keysym_t
, const char **);
53 void wsemul_dumb_detach(void *cookie
, u_int
*crowp
, u_int
*ccolp
);
54 void wsemul_dumb_resetop(void *, enum wsemul_resetops
);
56 const struct wsemul_ops wsemul_dumb_ops
= {
61 wsemul_dumb_translate
,
64 NULL
, /* getmsgattrs */
65 NULL
, /* setmsgattrs */
68 struct wsemul_dumb_emuldata
{
69 const struct wsdisplay_emulops
*emulops
;
72 u_int nrows
, ncols
, crow
, ccol
;
76 struct wsemul_dumb_emuldata wsemul_dumb_console_emuldata
;
79 wsemul_dumb_cnattach(const struct wsscreen_descr
*type
, void *cookie
,
80 int ccol
, int crow
, long defattr
)
82 struct wsemul_dumb_emuldata
*edp
;
84 edp
= &wsemul_dumb_console_emuldata
;
86 edp
->emulops
= type
->textops
;
87 edp
->emulcookie
= cookie
;
88 edp
->nrows
= type
->nrows
;
89 edp
->ncols
= type
->ncols
;
92 edp
->defattr
= defattr
;
99 wsemul_dumb_attach(int console
, const struct wsscreen_descr
*type
,
100 void *cookie
, int ccol
, int crow
, void *cbcookie
, long defattr
)
102 struct wsemul_dumb_emuldata
*edp
;
105 edp
= &wsemul_dumb_console_emuldata
;
107 edp
= malloc(sizeof *edp
, M_DEVBUF
, M_WAITOK
);
109 edp
->emulops
= type
->textops
;
110 edp
->emulcookie
= cookie
;
111 edp
->nrows
= type
->nrows
;
112 edp
->ncols
= type
->ncols
;
115 edp
->defattr
= defattr
;
118 edp
->cbcookie
= cbcookie
;
124 wsemul_dumb_output(void *cookie
, const u_char
*data
, u_int count
,
127 struct wsemul_dumb_emuldata
*edp
= cookie
;
132 (*edp
->emulops
->cursor
)(edp
->emulcookie
, 0, edp
->crow
, edp
->ccol
);
133 while (count
-- > 0) {
137 wsdisplay_emulbell(edp
->cbcookie
);
150 n
= min(8 - (edp
->ccol
& 7),
151 edp
->ncols
- edp
->ccol
- 1);
152 (*edp
->emulops
->erasecols
)(edp
->emulcookie
,
153 edp
->crow
, edp
->ccol
, n
, edp
->defattr
);
158 (*edp
->emulops
->eraserows
)(edp
->emulcookie
, 0,
159 edp
->nrows
, edp
->defattr
);
170 (*edp
->emulops
->putchar
)(edp
->emulcookie
, edp
->crow
,
171 edp
->ccol
, c
, edp
->defattr
);
174 /* if cur col is still on cur line, done. */
175 if (edp
->ccol
< edp
->ncols
)
178 /* wrap the column around. */
184 /* if the cur line isn't the last, incr and leave. */
185 if (edp
->crow
< edp
->nrows
- 1) {
189 n
= 1; /* number of lines to scroll */
190 (*edp
->emulops
->copyrows
)(edp
->emulcookie
, n
, 0,
192 (*edp
->emulops
->eraserows
)(edp
->emulcookie
,
193 edp
->nrows
- n
, n
, edp
->defattr
);
199 (*edp
->emulops
->cursor
)(edp
->emulcookie
, 1, edp
->crow
, edp
->ccol
);
203 wsemul_dumb_translate(void *cookie
, keysym_t in
,
210 wsemul_dumb_detach(void *cookie
, u_int
*crowp
, u_int
*ccolp
)
212 struct wsemul_dumb_emuldata
*edp
= cookie
;
216 if (edp
!= &wsemul_dumb_console_emuldata
)
221 wsemul_dumb_resetop(void *cookie
, enum wsemul_resetops op
)
223 struct wsemul_dumb_emuldata
*edp
= cookie
;
226 case WSEMUL_CLEARSCREEN
:
227 (*edp
->emulops
->eraserows
)(edp
->emulcookie
, 0, edp
->nrows
,
229 edp
->ccol
= edp
->crow
= 0;
230 (*edp
->emulops
->cursor
)(edp
->emulcookie
, 1, 0, 0);