More clean-ups and mouse fixes.
This commit is contained in:
@@ -24,6 +24,8 @@ add_library(dev OBJECT bugger.c cassette.c cartridge.c hasp.c hwm.c hwm_lm75.c h
|
||||
mouse.c mouse_bus.c mouse_serial.c mouse_ps2.c phoenix_486_jumper.c
|
||||
mouse_wacom_tablet.c serial_passthrough.c)
|
||||
|
||||
target_link_libraries(86Box atomic)
|
||||
|
||||
if(ISAMEM_RAMPAGE)
|
||||
target_compile_definitions(dev PRIVATE USE_ISAMEM_RAMPAGE)
|
||||
endif()
|
||||
|
||||
@@ -41,12 +41,6 @@ typedef struct mouse_t {
|
||||
} mouse_t;
|
||||
|
||||
int mouse_type = 0;
|
||||
atomic_int mouse_x;
|
||||
atomic_int mouse_y;
|
||||
atomic_int mouse_z;
|
||||
atomic_int mouse_buttons;
|
||||
atomic_int old_mouse_x;
|
||||
atomic_int old_mouse_y;
|
||||
int mouse_mode;
|
||||
int mouse_timed = 1;
|
||||
int mouse_tablet_in_proximity = 0;
|
||||
@@ -56,10 +50,6 @@ double mouse_x_abs;
|
||||
double mouse_y_abs;
|
||||
|
||||
double mouse_sensitivity = 1.0;
|
||||
_Atomic double mouse_x_error = 0.0;
|
||||
_Atomic double mouse_y_error = 0.0;
|
||||
_Atomic double mouse_x_raw = 0.0;
|
||||
_Atomic double mouse_y_raw = 0.0;
|
||||
|
||||
pc_timer_t mouse_timer; /* mouse event timer */
|
||||
|
||||
@@ -97,7 +87,7 @@ static mouse_t mouse_devices[] = {
|
||||
{ &mouse_internal_device },
|
||||
{ &mouse_logibus_device },
|
||||
{ &mouse_msinport_device },
|
||||
#if 0
|
||||
#ifdef USE_GENIBUS
|
||||
{ &mouse_genibus_device },
|
||||
#endif
|
||||
{ &mouse_mssystems_device },
|
||||
@@ -110,10 +100,18 @@ static mouse_t mouse_devices[] = {
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
static _Atomic double mouse_x;
|
||||
static _Atomic double mouse_y;
|
||||
static atomic_int mouse_z;
|
||||
static atomic_int mouse_buttons;
|
||||
|
||||
static int mouse_delta_b;
|
||||
static int mouse_old_b;
|
||||
|
||||
static const device_t *mouse_curr;
|
||||
static void *mouse_priv;
|
||||
static int mouse_nbut;
|
||||
static int (*mouse_dev_poll)(int x, int y, int z, int b, void *priv);
|
||||
static int (*mouse_dev_poll)(void *priv);
|
||||
static void (*mouse_poll_ex)(void) = NULL;
|
||||
|
||||
static double sample_rate = 200.0;
|
||||
@@ -136,70 +134,127 @@ mouse_log(const char *fmt, ...)
|
||||
# define mouse_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
void
|
||||
mouse_clear_x(void)
|
||||
{
|
||||
mouse_x = 0.0;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_clear_y(void)
|
||||
{
|
||||
mouse_y = 0.0;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_clear_coords(void)
|
||||
{
|
||||
mouse_x = mouse_y = mouse_z = 0;
|
||||
old_mouse_x = old_mouse_y = 0;
|
||||
mouse_x_error = mouse_y_error = 0.0;
|
||||
mouse_x_raw = mouse_y_raw = 0.0;
|
||||
mouse_clear_x();
|
||||
mouse_clear_y();
|
||||
|
||||
mouse_z = 0;
|
||||
}
|
||||
|
||||
/* Initialize the mouse module. */
|
||||
void
|
||||
mouse_init(void)
|
||||
static void
|
||||
mouse_clear_buttons(void)
|
||||
{
|
||||
/* Initialize local data. */
|
||||
mouse_clear_coords();
|
||||
mouse_buttons = 0x00;
|
||||
mouse_buttons = 0x00;
|
||||
mouse_old_b = 0x00;
|
||||
|
||||
mouse_type = MOUSE_TYPE_NONE;
|
||||
mouse_curr = NULL;
|
||||
mouse_priv = NULL;
|
||||
mouse_nbut = 0;
|
||||
mouse_dev_poll = NULL;
|
||||
mouse_delta_b = 0x00;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_close(void)
|
||||
mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs)
|
||||
{
|
||||
if (mouse_curr == NULL)
|
||||
return;
|
||||
double real_x = mouse_x;
|
||||
double smax_x;
|
||||
double rsmin_x;
|
||||
double smin_x;
|
||||
|
||||
mouse_curr = NULL;
|
||||
mouse_priv = NULL;
|
||||
mouse_nbut = 0;
|
||||
mouse_dev_poll = NULL;
|
||||
rsmin_x = (double) min;
|
||||
if (abs) {
|
||||
smax_x = (double) max + ABS(rsmin_x);
|
||||
max += ABS(min);
|
||||
real_x += rsmin_x;
|
||||
smin_x = 0;
|
||||
} else {
|
||||
smax_x = (double) max;
|
||||
smin_x = rsmin_x;
|
||||
}
|
||||
|
||||
timer_stop(&mouse_timer);
|
||||
/* Default the X and Y overflows to 1. */
|
||||
if (o_x != NULL)
|
||||
*o_x = 1;
|
||||
|
||||
if (real_x > smax_x) {
|
||||
*delta_x = abs ? (int) real_x : max;
|
||||
real_x -= smax_x;
|
||||
} else if (real_x < smin_x) {
|
||||
*delta_x = abs ? (int) real_x : min;
|
||||
real_x += ABS(smin_x);
|
||||
} else {
|
||||
*delta_x = (int) real_x;
|
||||
real_x = 0.0;
|
||||
if (o_x != NULL)
|
||||
*o_x = 0;
|
||||
}
|
||||
|
||||
if (abs)
|
||||
real_x -= rsmin_x;
|
||||
|
||||
mouse_x = real_x;
|
||||
}
|
||||
|
||||
static int
|
||||
mouse_scale_coord_x(int x, int mul)
|
||||
/* It appears all host platforms give us y in the Microsoft format
|
||||
(positive to the south), so for all non-Microsoft report formsts,
|
||||
we have to invert that. */
|
||||
void
|
||||
mouse_subtract_y(int *delta_y, int *o_y, int min, int max, int invert, int abs)
|
||||
{
|
||||
double temp_x = (double) x;
|
||||
double ratio = (double) monitors[0].mon_unscaled_size_x / (double) monitors[0].mon_res_x;
|
||||
double real_y = mouse_y;
|
||||
double smax_y;
|
||||
double rsmin_y;
|
||||
double smin_y;
|
||||
|
||||
if (mul)
|
||||
temp_x *= ratio;
|
||||
else
|
||||
temp_x /= ratio;
|
||||
if (invert)
|
||||
real_y = -real_y;
|
||||
|
||||
return (int) temp_x;
|
||||
}
|
||||
rsmin_y = (double) min;
|
||||
if (abs) {
|
||||
smax_y = (double) max + ABS(rsmin_y);
|
||||
max += ABS(min);
|
||||
real_y += rsmin_y;
|
||||
smin_y = 0;
|
||||
} else {
|
||||
smax_y = (double) max;
|
||||
smin_y = rsmin_y;
|
||||
}
|
||||
|
||||
static int
|
||||
mouse_scale_coord_y(int y, int mul)
|
||||
{
|
||||
double temp_y = (double) y;
|
||||
double ratio = (double) monitors[0].mon_efscrnsz_y / (double) monitors[0].mon_res_y;
|
||||
/* Default the X and Y overflows to 1. */
|
||||
if (o_y != NULL)
|
||||
*o_y = 1;
|
||||
|
||||
if (mul)
|
||||
temp_y *= ratio;
|
||||
else
|
||||
temp_y /= ratio;
|
||||
if (real_y > smax_y) {
|
||||
*delta_y = abs ? (int) real_y : max;
|
||||
real_y -= smax_y;
|
||||
} else if (real_y < smin_y) {
|
||||
*delta_y = abs ? (int) real_y : min;
|
||||
real_y += ABS(smin_y);
|
||||
} else {
|
||||
*delta_y = (int) real_y;
|
||||
real_y = 0.0;
|
||||
if (o_y != NULL)
|
||||
*o_y = 0;
|
||||
}
|
||||
|
||||
return (int) temp_y;
|
||||
if (abs)
|
||||
real_y -= rsmin_y;
|
||||
|
||||
if (invert)
|
||||
real_y = -real_y;
|
||||
|
||||
mouse_y = real_y;
|
||||
}
|
||||
|
||||
/* It appears all host platforms give us y in the Microsoft format
|
||||
@@ -209,95 +264,38 @@ void
|
||||
mouse_subtract_coords(int *delta_x, int *delta_y, int *o_x, int *o_y,
|
||||
int min, int max, int invert, int abs)
|
||||
{
|
||||
int real_x = mouse_x;
|
||||
int real_y = mouse_y;
|
||||
int smax_x;
|
||||
int smax_y;
|
||||
int rsmin_x;
|
||||
int rsmin_y;
|
||||
int smin_x;
|
||||
int smin_y;
|
||||
mouse_subtract_x(delta_x, o_x, min, max, abs);
|
||||
mouse_subtract_y(delta_y, o_y, min, max, invert, abs);
|
||||
}
|
||||
|
||||
if (invert)
|
||||
real_y = -real_y;
|
||||
int
|
||||
mouse_moved(void)
|
||||
{
|
||||
/* Convert them to integer so we treat < 1.0 and > -1.0 as 0. */
|
||||
int ret = (((int) floor(mouse_x) != 0) || ((int) floor(mouse_y) != 0));
|
||||
|
||||
rsmin_x = mouse_scale_coord_x(min, 0);
|
||||
rsmin_y = mouse_scale_coord_y(min, 0);
|
||||
if (abs) {
|
||||
smax_x = mouse_scale_coord_x(max, 0) + ABS(rsmin_x);
|
||||
smax_y = mouse_scale_coord_y(max, 0) + ABS(rsmin_y);
|
||||
max += ABS(min);
|
||||
real_x += rsmin_x;
|
||||
real_y += rsmin_y;
|
||||
smin_x = 0;
|
||||
smin_y = 0;
|
||||
} else {
|
||||
smax_x = mouse_scale_coord_x(max, 0);
|
||||
smax_y = mouse_scale_coord_y(max, 0);
|
||||
smin_x = rsmin_x;
|
||||
smin_y = rsmin_y;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Default the X and Y overflows to 1. */
|
||||
if (o_x != NULL)
|
||||
*o_x = 1;
|
||||
if (o_y != NULL)
|
||||
*o_y = 1;
|
||||
int
|
||||
mouse_state_changed(void)
|
||||
{
|
||||
int b_mask = (1 << mouse_nbut) - 1;
|
||||
int wheel = (mouse_nbut >= 4);
|
||||
int ret;
|
||||
|
||||
if (real_x > smax_x) {
|
||||
if (abs)
|
||||
*delta_x = mouse_scale_coord_x(real_x, 1);
|
||||
else
|
||||
*delta_x = max;
|
||||
real_x -= smax_x;
|
||||
} else if (real_x < smin_x) {
|
||||
if (abs)
|
||||
*delta_x = mouse_scale_coord_x(real_x, 1);
|
||||
else
|
||||
*delta_x = min;
|
||||
real_x += ABS(smin_x);
|
||||
} else {
|
||||
if (abs)
|
||||
*delta_x = mouse_scale_coord_x(real_x, 1);
|
||||
else
|
||||
*delta_x = mouse_scale_coord_x(real_x, 1);
|
||||
real_x = 0;
|
||||
if (o_x != NULL)
|
||||
*o_x = 0;
|
||||
}
|
||||
mouse_delta_b = (mouse_buttons ^ mouse_old_b);
|
||||
mouse_old_b = mouse_buttons;
|
||||
|
||||
if (real_y > smax_y) {
|
||||
if (abs)
|
||||
*delta_y = mouse_scale_coord_y(real_y, 1);
|
||||
else
|
||||
*delta_y = max;
|
||||
real_y -= smax_y;
|
||||
} else if (real_y < smin_y) {
|
||||
if (abs)
|
||||
*delta_y = mouse_scale_coord_y(real_y, 1);
|
||||
else
|
||||
*delta_y = min;
|
||||
real_y += ABS(smin_y);
|
||||
} else {
|
||||
if (abs)
|
||||
*delta_y = mouse_scale_coord_y(real_y, 1);
|
||||
else
|
||||
*delta_y = mouse_scale_coord_y(real_y, 1);
|
||||
real_y = 0;
|
||||
if (o_y != NULL)
|
||||
*o_y = 0;
|
||||
}
|
||||
ret = mouse_moved() || ((mouse_z != 0) && wheel) || (mouse_delta_b & b_mask);
|
||||
|
||||
if (abs) {
|
||||
real_x -= rsmin_x;
|
||||
real_y -= rsmin_y;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (invert)
|
||||
real_y = -real_y;
|
||||
|
||||
mouse_x = real_x;
|
||||
mouse_y = real_y;
|
||||
int
|
||||
mouse_mbut_changed(void)
|
||||
{
|
||||
return !!(mouse_delta_b & 0x04);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -319,41 +317,27 @@ mouse_timer_poll(UNUSED(void *priv))
|
||||
void
|
||||
mouse_scale(int x, int y)
|
||||
{
|
||||
double scaled_x = (((double) x) * mouse_sensitivity);
|
||||
double scaled_y = (((double) y) * mouse_sensitivity);
|
||||
double ratio_x = (double) monitors[0].mon_unscaled_size_x / (double) monitors[0].mon_res_x;
|
||||
double ratio_y = (double) monitors[0].mon_efscrnsz_y / (double) monitors[0].mon_res_y;
|
||||
|
||||
scaled_x += mouse_x_error;
|
||||
scaled_y += mouse_y_error;
|
||||
|
||||
mouse_x += (int) scaled_x;
|
||||
mouse_y += (int) scaled_y;
|
||||
|
||||
mouse_x_error = scaled_x - floor(scaled_x);
|
||||
mouse_y_error = scaled_y - floor(scaled_y);
|
||||
mouse_x += (((double) x) * mouse_sensitivity * ratio_x);
|
||||
mouse_y += (((double) y) * mouse_sensitivity * ratio_y);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_scale_x(int x)
|
||||
{
|
||||
double scaled_x = (((double) x) * mouse_sensitivity);
|
||||
double ratio_x = (double) monitors[0].mon_unscaled_size_x / (double) monitors[0].mon_res_x;
|
||||
|
||||
scaled_x += mouse_x_error;
|
||||
|
||||
mouse_x += (int) scaled_x;
|
||||
|
||||
mouse_x_error = scaled_x - floor(scaled_x);
|
||||
mouse_x += (((double) x) * mouse_sensitivity * ratio_x);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_scale_y(int y)
|
||||
{
|
||||
double scaled_y = (((double) y) * mouse_sensitivity);
|
||||
double ratio_y = (double) monitors[0].mon_efscrnsz_y / (double) monitors[0].mon_res_y;
|
||||
|
||||
scaled_y += mouse_y_error;
|
||||
|
||||
mouse_y += (int) scaled_y;
|
||||
|
||||
mouse_y_error = scaled_y - floor(scaled_y);
|
||||
mouse_y += (((double) y) * mouse_sensitivity * ratio_y);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -362,6 +346,32 @@ mouse_set_z(int z)
|
||||
mouse_z += z;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_clear_z(void)
|
||||
{
|
||||
mouse_z = 0;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_subtract_z(int *delta_z, int min, int max, int invert)
|
||||
{
|
||||
int real_z = invert ? -mouse_z : mouse_z;
|
||||
|
||||
if (mouse_z > max) {
|
||||
*delta_z = max;
|
||||
real_z -= max;
|
||||
} else if (mouse_z < min) {
|
||||
*delta_z = min;
|
||||
real_z += ABS(min);
|
||||
} else {
|
||||
*delta_z = mouse_z;
|
||||
mouse_clear_z();
|
||||
real_z = 0;
|
||||
}
|
||||
|
||||
mouse_z = invert ? -real_z : real_z;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_set_buttons_ex(int b)
|
||||
{
|
||||
@@ -386,39 +396,6 @@ mouse_set_sample_rate(double new_rate)
|
||||
timer_on_auto(&mouse_timer, 1000000.0 / sample_rate);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_reset(void)
|
||||
{
|
||||
if (mouse_curr != NULL)
|
||||
return; /* Mouse already initialized. */
|
||||
|
||||
mouse_log("MOUSE: reset(type=%d, '%s')\n",
|
||||
mouse_type, mouse_devices[mouse_type].device->name);
|
||||
|
||||
/* Clear local data. */
|
||||
mouse_clear_coords();
|
||||
mouse_buttons = 0x00;
|
||||
mouse_mode = 0;
|
||||
mouse_timed = 1;
|
||||
|
||||
mouse_x_error = mouse_y_error = 0.0;
|
||||
|
||||
/* If no mouse configured, we're done. */
|
||||
if (mouse_type == 0)
|
||||
return;
|
||||
|
||||
timer_add(&mouse_timer, mouse_timer_poll, NULL, 0);
|
||||
|
||||
/* Poll at 100 Hz, the default of a PS/2 mouse. */
|
||||
sample_rate = 100.0;
|
||||
timer_on_auto(&mouse_timer, 1000000.0 / sample_rate);
|
||||
|
||||
mouse_curr = mouse_devices[mouse_type].device;
|
||||
|
||||
if (mouse_curr != NULL)
|
||||
mouse_priv = device_add(mouse_curr);
|
||||
}
|
||||
|
||||
/* Callback from the hardware driver. */
|
||||
void
|
||||
mouse_set_buttons(int buttons)
|
||||
@@ -427,9 +404,10 @@ mouse_set_buttons(int buttons)
|
||||
}
|
||||
|
||||
void
|
||||
mouse_set_poll_ex(void (*poll_ex)(void))
|
||||
mouse_get_abs_coords(double *x_abs, double *y_abs)
|
||||
{
|
||||
mouse_poll_ex = poll_ex;
|
||||
*x_abs = mouse_x_abs;
|
||||
*y_abs = mouse_y_abs;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -442,14 +420,20 @@ mouse_process(void)
|
||||
mouse_poll_ex();
|
||||
else if ((mouse_mode == 0) && ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL))) {
|
||||
if (mouse_curr->poll != NULL)
|
||||
mouse_curr->poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_x_abs, mouse_y_abs, mouse_priv);
|
||||
mouse_curr->poll(mouse_priv);
|
||||
else
|
||||
mouse_dev_poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_priv);
|
||||
mouse_dev_poll(mouse_priv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mouse_set_poll(int (*func)(int, int, int, int, void *), void *arg)
|
||||
mouse_set_poll_ex(void (*poll_ex)(void))
|
||||
{
|
||||
mouse_poll_ex = poll_ex;
|
||||
}
|
||||
|
||||
void
|
||||
mouse_set_poll(int (*func)(void *), void *arg)
|
||||
{
|
||||
if (mouse_type != MOUSE_TYPE_INTERNAL)
|
||||
return;
|
||||
@@ -511,3 +495,63 @@ mouse_get_ndev(void)
|
||||
{
|
||||
return ((sizeof(mouse_devices) / sizeof(mouse_t)) - 1);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_reset(void)
|
||||
{
|
||||
if (mouse_curr != NULL)
|
||||
return; /* Mouse already initialized. */
|
||||
|
||||
mouse_log("MOUSE: reset(type=%d, '%s')\n",
|
||||
mouse_type, mouse_devices[mouse_type].device->name);
|
||||
|
||||
/* Clear local data. */
|
||||
mouse_clear_coords();
|
||||
mouse_clear_buttons();
|
||||
mouse_mode = 0;
|
||||
mouse_timed = 1;
|
||||
|
||||
/* If no mouse configured, we're done. */
|
||||
if (mouse_type == 0)
|
||||
return;
|
||||
|
||||
timer_add(&mouse_timer, mouse_timer_poll, NULL, 0);
|
||||
|
||||
/* Poll at 100 Hz, the default of a PS/2 mouse. */
|
||||
sample_rate = 100.0;
|
||||
timer_on_auto(&mouse_timer, 1000000.0 / sample_rate);
|
||||
|
||||
mouse_curr = mouse_devices[mouse_type].device;
|
||||
|
||||
if (mouse_curr != NULL)
|
||||
mouse_priv = device_add(mouse_curr);
|
||||
}
|
||||
|
||||
void
|
||||
mouse_close(void)
|
||||
{
|
||||
if (mouse_curr == NULL)
|
||||
return;
|
||||
|
||||
mouse_curr = NULL;
|
||||
mouse_priv = NULL;
|
||||
mouse_nbut = 0;
|
||||
mouse_dev_poll = NULL;
|
||||
|
||||
timer_stop(&mouse_timer);
|
||||
}
|
||||
|
||||
/* Initialize the mouse module. */
|
||||
void
|
||||
mouse_init(void)
|
||||
{
|
||||
/* Initialize local data. */
|
||||
mouse_clear_coords();
|
||||
mouse_clear_buttons();
|
||||
|
||||
mouse_type = MOUSE_TYPE_NONE;
|
||||
mouse_curr = NULL;
|
||||
mouse_priv = NULL;
|
||||
mouse_nbut = 0;
|
||||
mouse_dev_poll = NULL;
|
||||
}
|
||||
|
||||
@@ -475,12 +475,13 @@ ms_write(uint16_t port, uint8_t val, void *priv)
|
||||
|
||||
/* The emulator calls us with an update on the host mouse device. */
|
||||
static int
|
||||
bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double abs_y), void *priv)
|
||||
bm_poll(void *priv)
|
||||
{
|
||||
mouse_t *dev = (mouse_t *) priv;
|
||||
int delta_x;
|
||||
int delta_y;
|
||||
int xor;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
if (!mouse_capture && !video_fullscreen)
|
||||
return 1;
|
||||
@@ -488,8 +489,8 @@ bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double
|
||||
if (!(dev->flags & FLAG_ENABLED))
|
||||
return 1; /* Mouse is disabled, do nothing. */
|
||||
|
||||
if (!mouse_x && !mouse_y && !((b ^ dev->mouse_buttons_last) & 0x07)) {
|
||||
dev->mouse_buttons_last = b;
|
||||
if (!mouse_state_changed()) {
|
||||
dev->mouse_buttons_last = 0x00;
|
||||
return 1; /* State has not changed, do nothing. */
|
||||
}
|
||||
|
||||
@@ -503,11 +504,11 @@ bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double
|
||||
so update bits 6-3 here. */
|
||||
|
||||
/* If the mouse has moved, set bit 6. */
|
||||
if (mouse_x || mouse_y)
|
||||
if (mouse_moved())
|
||||
dev->mouse_buttons |= 0x40;
|
||||
|
||||
/* Set bits 3-5 according to button state changes. */
|
||||
xor = ((dev->current_b ^ dev->mouse_buttons) & 0x07) << 3;
|
||||
xor = ((dev->current_b ^ mouse_get_buttons_ex()) & 0x07) << 3;
|
||||
dev->mouse_buttons |= xor;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,42 +79,36 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main)
|
||||
int delta_y;
|
||||
int overflow_x;
|
||||
int overflow_y;
|
||||
int temp_z;
|
||||
int b = mouse_get_buttons_ex();
|
||||
int delta_z;
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, &overflow_x, &overflow_y,
|
||||
-256, 255, 1, 0);
|
||||
mouse_subtract_z(&delta_z, -8, 7, 1);
|
||||
|
||||
buff[0] = (overflow_y << 7) | (overflow_x << 6) |
|
||||
((delta_y & 0x0100) >> 3) | ((delta_x & 0x0100) >> 4) |
|
||||
(mouse_buttons & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03));
|
||||
(b & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03));
|
||||
buff[1] = (delta_x & 0x00ff);
|
||||
buff[2] = (delta_y & 0x00ff);
|
||||
|
||||
if (dev->z < -7) {
|
||||
temp_z = 7;
|
||||
temp_z += 7;
|
||||
} else if (mouse_z > 8) {
|
||||
temp_z = (-8) & 0x0f;
|
||||
mouse_z -= 8;
|
||||
} else {
|
||||
temp_z = (-mouse_y) & 0x0f;
|
||||
mouse_z = 0;
|
||||
}
|
||||
|
||||
kbc_at_dev_queue_add(dev, buff[0], main);
|
||||
kbc_at_dev_queue_add(dev, buff[1], main);
|
||||
kbc_at_dev_queue_add(dev, buff[2], main);
|
||||
if (dev->flags & FLAG_INTMODE) {
|
||||
delta_z &= 0x0f;
|
||||
|
||||
if (dev->flags & FLAG_5BTN) {
|
||||
if (mouse_buttons & 8)
|
||||
temp_z |= 0x10;
|
||||
if (mouse_buttons & 16)
|
||||
temp_z |= 0x20;
|
||||
if (b & 8)
|
||||
delta_z |= 0x10;
|
||||
if (b & 16)
|
||||
delta_z |= 0x20;
|
||||
} else {
|
||||
/* The wheel coordinate is sign-extended. */
|
||||
if (temp_z & 0x08)
|
||||
temp_z |= 0xf0;
|
||||
if (delta_z & 0x08)
|
||||
delta_z |= 0xf0;
|
||||
}
|
||||
kbc_at_dev_queue_add(dev, temp_z, main);
|
||||
kbc_at_dev_queue_add(dev, delta_z, main);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +138,7 @@ static void
|
||||
ps2_write(void *priv)
|
||||
{
|
||||
atkbc_dev_t *dev = (atkbc_dev_t *) priv;
|
||||
int b;
|
||||
uint8_t temp;
|
||||
uint8_t val;
|
||||
static uint8_t last_data[6] = { 0x00 };
|
||||
@@ -202,15 +197,16 @@ ps2_write(void *priv)
|
||||
|
||||
case 0xe9: /* status request */
|
||||
mouse_ps2_log("%s: Status request\n", dev->name);
|
||||
b = mouse_get_buttons_ex();
|
||||
kbc_at_dev_queue_add(dev, 0xfa, 0);
|
||||
temp = (dev->flags & 0x20);
|
||||
if (mouse_scan)
|
||||
temp |= FLAG_ENABLED;
|
||||
if (mouse_buttons & 1)
|
||||
if (b & 1)
|
||||
temp |= 4;
|
||||
if (mouse_buttons & 2)
|
||||
if (b & 2)
|
||||
temp |= 1;
|
||||
if ((mouse_buttons & 4) && (dev->flags & FLAG_INTELLI))
|
||||
if ((b & 4) && (dev->flags & FLAG_INTELLI))
|
||||
temp |= 2;
|
||||
kbc_at_dev_queue_add(dev, temp, 0);
|
||||
kbc_at_dev_queue_add(dev, dev->resolution, 0);
|
||||
@@ -304,20 +300,16 @@ ps2_write(void *priv)
|
||||
}
|
||||
|
||||
static int
|
||||
ps2_poll(int x, int y, int z, int b, UNUSED(double abs_x), UNUSED(double abs_y), void *priv)
|
||||
ps2_poll(void *priv)
|
||||
{
|
||||
atkbc_dev_t *dev = (atkbc_dev_t *) priv;
|
||||
int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3;
|
||||
|
||||
int cond = (!mouse_capture && !video_fullscreen) || (!mouse_scan || (!x && !y && !z && (b == dev->b))) ||
|
||||
int cond = (!mouse_capture && !video_fullscreen) || (!mouse_scan || mouse_state_changed()) ||
|
||||
((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) >= (FIFO_SIZE - packet_size)));
|
||||
|
||||
if (!cond) {
|
||||
dev->b = b;
|
||||
|
||||
if (dev->mode == MODE_STREAM)
|
||||
ps2_report_coordinates(dev, 1);
|
||||
}
|
||||
if (!cond && (dev->mode == MODE_STREAM))
|
||||
ps2_report_coordinates(dev, 1);
|
||||
|
||||
return cond;
|
||||
}
|
||||
@@ -343,9 +335,6 @@ mouse_ps2_init(const device_t *info)
|
||||
if (i > 4)
|
||||
dev->flags |= FLAG_EXPLORER;
|
||||
|
||||
if (i >= 4)
|
||||
i = 3;
|
||||
|
||||
mouse_ps2_log("%s: buttons=%d\n", dev->name, i);
|
||||
|
||||
/* Tell them how many buttons we have. */
|
||||
|
||||
@@ -82,8 +82,8 @@ typedef struct mouse_t {
|
||||
int8_t type; /* type of this device */
|
||||
int8_t port;
|
||||
|
||||
int old_buttons;
|
||||
int state;
|
||||
|
||||
int bps;
|
||||
int rps;
|
||||
|
||||
@@ -180,16 +180,17 @@ sermouse_report_msystems(mouse_t *dev)
|
||||
{
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -128, 127, 1, 0);
|
||||
|
||||
dev->buf[0] = 0x80;
|
||||
dev->buf[0] |= (mouse_buttons & 0x01) ? 0x00 : 0x04; /* left button */
|
||||
dev->buf[0] |= (b & 0x01) ? 0x00 : 0x04; /* left button */
|
||||
if (dev->but >= 3)
|
||||
dev->buf[0] |= (mouse_buttons & 0x04) ? 0x00 : 0x02; /* middle button */
|
||||
dev->buf[0] |= (b & 0x04) ? 0x00 : 0x02; /* middle button */
|
||||
else
|
||||
dev->buf[0] |= 0x02; /* middle button */
|
||||
dev->buf[0] |= (mouse_buttons & 0x02) ? 0x00 : 0x01; /* right button */
|
||||
dev->buf[0] |= (b & 0x02) ? 0x00 : 0x01; /* right button */
|
||||
dev->buf[1] = delta_x;
|
||||
dev->buf[2] = delta_y;
|
||||
dev->buf[2] = delta_x; /* same as byte 1 */
|
||||
@@ -203,14 +204,15 @@ sermouse_report_3bp(mouse_t *dev)
|
||||
{
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -128, 127, 1, 0);
|
||||
|
||||
dev->buf[0] = 0x80;
|
||||
dev->buf[0] |= (mouse_buttons & 0x01) ? 0x04 : 0x00; /* left button */
|
||||
dev->buf[0] |= (b & 0x01) ? 0x04 : 0x00; /* left button */
|
||||
if (dev->but >= 3)
|
||||
dev->buf[0] |= (mouse_buttons & 0x04) ? 0x02 : 0x00; /* middle button */
|
||||
dev->buf[0] |= (mouse_buttons & 0x02) ? 0x01 : 0x00; /* right button */
|
||||
dev->buf[0] |= (b & 0x04) ? 0x02 : 0x00; /* middle button */
|
||||
dev->buf[0] |= (b & 0x02) ? 0x01 : 0x00; /* right button */
|
||||
dev->buf[1] = delta_x;
|
||||
dev->buf[2] = delta_y;
|
||||
dev->buf[2] = delta_x; /* same as byte 1 */
|
||||
@@ -224,6 +226,7 @@ sermouse_report_mmseries(mouse_t *dev)
|
||||
{
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -127, 127, 1, 0);
|
||||
|
||||
@@ -233,10 +236,10 @@ sermouse_report_mmseries(mouse_t *dev)
|
||||
if (delta_y >= 0)
|
||||
dev->buf[0] |= 0x08;
|
||||
|
||||
dev->buf[0] |= (mouse_buttons & 0x01) ? 0x04 : 0x00; /* left button */
|
||||
dev->buf[0] |= (b & 0x01) ? 0x04 : 0x00; /* left button */
|
||||
if (dev->but >= 3)
|
||||
dev->buf[0] |= (mouse_buttons & 0x04) ? 0x02 : 0x00; /* middle button */
|
||||
dev->buf[0] |= (mouse_buttons & 0x02) ? 0x01 : 0x00; /* right button */
|
||||
dev->buf[0] |= (b & 0x04) ? 0x02 : 0x00; /* middle button */
|
||||
dev->buf[0] |= (b & 0x02) ? 0x01 : 0x00; /* right button */
|
||||
dev->buf[1] = ABS(delta_x) & 0x7f;
|
||||
dev->buf[2] = ABS(delta_y) & 0x7f;
|
||||
mouse_serial_log("MM series mouse report: %02X %02X %02X\n", dev->buf[0], dev->buf[1], dev->buf[2]);
|
||||
@@ -249,14 +252,15 @@ sermouse_report_bp1(mouse_t *dev, int abs)
|
||||
{
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -2048, 2047, 1, abs);
|
||||
|
||||
dev->buf[0] = 0x80;
|
||||
dev->buf[0] |= (mouse_buttons & 0x01) ? 0x10 : 0x00; /* left button */
|
||||
dev->buf[0] |= (b & 0x01) ? 0x10 : 0x00; /* left button */
|
||||
if (dev->but >= 3)
|
||||
dev->buf[0] |= (mouse_buttons & 0x04) ? 0x08 : 0x00; /* middle button */
|
||||
dev->buf[0] |= (mouse_buttons & 0x02) ? 0x04 : 0x00; /* right button */
|
||||
dev->buf[0] |= (b & 0x04) ? 0x08 : 0x00; /* middle button */
|
||||
dev->buf[0] |= (b & 0x02) ? 0x04 : 0x00; /* right button */
|
||||
dev->buf[1] = (delta_x & 0x3f);
|
||||
dev->buf[2] = ((delta_x >> 6) & 0x3f);
|
||||
dev->buf[3] = (delta_y & 0x3f);
|
||||
@@ -272,15 +276,17 @@ sermouse_report_ms(mouse_t *dev)
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int delta_z = 0;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -128, 127, 0, 0);
|
||||
mouse_subtract_z(&delta_z, -8, 7, 1);
|
||||
|
||||
dev->buf[0] = 0x40;
|
||||
dev->buf[0] |= (((delta_y >> 6) & 0x03) << 2);
|
||||
dev->buf[0] |= ((delta_x >> 6) & 0x03);
|
||||
if (mouse_buttons & 0x01)
|
||||
if (b & 0x01)
|
||||
dev->buf[0] |= 0x20;
|
||||
if (mouse_buttons & 0x02)
|
||||
if (b & 0x02)
|
||||
dev->buf[0] |= 0x10;
|
||||
dev->buf[1] = delta_x & 0x3f;
|
||||
dev->buf[2] = delta_y & 0x3f;
|
||||
@@ -288,12 +294,12 @@ sermouse_report_ms(mouse_t *dev)
|
||||
if (dev->but == 3) {
|
||||
len = 3;
|
||||
if (dev->format == FORMAT_MS) {
|
||||
if (mouse_buttons & 0x04) {
|
||||
if (b & 0x04) {
|
||||
dev->buf[3] = 0x20;
|
||||
len++;
|
||||
}
|
||||
} else {
|
||||
if ((mouse_buttons ^ dev->old_buttons) & 0x04) {
|
||||
if (mouse_mbut_changed()) {
|
||||
/* Microsoft 3-button mice send a fourth byte of 0x00 when the middle button
|
||||
has changed. */
|
||||
dev->buf[3] = 0x00;
|
||||
@@ -303,19 +309,8 @@ sermouse_report_ms(mouse_t *dev)
|
||||
} else if (dev->but == 4) {
|
||||
len = 4;
|
||||
|
||||
if (mouse_z > 7) {
|
||||
delta_z = 7;
|
||||
mouse_z -= 7;
|
||||
} else if (mouse_z < -8) {
|
||||
delta_z = -8;
|
||||
mouse_z += 8;
|
||||
} else {
|
||||
delta_z = mouse_z;
|
||||
mouse_z = 0;
|
||||
}
|
||||
|
||||
dev->buf[3] = delta_z & 0x0f;
|
||||
if (mouse_buttons & 0x04)
|
||||
if (b & 0x04)
|
||||
dev->buf[3] |= 0x10;
|
||||
} else
|
||||
len = 3;
|
||||
@@ -330,13 +325,14 @@ sermouse_report_hex(mouse_t *dev)
|
||||
uint8_t but = 0x00;
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int b = mouse_get_buttons_ex();
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -128, 127, 1, 0);
|
||||
|
||||
but |= (mouse_buttons & 0x01) ? 0x04 : 0x00; /* left button */
|
||||
but |= (b & 0x01) ? 0x04 : 0x00; /* left button */
|
||||
if (dev->but >= 3)
|
||||
but |= (mouse_buttons & 0x04) ? 0x02 : 0x00; /* middle button */
|
||||
but |= (mouse_buttons & 0x02) ? 0x01 : 0x00; /* right button */
|
||||
but |= (b & 0x04) ? 0x02 : 0x00; /* middle button */
|
||||
but |= (b & 0x02) ? 0x01 : 0x00; /* right button */
|
||||
|
||||
sprintf(ret, "%01X%02X%02X", but & 0x0f, (int8_t) delta_x, (int8_t) delta_y);
|
||||
|
||||
@@ -387,16 +383,9 @@ sermouse_report(mouse_t *dev)
|
||||
static void
|
||||
sermouse_transmit_report(mouse_t *dev, int from_report)
|
||||
{
|
||||
int z_changed = (dev->but == 4) ? mouse_z : 0;
|
||||
int b_changed = ((mouse_buttons ^ dev->old_buttons) & 0x07);
|
||||
|
||||
if (dev->but < 3)
|
||||
b_changed &= ~0x04;
|
||||
|
||||
if (mouse_capture && (mouse_x || mouse_y || z_changed || b_changed)) {
|
||||
if (mouse_capture && mouse_state_changed())
|
||||
sermouse_transmit(dev, sermouse_report(dev), from_report, 1);
|
||||
dev->old_buttons = mouse_buttons;
|
||||
} else {
|
||||
else {
|
||||
if (dev->prompt || dev->continuous)
|
||||
sermouse_set_period(dev, 0.0);
|
||||
else {
|
||||
@@ -418,7 +407,7 @@ sermouse_transmit_report(mouse_t *dev, int from_report)
|
||||
}
|
||||
|
||||
static int
|
||||
sermouse_poll(int x, int y, int z, int b, UNUSED(double abs_x), UNUSED(double abs_y), void *priv)
|
||||
sermouse_poll(void *priv)
|
||||
{
|
||||
mouse_t *dev = (mouse_t *) priv;
|
||||
|
||||
@@ -533,6 +522,7 @@ static void
|
||||
ltsermouse_process_command(mouse_t *dev)
|
||||
{
|
||||
int cmd_to_rps[9] = { 10, 20, 35, 70, 150, 0, -1, 100, 50 };
|
||||
int b;
|
||||
uint8_t format_codes[FORMATS_NUM] = {
|
||||
[FORMAT_BP1_ABS] = 0x0c,
|
||||
[FORMAT_BP1_REL] = 0x06,
|
||||
@@ -620,7 +610,8 @@ ltsermouse_process_command(mouse_t *dev)
|
||||
break;
|
||||
case 0x05:
|
||||
/* Diagnostic */
|
||||
dev->buf[0] = ((mouse_buttons & 0x01) << 2) | ((mouse_buttons & 0x06) >> 1);
|
||||
b = mouse_get_buttons_ex();
|
||||
dev->buf[0] = ((b & 0x01) << 2) | ((b & 0x06) >> 1);
|
||||
dev->buf[1] = dev->buf[2] = 0x00;
|
||||
sermouse_transmit(dev, 3, 0, 0);
|
||||
break;
|
||||
|
||||
@@ -424,9 +424,17 @@ wacom_write(UNUSED(struct serial_s *serial), void *priv, uint8_t data)
|
||||
}
|
||||
|
||||
static int
|
||||
wacom_poll(int x, int y, UNUSED(int z), int b, double abs_x, double abs_y, void *priv)
|
||||
wacom_poll(void *priv)
|
||||
{
|
||||
mouse_wacom_t *wacom = (mouse_wacom_t *) priv;
|
||||
int delta_x;
|
||||
int delta_y;
|
||||
int b = mouse_get_buttons_ex();
|
||||
double abs_x;
|
||||
double abs_y;
|
||||
|
||||
mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -32768, 32767, 0, 0);
|
||||
mouse_get_abs_coords(&abs_x, &abs_y);
|
||||
|
||||
if (wacom->settings_bits.cmd_set == WACOM_CMDSET_IV) {
|
||||
wacom->abs_x = abs_x * 5039. * (wacom->x_res / 1000.);
|
||||
@@ -442,8 +450,8 @@ wacom_poll(int x, int y, UNUSED(int z), int b, double abs_x, double abs_y, void
|
||||
wacom->abs_x = 0;
|
||||
if (wacom->abs_y < 0)
|
||||
wacom->abs_y = 0;
|
||||
wacom->rel_x = x;
|
||||
wacom->rel_y = y;
|
||||
wacom->rel_x = delta_x;
|
||||
wacom->rel_y = delta_y;
|
||||
}
|
||||
if (wacom->b != b)
|
||||
wacom->oldb = wacom->b;
|
||||
|
||||
Reference in New Issue
Block a user