2004-12-11 11:35:33 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2004-12-11 11:35:33 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2016-03-31 20:24:34 +03:00
|
|
|
// Copyright (C) 2004-2016 The Bochs Project
|
2004-12-11 11:35:33 +03:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-12-11 11:35:33 +03:00
|
|
|
|
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
// Initial/additional code by Ben Lunt 'fys at fysnet dot net'
|
|
|
|
// http://www.fysnet.net
|
2004-12-11 11:35:33 +03:00
|
|
|
|
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-01-27 01:24:03 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2004-12-11 11:35:33 +03:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
|
|
|
#include "iodev.h"
|
2008-12-29 23:16:08 +03:00
|
|
|
#include "busmouse.h"
|
2004-12-11 11:35:33 +03:00
|
|
|
|
|
|
|
#if BX_SUPPORT_BUSMOUSE
|
|
|
|
|
|
|
|
#define LOG_THIS theBusMouse->
|
|
|
|
|
|
|
|
bx_busm_c *theBusMouse = NULL;
|
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
// There is a difference between older hardware and newer hardware.
|
|
|
|
// Set this flag to indicate older hardware. I will explain the difference
|
|
|
|
// at each item this flag is used.
|
|
|
|
#define LEGACY_BUSMOUSE 0
|
2013-12-27 21:47:44 +04:00
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
#define BUS_MOUSE_IRQ 5
|
|
|
|
#define IRQ_MASK ((1<<5) >> BUS_MOUSE_IRQ)
|
|
|
|
|
|
|
|
// MS Inport Bus Mouse Adapter
|
|
|
|
#define INP_PORT_CONTROL 0x023C
|
|
|
|
#define INP_PORT_DATA 0x023D
|
|
|
|
#define INP_PORT_SIGNATURE 0x023E
|
|
|
|
#define INP_PORT_CONFIG 0x023F
|
|
|
|
|
|
|
|
#define INP_CTRL_READ_BUTTONS 0x00
|
|
|
|
#define INP_CTRL_READ_X 0x01
|
|
|
|
#define INP_CTRL_READ_Y 0x02
|
|
|
|
#define INP_CTRL_COMMAND 0x07
|
|
|
|
#define INP_CTRL_RAISE_IRQ 0x16
|
|
|
|
#define INP_CTRL_RESET 0x80
|
|
|
|
|
|
|
|
#define INP_HOLD_COUNTER (1 << 5)
|
|
|
|
#define INP_ENABLE_IRQ (1 << 0)
|
|
|
|
|
|
|
|
// MS/Logictech Standard Bus Mouse Adapter
|
|
|
|
#define BUSM_PORT_DATA 0x023C
|
|
|
|
#define BUSM_PORT_SIGNATURE 0x023D
|
|
|
|
#define BUSM_PORT_CONTROL 0x023E
|
|
|
|
#define BUSM_PORT_CONFIG 0x023F
|
|
|
|
|
|
|
|
#define HOLD_COUNTER (1 << 7)
|
|
|
|
#define READ_X (0 << 6)
|
|
|
|
#define READ_Y (1 << 6)
|
|
|
|
#define READ_LOW (0 << 5)
|
|
|
|
#define READ_HIGH (1 << 5)
|
|
|
|
#define DISABLE_IRQ (1 << 4)
|
|
|
|
|
|
|
|
#define READ_X_LOW (READ_X | READ_LOW)
|
|
|
|
#define READ_X_HIGH (READ_X | READ_HIGH)
|
|
|
|
#define READ_Y_LOW (READ_Y | READ_LOW)
|
|
|
|
#define READ_Y_HIGH (READ_Y | READ_HIGH)
|
2013-12-27 21:47:44 +04:00
|
|
|
|
|
|
|
|
2014-06-08 12:40:08 +04:00
|
|
|
int CDECL libbusmouse_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
// Create one instance of the busmouse device object.
|
2006-09-10 21:18:44 +04:00
|
|
|
theBusMouse = new bx_busm_c();
|
2004-12-11 11:35:33 +03:00
|
|
|
// Register this device.
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theBusMouse, BX_PLUGIN_BUSMOUSE);
|
|
|
|
return 0; // Success
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 12:40:08 +04:00
|
|
|
void CDECL libbusmouse_LTX_plugin_fini(void)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
delete theBusMouse;
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_busm_c::bx_busm_c()
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
2011-12-30 15:13:37 +04:00
|
|
|
put("busmouse", "BUSM");
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_busm_c::~bx_busm_c()
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
2012-08-19 12:16:20 +04:00
|
|
|
SIM->get_bochs_root()->remove("busmouse");
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_busm_c::init(void)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
2011-02-25 01:05:47 +03:00
|
|
|
BX_DEBUG(("Init $Id$"));
|
2004-12-11 11:35:33 +03:00
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
BX_BUSM_THIS type = SIM->get_param_enum(BXPN_MOUSE_TYPE)->get();
|
|
|
|
|
2004-12-11 11:35:33 +03:00
|
|
|
DEV_register_irq(BUS_MOUSE_IRQ, "Bus Mouse");
|
|
|
|
|
|
|
|
// Call our timer routine at 30hz
|
|
|
|
BX_BUSM_THIS timer_index =
|
|
|
|
bx_pc_system.register_timer(this, timer_handler, 33334, 1, 1, "bus mouse timer");
|
|
|
|
|
|
|
|
for (int i=0x23C; i<=0x23F; i++) {
|
|
|
|
DEV_register_ioread_handler(this, read_handler, i, "Bus Mouse", 1);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, i, "Bus Mouse", 1);
|
|
|
|
}
|
2009-03-03 23:34:50 +03:00
|
|
|
DEV_register_default_mouse(this, mouse_enq_static, NULL);
|
2004-12-11 11:35:33 +03:00
|
|
|
|
|
|
|
BX_BUSM_THIS mouse_delayed_dx = 0;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dy = 0;
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_BUSM_THIS mouse_buttons = 0;
|
2008-01-27 01:24:03 +03:00
|
|
|
BX_BUSM_THIS current_x =
|
|
|
|
BX_BUSM_THIS current_y =
|
2004-12-11 11:35:33 +03:00
|
|
|
BX_BUSM_THIS current_b = 0;
|
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
if (BX_BUSM_THIS type == BX_MOUSE_TYPE_INPORT) {
|
|
|
|
BX_BUSM_THIS control_val = 0; // the control port value
|
|
|
|
BX_BUSM_THIS mouse_buttons_last = 0;
|
|
|
|
} else {
|
|
|
|
BX_BUSM_THIS control_val = 0x1f; // the control port value
|
|
|
|
BX_BUSM_THIS config_val = 0x0e; // the config port value
|
|
|
|
BX_BUSM_THIS sig_val = 0; // the signature port value
|
|
|
|
}
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_BUSM_THIS command_val = 0; // command byte
|
2016-03-31 20:24:34 +03:00
|
|
|
BX_BUSM_THIS toggle_counter = 0; // signature byte / IRQ bit toggle
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_BUSM_THIS interrupts = 0; // interrupts off
|
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
if (BX_BUSM_THIS type == BX_MOUSE_TYPE_INPORT) {
|
|
|
|
BX_INFO(("MS Inport BusMouse initialized"));
|
|
|
|
} else {
|
|
|
|
BX_INFO(("Standard MS/Logitech BusMouse initialized"));
|
|
|
|
}
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_busm_c::register_state(void)
|
|
|
|
{
|
2012-02-12 22:43:20 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "busmouse", "Busmouse State");
|
2013-12-27 21:47:44 +04:00
|
|
|
BXRS_DEC_PARAM_FIELD(list, mouse_delayed_dx, BX_BUSM_THIS mouse_delayed_dx);
|
|
|
|
BXRS_DEC_PARAM_FIELD(list, mouse_delayed_dy, BX_BUSM_THIS mouse_delayed_dy);
|
|
|
|
BXRS_HEX_PARAM_FIELD(list, mouse_buttons, BX_BUSM_THIS mouse_buttons);
|
2016-03-31 20:24:34 +03:00
|
|
|
BXRS_HEX_PARAM_FIELD(list, mouse_buttons_last, BX_BUSM_THIS mouse_buttons_last);
|
2006-05-28 21:07:57 +04:00
|
|
|
BXRS_HEX_PARAM_FIELD(list, current_x, BX_BUSM_THIS current_x);
|
|
|
|
BXRS_HEX_PARAM_FIELD(list, current_y, BX_BUSM_THIS current_y);
|
|
|
|
BXRS_HEX_PARAM_FIELD(list, current_b, BX_BUSM_THIS current_b);
|
|
|
|
|
2013-12-27 21:47:44 +04:00
|
|
|
BXRS_HEX_PARAM_FIELD(list, control_val, BX_BUSM_THIS control_val);
|
2008-12-29 23:16:08 +03:00
|
|
|
BXRS_HEX_PARAM_FIELD(list, command_val, BX_BUSM_THIS command_val);
|
2016-03-31 20:24:34 +03:00
|
|
|
BXRS_HEX_PARAM_FIELD(list, toggle_counter, BX_BUSM_THIS toggle_counter);
|
2013-12-27 21:47:44 +04:00
|
|
|
BXRS_PARAM_BOOL(list, interrupts, BX_BUSM_THIS interrupts);
|
2016-03-31 20:24:34 +03:00
|
|
|
|
|
|
|
BXRS_HEX_PARAM_FIELD(list, config_val, BX_BUSM_THIS config_val);
|
|
|
|
BXRS_HEX_PARAM_FIELD(list, sig_val, BX_BUSM_THIS sig_val);
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static IO port read callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
|
|
|
Bit32u bx_busm_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
#if !BX_USE_BUSM_SMF
|
|
|
|
bx_busm_c *class_ptr = (bx_busm_c *) this_ptr;
|
2006-03-08 00:11:20 +03:00
|
|
|
return class_ptr->read(address, io_len);
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
Bit32u bx_busm_c::read(Bit32u address, unsigned io_len)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_BUSM_SMF
|
|
|
|
|
|
|
|
Bit8u value = 0;
|
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
if (BX_BUSM_THIS type == BX_MOUSE_TYPE_INPORT) {
|
|
|
|
switch (address) {
|
|
|
|
case INP_PORT_CONTROL:
|
|
|
|
value = BX_BUSM_THIS control_val;
|
|
|
|
break;
|
|
|
|
case INP_PORT_DATA:
|
|
|
|
switch (BX_BUSM_THIS command_val) {
|
|
|
|
case INP_CTRL_READ_BUTTONS:
|
|
|
|
value = BX_BUSM_THIS current_b;
|
|
|
|
#if !LEGACY_BUSMOUSE
|
|
|
|
value |= 0x40; // Newer Logitech mouse drivers look for bit 6 set
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case INP_CTRL_READ_X:
|
|
|
|
value = BX_BUSM_THIS current_x;
|
|
|
|
break;
|
|
|
|
case INP_CTRL_READ_Y:
|
|
|
|
value = BX_BUSM_THIS current_y;
|
|
|
|
break;
|
|
|
|
case INP_CTRL_COMMAND:
|
|
|
|
value = BX_BUSM_THIS control_val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BX_ERROR(("Reading data port in unsupported mode 0x%02x", BX_BUSM_THIS control_val));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INP_PORT_SIGNATURE:
|
|
|
|
if (!BX_BUSM_THIS toggle_counter) {
|
|
|
|
value = 0xDE;
|
|
|
|
} else {
|
|
|
|
value = 0x12; // Manufacturer id ?
|
|
|
|
}
|
|
|
|
BX_BUSM_THIS toggle_counter ^= 1;
|
|
|
|
break;
|
|
|
|
case INP_PORT_CONFIG:
|
|
|
|
BX_ERROR(("Unsupported read from port 0x%04x", address));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (address) {
|
|
|
|
case BUSM_PORT_CONTROL:
|
|
|
|
value = BX_BUSM_THIS control_val;
|
|
|
|
// this is to allow the driver to see which IRQ the card has "jumpered"
|
|
|
|
// only happens if IRQ's are enabled
|
|
|
|
BX_BUSM_THIS control_val |= 0x0F;
|
|
|
|
if ((BX_BUSM_THIS toggle_counter > 0x3FF)
|
|
|
|
// newer hardware only changes the bit when interrupts are on
|
|
|
|
// older hardware changes the bit no matter if interrupts are on or not
|
|
|
|
#if !LEGACY_BUSMOUSE
|
|
|
|
&& BX_BUSM_THIS interrupts
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
BX_BUSM_THIS control_val &= ~IRQ_MASK;
|
|
|
|
BX_BUSM_THIS toggle_counter = (BX_BUSM_THIS toggle_counter + 1) & 0x7FF;
|
|
|
|
break;
|
|
|
|
case BUSM_PORT_DATA:
|
|
|
|
switch (BX_BUSM_THIS control_val & 0x60) {
|
|
|
|
case READ_X_LOW:
|
|
|
|
value = BX_BUSM_THIS current_x & 0x0F;
|
|
|
|
break;
|
|
|
|
case READ_X_HIGH:
|
|
|
|
value = (BX_BUSM_THIS current_x >> 4) & 0x0F;
|
|
|
|
break;
|
|
|
|
case READ_Y_LOW:
|
|
|
|
value = BX_BUSM_THIS current_y & 0x0F;
|
|
|
|
break;
|
|
|
|
case READ_Y_HIGH:
|
|
|
|
value = ((BX_BUSM_THIS current_b ^ 7) << 5) | ((BX_BUSM_THIS current_y >> 4) & 0x0F);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BX_ERROR(("Reading data port in unsupported mode 0x%02x", BX_BUSM_THIS control_val));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUSM_PORT_CONFIG:
|
|
|
|
value = BX_BUSM_THIS config_val;
|
|
|
|
break;
|
|
|
|
case BUSM_PORT_SIGNATURE:
|
|
|
|
value = BX_BUSM_THIS sig_val;
|
|
|
|
break;
|
|
|
|
}
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_DEBUG(("read from address 0x%04x, value = 0x%02x ", address, value));
|
2004-12-11 11:35:33 +03:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static IO port write callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2004-12-11 11:35:33 +03:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_busm_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
#if !BX_USE_BUSM_SMF
|
|
|
|
bx_busm_c *class_ptr = (bx_busm_c *) this_ptr;
|
|
|
|
class_ptr->write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_busm_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_BUSM_SMF
|
|
|
|
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_DEBUG(("write to address 0x%04x, value = 0x%02x ", address, value));
|
2004-12-11 11:35:33 +03:00
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
if (BX_BUSM_THIS type == BX_MOUSE_TYPE_INPORT) {
|
|
|
|
switch (address) {
|
|
|
|
case INP_PORT_CONTROL:
|
2013-12-27 21:47:44 +04:00
|
|
|
switch (value) {
|
2016-03-31 20:24:34 +03:00
|
|
|
case INP_CTRL_RESET:
|
|
|
|
BX_BUSM_THIS control_val = 0;
|
|
|
|
BX_BUSM_THIS command_val = 0;
|
2013-12-27 21:47:44 +04:00
|
|
|
break;
|
2016-03-31 20:24:34 +03:00
|
|
|
case INP_CTRL_COMMAND:
|
|
|
|
case INP_CTRL_READ_BUTTONS:
|
|
|
|
case INP_CTRL_READ_X:
|
|
|
|
case INP_CTRL_READ_Y:
|
|
|
|
BX_BUSM_THIS command_val = value;
|
2013-12-27 21:47:44 +04:00
|
|
|
break;
|
2016-03-31 20:24:34 +03:00
|
|
|
case 0x87: // ???????
|
|
|
|
BX_BUSM_THIS control_val = 0;
|
|
|
|
BX_BUSM_THIS command_val = 0x07;
|
2013-12-27 21:47:44 +04:00
|
|
|
break;
|
2016-03-31 20:24:34 +03:00
|
|
|
default:
|
|
|
|
BX_ERROR(("Unsupported command written to port 0x%04x (value = 0x%02x)", address, value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INP_PORT_DATA:
|
|
|
|
DEV_pic_lower_irq(BUS_MOUSE_IRQ);
|
|
|
|
if (value == INP_CTRL_RAISE_IRQ) {
|
|
|
|
DEV_pic_raise_irq(BUS_MOUSE_IRQ);
|
|
|
|
} else {
|
|
|
|
switch (BX_BUSM_THIS command_val) {
|
|
|
|
case INP_CTRL_COMMAND:
|
|
|
|
BX_BUSM_THIS control_val = value;
|
|
|
|
BX_BUSM_THIS interrupts = (value & INP_ENABLE_IRQ) > 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BX_ERROR(("Unsupported write to port 0x%04x (value = 0x%02x)", address, value));
|
|
|
|
}
|
2013-12-27 21:47:44 +04:00
|
|
|
}
|
2016-03-31 20:24:34 +03:00
|
|
|
break;
|
|
|
|
case INP_PORT_SIGNATURE:
|
|
|
|
case INP_PORT_CONFIG:
|
|
|
|
BX_ERROR(("Unsupported write to port 0x%04x (value = 0x%02x)", address, value));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (address) {
|
|
|
|
case BUSM_PORT_CONTROL:
|
|
|
|
BX_BUSM_THIS control_val = value | 0x0F;
|
|
|
|
BX_BUSM_THIS interrupts = (value & DISABLE_IRQ) == 0;
|
|
|
|
DEV_pic_lower_irq(BUS_MOUSE_IRQ);
|
|
|
|
break;
|
|
|
|
case BUSM_PORT_CONFIG:
|
|
|
|
BX_BUSM_THIS config_val = value;
|
|
|
|
break;
|
|
|
|
case BUSM_PORT_SIGNATURE:
|
|
|
|
BX_BUSM_THIS sig_val = value;
|
|
|
|
break;
|
|
|
|
case BUSM_PORT_DATA:
|
|
|
|
BX_ERROR(("Unsupported write to port 0x%04x (value = 0x%02x)", address, value));
|
|
|
|
break;
|
|
|
|
}
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 21:47:44 +04:00
|
|
|
void bx_busm_c::mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state, bx_bool absxy)
|
2009-03-03 23:34:50 +03:00
|
|
|
{
|
|
|
|
((bx_busm_c*)dev)->mouse_enq(delta_x, delta_y, delta_z, button_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_busm_c::mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
// scale down the motion
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((delta_x < -1) || (delta_x > 1))
|
2004-12-11 11:35:33 +03:00
|
|
|
delta_x /= 2;
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((delta_y < -1) || (delta_y > 1))
|
2004-12-11 11:35:33 +03:00
|
|
|
delta_y /= 2;
|
|
|
|
|
2013-12-27 21:47:44 +04:00
|
|
|
if (delta_x > 127) delta_x =127;
|
|
|
|
if (delta_y > 127) delta_y =127;
|
|
|
|
if (delta_x < -128) delta_x = -128;
|
|
|
|
if (delta_y < -128) delta_y = -128;
|
2004-12-11 11:35:33 +03:00
|
|
|
|
2013-12-27 21:47:44 +04:00
|
|
|
BX_BUSM_THIS mouse_delayed_dx += delta_x;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dy -= delta_y;
|
2016-03-31 20:24:34 +03:00
|
|
|
|
|
|
|
// change button_state MRL to LMR
|
|
|
|
BX_BUSM_THIS mouse_buttons = (Bit8u) (((button_state & 1) << 2) |
|
|
|
|
((button_state & 4) >> 1) | ((button_state & 2) >> 1));
|
|
|
|
|
|
|
|
if (BX_BUSM_THIS type == BX_MOUSE_TYPE_INPORT) {
|
|
|
|
// The InPort button status is as so
|
|
|
|
// 00lmrLMR
|
|
|
|
// where lower case letters are changed in state
|
|
|
|
// where upper case letters are the state of that button
|
|
|
|
// TODO:
|
|
|
|
// Bochs needs to call this function one more time on a button release so that
|
|
|
|
// bits 5:3 get cleared. However, as is, it works with the code I tested it on,
|
|
|
|
// so no worries, so far.
|
|
|
|
if ((BX_BUSM_THIS mouse_buttons & (1<<2)) ||
|
|
|
|
((BX_BUSM_THIS mouse_buttons_last & (1<<2)) && !(BX_BUSM_THIS mouse_buttons & (1<<2))))
|
|
|
|
BX_BUSM_THIS mouse_buttons |= (1<<5);
|
|
|
|
if ((BX_BUSM_THIS mouse_buttons & (1<<1)) ||
|
|
|
|
((BX_BUSM_THIS mouse_buttons_last & (1<<1)) && !(BX_BUSM_THIS mouse_buttons & (1<<1))))
|
|
|
|
BX_BUSM_THIS mouse_buttons |= (1<<4);
|
|
|
|
if ((BX_BUSM_THIS mouse_buttons & (1<<0)) ||
|
|
|
|
((BX_BUSM_THIS mouse_buttons_last & (1<<0)) && !(BX_BUSM_THIS mouse_buttons & (1<<0))))
|
|
|
|
BX_BUSM_THIS mouse_buttons |= (1<<3);
|
|
|
|
BX_BUSM_THIS mouse_buttons_last = BX_BUSM_THIS mouse_buttons;
|
|
|
|
}
|
2013-12-27 21:47:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_busm_c::update_mouse_data()
|
|
|
|
{
|
|
|
|
int delta_x, delta_y;
|
2016-03-31 20:24:34 +03:00
|
|
|
bx_bool hold;
|
2004-12-11 11:35:33 +03:00
|
|
|
|
|
|
|
if (BX_BUSM_THIS mouse_delayed_dx > 127) {
|
|
|
|
delta_x = 127;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dx -= 127;
|
|
|
|
} else if (BX_BUSM_THIS mouse_delayed_dx < -128) {
|
|
|
|
delta_x = -128;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dx += 128;
|
|
|
|
} else {
|
|
|
|
delta_x = BX_BUSM_THIS mouse_delayed_dx;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dx = 0;
|
|
|
|
}
|
|
|
|
if (BX_BUSM_THIS mouse_delayed_dy > 127) {
|
|
|
|
delta_y = 127;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dy -= 127;
|
|
|
|
} else if (BX_BUSM_THIS mouse_delayed_dy < -128) {
|
|
|
|
delta_y = -128;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dy += 128;
|
|
|
|
} else {
|
|
|
|
delta_y = BX_BUSM_THIS mouse_delayed_dy;
|
|
|
|
BX_BUSM_THIS mouse_delayed_dy = 0;
|
|
|
|
}
|
2013-12-27 21:47:44 +04:00
|
|
|
|
2016-03-31 20:24:34 +03:00
|
|
|
if (BX_BUSM_THIS type == BX_MOUSE_TYPE_INPORT) {
|
|
|
|
hold = (BX_BUSM_THIS control_val & INP_HOLD_COUNTER) > 0;
|
|
|
|
} else {
|
|
|
|
hold = (BX_BUSM_THIS control_val & HOLD_COUNTER) > 0;
|
|
|
|
}
|
|
|
|
if (!hold) {
|
|
|
|
BX_BUSM_THIS current_x = (Bit8u) delta_x;
|
|
|
|
BX_BUSM_THIS current_y = (Bit8u) delta_y;
|
|
|
|
BX_BUSM_THIS current_b = BX_BUSM_THIS mouse_buttons;
|
|
|
|
}
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_busm_c::timer_handler(void *this_ptr)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
|
|
|
bx_busm_c *class_ptr = (bx_busm_c *) this_ptr;
|
|
|
|
class_ptr->busm_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called at 30hz
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_busm_c::busm_timer(void)
|
2004-12-11 11:35:33 +03:00
|
|
|
{
|
2016-03-31 20:24:34 +03:00
|
|
|
// The controller updates the data on every interrupt
|
|
|
|
// We just don't copy it to the current_X if the 'hold' bit is set
|
|
|
|
BX_BUSM_THIS update_mouse_data();
|
|
|
|
|
2004-12-11 11:35:33 +03:00
|
|
|
// if interrupts are on, fire the interrupt
|
2016-03-31 20:24:34 +03:00
|
|
|
if (BX_BUSM_THIS interrupts) {
|
2004-12-11 11:35:33 +03:00
|
|
|
DEV_pic_raise_irq(BUS_MOUSE_IRQ);
|
2016-03-31 20:24:34 +03:00
|
|
|
BX_DEBUG(("Interrupt Fired..."));
|
2004-12-11 11:35:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BX_SUPPORT_BUSMOUSE
|