1652e02d4Sakito /*
2652e02d4Sakito * Copyright (c) 1992 OMRON Corporation.
3*28a62f4dSbostic * Copyright (c) 1992, 1993
4*28a62f4dSbostic * The Regents of the University of California. All rights reserved.
5652e02d4Sakito *
6652e02d4Sakito * This code is derived from software contributed to Berkeley by
7652e02d4Sakito * OMRON Corporation.
8652e02d4Sakito *
9652e02d4Sakito * %sccs.include.redist.c%
10652e02d4Sakito *
11*28a62f4dSbostic * @(#)kbd.c 8.1 (Berkeley) 06/10/93
12652e02d4Sakito */
13652e02d4Sakito
14652e02d4Sakito /*
15652e02d4Sakito * kbd.c -- key-code decoding routine
16652e02d4Sakito * by A.Fujita, Dec-12-1992
17652e02d4Sakito */
18652e02d4Sakito
19652e02d4Sakito #include <sys/param.h>
20652e02d4Sakito #include <luna68k/stand/kbdreg.h>
21652e02d4Sakito
22652e02d4Sakito struct kbd_keymap kbd_keymap[] = {
23652e02d4Sakito KC_IGNORE, 0, 0, /* 0 [0x00] */
24652e02d4Sakito KC_IGNORE, 0, 0, /* 1 [0x01] */
25652e02d4Sakito KC_IGNORE, 0, 0, /* 2 [0x02] */
26652e02d4Sakito KC_IGNORE, 0, 0, /* 3 [0x03] */
27652e02d4Sakito KC_IGNORE, 0, 0, /* 4 [0x04] */
28652e02d4Sakito KC_IGNORE, 0, 0, /* 5 [0x05] */
29652e02d4Sakito KC_IGNORE, 0, 0, /* 6 [0x06] */
30652e02d4Sakito KC_IGNORE, 0, 0, /* 7 [0x07] */
31652e02d4Sakito KC_IGNORE, 0, 0, /* 8 [0x08] */
32652e02d4Sakito KC_CODE, 0x09, 0x09, /* 9 [0x09] TAB */
33652e02d4Sakito KC_SHIFT, KS_CTRL, KS_CTRL, /* 10 [0x0A] CTRL */
34652e02d4Sakito KC_IGNORE, 0, 0, /* 11 [0x0B] */
35652e02d4Sakito KC_SHIFT, KS_SHIFT, KS_SHIFT, /* 12 [0x0C] SHIFT */
36652e02d4Sakito KC_SHIFT, KS_SHIFT, KS_SHIFT, /* 13 [0x0D] SHIFT */
37652e02d4Sakito KC_IGNORE, 0, 0, /* 14 [0x0E] */
38652e02d4Sakito KC_SHIFT, KS_META, KS_META, /* 15 [0x0F] META */
39652e02d4Sakito KC_CODE, 0x1B, 0x1B, /* 16 [0x10] ESC */
40652e02d4Sakito KC_CODE, 0x08, 0x08, /* 17 [0x11] BS */
41652e02d4Sakito KC_CODE, 0x0D, 0x0D, /* 18 [0x12] CR */
42652e02d4Sakito KC_IGNORE, 0, 0, /* 19 [0x13] */
43652e02d4Sakito KC_CODE, 0x20, 0x20, /* 20 [0x14] SP */
44652e02d4Sakito KC_CODE, 0x7F, 0x7F, /* 21 [0x15] DEL */
45652e02d4Sakito KC_IGNORE, 0, 0, /* 22 [0x16] */
46652e02d4Sakito KC_IGNORE, 0, 0, /* 23 [0x17] */
47652e02d4Sakito KC_IGNORE, 0, 0, /* 24 [0x18] */
48652e02d4Sakito KC_IGNORE, 0, 0, /* 25 [0x19] */
49652e02d4Sakito KC_IGNORE, 0, 0, /* 26 [0x1A] */
50652e02d4Sakito KC_IGNORE, 0, 0, /* 27 [0x1B] */
51652e02d4Sakito KC_IGNORE, 0, 0, /* 28 [0x1C] */
52652e02d4Sakito KC_IGNORE, 0, 0, /* 29 [0x1D] */
53652e02d4Sakito KC_IGNORE, 0, 0, /* 30 [0x1E] */
54652e02d4Sakito KC_IGNORE, 0, 0, /* 31 [0x1F] */
55652e02d4Sakito KC_IGNORE, 0, 0, /* 32 [0x20] */
56652e02d4Sakito KC_IGNORE, 0, 0, /* 33 [0x21] */
57652e02d4Sakito KC_CODE, 0x31, 0x21, /* 34 [0x22] 1 */
58652e02d4Sakito KC_CODE, 0x32, 0x22, /* 35 [0x23] 2 */
59652e02d4Sakito KC_CODE, 0x33, 0x23, /* 36 [0x24] 3 */
60652e02d4Sakito KC_CODE, 0x34, 0x24, /* 37 [0x25] 4 */
61652e02d4Sakito KC_CODE, 0x35, 0x25, /* 38 [0x26] 5 */
62652e02d4Sakito KC_CODE, 0x36, 0x26, /* 39 [0x27] 6 */
63652e02d4Sakito KC_CODE, 0x37, 0x27, /* 40 [0x28] 7 */
64652e02d4Sakito KC_CODE, 0x38, 0x28, /* 41 [0x29] 8 */
65652e02d4Sakito KC_CODE, 0x39, 0x29, /* 42 [0x2A] 9 */
66652e02d4Sakito KC_CODE, 0x30, 0x30, /* 43 [0x2B] 0 */
67652e02d4Sakito KC_CODE, 0x2D, 0x3D, /* 44 [0x2C] - */
68652e02d4Sakito KC_CODE, 0x5E, 0x7E, /* 45 [0x2D] ^ */
69652e02d4Sakito KC_CODE, 0x5C, 0x7C, /* 46 [0x2E] \ */
70652e02d4Sakito KC_IGNORE, 0, 0, /* 47 [0x2F] */
71652e02d4Sakito KC_IGNORE, 0, 0, /* 48 [0x30] */
72652e02d4Sakito KC_IGNORE, 0, 0, /* 49 [0x31] */
73652e02d4Sakito KC_CODE, 0x71, 0x51, /* 50 [0x32] q */
74652e02d4Sakito KC_CODE, 0x77, 0x57, /* 51 [0x33] w */
75652e02d4Sakito KC_CODE, 0x65, 0x45, /* 52 [0x34] e */
76652e02d4Sakito KC_CODE, 0x72, 0x52, /* 53 [0x35] r */
77652e02d4Sakito KC_CODE, 0x74, 0x54, /* 54 [0x36] t */
78652e02d4Sakito KC_CODE, 0x79, 0x59, /* 55 [0x37] y */
79652e02d4Sakito KC_CODE, 0x75, 0x55, /* 56 [0x38] u */
80652e02d4Sakito KC_CODE, 0x69, 0x49, /* 57 [0x39] i */
81652e02d4Sakito KC_CODE, 0x6F, 0x4F, /* 58 [0x3A] o */
82652e02d4Sakito KC_CODE, 0x70, 0x50, /* 59 [0x3B] p */
83652e02d4Sakito KC_CODE, 0x40, 0x60, /* 60 [0x3C] @ */
84652e02d4Sakito KC_CODE, 0x5B, 0x7B, /* 61 [0x3D] [ */
85652e02d4Sakito KC_IGNORE, 0, 0, /* 62 [0x3E] */
86652e02d4Sakito KC_IGNORE, 0, 0, /* 63 [0x3F] */
87652e02d4Sakito KC_IGNORE, 0, 0, /* 64 [0x40] */
88652e02d4Sakito KC_IGNORE, 0, 0, /* 65 [0x41] */
89652e02d4Sakito KC_CODE, 0x61, 0x41, /* 66 [0x42] a */
90652e02d4Sakito KC_CODE, 0x73, 0x53, /* 67 [0x43] s */
91652e02d4Sakito KC_CODE, 0x64, 0x44, /* 68 [0x44] d */
92652e02d4Sakito KC_CODE, 0x66, 0x46, /* 69 [0x45] f */
93652e02d4Sakito KC_CODE, 0x67, 0x47, /* 70 [0x46] g */
94652e02d4Sakito KC_CODE, 0x68, 0x48, /* 71 [0x47] h */
95652e02d4Sakito KC_CODE, 0x6A, 0x4A, /* 72 [0x48] j */
96652e02d4Sakito KC_CODE, 0x6B, 0x4B, /* 73 [0x49] k */
97652e02d4Sakito KC_CODE, 0x6C, 0x4C, /* 74 [0x4A] l */
98652e02d4Sakito KC_CODE, 0x3B, 0x2B, /* 75 [0x4B] ; */
99652e02d4Sakito KC_CODE, 0x3A, 0x2A, /* 76 [0x4C] : */
100652e02d4Sakito KC_CODE, 0x5D, 0x7D, /* 77 [0x4D] ] */
101652e02d4Sakito KC_IGNORE, 0, 0, /* 78 [0x4E] */
102652e02d4Sakito KC_IGNORE, 0, 0, /* 79 [0x4F] */
103652e02d4Sakito KC_IGNORE, 0, 0, /* 80 [0x50] */
104652e02d4Sakito KC_IGNORE, 0, 0, /* 81 [0x51] */
105652e02d4Sakito KC_CODE, 0x7A, 0x5A, /* 82 [0x52] z */
106652e02d4Sakito KC_CODE, 0x78, 0x58, /* 83 [0x53] x */
107652e02d4Sakito KC_CODE, 0x63, 0x43, /* 84 [0x54] c */
108652e02d4Sakito KC_CODE, 0x76, 0x56, /* 85 [0x55] v */
109652e02d4Sakito KC_CODE, 0x62, 0x42, /* 86 [0x56] b */
110652e02d4Sakito KC_CODE, 0x6E, 0x4E, /* 87 [0x57] n */
111652e02d4Sakito KC_CODE, 0x6D, 0x4D, /* 88 [0x58] m */
112652e02d4Sakito KC_CODE, 0x2C, 0x3C, /* 89 [0x59] , */
113652e02d4Sakito KC_CODE, 0x2E, 0x3E, /* 90 [0x5A] . */
114652e02d4Sakito KC_CODE, 0x2F, 0x3F, /* 91 [0x5B] / */
115652e02d4Sakito KC_CODE, 0x5F, 0x5F, /* 92 [0x5C] _ */
116652e02d4Sakito KC_IGNORE, 0, 0, /* 93 [0x5D] */
117652e02d4Sakito KC_IGNORE, 0, 0, /* 94 [0x5E] */
118652e02d4Sakito KC_IGNORE, 0, 0, /* 95 [0x5F] */
119652e02d4Sakito KC_IGNORE, 0, 0, /* 96 [0x60] */
120652e02d4Sakito KC_IGNORE, 0, 0, /* 97 [0x61] */
121652e02d4Sakito KC_IGNORE, 0, 0, /* 98 [0x62] */
122652e02d4Sakito KC_IGNORE, 0, 0, /* 99 [0x63] */
123652e02d4Sakito KC_IGNORE, 0, 0, /* 100 [0x64] */
124652e02d4Sakito KC_IGNORE, 0, 0, /* 101 [0x65] */
125652e02d4Sakito KC_IGNORE, 0, 0, /* 102 [0x66] */
126652e02d4Sakito KC_IGNORE, 0, 0, /* 103 [0x67] */
127652e02d4Sakito KC_IGNORE, 0, 0, /* 104 [0x68] */
128652e02d4Sakito KC_IGNORE, 0, 0, /* 105 [0x69] */
129652e02d4Sakito KC_IGNORE, 0, 0, /* 106 [0x6A] */
130652e02d4Sakito KC_IGNORE, 0, 0, /* 107 [0x6B] */
131652e02d4Sakito KC_IGNORE, 0, 0, /* 108 [0x6C] */
132652e02d4Sakito KC_IGNORE, 0, 0, /* 109 [0x6D] */
133652e02d4Sakito KC_IGNORE, 0, 0, /* 110 [0x6E] */
134652e02d4Sakito KC_IGNORE, 0, 0, /* 111 [0x6F] */
135652e02d4Sakito KC_IGNORE, 0, 0, /* 112 [0x70] */
136652e02d4Sakito KC_IGNORE, 0, 0, /* 113 [0x71] */
137652e02d4Sakito KC_IGNORE, 0, 0, /* 114 [0x72] */
138652e02d4Sakito KC_IGNORE, 0, 0, /* 115 [0x73] */
139652e02d4Sakito KC_IGNORE, 0, 0, /* 116 [0x74] */
140652e02d4Sakito KC_IGNORE, 0, 0, /* 117 [0x75] */
141652e02d4Sakito KC_IGNORE, 0, 0, /* 118 [0x76] */
142652e02d4Sakito KC_IGNORE, 0, 0, /* 119 [0x77] */
143652e02d4Sakito KC_IGNORE, 0, 0, /* 120 [0x78] */
144652e02d4Sakito KC_IGNORE, 0, 0, /* 121 [0x79] */
145652e02d4Sakito KC_IGNORE, 0, 0, /* 122 [0x7A] */
146652e02d4Sakito KC_IGNORE, 0, 0, /* 123 [0x7B] */
147652e02d4Sakito KC_IGNORE, 0, 0, /* 124 [0x7C] */
148652e02d4Sakito KC_IGNORE, 0, 0, /* 125 [0x7D] */
149652e02d4Sakito KC_IGNORE, 0, 0, /* 126 [0x7E] */
150652e02d4Sakito KC_IGNORE, 0, 0, /* 127 [0x7F] */
151652e02d4Sakito };
152652e02d4Sakito
153652e02d4Sakito int shift_flag = 0;
154652e02d4Sakito int ctrl_flag = 0;
155652e02d4Sakito int meta_flag = 0;
156652e02d4Sakito
kbd_decode(code)157652e02d4Sakito kbd_decode(code)
158652e02d4Sakito register u_char code;
159652e02d4Sakito {
160946be0e8Sakito register unsigned int c, updown = 0;
161652e02d4Sakito
162652e02d4Sakito if (code & 0x80)
163652e02d4Sakito updown = 1;
164652e02d4Sakito
165652e02d4Sakito code &= 0x7F;
166652e02d4Sakito
167652e02d4Sakito c = kbd_keymap[code].km_type;
168652e02d4Sakito
169946be0e8Sakito if (c == KC_IGNORE)
170946be0e8Sakito return(KC_IGNORE);
171652e02d4Sakito
172946be0e8Sakito if ((c == KC_CODE) && updown)
173946be0e8Sakito return(KC_IGNORE);
174652e02d4Sakito
175946be0e8Sakito if (c == KC_SHIFT) {
176652e02d4Sakito switch(kbd_keymap[code].km_code[0]) {
177946be0e8Sakito
178652e02d4Sakito case KS_SHIFT:
179652e02d4Sakito shift_flag = 1 - updown;
180652e02d4Sakito break;
181652e02d4Sakito
182652e02d4Sakito case KS_CTRL:
183652e02d4Sakito ctrl_flag = 1 - updown;
184652e02d4Sakito break;
185652e02d4Sakito
186652e02d4Sakito case KS_META:
187652e02d4Sakito meta_flag = 1 - updown;
188652e02d4Sakito break;
189652e02d4Sakito }
190652e02d4Sakito
191946be0e8Sakito return(KC_IGNORE);
192652e02d4Sakito }
193652e02d4Sakito
194946be0e8Sakito if (shift_flag)
195946be0e8Sakito c = kbd_keymap[code].km_code[1];
196946be0e8Sakito else
197946be0e8Sakito c = kbd_keymap[code].km_code[0];
198652e02d4Sakito
199652e02d4Sakito if (meta_flag)
200946be0e8Sakito c |= 0x80;
201946be0e8Sakito
202652e02d4Sakito if (ctrl_flag)
203946be0e8Sakito c &= 0x1F;
204652e02d4Sakito
205652e02d4Sakito return(c);
206652e02d4Sakito }
207