1 /* $OpenBSD: kbd.c,v 1.2 2023/01/10 17:10:57 miod Exp $ */
2 /* $NetBSD: kbd.c,v 1.1 2013/01/05 17:44:24 tsutsui Exp $ */
3
4 /*
5 * Copyright (c) 1992 OMRON Corporation.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * OMRON Corporation.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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 the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kbd.c 8.1 (Berkeley) 6/10/93
39 */
40 /*
41 * Copyright (c) 1992, 1993
42 * The Regents of the University of California. All rights reserved.
43 *
44 * This code is derived from software contributed to Berkeley by
45 * OMRON Corporation.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)kbd.c 8.1 (Berkeley) 6/10/93
72 */
73
74 /*
75 * kbd.c -- key-code decoding routine
76 * by A.Fujita, Dec-12-1992
77 */
78
79 #include <sys/param.h>
80 #include <luna88k/stand/boot/samachdep.h>
81 #include <luna88k/stand/boot/kbdreg.h>
82
83 const struct kbd_keymap kbd_keymap[] = {
84 { KC_IGNORE, { 0, 0 } }, /* 0 [0x00] */
85 { KC_IGNORE, { 0, 0 } }, /* 1 [0x01] */
86 { KC_IGNORE, { 0, 0 } }, /* 2 [0x02] */
87 { KC_IGNORE, { 0, 0 } }, /* 3 [0x03] */
88 { KC_IGNORE, { 0, 0 } }, /* 4 [0x04] */
89 { KC_IGNORE, { 0, 0 } }, /* 5 [0x05] */
90 { KC_IGNORE, { 0, 0 } }, /* 6 [0x06] */
91 { KC_IGNORE, { 0, 0 } }, /* 7 [0x07] */
92 { KC_IGNORE, { 0, 0 } }, /* 8 [0x08] */
93 { KC_CODE, { 0x09, 0x09 } }, /* 9 [0x09] TAB */
94 { KC_SHIFT, { KS_CTRL, KS_CTRL } }, /* 10 [0x0A] CTRL */
95 { KC_IGNORE, { 0, 0 } }, /* 11 [0x0B] */
96 { KC_SHIFT, { KS_SHIFT, KS_SHIFT } }, /* 12 [0x0C] SHIFT */
97 { KC_SHIFT, { KS_SHIFT, KS_SHIFT } }, /* 13 [0x0D] SHIFT */
98 { KC_IGNORE, { 0, 0 } }, /* 14 [0x0E] */
99 { KC_SHIFT, { KS_META, KS_META } }, /* 15 [0x0F] META */
100 { KC_CODE, { 0x1B, 0x1B } }, /* 16 [0x10] ESC */
101 { KC_CODE, { 0x08, 0x08 } }, /* 17 [0x11] BS */
102 { KC_CODE, { 0x0D, 0x0D } }, /* 18 [0x12] CR */
103 { KC_IGNORE, { 0, 0 } }, /* 19 [0x13] */
104 { KC_CODE, { 0x20, 0x20 } }, /* 20 [0x14] SP */
105 { KC_CODE, { 0x7F, 0x7F } }, /* 21 [0x15] DEL */
106 { KC_IGNORE, { 0, 0 } }, /* 22 [0x16] */
107 { KC_IGNORE, { 0, 0 } }, /* 23 [0x17] */
108 { KC_IGNORE, { 0, 0 } }, /* 24 [0x18] */
109 { KC_IGNORE, { 0, 0 } }, /* 25 [0x19] */
110 { KC_IGNORE, { 0, 0 } }, /* 26 [0x1A] */
111 { KC_IGNORE, { 0, 0 } }, /* 27 [0x1B] */
112 { KC_IGNORE, { 0, 0 } }, /* 28 [0x1C] */
113 { KC_IGNORE, { 0, 0 } }, /* 29 [0x1D] */
114 { KC_IGNORE, { 0, 0 } }, /* 30 [0x1E] */
115 { KC_IGNORE, { 0, 0 } }, /* 31 [0x1F] */
116 { KC_IGNORE, { 0, 0 } }, /* 32 [0x20] */
117 { KC_IGNORE, { 0, 0 } }, /* 33 [0x21] */
118 { KC_CODE, { 0x31, 0x21 } }, /* 34 [0x22] 1 */
119 { KC_CODE, { 0x32, 0x22 } }, /* 35 [0x23] 2 */
120 { KC_CODE, { 0x33, 0x23 } }, /* 36 [0x24] 3 */
121 { KC_CODE, { 0x34, 0x24 } }, /* 37 [0x25] 4 */
122 { KC_CODE, { 0x35, 0x25 } }, /* 38 [0x26] 5 */
123 { KC_CODE, { 0x36, 0x26 } }, /* 39 [0x27] 6 */
124 { KC_CODE, { 0x37, 0x27 } }, /* 40 [0x28] 7 */
125 { KC_CODE, { 0x38, 0x28 } }, /* 41 [0x29] 8 */
126 { KC_CODE, { 0x39, 0x29 } }, /* 42 [0x2A] 9 */
127 { KC_CODE, { 0x30, 0x30 } }, /* 43 [0x2B] 0 */
128 { KC_CODE, { 0x2D, 0x3D } }, /* 44 [0x2C] - */
129 { KC_CODE, { 0x5E, 0x7E } }, /* 45 [0x2D] ^ */
130 { KC_CODE, { 0x5C, 0x7C } }, /* 46 [0x2E] \ */
131 { KC_IGNORE, { 0, 0 } }, /* 47 [0x2F] */
132 { KC_IGNORE, { 0, 0 } }, /* 48 [0x30] */
133 { KC_IGNORE, { 0, 0 } }, /* 49 [0x31] */
134 { KC_CODE, { 0x71, 0x51 } }, /* 50 [0x32] q */
135 { KC_CODE, { 0x77, 0x57 } }, /* 51 [0x33] w */
136 { KC_CODE, { 0x65, 0x45 } }, /* 52 [0x34] e */
137 { KC_CODE, { 0x72, 0x52 } }, /* 53 [0x35] r */
138 { KC_CODE, { 0x74, 0x54 } }, /* 54 [0x36] t */
139 { KC_CODE, { 0x79, 0x59 } }, /* 55 [0x37] y */
140 { KC_CODE, { 0x75, 0x55 } }, /* 56 [0x38] u */
141 { KC_CODE, { 0x69, 0x49 } }, /* 57 [0x39] i */
142 { KC_CODE, { 0x6F, 0x4F } }, /* 58 [0x3A] o */
143 { KC_CODE, { 0x70, 0x50 } }, /* 59 [0x3B] p */
144 { KC_CODE, { 0x40, 0x60 } }, /* 60 [0x3C] @ */
145 { KC_CODE, { 0x5B, 0x7B } }, /* 61 [0x3D] [ */
146 { KC_IGNORE, { 0, 0 } }, /* 62 [0x3E] */
147 { KC_IGNORE, { 0, 0 } }, /* 63 [0x3F] */
148 { KC_IGNORE, { 0, 0 } }, /* 64 [0x40] */
149 { KC_IGNORE, { 0, 0 } }, /* 65 [0x41] */
150 { KC_CODE, { 0x61, 0x41 } }, /* 66 [0x42] a */
151 { KC_CODE, { 0x73, 0x53 } }, /* 67 [0x43] s */
152 { KC_CODE, { 0x64, 0x44 } }, /* 68 [0x44] d */
153 { KC_CODE, { 0x66, 0x46 } }, /* 69 [0x45] f */
154 { KC_CODE, { 0x67, 0x47 } }, /* 70 [0x46] g */
155 { KC_CODE, { 0x68, 0x48 } }, /* 71 [0x47] h */
156 { KC_CODE, { 0x6A, 0x4A } }, /* 72 [0x48] j */
157 { KC_CODE, { 0x6B, 0x4B } }, /* 73 [0x49] k */
158 { KC_CODE, { 0x6C, 0x4C } }, /* 74 [0x4A] l */
159 { KC_CODE, { 0x3B, 0x2B } }, /* 75 [0x4B] ; */
160 { KC_CODE, { 0x3A, 0x2A } }, /* 76 [0x4C] : */
161 { KC_CODE, { 0x5D, 0x7D } }, /* 77 [0x4D] ] */
162 { KC_IGNORE, { 0, 0 } }, /* 78 [0x4E] */
163 { KC_IGNORE, { 0, 0 } }, /* 79 [0x4F] */
164 { KC_IGNORE, { 0, 0 } }, /* 80 [0x50] */
165 { KC_IGNORE, { 0, 0 } }, /* 81 [0x51] */
166 { KC_CODE, { 0x7A, 0x5A } }, /* 82 [0x52] z */
167 { KC_CODE, { 0x78, 0x58 } }, /* 83 [0x53] x */
168 { KC_CODE, { 0x63, 0x43 } }, /* 84 [0x54] c */
169 { KC_CODE, { 0x76, 0x56 } }, /* 85 [0x55] v */
170 { KC_CODE, { 0x62, 0x42 } }, /* 86 [0x56] b */
171 { KC_CODE, { 0x6E, 0x4E } }, /* 87 [0x57] n */
172 { KC_CODE, { 0x6D, 0x4D } }, /* 88 [0x58] m */
173 { KC_CODE, { 0x2C, 0x3C } }, /* 89 [0x59] , */
174 { KC_CODE, { 0x2E, 0x3E } }, /* 90 [0x5A] . */
175 { KC_CODE, { 0x2F, 0x3F } }, /* 91 [0x5B] / */
176 { KC_CODE, { 0x5F, 0x5F } }, /* 92 [0x5C] _ */
177 { KC_IGNORE, { 0, 0 } }, /* 93 [0x5D] */
178 { KC_IGNORE, { 0, 0 } }, /* 94 [0x5E] */
179 { KC_IGNORE, { 0, 0 } }, /* 95 [0x5F] */
180 { KC_IGNORE, { 0, 0 } }, /* 96 [0x60] */
181 { KC_IGNORE, { 0, 0 } }, /* 97 [0x61] */
182 { KC_IGNORE, { 0, 0 } }, /* 98 [0x62] */
183 { KC_IGNORE, { 0, 0 } }, /* 99 [0x63] */
184 { KC_IGNORE, { 0, 0 } }, /* 100 [0x64] */
185 { KC_IGNORE, { 0, 0 } }, /* 101 [0x65] */
186 { KC_IGNORE, { 0, 0 } }, /* 102 [0x66] */
187 { KC_IGNORE, { 0, 0 } }, /* 103 [0x67] */
188 { KC_IGNORE, { 0, 0 } }, /* 104 [0x68] */
189 { KC_IGNORE, { 0, 0 } }, /* 105 [0x69] */
190 { KC_IGNORE, { 0, 0 } }, /* 106 [0x6A] */
191 { KC_IGNORE, { 0, 0 } }, /* 107 [0x6B] */
192 { KC_IGNORE, { 0, 0 } }, /* 108 [0x6C] */
193 { KC_IGNORE, { 0, 0 } }, /* 109 [0x6D] */
194 { KC_IGNORE, { 0, 0 } }, /* 110 [0x6E] */
195 { KC_IGNORE, { 0, 0 } }, /* 111 [0x6F] */
196 { KC_IGNORE, { 0, 0 } }, /* 112 [0x70] */
197 { KC_IGNORE, { 0, 0 } }, /* 113 [0x71] */
198 { KC_IGNORE, { 0, 0 } }, /* 114 [0x72] */
199 { KC_IGNORE, { 0, 0 } }, /* 115 [0x73] */
200 { KC_IGNORE, { 0, 0 } }, /* 116 [0x74] */
201 { KC_IGNORE, { 0, 0 } }, /* 117 [0x75] */
202 { KC_IGNORE, { 0, 0 } }, /* 118 [0x76] */
203 { KC_IGNORE, { 0, 0 } }, /* 119 [0x77] */
204 { KC_IGNORE, { 0, 0 } }, /* 120 [0x78] */
205 { KC_IGNORE, { 0, 0 } }, /* 121 [0x79] */
206 { KC_IGNORE, { 0, 0 } }, /* 122 [0x7A] */
207 { KC_IGNORE, { 0, 0 } }, /* 123 [0x7B] */
208 { KC_IGNORE, { 0, 0 } }, /* 124 [0x7C] */
209 { KC_IGNORE, { 0, 0 } }, /* 125 [0x7D] */
210 { KC_IGNORE, { 0, 0 } }, /* 126 [0x7E] */
211 { KC_IGNORE, { 0, 0 } }, /* 127 [0x7F] */
212 };
213
214 int shift_flag = 0;
215 int ctrl_flag = 0;
216 int meta_flag = 0;
217
218 int
kbd_decode(u_char code)219 kbd_decode(u_char code)
220 {
221 unsigned int c, updown = 0;
222
223 if (code & 0x80)
224 updown = 1;
225
226 code &= 0x7F;
227
228 c = kbd_keymap[code].km_type;
229
230 if (c == KC_IGNORE)
231 return(KC_IGNORE);
232
233 if ((c == KC_CODE) && updown)
234 return(KC_IGNORE);
235
236 if (c == KC_SHIFT) {
237 switch(kbd_keymap[code].km_code[0]) {
238
239 case KS_SHIFT:
240 shift_flag = 1 - updown;
241 break;
242
243 case KS_CTRL:
244 ctrl_flag = 1 - updown;
245 break;
246
247 case KS_META:
248 meta_flag = 1 - updown;
249 break;
250 }
251
252 return(KC_IGNORE);
253 }
254
255 if (shift_flag)
256 c = kbd_keymap[code].km_code[1];
257 else
258 c = kbd_keymap[code].km_code[0];
259
260 if (meta_flag)
261 c |= 0x80;
262
263 if (ctrl_flag)
264 c &= 0x1F;
265
266 return(c);
267 }
268