Moved method release_keys() to the common devices code to make sure this

feature also affects the removable (USB) keyboard.
This commit is contained in:
Volker Ruppert 2017-04-22 15:32:07 +00:00
parent 4ebe5e6879
commit 1ffac6a461
5 changed files with 20 additions and 24 deletions

View File

@ -140,6 +140,9 @@ void bx_devices_c::init(BX_MEM_C *newmem)
// removable devices init
bx_keyboard.dev = NULL;
bx_keyboard.gen_scancode = NULL;
for (i = 0; i < BX_KEY_NBKEYS; i++) {
bx_keyboard.bxkey_state[i] = 0;
}
for (i=0; i < 2; i++) {
bx_mouse[i].dev = NULL;
bx_mouse[i].enq_event = NULL;
@ -340,6 +343,7 @@ void bx_devices_c::reset(unsigned type)
#endif
mem->disable_smram();
bx_reset_plugins(type);
release_keys();
}
void bx_devices_c::register_state()
@ -1103,11 +1107,12 @@ void bx_devices_c::unregister_removable_mouse(void *dev)
}
}
// common keyboard device handler
// common keyboard device handlers
void bx_devices_c::gen_scancode(Bit32u key)
{
bx_bool ret = 0;
bx_keyboard.bxkey_state[key & 0xff] = ((key & BX_KEY_RELEASED) == 0);
if (bx_keyboard.dev != NULL) {
ret = bx_keyboard.gen_scancode(bx_keyboard.dev, key);
}
@ -1116,6 +1121,16 @@ void bx_devices_c::gen_scancode(Bit32u key)
}
}
void bx_devices_c::release_keys()
{
for (int i = 0; i < BX_KEY_NBKEYS; i++) {
if (bx_keyboard.bxkey_state[i]) {
gen_scancode(i | BX_KEY_RELEASED);
bx_keyboard.bxkey_state[i] = 0;
}
}
}
// common mouse device handlers
void bx_devices_c::mouse_enabled_changed(bx_bool enabled)
{

View File

@ -128,9 +128,6 @@ public:
virtual void paste_bytes(Bit8u *data, Bit32s length) {
STUBFUNC(keyboard, paste_bytes);
}
virtual void release_keys(void) {
STUBFUNC(keyboard, release_keys);
}
};
class BOCHSAPI bx_hard_drive_stub_c : public bx_devmodel_c {
@ -396,6 +393,7 @@ public:
void register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq, bx_mouse_enabled_changed_t mouse_enabled_changed);
void unregister_removable_mouse(void *dev);
void gen_scancode(Bit32u key);
void release_keys(void);
void mouse_enabled_changed(bx_bool enabled);
void mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state, bx_bool absxy);
@ -520,6 +518,7 @@ private:
struct {
void *dev;
bx_kbd_gen_scancode_t gen_scancode;
bx_bool bxkey_state[BX_KEY_NBKEYS];
} bx_keyboard;
struct {

View File

@ -207,10 +207,6 @@ void bx_keyb_c::init(void)
DEV_register_default_mouse(this, mouse_enq_static, mouse_enabled_changed_static);
}
for (i = 0; i < BX_KEY_NBKEYS; i++) {
bxkey_state[i] = 0;
}
// init runtime parameter
SIM->get_param_num(BXPN_KBD_PASTE_DELAY)->set_handler(kbd_param_handler);
SIM->get_param_num(BXPN_MOUSE_ENABLED)->set_handler(kbd_param_handler);
@ -221,7 +217,6 @@ void bx_keyb_c::reset(unsigned type)
if (BX_KEY_THIS pastebuf != NULL) {
BX_KEY_THIS stop_paste = 1;
}
BX_KEY_THIS release_keys();
}
void bx_keyb_c::register_state(void)
@ -764,16 +759,6 @@ void bx_keyb_c::paste_bytes(Bit8u *bytes, Bit32s length)
BX_KEY_THIS service_paste_buf();
}
void bx_keyb_c::release_keys()
{
for (int i = 0; i < BX_KEY_NBKEYS; i++) {
if (bxkey_state[i]) {
BX_KEY_THIS gen_scancode(i | BX_KEY_RELEASED);
bxkey_state[i] = 0;
}
}
}
void bx_keyb_c::gen_scancode(Bit32u key)
{
unsigned char *scancode;
@ -785,7 +770,6 @@ void bx_keyb_c::gen_scancode(Bit32u key)
}
BX_DEBUG(("gen_scancode(): %s %s", bx_keymap.getBXKeyName(key), (key >> 31)?"released":"pressed"));
bxkey_state[key & 0xff] = ((key & BX_KEY_RELEASED) == 0);
if (!BX_KEY_THIS s.kbd_controller.scancodes_translate)
BX_DEBUG(("keyboard: gen_scancode with scancode_translate cleared"));

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2014 The Bochs Project
// Copyright (C) 2002-2017 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -47,7 +47,6 @@ public:
// override stubs from bx_keyb_stub_c
virtual void gen_scancode(Bit32u key);
virtual void paste_bytes(Bit8u *data, Bit32s length);
virtual void release_keys(void);
virtual void register_state(void);
virtual void after_restore_state(void);
@ -229,7 +228,6 @@ private:
static void timer_handler(void *);
int timer_handle;
int statusbar_id[3];
bx_bool bxkey_state[BX_KEY_NBKEYS];
};
#endif // #ifndef _PCKEY_H

View File

@ -171,7 +171,7 @@ extern "C" {
#define DEV_kbd_gen_scancode(key) (bx_devices.gen_scancode(key))
#define DEV_kbd_paste_bytes(bytes, count) \
(bx_devices.pluginKeyboard->paste_bytes(bytes,count))
#define DEV_kbd_release_keys() (bx_devices.pluginKeyboard->release_keys())
#define DEV_kbd_release_keys() (bx_devices.release_keys())
///////// mouse macros
#define DEV_mouse_enabled_changed(en) (bx_devices.mouse_enabled_changed(en))