]>
Commit | Line | Data |
---|---|---|
6093edb5 JW |
1 | #ifndef KEYHELP_H |
2 | #define KEYHELP_H | |
3 | ||
4 | #define KEY_IDT_ENTRY 0x21 | |
5 | #define KEYBOARD_PORT 0x60 | |
6 | ||
7 | /** Return type of process_scancode. Four bytes wide, which are broken down as | |
8 | * follows: | |
9 | * | |
10 | * - The top two (most significant) bytes are a state field composed of the | |
11 | * KH_*_KEY, KH_*_LOCK, and KH_RESULT_* values below. | |
12 | * - The third byte is defined as the "raw" result and gives a cannonical, | |
13 | * unshifted name for the key pressed, if KH_HASDATA() gives true | |
14 | * [KH_RESULT_HASDATA on]. | |
15 | * - The fourth (least significant byte) gives a "common" value of the result. | |
16 | * This is the representation subject to all modifier keys. | |
17 | */ | |
18 | typedef int kh_type; | |
19 | ||
20 | /**@{ kh_type bitfield breakdown definitions */ | |
21 | #define KH_STATE_SHIFT 16 | |
22 | #define KH_STATE_SMASK 0x0FF00 | |
23 | #define KH_RMODS_SHIFT 16 | |
24 | #define KH_RMODS_SMASK 0x000F | |
25 | /* Note that there are bits in neither of these MASKs; these are reserved for | |
26 | * future expanson; see commentary below. | |
27 | */ | |
28 | #define KH_RAWCHAR_SHIFT 8 | |
29 | #define KH_RAWCHAR_SMASK 0x0FF | |
30 | #define KH_CHAR_SHIFT 0 | |
31 | #define KH_CHAR_SMASK 0x0FF | |
32 | /**@}*/ | |
33 | ||
34 | /**@{ Utility macros for parsing the return of process_scancode() */ | |
35 | /** Extract STATE fields from return type */ | |
36 | #define KH_STATE(k) ((k >> KH_STATE_SHIFT) & KH_STATE_SMASK) | |
37 | /** Extract RMODS fields from return type */ | |
38 | #define KH_RMODS(k) ((k >> KH_RMODS_SHIFT) & KH_RMODS_SMASK) | |
39 | /** Extract RAWCHAR field from return type */ | |
40 | #define KH_GETRAW(k) ((k >> KH_RAWCHAR_SHIFT) & KH_RAWCHAR_SMASK) | |
41 | /** Extract CHARACTER field from return type */ | |
42 | #define KH_GETCHAR(k) ((k >> KH_CHAR_SHIFT) & KH_CHAR_SMASK) | |
43 | ||
44 | /** Return nonzero if the CapsLock is on in the status word k */ | |
45 | #define KH_CAPSLOCK(k) (!!((k>>KH_STATE_SHIFT)&KH_CAPS_LOCK)) | |
46 | /** Return nonzero if either shift is down in the status word k */ | |
47 | #define KH_SHIFT(k) (!!((k>>KH_STATE_SHIFT)&(KH_LSHIFT_KEY|KH_RSHIFT_KEY))) | |
48 | /** Return nonzero if either ctl is down in the status word k */ | |
49 | #define KH_CTL(k) (!!((k>>KH_STATE_SHIFT)&(KH_LCONTROL_KEY|KH_RCONTROL_KEY))) | |
50 | /** Return nonzero if either alt is down in the status word k */ | |
51 | #define KH_ALT(k) (!!((k>>KH_STATE_SHIFT)&(KH_LALT_KEY|KH_RALT_KEY))) | |
52 | ||
53 | /** Return nonzero if the status word k contains a raw character value */ | |
54 | #define KH_HASRAW(k) (!!((k>>KH_RMODS_SHIFT)&KH_RESULT_HASRAW)) | |
55 | /** Return nonzero if the status word k contains a character value */ | |
56 | #define KH_HASDATA(k) (!!((k>>KH_RMODS_SHIFT)&KH_RESULT_HASDATA)) | |
57 | /** Return nonzero if the status word k results are from the Numeric Pad. | |
58 | * @pre Valid only if KH_HASDATA(k) is nonzero. */ | |
59 | #define KH_NUMPAD(k) (!!((k>>KH_RMODS_SHIFT)&KH_RESULT_NUMPAD)) | |
60 | /** Return nonzero if the status work k results from a key going down. | |
61 | * @pre Valid only if KH_HASDATA(k) is nonzero. */ | |
62 | #define KH_ISMAKE(k) (!!((k>>KH_RMODS_SHIFT)&KH_RESULT_MAKE)) | |
63 | ||
64 | /** Return nonzero if the status word k character is from the | |
65 | * 410 Upper Code Plane. | |
66 | * | |
67 | * @pre Valid only if KH_HASDATA(k) is nonzero. */ | |
68 | #define KH_ISEXTENDED(k) (!!(KH_GETCHAR(k)&0x80)) | |
69 | ||
70 | /** Return nonzero if the status word k raw result character is from | |
71 | * the 410 Upper Code Plane. | |
72 | * | |
73 | * @pre Valid only if KH_HASDATA(k) is nonzero. */ | |
74 | #define KH_ISRAWEXTENDED(k) (!!(KH_GETRAW(k)&0x80)) | |
75 | /**@}*/ | |
76 | ||
77 | /**@{ key_state variables */ | |
78 | /** Left shift */ | |
79 | #define KH_LSHIFT_KEY 0x8000 | |
80 | /** Right shift */ | |
81 | #define KH_RSHIFT_KEY 0x4000 | |
82 | /** Left control */ | |
83 | #define KH_LCONTROL_KEY 0x2000 | |
84 | /** Right control */ | |
85 | #define KH_RCONTROL_KEY 0x1000 | |
86 | /** Left alt */ | |
87 | #define KH_LALT_KEY 0x0800 | |
88 | /** Right alt */ | |
89 | #define KH_RALT_KEY 0x0400 | |
90 | /** Caps lock */ | |
91 | #define KH_CAPS_LOCK 0x0200 | |
92 | /** Num lock */ | |
93 | #define KH_NUM_LOCK 0x0100 | |
94 | /**@}*/ | |
95 | ||
96 | /* Reserved bits in range 0x00F0; these are currently NOT inside either of the | |
97 | * MASKS above. | |
98 | * | |
99 | * @bug Currently the LGUI and RGUI modifiers are ignored. | |
100 | * @bug Currently ScrollLock is not treated as a modifier. | |
101 | */ | |
102 | ||
103 | /**@{*/ | |
104 | /** Result contains a meaningful answer beyond the modifier bits. If this | |
105 | * bit is OFF in the returned word, the calling implementation SHOULD NOT | |
106 | * make access to either the result or the raw result. | |
107 | * | |
108 | * (As a debugging hint, the current implementation should be returning zeros | |
109 | * in those fields in this case. If lots of zeros seem to be going to | |
110 | * screen, check one's handling of this case!) | |
111 | */ | |
112 | #define KH_RESULT_HASRAW 0x08 | |
113 | ||
114 | /** Result contains a meaningful answer beyond the modifier bits and raw | |
115 | * code. That is to say that this contains a translated code that you | |
116 | * probably care about. | |
117 | */ | |
118 | #define KH_RESULT_HASDATA 0x04 | |
119 | ||
120 | /** Signals that the result is from the Numeric Pad. This implementation | |
121 | * will return ASCII values regardless of NumLock status, leaving to callers | |
122 | * to do more meaningful things for the non-ASCII meanings. */ | |
123 | #define KH_RESULT_NUMPAD 0x02 | |
124 | ||
125 | /** If KH_RESULT_HASDATA, this bit is asserted for MAKE events and clear for | |
126 | * BREAK events. Traditional parsing logic probably only wants to emit | |
127 | * chars when KH_RESULT_MAKE is turned on. | |
128 | */ | |
129 | #define KH_RESULT_MAKE 0x01 | |
130 | /**@}*/ | |
131 | ||
132 | enum kh_extended_e { | |
133 | /* Some control codes are returned within the ASCII encoding scheme, where | |
134 | * the ASCII definition is sufficiently close to what we're after. | |
135 | */ | |
136 | KHE_ESCAPE = 0x1B, | |
137 | KHE_BACKSPACE = '\b', | |
138 | KHE_TAB = '\t', | |
139 | KHE_ENTER = '\n', | |
140 | ||
141 | /* | |
142 | * The remainder of ASCII, from 0x20 - 0x7F, is returned as ASCII. But then | |
143 | * we run out of mappings and, rather than inventing a mapping to the unused | |
144 | * control characters, we invent our own upper code plane, which we'll call | |
145 | * the 410 Upper Code Plane. | |
146 | */ | |
147 | ||
148 | KHE_UNDEFINED = 0x80, /**< A non-ASCII character for which we don't have an | |
149 | escape sequence. Traditional results would have | |
150 | been to return a '?' but this leaves the behavior | |
151 | to the implementation */ | |
152 | ||
153 | KHE_ARROW_UP, | |
154 | KHE_ARROW_LEFT, | |
155 | KHE_ARROW_DOWN, | |
156 | KHE_ARROW_RIGHT, | |
157 | ||
158 | /* Modifiers */ | |
159 | KHE_LALT, | |
160 | KHE_RALT, | |
161 | KHE_LCTL, | |
162 | KHE_RCTL, | |
163 | KHE_LSHIFT, | |
164 | KHE_RSHIFT, | |
165 | /* KHE_LGUI, */ | |
166 | /* KHE_RGUI, */ | |
167 | KHE_CAPSLOCK, | |
168 | KHE_NUMLOCK, | |
169 | ||
170 | /* F keys */ | |
171 | KHE_F1, | |
172 | KHE_F2, | |
173 | KHE_F3, | |
174 | KHE_F4, | |
175 | KHE_F5, | |
176 | KHE_F6, | |
177 | KHE_F7, | |
178 | KHE_F8, | |
179 | KHE_F9, | |
180 | KHE_F10, | |
181 | KHE_F11, | |
182 | KHE_F12, | |
183 | ||
184 | /* Sequenced characters */ | |
185 | KHE_PAUSE, | |
186 | KHE_PRINT_SCREEN, | |
187 | ||
188 | /** | |
189 | * @bug Coming soon... | |
190 | * Well now, THIS is going to be a fun case. Since we SHOULD move to | |
191 | * processing the Numeric Pad in the driver, we need to know what KP5 without | |
192 | * NumLock Turned on is... it's this key, which is best defined as | |
193 | * "KP5 without NumLock," known as "BEGIN". | |
194 | */ | |
195 | /* KHE_BEGIN, */ | |
196 | ||
197 | /** | |
198 | * @bug We do not handle these at the moment. | |
199 | */ | |
200 | /* KHE_HOME, */ | |
201 | /* KHE_END, */ | |
202 | /* KHE_INSERT, */ | |
203 | /* KHE_PAGE_UP, */ | |
204 | /* KHE_PAGE_DOWN, */ | |
205 | /* KHE_APPS, */ /* The "context menu" key */ | |
206 | }; | |
207 | ||
208 | kh_type process_scancode(int keypress); | |
209 | ||
210 | #endif |