Keyboard size optimizations

This commit is contained in:
Micah Dowty 2011-03-23 22:38:14 +00:00
parent 962563d1e7
commit 6ad70d0e71
2 changed files with 58 additions and 65 deletions

View file

@ -53,12 +53,7 @@
* Global keyboard state * Global keyboard state
*/ */
static struct { KeyboardPrivate gKeyboard;
Bool escape;
KeyboardIRQHandler handler;
uint32 keyDown[roundup(KEY_MAX, 32)];
} gKeyboard;
/* /*
* KeyboardWrite -- * KeyboardWrite --
@ -122,24 +117,6 @@ KeyboardReadCB(void)
} }
/*
* KeyboardSetKeyPressed --
*
* Set a key's up/down state.
*/
static void
KeyboardSetKeyPressed(Keycode k, Bool down)
{
uint32 mask = 1 << (k & 0x1F);
if (down) {
gKeyboard.keyDown[k >> 5] |= mask;
} else {
gKeyboard.keyDown[k >> 5] &= ~mask;
}
}
/* /*
* KeyboardTranslate -- * KeyboardTranslate --
* *
@ -287,7 +264,7 @@ KeyboardTranslate(KeyEvent *event)
} }
} }
KeyboardSetKeyPressed(event->rawKey, event->pressed); gKeyboard.keyDown[event->rawKey] = event->pressed;
} }
@ -334,39 +311,3 @@ Keyboard_Init(void)
Intr_SetMask(KB_IRQ, TRUE); Intr_SetMask(KB_IRQ, TRUE);
Intr_SetHandler(IRQ_VECTOR(KB_IRQ), KeyboardHandlerInternal); Intr_SetHandler(IRQ_VECTOR(KB_IRQ), KeyboardHandlerInternal);
} }
/*
* Keyboard_IsKeyPressed --
*
* Check whether a key, identified by Keycode, is down.
*/
fastcall Bool
Keyboard_IsKeyPressed(Keycode k)
{
if (k < KEY_MAX) {
return (gKeyboard.keyDown[k >> 5] >> (k & 0x1F)) & 1;
}
return FALSE;
}
/*
* Keyboard_SetHandler --
*
* Set a handler that will receive translated keys and scancodes.
* This handler is run within the IRQ handler, so it must complete
* quickly and use minimal stack space.
*
* The handler will be called once per scancode byte, regardless of
* whether that byte ended a key event or not. If event->key is
* zero, the event can be ignored unless you're interested in
* seeing the raw scancodes.
*/
fastcall void
Keyboard_SetHandler(KeyboardIRQHandler handler)
{
gKeyboard.handler = handler;
}

View file

@ -91,8 +91,60 @@ typedef struct KeyEvent {
typedef fastcall void (*KeyboardIRQHandler)(KeyEvent *event); typedef fastcall void (*KeyboardIRQHandler)(KeyEvent *event);
fastcall void Keyboard_Init(void); /*
fastcall Bool Keyboard_IsKeyPressed(Keycode key); * Private data, used by the inline functions below.
fastcall void Keyboard_SetHandler(KeyboardIRQHandler handler); */
#endif /* __VGA_TEXT_H__ */ typedef struct KeyboardPrivate {
Bool escape;
KeyboardIRQHandler handler;
Bool keyDown[KEY_MAX];
} KeyboardPrivate;
extern KeyboardPrivate gKeyboard;
/*
* Public Functions
*/
fastcall void Keyboard_Init(void);
/*
* Keyboard_IsKeyPressed --
*
* Check whether a key, identified by Keycode, is down.
*/
static inline Bool
Keyboard_IsKeyPressed(Keycode k)
{
if (k < KEY_MAX) {
return gKeyboard.keyDown[k];
}
return FALSE;
}
/*
* Keyboard_SetHandler --
*
* Set a handler that will receive translated keys and scancodes.
* This handler is run within the IRQ handler, so it must complete
* quickly and use minimal stack space.
*
* The handler will be called once per scancode byte, regardless of
* whether that byte ended a key event or not. If event->key is
* zero, the event can be ignored unless you're interested in
* seeing the raw scancodes.
*/
static inline void
Keyboard_SetHandler(KeyboardIRQHandler handler)
{
gKeyboard.handler = handler;
}
#endif /* __KEYBOARD_H__ */