• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

FreeBSD bhyve keyboard layout patch


Commit MetaInfo

Révision6ef7697d82bf17b355724d59392e910865d1f082 (tree)
l'heure2021-01-24 19:49:31
AuteurKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Message de Log

Put keyboard layout setting file generation tools from FreeBSD VT kbd file for git repository.

Change Summary

Modification

--- /dev/null
+++ b/work/generate_keymap_tools/generate_kbdmap.c
@@ -0,0 +1,568 @@
1+/*-
2+* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3+ *
4+ * Copyright (c) 2020 Koine Yuusuke(koinec) <koinec@users.osdn.me>
5+ * All rights reserved.
6+ *
7+ * Redistribution and use in source and binary forms, with or without
8+ * modification, are permitted provided that the following conditions
9+ * are met:
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+ * SUCH DAMAGE.
27+ */
28+
29+#include<sys/types.h>
30+#include<sys/stat.h>
31+#include<stdio.h>
32+#include<stdlib.h>
33+#include<fcntl.h>
34+#include<unistd.h>
35+#include<string.h>
36+
37+// Dup: 0x41->0x02/0x83, 0x54->0x7f/0x84
38+const uint8_t i8042_detranslation[256] = {
39+ /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
40+ 0, 0x76, 0x16, 0x1E, 0x26, 0x25, 0x2e, 0x36, 0x3d, 0x3e, 0x46, 0x45, 0x4e, 0x55, 0x66, 0x0d,
41+ 0x15, 0x1d, 0x24, 0x2d, 0x2c, 0x35, 0x3c, 0x43, 0x44, 0x4d, 0x54, 0x5b, 0x5a, 0x14, 0x1c, 0x1b,
42+ 0x23, 0x2b, 0x34, 0x33, 0x3b, 0x42, 0x4b, 0x4c, 0x52, 0x0e, 0x12, 0x5d, 0x1a, 0x22, 0x21, 0x2a,
43+ 0x32, 0x31, 0x3a, 0x41, 0x49, 0x4a, 0x59, 0x7c, 0x11, 0x29, 0x58, 0x05, 0x06, 0x04, 0x0c, 0x03,
44+
45+ 0x0b, 0x83, 0x0a, 0x01, 0x09, 0x77, 0x7e, 0x6c, 0x75, 0x7d, 0x7b, 0x6b, 0x73, 0x74, 0x79, 0x69,
46+ 0x72, 0x7a, 0x70, 0x71, 0x7f, 0x60, 0x61, 0x78, 0x07, 0x0f, 0x17, 0x1f, 0x27, 0x2f, 0x37, 0x3f,
47+ 0x47, 0x4f, 0x56, 0x5e, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x57, 0x6f,
48+ 0x13, 0x19, 0x39, 0x51, 0x53, 0x5c, 0x5f, 0x62, 0x63, 0x64, 0x65, 0x67, 0x68, 0x6a, 0x6d, 0x6e,
49+
50+ 0x80, 0x81, 0x82, 0, 0, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
51+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
52+ 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAa, 0xAb, 0xAc, 0xAd, 0xAe, 0xAf,
53+ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBa, 0xBb, 0xBc, 0xBd, 0xBe, 0xBf,
54+
55+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCa, 0xCb, 0xCc, 0xCd, 0xCe, 0xCf,
56+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDa, 0xDb, 0xDc, 0xDd, 0xDe, 0xDf,
57+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEa, 0xEb, 0xEc, 0xEd, 0xEe, 0xEf,
58+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFa, 0xFb, 0xFc, 0xFd, 0xFe, 0xFf
59+};
60+
61+struct kbdmap_define {
62+ char keyname[8];
63+ char lockstate;
64+ uint16_t keysym[3];
65+};
66+
67+struct kbdmap_define kbdmaps[] = {
68+ {"bs", 'O', {0xff08, 0, 0}}, /* Back space */
69+ {"ht", 'O', {0xff09, 0, 0}}, /* Tab */
70+ {"cr", 'O', {0xff0d, 0, 0xff8d}}, /* Return / / Keypad Enter */
71+ {"esc", 'O', {0xff1b, 0, 0}}, /* Escape */
72+ {"lshift", 'O', {0xffe1, 0, 0}}, /* Left shift */
73+ {"rshift", 'O', {0xffe2, 0, 0}}, /* Right shift */
74+ {"lctrl", 'O', {0xffe3, 0, 0}}, /* Left control */
75+ {"ctrl", 'O', {0xffe3, 0, 0}}, /* Left control (alias name) */
76+ {"rctrl", 'O', { 0, 0, 0xffe4}}, /* Right control */
77+ {"lalt", 'O', {0xffe9, 0, 0}}, /* Left alt */
78+ {"alt", 'O', {0xffe9, 0, 0}}, /* Left alt (alias name) */
79+ {"ralt", 'O', { 0, 0, 0xffea}}, /* Right alt */
80+ {"fkey01", 'O', {0xffbe, 0, 0}}, /* F1 */
81+ {"fkey02", 'O', {0xffbf, 0, 0}}, /* F2 */
82+ {"fkey03", 'O', {0xffc0, 0, 0}}, /* F3 */
83+ {"fkey04", 'O', {0xffc1, 0, 0}}, /* F4 */
84+ {"fkey05", 'O', {0xffc2, 0, 0}}, /* F5 */
85+ {"fkey06", 'O', {0xffc3, 0, 0}}, /* F6 */
86+ {"fkey07", 'O', {0xffc4, 0, 0}}, /* F7 */
87+ {"fkey08", 'O', {0xffc5, 0, 0}}, /* F8 */
88+ {"fkey09", 'O', {0xffc6, 0, 0}}, /* F9 */
89+ {"fkey10", 'O', {0xffc7, 0, 0}}, /* F10 */
90+ {"fkey11", 'O', {0xffc8, 0, 0}}, /* F11 */
91+ {"fkey12", 'O', {0xffc9, 0, 0}}, /* F12 */
92+ {"del", 'O', {0xffff, 0, 0}}, /* Del */
93+ {"slock", 'O', {0xff14, 0, 0}}, /* ScrollLock */
94+ {"nlock", 'O', {0xff7f, 0, 0}}, /* NumLock */
95+ {"fkey49", 'N', {0xff95, 0xffb7, 0xff50}}, /* Kyepad home / Keypad 7 / Grey Home */
96+ {"fkey50", 'N', {0xff97, 0xffb8, 0xff52}}, /* Keypad up arrow / Keypad 8 / Grey Up arrow */
97+ {"fkey51", 'N', {0xff9a, 0xffb9, 0xff55}}, /* Keypad PgUp / Keypad 9 / Grey PgUp*/
98+ {"fkey52", 'N', {0xffad, 0, 0}}, /* Keypad minus */
99+ {"fkey53", 'N', {0xff96, 0xffb4, 0xff51}}, /* Keypad left arrow / Keypad 4 / Grey Left Arrow*/
100+ {"fkey54", 'N', {0xffb5, 0, 0}}, /* Keypad 5 */
101+ {"fkey55", 'N', {0xff98, 0xffb6, 0xff53}}, /* Keypad right arrow / Keypad 6 / Grey Right arrow */
102+ {"fkey56", 'N', {0xffab, 0, 0}}, /* Keypad plus */
103+ {"fkey57", 'N', {0xff9c, 0xffb1, 0xff57}}, /* Keypad end / Keypad 1 / Grey End */
104+ {"fkey58", 'N', {0xff99, 0xffb2, 0xff54}}, /* Keypad down arrow / Keypad 2 / Grey Down arrow */
105+ {"fkey59", 'N', {0xff9b, 0xffb3, 0xff56}}, /* Keypad PgDown / Keypad 3 / Grey PgDown */
106+ {"fkey60", 'N', {0xff9e, 0xffb0, 0xff63}}, /* Keypad ins / Keypad 0 / Grey Ins */
107+ {"fkey61", 'N', {0xff9f, 0, 0}}, /* Keypad del */
108+ {"null", 'E', { 0, 0, 0}} /* Array Terminator */
109+
110+ //{"fkey54", '0', {0xff9d, 0, 0}}, /* Keypad empty */
111+ //{"", '0', 0xffaf}, /* Keypad slash */
112+ //{"", '0', 0xffaa}, /* Keypad asterisk */
113+ //{"", '0', 0xffae}, /* Keypad . */
114+ //{"", '0', 0xffe7, XXX}, Left meta */
115+ //{"", '0', 0xffe8, XXX}, Right meta */
116+ //{"", '0', 0xfe03}, /* AltGr */
117+ //{"", '0', 0xffeb}, /* Left Windows */
118+ //{"", '0', 0xffec}, /* Right Windows */
119+};
120+
121+
122+struct keytranslation {
123+ uint16_t keysym;
124+ uint8_t scancode;
125+ uint8_t prefix;
126+ uint8_t mode;
127+ uint8_t uscode;
128+};
129+
130+
131+struct keytranslation keytrans[] = {
132+ /* 0x2* */
133+ { 0x20, 0x29, 0x00, 0xff, 0x29},
134+ { 0x21, 0x16, 0x00, 0xff, 0x16},
135+ { 0x22, 0x52, 0x00, 0xff, 0x52},
136+ { 0x23, 0x26, 0x00, 0xff, 0x26},
137+ { 0x24, 0x25, 0x00, 0xff, 0x25},
138+ { 0x25, 0x2e, 0x00, 0xff, 0x2e},
139+ { 0x26, 0x3d, 0x00, 0xff, 0x3d},
140+ { 0x27, 0x52, 0x00, 0xff, 0x52},
141+ { 0x28, 0x46, 0x00, 0xff, 0x46},
142+ { 0x29, 0x45, 0x00, 0xff, 0x45},
143+ { 0x2a, 0x3e, 0x00, 0xff, 0x3e},
144+ { 0x2b, 0x55, 0x00, 0xff, 0x55},
145+ { 0x2c, 0x41, 0x00, 0xff, 0x41},
146+ { 0x2d, 0x4e, 0x00, 0xff, 0x4e},
147+ { 0x2e, 0x49, 0x00, 0xff, 0x49},
148+ { 0x2f, 0x4a, 0x00, 0xff, 0x4a},
149+ /* 0x3* */
150+ { 0x30, 0x45, 0x00, 0xff, 0x45},
151+ { 0x31, 0x16, 0x00, 0xff, 0x16},
152+ { 0x32, 0x1e, 0x00, 0xff, 0x1e},
153+ { 0x33, 0x26, 0x00, 0xff, 0x26},
154+ { 0x34, 0x25, 0x00, 0xff, 0x25},
155+ { 0x35, 0x2e, 0x00, 0xff, 0x2e},
156+ { 0x36, 0x36, 0x00, 0xff, 0x36},
157+ { 0x37, 0x3d, 0x00, 0xff, 0x3d},
158+ { 0x38, 0x3e, 0x00, 0xff, 0x3e},
159+ { 0x39, 0x46, 0x00, 0xff, 0x46},
160+ { 0x3a, 0x4c, 0x00, 0xff, 0x4c},
161+ { 0x3b, 0x4c, 0x00, 0xff, 0x4c},
162+ { 0x3c, 0x41, 0x00, 0xff, 0x41},
163+ { 0x3d, 0x55, 0x00, 0xff, 0x55},
164+ { 0x3e, 0x49, 0x00, 0xff, 0x49},
165+ { 0x3f, 0x4a, 0x00, 0xff, 0x4a},
166+ /* 0x4* */
167+ { 0x40, 0x1e, 0x00, 0xff, 0x1e},
168+ { 0x41, 0x1c, 0x00, 0xff, 0x1c},
169+ { 0x42, 0x32, 0x00, 0xff, 0x32},
170+ { 0x43, 0x21, 0x00, 0xff, 0x21},
171+ { 0x44, 0x23, 0x00, 0xff, 0x23},
172+ { 0x45, 0x24, 0x00, 0xff, 0x24},
173+ { 0x46, 0x2b, 0x00, 0xff, 0x2b},
174+ { 0x47, 0x34, 0x00, 0xff, 0x34},
175+ { 0x48, 0x33, 0x00, 0xff, 0x33},
176+ { 0x49, 0x43, 0x00, 0xff, 0x43},
177+ { 0x4a, 0x3b, 0x00, 0xff, 0x3b},
178+ { 0x4b, 0x42, 0x00, 0xff, 0x42},
179+ { 0x4c, 0x4b, 0x00, 0xff, 0x4b},
180+ { 0x4d, 0x3a, 0x00, 0xff, 0x3a},
181+ { 0x4e, 0x31, 0x00, 0xff, 0x31},
182+ { 0x4f, 0x44, 0x00, 0xff, 0x44},
183+ /* 0x5* */
184+ { 0x50, 0x4d, 0x00, 0xff, 0x4d},
185+ { 0x51, 0x15, 0x00, 0xff, 0x15},
186+ { 0x52, 0x2d, 0x00, 0xff, 0x2d},
187+ { 0x53, 0x1b, 0x00, 0xff, 0x1b},
188+ { 0x54, 0x2c, 0x00, 0xff, 0x2c},
189+ { 0x55, 0x3c, 0x00, 0xff, 0x3c},
190+ { 0x56, 0x2a, 0x00, 0xff, 0x2a},
191+ { 0x57, 0x1d, 0x00, 0xff, 0x1d},
192+ { 0x58, 0x22, 0x00, 0xff, 0x22},
193+ { 0x59, 0x35, 0x00, 0xff, 0x35},
194+ { 0x5a, 0x1a, 0x00, 0xff, 0x1a},
195+ { 0x5b, 0x54, 0x00, 0xff, 0x54},
196+ { 0x5c, 0x5d, 0x00, 0xff, 0x5d},
197+ { 0x5d, 0x5b, 0x00, 0xff, 0x5b},
198+ { 0x5e, 0x36, 0x00, 0xff, 0x36},
199+ { 0x5f, 0x4e, 0x00, 0xff, 0x4e},
200+ /* 0x6* */
201+ { 0x60, 0x0e, 0x00, 0xff, 0x0e},
202+ { 0x61, 0x1c, 0x00, 0xff, 0x1c},
203+ { 0x62, 0x32, 0x00, 0xff, 0x32},
204+ { 0x63, 0x21, 0x00, 0xff, 0x21},
205+ { 0x64, 0x23, 0x00, 0xff, 0x23},
206+ { 0x65, 0x24, 0x00, 0xff, 0x24},
207+ { 0x66, 0x2b, 0x00, 0xff, 0x2b},
208+ { 0x67, 0x34, 0x00, 0xff, 0x34},
209+ { 0x68, 0x33, 0x00, 0xff, 0x33},
210+ { 0x69, 0x43, 0x00, 0xff, 0x43},
211+ { 0x6a, 0x3b, 0x00, 0xff, 0x3b},
212+ { 0x6b, 0x42, 0x00, 0xff, 0x42},
213+ { 0x6c, 0x4b, 0x00, 0xff, 0x4b},
214+ { 0x6d, 0x3a, 0x00, 0xff, 0x3a},
215+ { 0x6e, 0x31, 0x00, 0xff, 0x31},
216+ { 0x6f, 0x44, 0x00, 0xff, 0x44},
217+ /* 0x7* */
218+ { 0x70, 0x4d, 0x00, 0xff, 0x4d},
219+ { 0x71, 0x15, 0x00, 0xff, 0x15},
220+ { 0x72, 0x2d, 0x00, 0xff, 0x2d},
221+ { 0x73, 0x1b, 0x00, 0xff, 0x1b},
222+ { 0x74, 0x2c, 0x00, 0xff, 0x2c},
223+ { 0x75, 0x3c, 0x00, 0xff, 0x3c},
224+ { 0x76, 0x2a, 0x00, 0xff, 0x2a},
225+ { 0x77, 0x1d, 0x00, 0xff, 0x1d},
226+ { 0x78, 0x22, 0x00, 0xff, 0x22},
227+ { 0x79, 0x35, 0x00, 0xff, 0x35},
228+ { 0x7a, 0x1a, 0x00, 0xff, 0x1a},
229+ { 0x7b, 0x54, 0x00, 0xff, 0x54},
230+ { 0x7c, 0x5d, 0x00, 0xff, 0x5d},
231+ { 0x7d, 0x5b, 0x00, 0xff, 0x5b},
232+ { 0x7e, 0x0e, 0x00, 0xff, 0x0e},
233+ /*{ 0x7f, 0x00, 0x00, 0xff, 0x00}, */
234+
235+ /* Functional Key --------------- */
236+ {0xff08, 0x66, 0x00, 0xff, 0x66}, /* Back space */
237+ {0xff09, 0x0d, 0x00, 0xff, 0x0d}, /* Tab */
238+ {0xff0d, 0x5a, 0x00, 0xff, 0x5a}, /* Return */
239+ {0xff1b, 0x76, 0x00, 0xff, 0x76}, /* Escape */
240+ {0xff50, 0x6c, 0xe0, 0xff, 0x6c}, /* Home */
241+ {0xff51, 0x6b, 0xe0, 0xff, 0x6b}, /* Left arrow */
242+ {0xff52, 0x75, 0xe0, 0xff, 0x75}, /* Up arrow */
243+ {0xff53, 0x74, 0xe0, 0xff, 0x74}, /* Right arrow */
244+ {0xff54, 0x72, 0xe0, 0xff, 0x72}, /* Down arrow */
245+ {0xff55, 0x7d, 0xe0, 0xff, 0x7d}, /* PgUp */
246+ {0xff56, 0x7a, 0xe0, 0xff, 0x7a}, /* PgDown */
247+ {0xff57, 0x69, 0xe0, 0xff, 0x69}, /* End */
248+ {0xff63, 0x70, 0xe0, 0xff, 0x70}, /* Ins */
249+ {0xff8d, 0x5a, 0xe0, 0xff, 0x5a}, /* Keypad Enter */
250+ {0xffe1, 0x12, 0x00, 0xff, 0x12}, /* Left shift */
251+ {0xffe2, 0x59, 0x00, 0xff, 0x59}, /* Right shift */
252+ {0xffe3, 0x14, 0x00, 0xff, 0x14}, /* Left control */
253+ {0xffe4, 0x14, 0xe0, 0xff, 0x14}, /* Right control */
254+ /* {0xffe7, XXX}, Left meta */
255+ /* {0xffe8, XXX}, Right meta */
256+ {0xffe9, 0x11, 0x00, 0xff, 0x11}, /* Left alt */
257+ {0xfe03, 0x11, 0xe0, 0xff, 0x11}, /* AltGr */
258+ {0xffea, 0x11, 0xe0, 0xff, 0x11}, /* Right alt */
259+ {0xffeb, 0x1f, 0xe0, 0xff, 0x1f}, /* Left Windows */
260+ {0xffec, 0x27, 0xe0, 0xff, 0x27}, /* Right Windows */
261+ {0xffbe, 0x05, 0x00, 0xff, 0x05}, /* F1 */
262+ {0xffbf, 0x06, 0x00, 0xff, 0x06}, /* F2 */
263+ {0xffc0, 0x04, 0x00, 0xff, 0x04}, /* F3 */
264+ {0xffc1, 0x0c, 0x00, 0xff, 0x0c}, /* F4 */
265+ {0xffc2, 0x03, 0x00, 0xff, 0x03}, /* F5 */
266+ {0xffc3, 0x0b, 0x00, 0xff, 0x0b}, /* F6 */
267+ {0xffc4, 0x83, 0x00, 0xff, 0x83}, /* F7 */
268+ {0xffc5, 0x0a, 0x00, 0xff, 0x0a}, /* F8 */
269+ {0xffc6, 0x01, 0x00, 0xff, 0x01}, /* F9 */
270+ {0xffc7, 0x09, 0x00, 0xff, 0x09}, /* F10 */
271+ {0xffc8, 0x78, 0x00, 0xff, 0x78}, /* F11 */
272+ {0xffc9, 0x07, 0x00, 0xff, 0x07}, /* F12 */
273+ {0xffff, 0x71, 0xe0, 0xff, 0x71}, /* Del */
274+ {0xff14, 0x7e, 0x00, 0xff, 0x7e}, /* ScrollLock */
275+ /* NumLock and Keypads -----------*/
276+ {0xff7f, 0x77, 0x00, 0xff, 0x77}, /* NumLock */
277+ {0xffaf, 0x4a, 0xe0, 0xff, 0x4a}, /* Keypad slash */
278+ {0xffaa, 0x7c, 0x00, 0xff, 0x7c}, /* Keypad asterisk */
279+ {0xffad, 0x7b, 0x00, 0xff, 0x7b}, /* Keypad minus */
280+ {0xffab, 0x79, 0x00, 0xff, 0x79}, /* Keypad plus */
281+ {0xffb7, 0x6c, 0x00, 0xff, 0x6c}, /* Keypad 7 */
282+ {0xff95, 0x6c, 0x00, 0xff, 0x6c}, /* Keypad home */
283+ {0xffb8, 0x75, 0x00, 0xff, 0x75}, /* Keypad 8 */
284+ {0xff97, 0x75, 0x00, 0xff, 0x75}, /* Keypad up arrow */
285+ {0xffb9, 0x7d, 0x00, 0xff, 0x7d}, /* Keypad 9 */
286+ {0xff9a, 0x7d, 0x00, 0xff, 0x7d}, /* Keypad PgUp */
287+ {0xffb4, 0x6b, 0x00, 0xff, 0x6b}, /* Keypad 4 */
288+ {0xff96, 0x6b, 0x00, 0xff, 0x6b}, /* Keypad left arrow */
289+ {0xffb5, 0x73, 0x00, 0xff, 0x73}, /* Keypad 5 */
290+ {0xff9d, 0x73, 0x00, 0xff, 0x73}, /* Keypad empty */
291+ {0xffb6, 0x74, 0x00, 0xff, 0x74}, /* Keypad 6 */
292+ {0xff98, 0x74, 0x00, 0xff, 0x74}, /* Keypad right arrow */
293+ {0xffb1, 0x69, 0x00, 0xff, 0x69}, /* Keypad 1 */
294+ {0xff9c, 0x69, 0x00, 0xff, 0x69}, /* Keypad end */
295+ {0xffb2, 0x72, 0x00, 0xff, 0x72}, /* Keypad 2 */
296+ {0xff99, 0x72, 0x00, 0xff, 0x72}, /* Keypad down arrow */
297+ {0xffb3, 0x7a, 0x00, 0xff, 0x7a}, /* Keypad 3 */
298+ {0xff9b, 0x7a, 0x00, 0xff, 0x7a}, /* Keypad PgDown */
299+ {0xffb0, 0x70, 0x00, 0xff, 0x70}, /* Keypad 0 */
300+ {0xff9e, 0x70, 0x00, 0xff, 0x70}, /* Keypad ins */
301+ {0xffae, 0x71, 0x00, 0xff, 0x71}, /* Keypad . */
302+ {0xff9f, 0x71, 0x00, 0xff, 0x71}, /* Keypad del */
303+ { 0, 0, 0, 0xff, 0} /* Terminator */
304+};
305+
306+
307+int parseline(int *scancode, char keyname[][8], char *lockstate, char *line)
308+{
309+ int cnt;
310+ char *start;
311+
312+ if (NULL == line)
313+ return 1;
314+
315+ if (line[0] == '#')
316+ return 2;
317+
318+ line[5] = '\0';
319+ if (sscanf((line + 2), "%3d", scancode) != 1)
320+ return 3;
321+
322+ //printf(" test %3d: ", *scancode);
323+
324+ for(cnt = 0; cnt < 8; cnt++) {
325+ start = line + 8 + (cnt * 7);
326+ start[6] = '\0';
327+
328+ if ((start[0] == '\'') && (start[2] == '\'')) {
329+ keyname[cnt][0] = '\'';
330+ keyname[cnt][1] = start[1];
331+ keyname[cnt][2] = '\'';
332+ keyname[cnt][3] = '\0';
333+ }
334+ else {
335+ sscanf(start, "%6s", keyname[cnt]);
336+ }
337+
338+ //printf( "[%d] %6s ", cnt, keyname[cnt]);
339+ }
340+
341+ *lockstate = line[65];
342+ //printf( "%c\n", *lockstate);
343+
344+ return 0;
345+}
346+
347+
348+uint16_t get_orig_scancode( int scancode )
349+{
350+ uint16_t origcode = 0;
351+
352+ if (scancode >= 256)
353+ return origcode;
354+
355+ origcode = i8042_detranslation[scancode];
356+
357+ switch (scancode) {
358+ case 0x1C: /* right enter key */
359+ case 0x1D: /* right ctrl key */
360+ case 0x35: /* keypad divide key */
361+ case 0x37: /* print scrn key */
362+ case 0x38: /* right alt key (alt gr) */
363+ //case 0x68: /* ctrl-pause/break on AT 101 */
364+ case 0x47: /* grey home key */
365+ case 0x48: /* grey up arrow key */
366+ case 0x49: /* grey page up key */
367+ case 0x4B: /* grey left arrow key */
368+ case 0x4D: /* grey right arrow key */
369+ case 0x4F: /* grey end key */
370+ case 0x50: /* grey down arrow key */
371+ case 0x51: /* grey page down key */
372+ case 0x52: /* grey insert key */
373+ case 0x53: /* grey delete key */
374+ case 0x5B: /* left Window key */
375+ case 0x5C: /* right Window key */
376+ case 0x5D: /* menu key */
377+ case 0x5E: /* power key */
378+ case 0x5F: /* sleep key */
379+ case 0x63: /* wake key */
380+ origcode = 0xE000 | origcode; break;
381+ default:
382+ break;
383+ }
384+
385+ return origcode;
386+}
387+
388+
389+int get_keysym(uint16_t keysym[3], char *keyname, char lockstate)
390+{
391+ struct kbdmap_define *maptbl;
392+
393+ keysym[0] = 0;
394+ keysym[1] = 0;
395+ keysym[2] = 0;
396+
397+
398+ if (keyname == NULL)
399+ return 0;
400+
401+ if ((keyname[0] == '\'') && (keyname[2] == '\'') && (keyname[3] == '\0')) {
402+ keysym[0] = (uint16_t)keyname[1];
403+ return 1;
404+ }
405+
406+ maptbl = kbdmaps;
407+ do {
408+ if ((!strncmp(maptbl->keyname, keyname, 7)) && (maptbl->lockstate == lockstate)) {
409+ keysym[0] = maptbl->keysym[0];
410+ keysym[1] = maptbl->keysym[1];
411+ keysym[2] = maptbl->keysym[2];
412+ return 3;
413+ }
414+ } while((++maptbl)->lockstate != 'E');
415+
416+ return 0;
417+}
418+
419+
420+int update_keytranslation( uint16_t keysym, uint16_t origcode, uint8_t mode, uint8_t flag)
421+{
422+ uint8_t scancode;
423+ uint8_t prefix;
424+ struct keytranslation *trans;
425+
426+ if (keysym == 0)
427+ return 0;
428+
429+ prefix = ((origcode & 0xE000) ? 0xE0 : 0x00);
430+ scancode = (uint8_t)(origcode & 0x00ff);
431+
432+ trans = keytrans;
433+ do {
434+ if (trans->keysym != keysym)
435+ continue;
436+
437+ if (trans->mode <= mode)
438+ continue;
439+ /*
440+ else if (trans->mode == mode) {
441+ if (trans->scancode < scancode)
442+ continue;
443+ }
444+ */
445+
446+ //printf(" %02x: %02x %02x %d\n", keysym, scancode, prefix, mode );
447+ trans->scancode =scancode;
448+ trans->prefix = prefix & flag;
449+ trans->mode = mode;
450+ break;
451+
452+ } while( (++trans)->keysym != 0);
453+
454+ return 0;
455+}
456+
457+
458+int output_keytranslation(void)
459+{
460+ struct keytranslation *trans;
461+
462+ trans = keytrans;
463+ do {
464+ if (trans->scancode != trans->uscode) {
465+ if(trans->keysym < 0x80)
466+ printf("'%c',", (char)(trans->keysym & 0x00ff));
467+ else
468+ printf("0x%04x,", trans->keysym);
469+
470+ printf("0x%02x", trans->scancode);
471+
472+ if (trans->prefix)
473+ printf(",0x%x;\t", trans->prefix);
474+ else
475+ printf(";\t");
476+
477+ // for Debug
478+ printf(" mode=%x us=%x %x\n", trans->mode, trans->uscode, trans->keysym );
479+ }
480+
481+ } while( (++trans)->keysym != 0);
482+
483+ return 0;
484+}
485+
486+
487+int main( int argc, char *argv[] )
488+{
489+ int err;
490+ int ret = 0;
491+ int fd;
492+ char *buf, *next, *line;
493+ int scancode;
494+ char lockstate;
495+ char keyname[8][8];
496+ struct stat sb;
497+ size_t sz;
498+ uint16_t origcode;
499+ int cnt;
500+ uint16_t keysym[3];
501+
502+ if( 3 != argc )
503+ return 1;
504+
505+ err = stat(argv[1], &sb);
506+ if (err)
507+ return 2;
508+
509+ buf = (char *)malloc(sizeof(char) * sb.st_size);
510+ if (buf == NULL)
511+ return 3;
512+
513+
514+ fd = open(argv[1], O_RDONLY);
515+ if (fd == -1) {
516+ ret = 4;
517+ goto post;
518+ }
519+
520+ sz = read(fd, buf, sb.st_size);
521+
522+ close(fd);
523+
524+ if (sz != sb.st_size) {
525+ ret = 5;
526+ goto post;
527+ }
528+
529+ next = buf;
530+ while ((line = strsep(&next, "\n")) != NULL) {
531+ memset( (char *)keyname, 0x00, sizeof(char) * 8 * 8 );
532+
533+ if (!parseline(&scancode, keyname, &lockstate, line)) {
534+
535+ origcode = get_orig_scancode(scancode);
536+
537+ // alt ---
538+ cnt = get_keysym(keysym, keyname[4], lockstate);
539+ for( --cnt; cnt >= 0; cnt-- )
540+ update_keytranslation( keysym[cnt], origcode, (uint8_t)4, ((cnt==2) ? 0xff: 0x00));
541+
542+ // shift ---
543+ cnt = get_keysym(keysym, keyname[1], lockstate);
544+ for( --cnt; cnt >= 0; cnt-- )
545+ update_keytranslation( keysym[cnt], origcode, (uint8_t)1, ((cnt==2) ? 0xff: 0x00));
546+
547+ // base ---
548+ cnt = get_keysym(keysym, keyname[0], lockstate);
549+ for( --cnt; cnt >= 0; cnt-- )
550+ update_keytranslation( keysym[cnt], origcode, (uint8_t)0, ((cnt==2) ? 0xff: 0x00));
551+
552+
553+ //printf(" %2d -> %04x %7s[%4x : %4x : %4x] %c\n",
554+ //scancode, origcode,
555+ //keyname[0], keysym[0], keysym[1], keysym[2], lockstate);
556+ }
557+ }
558+
559+
560+ output_keytranslation();
561+
562+post:
563+ free(buf);
564+
565+ return ret;
566+}
567+
568+
--- /dev/null
+++ b/work/generate_keymap_tools/generatekbdlayout.sh
@@ -0,0 +1,26 @@
1+#!/bin/sh
2+
3+outfile=""
4+
5+for srcfile in /usr/share/vt/keymaps/*.kbd
6+do
7+ outfile=`basename $srcfile | sed -e 's/\.kbd$//'`
8+ basefile=`basename $srcfile`
9+
10+ langstr=`grep "$basefile:en:" /usr/share/vt/keymaps/INDEX.keymaps | grep ':en:' | sed -e 's/.*:en://'`
11+ touch $outfile
12+ echo "# bhyve ps2kbd keyboard layout file" >> $outfile
13+ echo "# ($outfile : $langstr)" >> $outfile
14+ echo "#" >> $outfile
15+ echo "# Create by: Koine Yuusuke(koinec) <koinec@users.osdn.me>" >> $outfile
16+ echo "#" >> $outfile
17+ echo '# $FreeBSD$' >> $outfile
18+ echo "" >> $outfile
19+
20+ ./generate_kbdmap $srcfile >> $outfile
21+
22+ echo "" >> $outfile
23+
24+ echo "Converted $basefile"
25+done
26+