KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
keyboard.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/maple/keyboard.h
4 Copyright (C) 2000-2002 Jordan DeLong and Megan Potter
5 Copyright (C) 2012 Lawrence Sebald
6
7*/
8
9/** \file dc/maple/keyboard.h
10 \brief Definitions for using the keyboard device.
11 \ingroup kbd
12
13 This file contains the definitions needed to access the Maple keyboard
14 device. Obviously, this corresponds to the MAPLE_FUNC_KEYBOARD function
15 code.
16
17 \author Jordan DeLong
18 \author Megan Potter
19 \author Lawrence Sebald
20*/
21
22#ifndef __DC_MAPLE_KEYBOARD_H
23#define __DC_MAPLE_KEYBOARD_H
24
25#include <sys/cdefs.h>
26__BEGIN_DECLS
27
28#include <arch/types.h>
29#include <dc/maple.h>
30
31/** \defgroup kbd Keyboard
32 \brief Driver for the Dreamcast's Keyboard Input Device
33 \ingroup peripherals
34*/
35
36/** \defgroup kbd_mods Modifier Keys
37 \brief Masks for the various keyboard modifier keys
38 \ingroup kbd
39
40 These are the various modifiers that can be pressed on the keyboard, and are
41 reflected in the modifiers field of kbd_cond_t.
42 @{
43*/
44#define KBD_MOD_LCTRL (1<<0)
45#define KBD_MOD_LSHIFT (1<<1)
46#define KBD_MOD_LALT (1<<2)
47#define KBD_MOD_S1 (1<<3)
48#define KBD_MOD_RCTRL (1<<4)
49#define KBD_MOD_RSHIFT (1<<5)
50#define KBD_MOD_RALT (1<<6)
51#define KBD_MOD_S2 (1<<7)
52/** @} */
53
54/** \defgroup kbd_leds LEDs
55 \brief Values for the different keyboard LEDs
56 \ingroup kbd
57
58 This is the LEDs that can be turned on and off on the keyboard. This list
59 may not be exhaustive. Think of these sorta like an extension of the
60 modifiers list.
61 @{
62*/
63#define KBD_LED_NUMLOCK (1<<0)
64#define KBD_LED_CAPSLOCK (1<<1)
65#define KBD_LED_SCRLOCK (1<<2)
66/** @} */
67
68/** \defgroup kbd_keys Keys
69 \brief Values representing the various keyboard keys
70 \ingroup kbd
71
72 This is the list of keys that are on the keyboard that may be pressed. The
73 keyboard returns keys in this format.
74
75 These are the raw keycodes returned by the US keyboard, and thus only cover
76 the keys on US keyboards.
77 @{
78*/
79#define KBD_KEY_NONE 0x00
80#define KBD_KEY_ERROR 0x01
81#define KBD_KEY_ERR2 0x02
82#define KBD_KEY_ERR3 0x03
83#define KBD_KEY_A 0x04
84#define KBD_KEY_B 0x05
85#define KBD_KEY_C 0x06
86#define KBD_KEY_D 0x07
87#define KBD_KEY_E 0x08
88#define KBD_KEY_F 0x09
89#define KBD_KEY_G 0x0a
90#define KBD_KEY_H 0x0b
91#define KBD_KEY_I 0x0c
92#define KBD_KEY_J 0x0d
93#define KBD_KEY_K 0x0e
94#define KBD_KEY_L 0x0f
95#define KBD_KEY_M 0x10
96#define KBD_KEY_N 0x11
97#define KBD_KEY_O 0x12
98#define KBD_KEY_P 0x13
99#define KBD_KEY_Q 0x14
100#define KBD_KEY_R 0x15
101#define KBD_KEY_S 0x16
102#define KBD_KEY_T 0x17
103#define KBD_KEY_U 0x18
104#define KBD_KEY_V 0x19
105#define KBD_KEY_W 0x1a
106#define KBD_KEY_X 0x1b
107#define KBD_KEY_Y 0x1c
108#define KBD_KEY_Z 0x1d
109#define KBD_KEY_1 0x1e
110#define KBD_KEY_2 0x1f
111#define KBD_KEY_3 0x20
112#define KBD_KEY_4 0x21
113#define KBD_KEY_5 0x22
114#define KBD_KEY_6 0x23
115#define KBD_KEY_7 0x24
116#define KBD_KEY_8 0x25
117#define KBD_KEY_9 0x26
118#define KBD_KEY_0 0x27
119#define KBD_KEY_ENTER 0x28
120#define KBD_KEY_ESCAPE 0x29
121#define KBD_KEY_BACKSPACE 0x2a
122#define KBD_KEY_TAB 0x2b
123#define KBD_KEY_SPACE 0x2c
124#define KBD_KEY_MINUS 0x2d
125#define KBD_KEY_PLUS 0x2e
126#define KBD_KEY_LBRACKET 0x2f
127#define KBD_KEY_RBRACKET 0x30
128#define KBD_KEY_BACKSLASH 0x31
129#define KBD_KEY_SEMICOLON 0x33
130#define KBD_KEY_QUOTE 0x34
131#define KBD_KEY_TILDE 0x35
132#define KBD_KEY_COMMA 0x36
133#define KBD_KEY_PERIOD 0x37
134#define KBD_KEY_SLASH 0x38
135#define KBD_KEY_CAPSLOCK 0x39
136#define KBD_KEY_F1 0x3a
137#define KBD_KEY_F2 0x3b
138#define KBD_KEY_F3 0x3c
139#define KBD_KEY_F4 0x3d
140#define KBD_KEY_F5 0x3e
141#define KBD_KEY_F6 0x3f
142#define KBD_KEY_F7 0x40
143#define KBD_KEY_F8 0x41
144#define KBD_KEY_F9 0x42
145#define KBD_KEY_F10 0x43
146#define KBD_KEY_F11 0x44
147#define KBD_KEY_F12 0x45
148#define KBD_KEY_PRINT 0x46
149#define KBD_KEY_SCRLOCK 0x47
150#define KBD_KEY_PAUSE 0x48
151#define KBD_KEY_INSERT 0x49
152#define KBD_KEY_HOME 0x4a
153#define KBD_KEY_PGUP 0x4b
154#define KBD_KEY_DEL 0x4c
155#define KBD_KEY_END 0x4d
156#define KBD_KEY_PGDOWN 0x4e
157#define KBD_KEY_RIGHT 0x4f
158#define KBD_KEY_LEFT 0x50
159#define KBD_KEY_DOWN 0x51
160#define KBD_KEY_UP 0x52
161#define KBD_KEY_PAD_NUMLOCK 0x53
162#define KBD_KEY_PAD_DIVIDE 0x54
163#define KBD_KEY_PAD_MULTIPLY 0x55
164#define KBD_KEY_PAD_MINUS 0x56
165#define KBD_KEY_PAD_PLUS 0x57
166#define KBD_KEY_PAD_ENTER 0x58
167#define KBD_KEY_PAD_1 0x59
168#define KBD_KEY_PAD_2 0x5a
169#define KBD_KEY_PAD_3 0x5b
170#define KBD_KEY_PAD_4 0x5c
171#define KBD_KEY_PAD_5 0x5d
172#define KBD_KEY_PAD_6 0x5e
173#define KBD_KEY_PAD_7 0x5f
174#define KBD_KEY_PAD_8 0x60
175#define KBD_KEY_PAD_9 0x61
176#define KBD_KEY_PAD_0 0x62
177#define KBD_KEY_PAD_PERIOD 0x63
178#define KBD_KEY_S3 0x65
179/** @} */
180
181/** \defgroup kbd_regions Region Codes
182 \brief Region codes for the Dreamcast keyboard
183 \ingroup kbd
184
185 This is the list of possible values for the "region" field in the
186 kbd_state_t structure.
187 @{
188*/
189#define KBD_REGION_JP 1 /**< \brief Japanese keyboard */
190#define KBD_REGION_US 2 /**< \brief US keyboard */
191#define KBD_REGION_UK 3 /**< \brief UK keyboard */
192#define KBD_REGION_DE 4 /**< \brief German keyboard */
193#define KBD_REGION_FR 5 /**< \brief French keyboard */
194#define KBD_REGION_IT 6 /**< \brief Italian keyboard (not supported yet) */
195#define KBD_REGION_ES 7 /**< \brief Spanish keyboard */
196/** @} */
197
198/** \defgroup key_states Key States
199 \brief States each key can be in.
200 \ingroup kbd
201
202 These are the different 'states' each key can be in. They are stored in
203 kbd_state_t->matrix, and manipulated/checked by kbd_check_poll.
204
205 none-> pressed or none
206 was pressed-> pressed or none
207 pressed-> was_pressed
208 @{
209*/
210#define KEY_STATE_NONE 0
211#define KEY_STATE_WAS_PRESSED 1
212#define KEY_STATE_PRESSED 2
213/** @} */
214
215/** \brief Maximum number of keys the DC can read simultaneously.
216 \ingroup kbd
217 This is a hardware constant. The define prevents the magic number '6' from appearing.
218**/
219#define MAX_PRESSED_KEYS 6
220
221/** \brief Maximum number of keys a DC keyboard can have.
222 \ingroup kbd
223 This is a hardware constant. The define prevents the magic number '256' from appearing.
224**/
225#define MAX_KBD_KEYS 256
226
227/** \brief Size of a keyboard queue.
228 \ingroup kbd
229
230 Each keyboard queue will hold this many elements. Once the queue fills, no
231 new elements will be placed on the queue. As long as you check the queue
232 relatively frequently, the default of 16 should be plenty.
233
234 \note This <strong>MUST</strong> be a power of two.
235*/
236#define KBD_QUEUE_SIZE 16
237
238/** \brief Keyboard keymap.
239 \ingroup kbd
240
241 This structure represents a mapping from raw key values to ASCII values, if
242 appropriate. This handles base values as well as shifted ("shift" and "Alt"
243 keys) values.
244
245 \headerfile dc/maple/keyboard.h
246*/
247typedef struct kbd_keymap {
252
253/** \brief Keyboard raw condition structure.
254 \ingroup kbd
255
256 This structure is what the keyboard responds with as its current status.
257
258 \headerfile dc/maple/keyboard.h
259*/
260typedef struct {
261 uint8 modifiers; /**< \brief Bitmask of set modifiers. */
262 uint8 leds; /**< \brief Bitmask of set LEDs */
263 uint8 keys[MAX_PRESSED_KEYS]; /**< \brief Key codes for currently pressed keys. */
264} kbd_cond_t;
265
266/** \brief Keyboard status structure.
267 \ingroup kbd
268
269 This structure holds information about the current status of the keyboard
270 device. This is what maple_dev_status() will return.
271
272 \headerfile dc/maple/keyboard.h
273*/
274typedef struct kbd_state {
275 /** \brief The latest raw condition of the keyboard. */
277
278 /** \brief Key array.
279
280 This array lists the state of all possible keys on the keyboard. It can
281 be used for key repeat and debouncing. This will be non-zero if the key
282 is currently being pressed.
283
284 \see kbd_keys
285 */
287
288 /** \brief Modifier key status. */
290
291 /** \brief Keyboard type/region. */
293
294 /** \brief Individual keyboard queue.
295 You should not access this variable directly. Please use the appropriate
296 function to access it. */
298 int queue_tail; /**< \brief Key queue tail. */
299 int queue_head; /**< \brief Key queue head. */
300 volatile int queue_len; /**< \brief Current length of queue. */
301
302 uint8 kbd_repeat_key; /**< \brief Key that is repeating. */
303 uint64 kbd_repeat_timer; /**< \brief Time that the next repeat will trigger. */
305
306/** \brief Activate or deactivate global key queueing.
307 \ingroup kbd
308 \deprecated
309
310 This function will turn the internal keyboard queueing on or off. Note that
311 there is only one queue for the whole system, no matter how many keyboards
312 are attached, and the queue is of fairly limited length. Turning queueing
313 off is useful (for instance) in a game where individual keypresses don't
314 mean as much as having the keys up or down does.
315
316 You can clear the queue (without popping all the keys off) by setting the
317 active value to a different value than it was.
318
319 The queue is by default on, unless you turn it off.
320
321 \param active Set to non-zero to activate the queue.
322 \note The global queue does not account for non-US
323 keyboard layouts and is deprecated. Please use the
324 individual queues instead for future code.
325*/
326void kbd_set_queue(int active) __attribute__((deprecated));
327
328/** \brief Pop a key off the global keyboard queue.
329 \ingroup kbd
330 \deprecated
331
332 This function pops the front off of the keyboard queue, and returns the
333 value to the caller. The value returned will be the ASCII value of the key
334 pressed (accounting for the shift keys being pressed).
335
336 If a key does not have an ASCII value associated with it, the raw key code
337 will be returned, shifted up by 8 bits.
338
339 \return The value at the front of the queue, or -1 if there
340 are no keys in the queue or queueing is off.
341 \note This function does not account for non-US keyboard
342 layouts properly (for compatibility with old code),
343 and is deprecated. Use the individual keyboard
344 queues instead to properly account for non-US
345 keyboards.
346 \see kbd_queue_pop()
347*/
348int kbd_get_key(void) __attribute__((deprecated));
349
350/** \brief Pop a key off a specific keyboard's queue.
351 \ingroup kbd
352
353 This function pops the front element off of the specified keyboard queue,
354 and returns the value of that key to the caller.
355
356 If the xlat parameter is non-zero and the key represents an ISO-8859-1
357 character, that is the value that will be returned from this function.
358 Otherwise if xlat is non-zero, it will be the raw key code, shifted up by 8
359 bits.
360
361 If the xlat parameter is zero, the lower 8 bits of the returned value will
362 be the raw key code. The next 8 bits will be the modifier keys that were
363 down when the key was pressed (a bitfield of KBD_MOD_* values). The next 3
364 bits will be the lock key status (a bitfield of KBD_LED_* values).
365
366 \param dev The keyboard device to read from.
367 \param xlat Set to non-zero to do key translation. Otherwise,
368 you'll simply get the raw key value. Raw key values
369 are not mapped at all, so you are responsible for
370 figuring out what it is by the region.
371
372 \return The value at the front of the queue, or -1 if there
373 are no keys in the queue.
374*/
375int kbd_queue_pop(maple_device_t *dev, int xlat);
376
377/* \cond */
378/* Init / Shutdown */
379void kbd_init(void);
380void kbd_shutdown(void);
381/* \endcond */
382
383__END_DECLS
384
385#endif /* __DC_MAPLE_KEYBOARD_H */
int kbd_get_key(void)
Pop a key off the global keyboard queue.
#define MAX_PRESSED_KEYS
Maximum number of keys the DC can read simultaneously.
Definition keyboard.h:219
void kbd_set_queue(int active)
Activate or deactivate global key queueing.
#define MAX_KBD_KEYS
Maximum number of keys a DC keyboard can have.
Definition keyboard.h:225
int kbd_queue_pop(maple_device_t *dev, int xlat)
Pop a key off a specific keyboard's queue.
#define KBD_QUEUE_SIZE
Size of a keyboard queue.
Definition keyboard.h:236
unsigned long long uint64
64-bit unsigned integer
Definition types.h:32
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
unsigned char uint8
8-bit unsigned integer
Definition types.h:35
Maple Bus driver interface.
Keyboard raw condition structure.
Definition keyboard.h:260
uint8 modifiers
Bitmask of set modifiers.
Definition keyboard.h:261
uint8 leds
Bitmask of set LEDs.
Definition keyboard.h:262
Keyboard keymap.
Definition keyboard.h:247
Keyboard status structure.
Definition keyboard.h:274
uint8 kbd_repeat_key
Key that is repeating.
Definition keyboard.h:302
volatile int queue_len
Current length of queue.
Definition keyboard.h:300
int queue_tail
Key queue tail.
Definition keyboard.h:298
int shift_keys
Modifier key status.
Definition keyboard.h:289
kbd_cond_t cond
The latest raw condition of the keyboard.
Definition keyboard.h:276
uint64 kbd_repeat_timer
Time that the next repeat will trigger.
Definition keyboard.h:303
int queue_head
Key queue head.
Definition keyboard.h:299
int region
Keyboard type/region.
Definition keyboard.h:292
One maple device.
Definition maple.h:270
Common integer types.