expose keyboard flags/mods state publically. don't preserve old state
since we're maintaining the keyboard flags/led state in the same way in our handler, there should be no need to restore the previous bios handler's flags/led state when returning
This commit is contained in:
parent
dcb8f3edaf
commit
365b628d66
80
DGLKBRD.C
80
DGLKBRD.C
|
@ -15,19 +15,10 @@
|
||||||
|
|
||||||
#define KEYBRD_FLAGS_ADDR 0x417
|
#define KEYBRD_FLAGS_ADDR 0x417
|
||||||
|
|
||||||
#define KEYBRD_FLAGS_SCROLLOCK 0x10
|
|
||||||
#define KEYBRD_FLAGS_NUMLOCK 0x20
|
|
||||||
#define KEYBRD_FLAGS_CAPSLOCK 0x40
|
|
||||||
|
|
||||||
#define KEYBRD_LED_SCROLLOCK 0x1
|
#define KEYBRD_LED_SCROLLOCK 0x1
|
||||||
#define KEYBRD_LED_NUMLOCK 0x2
|
#define KEYBRD_LED_NUMLOCK 0x2
|
||||||
#define KEYBRD_LED_CAPSLOCK 0x4
|
#define KEYBRD_LED_CAPSLOCK 0x4
|
||||||
|
|
||||||
#define KEYBRD_MOD_EXTENDED 0x1
|
|
||||||
#define KEYBRD_MOD_SHIFT 0x2
|
|
||||||
#define KEYBRD_MOD_NUMLOCK 0x4
|
|
||||||
#define KEYBRD_MOD_CAPSLOCK 0x8
|
|
||||||
|
|
||||||
#define KEY_EXTENDED ((KEY)0xe0)
|
#define KEY_EXTENDED ((KEY)0xe0)
|
||||||
|
|
||||||
static boolean _installed = FALSE;
|
static boolean _installed = FALSE;
|
||||||
|
@ -37,18 +28,16 @@ volatile ubyte keys[128];
|
||||||
|
|
||||||
volatile KEY _key_last_scan;
|
volatile KEY _key_last_scan;
|
||||||
volatile KEY _key_scan;
|
volatile KEY _key_scan;
|
||||||
volatile uword _key_flags;
|
volatile uword key_flags;
|
||||||
volatile uword _key_mod;
|
volatile uword key_mod;
|
||||||
|
|
||||||
uword _old_flags;
|
|
||||||
|
|
||||||
void (interrupt far *_old_handler)();
|
void (interrupt far *_old_handler)();
|
||||||
|
|
||||||
static void reset_key_states() {
|
static void reset_key_states() {
|
||||||
_key_last_scan = 0;
|
_key_last_scan = 0;
|
||||||
_key_scan = 0;
|
_key_scan = 0;
|
||||||
_key_flags = 0;
|
key_flags = 0;
|
||||||
_key_mod = 0;
|
key_mod = 0;
|
||||||
memset((void*)keys, 0, 128);
|
memset((void*)keys, 0, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +98,12 @@ static void push_keyboard_event(KEY key, EVENT_ACTION action) {
|
||||||
keyboard_event->type = EVENT_TYPE_KEYBOARD;
|
keyboard_event->type = EVENT_TYPE_KEYBOARD;
|
||||||
keyboard_event->keyboard.key = key;
|
keyboard_event->keyboard.key = key;
|
||||||
keyboard_event->keyboard.action = action;
|
keyboard_event->keyboard.action = action;
|
||||||
keyboard_event->keyboard.mod = _key_mod;
|
keyboard_event->keyboard.mod = key_mod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean handler_filter_keys(void) {
|
static boolean handler_filter_keys(void) {
|
||||||
if (BIT_ISSET(KEYBRD_MOD_EXTENDED, _key_mod)) {
|
if (BIT_ISSET(KEYBRD_MOD_EXTENDED, key_mod)) {
|
||||||
// extended key + leftshift comes with cursor key presses when
|
// extended key + leftshift comes with cursor key presses when
|
||||||
// numlock is enabled
|
// numlock is enabled
|
||||||
if ((_key_scan & 0x7f) == (KEY)KEY_LEFTSHIFT)
|
if ((_key_scan & 0x7f) == (KEY)KEY_LEFTSHIFT)
|
||||||
|
@ -126,19 +115,19 @@ static boolean handler_filter_keys(void) {
|
||||||
static void handler_update_flags_and_leds(void) {
|
static void handler_update_flags_and_leds(void) {
|
||||||
switch (_key_scan) {
|
switch (_key_scan) {
|
||||||
case (KEY)KEY_CAPSLOCK:
|
case (KEY)KEY_CAPSLOCK:
|
||||||
BIT_TOGGLE(KEYBRD_FLAGS_CAPSLOCK, _key_flags);
|
BIT_TOGGLE(KEYBRD_FLAGS_CAPSLOCK, key_flags);
|
||||||
update_kb_led(_key_flags);
|
update_kb_led(key_flags);
|
||||||
set_kb_flags(_key_flags);
|
set_kb_flags(key_flags);
|
||||||
break;
|
break;
|
||||||
case (KEY)KEY_NUMLOCK:
|
case (KEY)KEY_NUMLOCK:
|
||||||
BIT_TOGGLE(KEYBRD_FLAGS_NUMLOCK, _key_flags);
|
BIT_TOGGLE(KEYBRD_FLAGS_NUMLOCK, key_flags);
|
||||||
update_kb_led(_key_flags);
|
update_kb_led(key_flags);
|
||||||
set_kb_flags(_key_flags);
|
set_kb_flags(key_flags);
|
||||||
break;
|
break;
|
||||||
case (KEY)KEY_SCROLLLOCK:
|
case (KEY)KEY_SCROLLLOCK:
|
||||||
BIT_TOGGLE(KEYBRD_FLAGS_SCROLLOCK, _key_flags);
|
BIT_TOGGLE(KEYBRD_FLAGS_SCROLLOCK, key_flags);
|
||||||
update_kb_led(_key_flags);
|
update_kb_led(key_flags);
|
||||||
set_kb_flags(_key_flags);
|
set_kb_flags(key_flags);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -146,20 +135,20 @@ static void handler_update_flags_and_leds(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handler_update_modifiers(void) {
|
static void handler_update_modifiers(void) {
|
||||||
if (BIT_ISSET(KEYBRD_FLAGS_NUMLOCK, _key_flags))
|
if (BIT_ISSET(KEYBRD_FLAGS_NUMLOCK, key_flags))
|
||||||
BIT_SET(KEYBRD_MOD_NUMLOCK, _key_mod);
|
BIT_SET(KEYBRD_MOD_NUMLOCK, key_mod);
|
||||||
else
|
else
|
||||||
BIT_CLEAR(KEYBRD_MOD_NUMLOCK, _key_mod);
|
BIT_CLEAR(KEYBRD_MOD_NUMLOCK, key_mod);
|
||||||
|
|
||||||
if (BIT_ISSET(KEYBRD_FLAGS_CAPSLOCK, _key_flags))
|
if (BIT_ISSET(KEYBRD_FLAGS_CAPSLOCK, key_flags))
|
||||||
BIT_SET(KEYBRD_MOD_CAPSLOCK, _key_mod);
|
BIT_SET(KEYBRD_MOD_CAPSLOCK, key_mod);
|
||||||
else
|
else
|
||||||
BIT_CLEAR(KEYBRD_MOD_CAPSLOCK, _key_mod);
|
BIT_CLEAR(KEYBRD_MOD_CAPSLOCK, key_mod);
|
||||||
|
|
||||||
if (keys[KEY_LEFTSHIFT] || keys[KEY_RIGHTSHIFT])
|
if (keys[KEY_LEFTSHIFT] || keys[KEY_RIGHTSHIFT])
|
||||||
BIT_SET(KEYBRD_MOD_SHIFT, _key_mod);
|
BIT_SET(KEYBRD_MOD_SHIFT, key_mod);
|
||||||
else
|
else
|
||||||
BIT_CLEAR(KEYBRD_MOD_SHIFT, _key_mod);
|
BIT_CLEAR(KEYBRD_MOD_SHIFT, key_mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// keyboard interrupt handler
|
// keyboard interrupt handler
|
||||||
|
@ -168,7 +157,7 @@ void interrupt far kb_int_handler(void) {
|
||||||
_key_scan = inp(KEYBRD_DATA_PORT);
|
_key_scan = inp(KEYBRD_DATA_PORT);
|
||||||
if (_key_scan == KEY_EXTENDED) {
|
if (_key_scan == KEY_EXTENDED) {
|
||||||
// extended key scan
|
// extended key scan
|
||||||
BIT_SET(KEYBRD_MOD_EXTENDED, _key_mod);
|
BIT_SET(KEYBRD_MOD_EXTENDED, key_mod);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!handler_filter_keys()) {
|
if (!handler_filter_keys()) {
|
||||||
|
@ -192,7 +181,7 @@ void interrupt far kb_int_handler(void) {
|
||||||
_key_last_scan = _key_scan;
|
_key_last_scan = _key_scan;
|
||||||
}
|
}
|
||||||
|
|
||||||
BIT_CLEAR(KEYBRD_MOD_EXTENDED, _key_mod);
|
BIT_CLEAR(KEYBRD_MOD_EXTENDED, key_mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// indicate key event was processed to keyboard controller
|
// indicate key event was processed to keyboard controller
|
||||||
|
@ -210,21 +199,12 @@ boolean keyboard_init(void) {
|
||||||
|
|
||||||
reset_key_states();
|
reset_key_states();
|
||||||
|
|
||||||
// preserve old flags
|
key_flags = get_kb_flags();
|
||||||
_old_flags = get_kb_flags();
|
|
||||||
_key_flags = _old_flags;
|
|
||||||
|
|
||||||
handler_update_modifiers();
|
handler_update_modifiers();
|
||||||
|
|
||||||
_old_handler = _dos_getvect(9);
|
_old_handler = _dos_getvect(9);
|
||||||
_dos_setvect(9, kb_int_handler);
|
_dos_setvect(9, kb_int_handler);
|
||||||
|
|
||||||
// turn off keyboard LEDs since our interrupt handler does not currently
|
|
||||||
// respect the num/caps/scroll lock statuses
|
|
||||||
int_disable();
|
|
||||||
update_kb_led(_key_flags);
|
|
||||||
int_enable();
|
|
||||||
|
|
||||||
_installed = TRUE;
|
_installed = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -233,16 +213,8 @@ boolean keyboard_shutdown(void) {
|
||||||
if (!_installed)
|
if (!_installed)
|
||||||
return TRUE; // don't care
|
return TRUE; // don't care
|
||||||
|
|
||||||
// reset keyboard LEDs to previous state
|
|
||||||
int_disable();
|
|
||||||
update_kb_led(_old_flags);
|
|
||||||
int_enable();
|
|
||||||
|
|
||||||
_dos_setvect(9, _old_handler);
|
_dos_setvect(9, _old_handler);
|
||||||
|
|
||||||
// restore keyboard flags to previous state
|
|
||||||
set_kb_flags(_old_flags);
|
|
||||||
|
|
||||||
reset_key_states();
|
reset_key_states();
|
||||||
|
|
||||||
_installed = FALSE;
|
_installed = FALSE;
|
||||||
|
|
12
DGLKBRD.H
12
DGLKBRD.H
|
@ -6,11 +6,23 @@
|
||||||
|
|
||||||
typedef byte KEY;
|
typedef byte KEY;
|
||||||
|
|
||||||
|
#define KEYBRD_FLAGS_SCROLLOCK 0x10
|
||||||
|
#define KEYBRD_FLAGS_NUMLOCK 0x20
|
||||||
|
#define KEYBRD_FLAGS_CAPSLOCK 0x40
|
||||||
|
|
||||||
|
#define KEYBRD_MOD_EXTENDED 0x1
|
||||||
|
#define KEYBRD_MOD_SHIFT 0x2
|
||||||
|
#define KEYBRD_MOD_NUMLOCK 0x4
|
||||||
|
#define KEYBRD_MOD_CAPSLOCK 0x8
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Current state of the keyboard.
|
* Current state of the keyboard.
|
||||||
*/
|
*/
|
||||||
extern volatile ubyte keys[128];
|
extern volatile ubyte keys[128];
|
||||||
|
|
||||||
|
extern volatile uword key_flags;
|
||||||
|
extern volatile uword key_mod;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Installs a custom keyboard interrupt handler.
|
* Installs a custom keyboard interrupt handler.
|
||||||
* @return TRUE on success
|
* @return TRUE on success
|
||||||
|
|
Loading…
Reference in a new issue