4 #define KEY_IDT_ENTRY 0x21
5 #define KEYBOARD_PORT 0x60
7 /** Return type of process_scancode. Four bytes wide, which are broken down as
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.
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.
28 #define KH_RAWCHAR_SHIFT 8
29 #define KH_RAWCHAR_SMASK 0x0FF
30 #define KH_CHAR_SHIFT 0
31 #define KH_CHAR_SMASK 0x0FF
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)
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)))
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))
64 /** Return nonzero if the status word k character is from the
65 * 410 Upper Code Plane.
67 * @pre Valid only if KH_HASDATA(k) is nonzero. */
68 #define KH_ISEXTENDED(k) (!!(KH_GETCHAR(k)&0x80))
70 /** Return nonzero if the status word k raw result character is from
71 * the 410 Upper Code Plane.
73 * @pre Valid only if KH_HASDATA(k) is nonzero. */
74 #define KH_ISRAWEXTENDED(k) (!!(KH_GETRAW(k)&0x80))
77 /**@{ key_state variables */
79 #define KH_LSHIFT_KEY 0x8000
81 #define KH_RSHIFT_KEY 0x4000
83 #define KH_LCONTROL_KEY 0x2000
85 #define KH_RCONTROL_KEY 0x1000
87 #define KH_LALT_KEY 0x0800
89 #define KH_RALT_KEY 0x0400
91 #define KH_CAPS_LOCK 0x0200
93 #define KH_NUM_LOCK 0x0100
96 /* Reserved bits in range 0x00F0; these are currently NOT inside either of the
99 * @bug Currently the LGUI and RGUI modifiers are ignored.
100 * @bug Currently ScrollLock is not treated as a modifier.
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.
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!)
112 #define KH_RESULT_HASRAW 0x08
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.
118 #define KH_RESULT_HASDATA 0x04
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
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.
129 #define KH_RESULT_MAKE 0x01
133 /* Some control codes are returned within the ASCII encoding scheme, where
134 * the ASCII definition is sufficiently close to what we're after.
137 KHE_BACKSPACE = '\b',
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.
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 */
184 /* Sequenced characters */
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".
198 * @bug We do not handle these at the moment.
205 /* KHE_APPS, */ /* The "context menu" key */
208 kh_type process_scancode(int keypress);