xref: /netbsd-src/sys/dev/hpc/pckbd_encode.c (revision 95e1ffb15694e54f29f8baaa4232152b703c2a5a)
1*95e1ffb1Schristos /*	$NetBSD: pckbd_encode.c,v 1.4 2005/12/11 12:21:22 christos Exp $	*/
2659f65e0Such 
3659f65e0Such /*-
4659f65e0Such  * Copyright (c) 2000 TAKEMRUA, Shin All rights reserved.
5659f65e0Such  *
6659f65e0Such  * Redistribution and use in source and binary forms, with or without
7659f65e0Such  * modification, are permitted provided that the following conditions
8659f65e0Such  * are met:
9659f65e0Such  * 1. Redistributions of source code must retain the above copyright
10659f65e0Such  *    notice, this list of conditions and the following disclaimer.
11659f65e0Such  * 2. Redistributions in binary form must reproduce the above copyright
12659f65e0Such  *    notice, this list of conditions and the following disclaimer in the
13659f65e0Such  *    documentation and/or other materials provided with the distribution.
14659f65e0Such  * 3. All advertising materials mentioning features or use of this software
15659f65e0Such  *    must display the following acknowledgement:
16659f65e0Such  *	This product includes software developed by the PocketBSD project
17659f65e0Such  *	and its contributors.
18659f65e0Such  * 4. Neither the name of the project nor the names of its contributors
19659f65e0Such  *    may be used to endorse or promote products derived from this software
20659f65e0Such  *    without specific prior written permission.
21659f65e0Such  *
22659f65e0Such  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23659f65e0Such  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24659f65e0Such  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25659f65e0Such  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26659f65e0Such  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27659f65e0Such  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28659f65e0Such  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29659f65e0Such  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30659f65e0Such  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31659f65e0Such  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32659f65e0Such  * SUCH DAMAGE.
33659f65e0Such  *
34659f65e0Such  */
35659f65e0Such 
36b84f53efSlukem #include <sys/cdefs.h>
37*95e1ffb1Schristos __KERNEL_RCSID(0, "$NetBSD: pckbd_encode.c,v 1.4 2005/12/11 12:21:22 christos Exp $");
38b84f53efSlukem 
39659f65e0Such #include "opt_wsdisplay_compat.h"
40659f65e0Such 
41659f65e0Such #ifdef WSDISPLAY_COMPAT_RAWKBD
42659f65e0Such #include <sys/param.h>
43659f65e0Such #include <dev/wscons/wsconsio.h>
44dff5222dSbjh21 #include <dev/pckbport/pckbdreg.h>
45659f65e0Such #include <dev/hpc/pckbd_encode.h>
46659f65e0Such 
47659f65e0Such /*
48659f65e0Such  * pckbd_encode() is inverse function of pckbd_decode() in dev/pckbc/pckbd.c.
49659f65e0Such  */
50659f65e0Such int
pckbd_encode(u_int type,int datain,u_char * dataout)51659f65e0Such pckbd_encode(u_int type, int datain, u_char *dataout)
52659f65e0Such {
53659f65e0Such 	int res;
54659f65e0Such 	u_char updown;
55659f65e0Such 
56659f65e0Such 	res = 0;
57659f65e0Such 	updown = (type == WSCONS_EVENT_KEY_UP) ? 0x80 : 0;
58659f65e0Such 
59659f65e0Such 	/* 0x7f means BREAK key */
60659f65e0Such 	if (datain == 0x7f) {
61659f65e0Such 		dataout[res++] = KBR_EXTENDED1;
62659f65e0Such 		dataout[res++] = (0x1d | updown);
63659f65e0Such 		datain = 0x45;
64659f65e0Such 	}
65659f65e0Such 
66659f65e0Such  	/* extended keys */
67659f65e0Such 	if (datain & 0x80) {
68659f65e0Such 		dataout[res++] = KBR_EXTENDED0;
69659f65e0Such 		datain &= 0x7f;
70659f65e0Such 	}
71659f65e0Such 
72659f65e0Such 	dataout[res++] = (datain | updown);
73659f65e0Such 
74659f65e0Such 	return (res);
75659f65e0Such }
76659f65e0Such #endif /* WSDISPLAY_COMPAT_RAWKBD */
77