diff --git a/bochs/iodev/devices.cc b/bochs/iodev/devices.cc index 187c6e825..1c4e40035 100644 --- a/bochs/iodev/devices.cc +++ b/bochs/iodev/devices.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: devices.cc,v 1.141 2009-02-23 18:38:25 vruppert Exp $ +// $Id: devices.cc,v 1.142 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -120,7 +120,7 @@ void bx_devices_c::init(BX_MEM_C *newmem) const char *plugname; #endif - BX_DEBUG(("Init $Id: devices.cc,v 1.141 2009-02-23 18:38:25 vruppert Exp $")); + BX_DEBUG(("Init $Id: devices.cc,v 1.142 2009-03-02 21:21:16 vruppert Exp $")); mem = newmem; /* set builtin default handlers, will be overwritten by the real default handler */ @@ -153,6 +153,9 @@ void bx_devices_c::init(BX_MEM_C *newmem) } // common mouse settings + bx_mouse_dev = NULL; + bx_mouse_enq = NULL; + bx_mouse_enabled_changed = NULL; mouse_captured = SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get(); mouse_type = SIM->get_param_enum(BXPN_MOUSE_TYPE)->get(); @@ -1060,42 +1063,48 @@ bx_bool bx_devices_c::is_usb_uhci_enabled(void) } // common mouse device handlers +void bx_devices_c::register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq, + bx_mouse_enabled_changed_t mouse_enabled_changed) +{ + if (bx_mouse_dev == NULL) { + bx_mouse_dev = dev; + bx_mouse_enq = mouse_enq; + bx_mouse_enabled_changed = mouse_enabled_changed; + } +} + +void bx_devices_c::unregister_removable_mouse(void *dev) +{ + if (dev == bx_mouse_dev) { + bx_mouse_dev = NULL; + bx_mouse_enq = NULL; + bx_mouse_enabled_changed = NULL; + } +} + void bx_devices_c::mouse_enabled_changed(bx_bool enabled) { mouse_captured = enabled; -#if BX_SUPPORT_USB_UHCI - if (pluginUSB_UHCI->usb_mouse_enabled_changed(enabled)) { + if (bx_mouse_dev != NULL) { + bx_mouse_enabled_changed(bx_mouse_dev, enabled); return; } -#endif -#if BX_SUPPORT_USB_OHCI - if (pluginUSB_OHCI->usb_mouse_enabled_changed(enabled)) { - return; - } -#endif pluginKeyboard->mouse_enabled_changed(enabled); } void bx_devices_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state) { - // If mouse events are disabled on the GUI headerbar, don't // generate any mouse data if (!mouse_captured) return; - // if an usb mouse is connected, redirect mouse data to the usb device -#if BX_SUPPORT_USB_UHCI - if (pluginUSB_UHCI->usb_mouse_enq(delta_x, delta_y, delta_z, button_state)) { + // if a removable mouse is connected, redirect mouse data to the device + if (bx_mouse_dev != NULL) { + bx_mouse_enq(bx_mouse_dev, delta_x, delta_y, delta_z, button_state); return; } -#endif -#if BX_SUPPORT_USB_OHCI - if (pluginUSB_OHCI->usb_mouse_enq(delta_x, delta_y, delta_z, button_state)) { - return; - } -#endif // if type == serial, redirect mouse data to the serial device if ((mouse_type == BX_MOUSE_TYPE_SERIAL) || diff --git a/bochs/iodev/iodev.h b/bochs/iodev/iodev.h index 9679b9ca4..40069d166 100644 --- a/bochs/iodev/iodev.h +++ b/bochs/iodev/iodev.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: iodev.h,v 1.111 2009-02-23 18:38:25 vruppert Exp $ +// $Id: iodev.h,v 1.112 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -48,6 +48,9 @@ class bx_g2h_c; typedef Bit32u (*bx_read_handler_t)(void *, Bit32u, unsigned); typedef void (*bx_write_handler_t)(void *, Bit32u, Bit32u, unsigned); +typedef void (*bx_mouse_enq_t)(void *, int, int, int, unsigned); +typedef void (*bx_mouse_enabled_changed_t)(void *, bx_bool); + #if BX_USE_DEV_SMF # define BX_DEV_SMF static # define BX_DEV_THIS bx_devices. @@ -332,12 +335,6 @@ public: #if BX_SUPPORT_PCIUSB class BOCHSAPI bx_pci_usb_stub_c : public bx_devmodel_c, public bx_pci_device_stub_c { public: - virtual bx_bool usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state) { - return 0; - } - virtual bx_bool usb_mouse_enabled_changed(bx_bool enabled) { - return 0; - } virtual bx_bool usb_key_enq(Bit8u *scan_code) { return 0; } @@ -424,6 +421,8 @@ public: bx_bool unregister_irq(unsigned irq, const char *name); Bit32u inp(Bit16u addr, unsigned io_len) BX_CPP_AttrRegparmN(2); void outp(Bit16u addr, Bit32u value, unsigned io_len) BX_CPP_AttrRegparmN(3); + 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 mouse_enabled_changed(bx_bool enabled); void mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state); @@ -538,6 +537,9 @@ private: bx_bool mouse_captured; // host mouse capture enabled Bit8u mouse_type; + void *bx_mouse_dev; + bx_mouse_enq_t bx_mouse_enq; + bx_mouse_enabled_changed_t bx_mouse_enabled_changed; int timer_handle; diff --git a/bochs/iodev/usb_hid.cc b/bochs/iodev/usb_hid.cc index f9f14a5ab..c2ad023d8 100644 --- a/bochs/iodev/usb_hid.cc +++ b/bochs/iodev/usb_hid.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: usb_hid.cc,v 1.14 2009-02-14 10:06:20 vruppert Exp $ +// $Id: usb_hid.cc,v 1.15 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 Volker Ruppert @@ -360,8 +360,10 @@ usb_hid_device_c::usb_hid_device_c(usbdev_type type) d.speed = USB_SPEED_LOW; if (d.type == USB_DEV_TYPE_MOUSE) { strcpy(d.devname, "USB Mouse"); + DEV_register_removable_mouse((void*)this, mouse_enq_static, mouse_enabled_changed); } else if (d.type == USB_DEV_TYPE_TABLET) { strcpy(d.devname, "USB Tablet"); + DEV_register_removable_mouse((void*)this, mouse_enq_static, mouse_enabled_changed); } else if (d.type == USB_DEV_TYPE_KEYPAD) { strcpy(d.devname, "USB/PS2 Keypad"); } @@ -373,6 +375,10 @@ usb_hid_device_c::usb_hid_device_c(usbdev_type type) usb_hid_device_c::~usb_hid_device_c(void) { + if ((d.type == USB_DEV_TYPE_MOUSE) || + (d.type == USB_DEV_TYPE_TABLET)) { + DEV_unregister_removable_mouse((void*)this); + } } void usb_hid_device_c::register_state_specific(bx_list_c *parent) @@ -659,6 +665,16 @@ int usb_hid_device_c::mouse_poll(Bit8u *buf, int len) return l; } +void usb_hid_device_c::mouse_enabled_changed(void *dev, bx_bool enabled) +{ + if (enabled) ((usb_hid_device_c*)dev)->handle_reset(); +} + +void usb_hid_device_c::mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state) +{ + ((usb_hid_device_c*)dev)->mouse_enq(delta_x, delta_y, delta_z, button_state); +} + void usb_hid_device_c::mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state) { if (d.type == USB_DEV_TYPE_MOUSE) { diff --git a/bochs/iodev/usb_hid.h b/bochs/iodev/usb_hid.h index 2946cab42..4dfbbfaec 100644 --- a/bochs/iodev/usb_hid.h +++ b/bochs/iodev/usb_hid.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: usb_hid.h,v 1.9 2009-02-08 09:05:52 vruppert Exp $ +// $Id: usb_hid.h,v 1.10 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 Volker Ruppert @@ -34,11 +34,7 @@ public: virtual int handle_control(int request, int value, int index, int length, Bit8u *data); virtual int handle_data(USBPacket *p); virtual void register_state_specific(bx_list_c *parent); - void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state); bx_bool key_enq(Bit8u *scan_code); -protected: - int mouse_poll(Bit8u *buf, int len); - int keypad_poll(Bit8u *buf, int len); private: struct { @@ -52,6 +48,12 @@ private: Bit8u saved_key[8]; Bit8u key_pad_packet[8]; } s; + + static void mouse_enabled_changed(void *dev, bx_bool enabled); + static void mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state); + void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state); + int mouse_poll(Bit8u *buf, int len); + int keypad_poll(Bit8u *buf, int len); }; #endif diff --git a/bochs/iodev/usb_ohci.cc b/bochs/iodev/usb_ohci.cc index e856df1e7..f6062d97f 100644 --- a/bochs/iodev/usb_ohci.cc +++ b/bochs/iodev/usb_ohci.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: usb_ohci.cc,v 1.12 2009-03-01 19:29:36 vruppert Exp $ +// $Id: usb_ohci.cc,v 1.13 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net) @@ -152,7 +152,6 @@ void bx_usb_ohci_c::init(void) for (i=0; iget_type(); - if ((type == USB_DEV_TYPE_MOUSE) || - (type == USB_DEV_TYPE_TABLET)) { - if (BX_OHCI_THIS hub.usb_port[port].device == BX_OHCI_THIS mousedev) { - BX_OHCI_THIS mousedev = NULL; - } - } else if (type == USB_DEV_TYPE_KEYPAD) { + if (type == USB_DEV_TYPE_KEYPAD) { if (BX_OHCI_THIS hub.usb_port[port].device == BX_OHCI_THIS keybdev) { BX_OHCI_THIS keybdev = NULL; } @@ -1479,15 +1467,6 @@ void bx_usb_ohci_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_l BX_DEBUG(("USB OHCI write register 0x%02x value 0x%s", address, szTmp)); } -bx_bool bx_usb_ohci_c::usb_mouse_enabled_changed(bx_bool enabled) -{ - if (BX_OHCI_THIS mousedev != NULL) { - if (enabled) mousedev->handle_reset(); - return 1; - } - return 0; -} - void bx_usb_ohci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected) { usb_device_c *device = BX_OHCI_THIS hub.usb_port[port].device; @@ -1522,15 +1501,6 @@ void bx_usb_ohci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connect } } -bx_bool bx_usb_ohci_c::usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state) -{ - if (BX_OHCI_THIS mousedev != NULL) { - mousedev->mouse_enq(delta_x, delta_y, delta_z, button_state); - return 1; - } - return 0; -} - bx_bool bx_usb_ohci_c::usb_key_enq(Bit8u *scan_code) { if (BX_OHCI_THIS keybdev != NULL) { diff --git a/bochs/iodev/usb_ohci.h b/bochs/iodev/usb_ohci.h index 439206919..800c2b2c1 100644 --- a/bochs/iodev/usb_ohci.h +++ b/bochs/iodev/usb_ohci.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: usb_ohci.h,v 1.8 2009-03-01 19:29:36 vruppert Exp $ +// $Id: usb_ohci.h,v 1.9 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net) @@ -253,8 +253,6 @@ public: virtual ~bx_usb_ohci_c(); virtual void init(void); virtual void reset(unsigned); - virtual bx_bool usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state); - virtual bx_bool usb_mouse_enabled_changed(bx_bool enable); virtual bx_bool usb_key_enq(Bit8u *scan_code); virtual void register_state(void); virtual void after_restore_state(void); @@ -269,7 +267,6 @@ private: bx_usb_ohci_t hub; Bit8u *device_buffer; - usb_hid_device_c *mousedev; usb_hid_device_c *keybdev; USBPacket usb_packet; diff --git a/bochs/iodev/usb_uhci.cc b/bochs/iodev/usb_uhci.cc index 358cbfeb8..53830f108 100644 --- a/bochs/iodev/usb_uhci.cc +++ b/bochs/iodev/usb_uhci.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: usb_uhci.cc,v 1.10 2009-03-01 19:29:36 vruppert Exp $ +// $Id: usb_uhci.cc,v 1.11 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net) @@ -116,7 +116,6 @@ void bx_usb_uhci_c::init(void) for (i=0; iget_type(); - if ((type == USB_DEV_TYPE_MOUSE) || - (type == USB_DEV_TYPE_TABLET)) { - if (BX_UHCI_THIS hub.usb_port[port].device == BX_UHCI_THIS mousedev) { - BX_UHCI_THIS mousedev = NULL; - } - } else if (type == USB_DEV_TYPE_KEYPAD) { + if (type == USB_DEV_TYPE_KEYPAD) { if (BX_UHCI_THIS hub.usb_port[port].device == BX_UHCI_THIS keybdev) { BX_UHCI_THIS keybdev = NULL; } @@ -1080,15 +1068,6 @@ void bx_usb_uhci_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_l BX_DEBUG(("USB UHCI write register 0x%02x value 0x%s", address, szTmp)); } -bx_bool bx_usb_uhci_c::usb_mouse_enabled_changed(bx_bool enabled) -{ - if (BX_UHCI_THIS mousedev != NULL) { - if (enabled) mousedev->handle_reset(); - return 1; - } - return 0; -} - void bx_usb_uhci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected) { usb_device_c *device = BX_UHCI_THIS hub.usb_port[port].device; @@ -1141,15 +1120,6 @@ void bx_usb_uhci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connect } } -bx_bool bx_usb_uhci_c::usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state) -{ - if (BX_UHCI_THIS mousedev != NULL) { - mousedev->mouse_enq(delta_x, delta_y, delta_z, button_state); - return 1; - } - return 0; -} - bx_bool bx_usb_uhci_c::usb_key_enq(Bit8u *scan_code) { if (BX_UHCI_THIS keybdev != NULL) { diff --git a/bochs/iodev/usb_uhci.h b/bochs/iodev/usb_uhci.h index 56b25f292..5929e74e6 100644 --- a/bochs/iodev/usb_uhci.h +++ b/bochs/iodev/usb_uhci.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: usb_uhci.h,v 1.6 2009-03-01 19:29:36 vruppert Exp $ +// $Id: usb_uhci.h,v 1.7 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net) @@ -187,8 +187,6 @@ public: virtual ~bx_usb_uhci_c(); virtual void init(void); virtual void reset(unsigned); - virtual bx_bool usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state); - virtual bx_bool usb_mouse_enabled_changed(bx_bool enabled); virtual bx_bool usb_key_enq(Bit8u *scan_code); virtual void register_state(void); virtual void after_restore_state(void); @@ -204,7 +202,6 @@ private: bx_bool busy; Bit8u *device_buffer; - usb_hid_device_c *mousedev; usb_hid_device_c *keybdev; USBPacket usb_packet; diff --git a/bochs/plugin.h b/bochs/plugin.h index 14020b6a1..6701cd2e0 100644 --- a/bochs/plugin.h +++ b/bochs/plugin.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: plugin.h,v 1.75 2009-02-23 18:38:25 vruppert Exp $ +// $Id: plugin.h,v 1.76 2009-03-02 21:21:16 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2009 The Bochs Project @@ -124,6 +124,8 @@ extern "C" { #define DEV_mouse_enabled_changed(en) (bx_devices.mouse_enabled_changed(en)) #define DEV_mouse_motion(dx, dy, state) (bx_devices.mouse_motion(dx, dy, 0, state)) #define DEV_mouse_motion_ext(dx, dy, dz, state) (bx_devices.mouse_motion(dx, dy, dz, state)) +#define DEV_register_removable_mouse(a,b,c) (bx_devices.register_removable_mouse(a,b,c)) +#define DEV_unregister_removable_mouse(a) (bx_devices.unregister_removable_mouse(a)) ///////// I/O APIC macros #define DEV_ioapic_present() (bx_devices.pluginIOAPIC != &bx_devices.stubIOAPIC)