Completely reworked mouse handling - should now be smoother due to there no longer being a multi-layered game of telephone going on with all the various interim coordinate counters, also rewritten the serial mouse emulation ground ground up.

This commit is contained in:
OBattler
2023-08-07 18:49:58 +02:00
parent cdb415ef0f
commit c695cb8ded
25 changed files with 1155 additions and 990 deletions

View File

@@ -1279,10 +1279,12 @@ pc_run(void)
startblit(); startblit();
cpu_exec(cpu_s->rspeed / 100); cpu_exec(cpu_s->rspeed / 100);
#ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */ #ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */
// if (gdbstub_step == GDBSTUB_EXEC) if (gdbstub_step == GDBSTUB_EXEC) {
#endif #endif
#if 0 if (!mouse_timed)
mouse_process(); mouse_process();
#ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */
}
#endif #endif
joystick_process(); joystick_process();
endblit(); endblit();

View File

@@ -19,7 +19,9 @@
* Copyright 2016-2018 Miran Grca. * Copyright 2016-2018 Miran Grca.
* Copyright 2017-2018 Fred N. van Kempen. * Copyright 2017-2018 Fred N. van Kempen.
*/ */
#include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdatomic.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@@ -37,17 +39,22 @@ typedef struct mouse_t {
} mouse_t; } mouse_t;
int mouse_type = 0; int mouse_type = 0;
int mouse_x; atomic_int mouse_x;
int mouse_y; atomic_int mouse_y;
int mouse_z; atomic_int mouse_z;
int mouse_buttons; atomic_int mouse_buttons;
int mouse_mode; int mouse_mode;
int mouse_timed = 1;
int mouse_tablet_in_proximity = 0; int mouse_tablet_in_proximity = 0;
int tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */ int tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */
double mouse_x_abs; double mouse_x_abs;
double mouse_y_abs; double mouse_y_abs;
double mouse_sensitivity = 1.0;
double mouse_x_error = 0.0;
double mouse_y_error = 0.0;
pc_timer_t mouse_timer; /* mouse event timer */ pc_timer_t mouse_timer; /* mouse event timer */
static const device_t mouse_none_device = { static const device_t mouse_none_device = {
@@ -155,22 +162,81 @@ mouse_close(void)
static void static void
mouse_timer_poll(UNUSED(void *priv)) mouse_timer_poll(UNUSED(void *priv))
{ {
/* Poll at 255 Hz, maximum supported by PS/2 mic. */ /* Poll at the specified sample rate. */
timer_on_auto(&mouse_timer, 1000000.0 / sample_rate); timer_on_auto(&mouse_timer, 1000000.0 / sample_rate);
#ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */ #ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */
if (gdbstub_step == GDBSTUB_EXEC) if (gdbstub_step == GDBSTUB_EXEC) {
#endif #endif
mouse_process(); if (mouse_timed)
mouse_process();
#ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */
}
#endif
}
void
mouse_scale(int x, int y)
{
pclog("mouse_scale()\n");
double scaled_x = (((double) x) * mouse_sensitivity) + mouse_x_error;
double scaled_y = (((double) y) * mouse_sensitivity) + 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);
}
void
mouse_scale_x(int x)
{
double scaled_x = ((double) x) * mouse_sensitivity + mouse_x_error;
mouse_x += (int) scaled_x;
mouse_x_error = scaled_x - ((double) mouse_x);
}
void
mouse_scale_y(int y)
{
double scaled_y = ((double) y) * mouse_sensitivity + mouse_y_error;
mouse_y += (int) scaled_y;
mouse_y_error = scaled_y - ((double) mouse_y);
}
void
mouse_set_z(int z)
{
mouse_z += z;
}
void
mouse_set_buttons_ex(int b)
{
mouse_buttons = b;
}
int
mouse_get_buttons_ex(void)
{
return mouse_buttons;
} }
void void
mouse_set_sample_rate(double new_rate) mouse_set_sample_rate(double new_rate)
{ {
mouse_timed = (new_rate > 0.0);
timer_stop(&mouse_timer); timer_stop(&mouse_timer);
sample_rate = new_rate; sample_rate = new_rate;
timer_on_auto(&mouse_timer, 1000000.0 / sample_rate); if (mouse_timed)
timer_on_auto(&mouse_timer, 1000000.0 / sample_rate);
} }
void void
@@ -186,6 +252,9 @@ mouse_reset(void)
mouse_x = mouse_y = mouse_z = 0; mouse_x = mouse_y = mouse_z = 0;
mouse_buttons = 0x00; mouse_buttons = 0x00;
mouse_mode = 0; mouse_mode = 0;
mouse_timed = 1;
mouse_x_error = mouse_y_error = 0.0;
/* If no mouse configured, we're done. */ /* If no mouse configured, we're done. */
if (mouse_type == 0) if (mouse_type == 0)
@@ -222,19 +291,14 @@ mouse_process(void)
if (mouse_curr == NULL) if (mouse_curr == NULL)
return; return;
if (mouse_poll_ex) if ((mouse_mode >= 1) && mouse_poll_ex)
mouse_poll_ex(); mouse_poll_ex();
else
mouse_poll();
if ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL)) { if ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL)) {
if (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_x, mouse_y, mouse_z, mouse_buttons, mouse_x_abs, mouse_y_abs, mouse_priv);
else else
mouse_dev_poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_priv); mouse_dev_poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_priv);
/* Reset mouse deltas. */
mouse_x = mouse_y = mouse_z = 0;
} }
} }

View File

@@ -68,6 +68,7 @@
*/ */
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdatomic.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@@ -80,6 +81,7 @@
#include <86box/timer.h> #include <86box/timer.h>
#include <86box/device.h> #include <86box/device.h>
#include <86box/mouse.h> #include <86box/mouse.h>
#include <86box/plat.h>
#include <86box/plat_unused.h> #include <86box/plat_unused.h>
#include <86box/random.h> #include <86box/random.h>
@@ -147,8 +149,6 @@ typedef struct mouse {
int irq; int irq;
int bn; int bn;
int flags; int flags;
int mouse_delayed_dx;
int mouse_delayed_dy;
int mouse_buttons; int mouse_buttons;
int mouse_buttons_last; int mouse_buttons_last;
int toggle_counter; int toggle_counter;
@@ -480,10 +480,13 @@ bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double
mouse_t *dev = (mouse_t *) priv; mouse_t *dev = (mouse_t *) priv;
int xor ; int xor ;
if (!mouse_capture && !video_fullscreen)
return 1;
if (!(dev->flags & FLAG_ENABLED)) if (!(dev->flags & FLAG_ENABLED))
return 1; /* Mouse is disabled, do nothing. */ return 1; /* Mouse is disabled, do nothing. */
if (!x && !y && !((b ^ dev->mouse_buttons_last) & 0x07)) { if (!mouse_x && !mouse_y && !((b ^ dev->mouse_buttons_last) & 0x07)) {
dev->mouse_buttons_last = b; dev->mouse_buttons_last = b;
return 1; /* State has not changed, do nothing. */ return 1; /* State has not changed, do nothing. */
} }
@@ -498,7 +501,7 @@ bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double
so update bits 6-3 here. */ so update bits 6-3 here. */
/* If the mouse has moved, set bit 6. */ /* If the mouse has moved, set bit 6. */
if (x || y) if (mouse_x || mouse_y)
dev->mouse_buttons |= 0x40; dev->mouse_buttons |= 0x40;
/* Set bits 3-5 according to button state changes. */ /* Set bits 3-5 according to button state changes. */
@@ -508,26 +511,30 @@ bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double
dev->mouse_buttons_last = b; dev->mouse_buttons_last = b;
/* Clamp x and y to between -128 and 127 (int8_t range). */ if (!dev->timer_enabled) {
if (x > 127)
x = 127;
if (x < -128)
x = -128;
if (y > 127)
y = 127;
if (y < -128)
y = -128;
if (dev->timer_enabled) {
/* Update delayed coordinates. */
dev->mouse_delayed_dx += x;
dev->mouse_delayed_dy += y;
} else {
/* If the counters are not frozen, update them. */ /* If the counters are not frozen, update them. */
if (!(dev->flags & FLAG_HOLD)) { if (!(dev->flags & FLAG_HOLD)) {
dev->current_x = (int8_t) x; if (mouse_x > 127) {
dev->current_y = (int8_t) y; dev->current_x = 127;
mouse_x -= 127;
} else if (mouse_x < 1-128) {
dev->current_x = -128;
mouse_x += 128;
} else {
dev->current_x = mouse_x;
mouse_x = 0;
}
if (mouse_y > 127) {
dev->current_y = 127;
mouse_y -= 127;
} else if (mouse_y < 1-128) {
dev->current_y = -128;
mouse_y += 128;
} else {
dev->current_y = mouse_y;
mouse_y = 0;
}
dev->current_b = dev->mouse_buttons; dev->current_b = dev->mouse_buttons;
} }
@@ -538,6 +545,7 @@ bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double
bm_log("DEBUG: Data Interrupt Fired...\n"); bm_log("DEBUG: Data Interrupt Fired...\n");
} }
} }
return 0; return 0;
} }
@@ -548,31 +556,31 @@ bm_update_data(mouse_t *dev)
{ {
int delta_x; int delta_x;
int delta_y; int delta_y;
int xor ; int xor;
/* If the counters are not frozen, update them. */ /* If the counters are not frozen, update them. */
if (!(dev->flags & FLAG_HOLD)) { if ((mouse_capture || video_fullscreen) && !(dev->flags & FLAG_HOLD)) {
/* Update the deltas and the delays. */ /* Update the deltas and the delays. */
if (dev->mouse_delayed_dx > 127) { if (mouse_x > 127) {
delta_x = 127; delta_x = 127;
dev->mouse_delayed_dx -= 127; mouse_x -= 127;
} else if (dev->mouse_delayed_dx < -128) { } else if (mouse_x < -128) {
delta_x = -128; delta_x = -128;
dev->mouse_delayed_dx += 128; mouse_x += 128;
} else { } else {
delta_x = dev->mouse_delayed_dx; delta_x = mouse_x;
dev->mouse_delayed_dx = 0; mouse_x = 0;
} }
if (dev->mouse_delayed_dy > 127) { if (mouse_y > 127) {
delta_y = 127; delta_y = 127;
dev->mouse_delayed_dy -= 127; mouse_y -= 127;
} else if (dev->mouse_delayed_dy < -128) { } else if (mouse_y < -128) {
delta_y = -128; delta_y = -128;
dev->mouse_delayed_dy += 128; mouse_y += 128;
} else { } else {
delta_y = dev->mouse_delayed_dy; delta_y = mouse_y;
dev->mouse_delayed_dy = 0; mouse_y = 0;
} }
dev->current_x = (int8_t) delta_x; dev->current_x = (int8_t) delta_x;
@@ -659,8 +667,6 @@ bm_init(const device_t *info)
} }
mouse_set_buttons(dev->bn); mouse_set_buttons(dev->bn);
dev->mouse_delayed_dx = 0;
dev->mouse_delayed_dy = 0;
dev->mouse_buttons = 0; dev->mouse_buttons = 0;
dev->mouse_buttons_last = 0; dev->mouse_buttons_last = 0;
dev->sig_val = 0; /* the signature port value */ dev->sig_val = 0; /* the signature port value */
@@ -707,6 +713,8 @@ bm_init(const device_t *info)
else else
bm_log("Standard MS/Logitech BusMouse initialized\n"); bm_log("Standard MS/Logitech BusMouse initialized\n");
mouse_set_sample_rate(0.0);
return dev; return dev;
} }

View File

@@ -13,6 +13,7 @@
* Authors: Fred N. van Kempen, <decwiz@yahoo.com> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
*/ */
#include <stdarg.h> #include <stdarg.h>
#include <stdatomic.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@@ -23,6 +24,7 @@
#include <86box/device.h> #include <86box/device.h>
#include <86box/keyboard.h> #include <86box/keyboard.h>
#include <86box/mouse.h> #include <86box/mouse.h>
#include <86box/plat.h>
#include <86box/plat_unused.h> #include <86box/plat_unused.h>
enum { enum {
@@ -75,40 +77,51 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main)
uint8_t buff[3] = { 0x08, 0x00, 0x00 }; uint8_t buff[3] = { 0x08, 0x00, 0x00 };
int temp_z; int temp_z;
if (dev->x > 255) { if (mouse_x > 255) {
dev->x = 255;
buff[0] |= 0x40; buff[0] |= 0x40;
buff[1] = 255;
mouse_x -= 255;
} else if (mouse_x < -256) {
buff[0] |= (0x40 | 0x10);
mouse_x += 256;
} else {
if (mouse_x < 0)
buff[0] |= 0x10;
buff[1] = mouse_x;
mouse_x = 0;
} }
if (dev->x < -256) {
dev->x = -256;
buff[0] |= 0x40;
}
if (dev->y > 255) {
dev->y = 255;
buff[0] |= 0x80;
}
if (dev->y < -256) {
dev->y = -256;
buff[0] |= 0x80;
}
if (dev->z < -8)
dev->z = -8;
if (dev->z > 7)
dev->z = 7;
if (dev->x < 0) if (mouse_y < -255) {
buff[0] |= 0x10; buff[0] |= 0x80;
if (dev->y < 0) buff[2] = 255;
buff[0] |= 0x20; mouse_y += 255;
buff[0] |= (dev->b & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03)); } else if (mouse_y > 256) {
buff[1] = (dev->x & 0xff); buff[0] |= (0x80 | 0x20);
buff[2] = (dev->y & 0xff); mouse_y -= 256;
} else {
if (mouse_y > 0)
buff[0] |= 0x20;
buff[2] = -mouse_y;
mouse_y = 0;
}
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;
}
buff[0] |= (mouse_buttons & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03));
kbc_at_dev_queue_add(dev, buff[0], main); 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[1], main);
kbc_at_dev_queue_add(dev, buff[2], main); kbc_at_dev_queue_add(dev, buff[2], main);
if (dev->flags & FLAG_INTMODE) { if (dev->flags & FLAG_INTMODE) {
temp_z = dev->z & 0x0f;
if (dev->flags & FLAG_5BTN) { if (dev->flags & FLAG_5BTN) {
if (mouse_buttons & 8) if (mouse_buttons & 8)
temp_z |= 0x10; temp_z |= 0x10;
@@ -121,8 +134,6 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main)
} }
kbc_at_dev_queue_add(dev, temp_z, main); kbc_at_dev_queue_add(dev, temp_z, main);
} }
dev->x = dev->y = dev->z = 0;
} }
static void static void
@@ -132,7 +143,7 @@ ps2_set_defaults(atkbc_dev_t *dev)
dev->rate = 100; dev->rate = 100;
mouse_set_sample_rate(100.0); mouse_set_sample_rate(100.0);
dev->resolution = 2; dev->resolution = 2;
dev->flags &= 0x88; dev->flags &= 0x188;
mouse_scan = 0; mouse_scan = 0;
} }
@@ -316,25 +327,17 @@ ps2_poll(int x, int y, int z, int b, UNUSED(double abs_x), UNUSED(double abs_y),
atkbc_dev_t *dev = (atkbc_dev_t *) priv; atkbc_dev_t *dev = (atkbc_dev_t *) priv;
int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3; int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3;
if (!mouse_scan || (!x && !y && !z && (b == dev->b))) int cond = (!mouse_capture && !video_fullscreen) || (!mouse_scan || (!x && !y && !z && (b == dev->b))) ||
return 0xff; ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) >= (FIFO_SIZE - packet_size)));
if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) { if (!cond) {
dev->x = x;
dev->y = -y;
dev->z = -z;
dev->b = b;
} else {
dev->x += x;
dev->y -= y;
dev->z -= z;
dev->b = b; dev->b = b;
if (dev->mode == MODE_STREAM)
ps2_report_coordinates(dev, 1);
} }
if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) return cond;
ps2_report_coordinates(dev, 1);
return 0;
} }
/* /*

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,11 @@
#ifndef EMU_MOUSE_H #ifndef EMU_MOUSE_H
#define EMU_MOUSE_H #define EMU_MOUSE_H
#ifndef __cplusplus
/* Yes, a big no-no, but I'm saving myself time here. */
#include <stdatomic.h>
#endif
#define MOUSE_TYPE_NONE 0 /* no mouse configured */ #define MOUSE_TYPE_NONE 0 /* no mouse configured */
#define MOUSE_TYPE_INTERNAL 1 /* machine has internal mouse */ #define MOUSE_TYPE_INTERNAL 1 /* machine has internal mouse */
#define MOUSE_TYPE_LOGIBUS 2 /* Logitech/ATI Bus Mouse */ #define MOUSE_TYPE_LOGIBUS 2 /* Logitech/ATI Bus Mouse */
@@ -39,20 +44,26 @@
#define MOUSE_TYPE_ONBOARD 0x80 /* Mouse is an on-board version of one of the above. */ #define MOUSE_TYPE_ONBOARD 0x80 /* Mouse is an on-board version of one of the above. */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#else
extern atomic_int mouse_x;
extern atomic_int mouse_y;
extern atomic_int mouse_z;
extern atomic_int mouse_buttons;
#endif #endif
extern int mouse_type; extern int mouse_type;
extern int mouse_x;
extern int mouse_y;
extern int mouse_z;
extern int mouse_mode; /* 1 = Absolute, 0 = Relative */ extern int mouse_mode; /* 1 = Absolute, 0 = Relative */
extern int mouse_timed; /* 1 = Timed, 0 = Constant */
extern int mouse_tablet_in_proximity; extern int mouse_tablet_in_proximity;
extern double mouse_x_abs; extern double mouse_x_abs;
extern double mouse_y_abs; extern double mouse_y_abs;
extern int mouse_buttons;
extern int tablet_tool_type; extern int tablet_tool_type;
extern double mouse_sensitivity;
extern double mouse_x_error;
extern double mouse_y_error;
#ifdef EMU_DEVICE_H #ifdef EMU_DEVICE_H
extern const device_t *mouse_get_device(int mouse); extern const device_t *mouse_get_device(int mouse);
@@ -79,11 +90,16 @@ extern void mouse_set_buttons(int buttons);
extern void mouse_set_poll_ex(void (*poll_ex)(void)); extern void mouse_set_poll_ex(void (*poll_ex)(void));
extern void mouse_process(void); extern void mouse_process(void);
extern void mouse_set_poll(int (*f)(int, int, int, int, void *), void *); extern void mouse_set_poll(int (*f)(int, int, int, int, void *), void *);
extern void mouse_poll(void);
extern void mouse_bus_set_irq(void *priv, int irq); extern void mouse_bus_set_irq(void *priv, int irq);
extern void mouse_set_sample_rate(double new_rate); extern void mouse_set_sample_rate(double new_rate);
extern void mouse_scale(int x, int y);
extern void mouse_scale_x(int x);
extern void mouse_scale_y(int y);
extern void mouse_set_z(int z);
extern void mouse_set_buttons_ex(int b);
extern int mouse_get_buttons_ex(void);
extern char *mouse_get_name(int mouse); extern char *mouse_get_name(int mouse);
extern char *mouse_get_internal_name(int mouse); extern char *mouse_get_internal_name(int mouse);

View File

@@ -318,8 +318,12 @@ inb(uint16_t port)
amstrad_latch = AMSTRAD_SW9 | 0x80000000; amstrad_latch = AMSTRAD_SW9 | 0x80000000;
} }
if (!found) if (!found) {
cycles -= io_delay; if (is286)
cycles -= io_delay;
else
sub_cycles(io_delay);
}
/* TriGem 486-BIOS MHz output. */ /* TriGem 486-BIOS MHz output. */
#if 0 #if 0
@@ -327,7 +331,16 @@ inb(uint16_t port)
ret = 0xfe; ret = 0xfe;
#endif #endif
io_log("[%04X:%08X] (%i, %i, %04i) in b(%04X) = %02X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret); /* if (port == 0x23)
ret = 0x00; */
if (port == 0x7f)
ret = 0x00;
// if ((port != 0x42) && (port != 0x61) && (port != 0x3b4) && (port != 0x3ba) && (port != 0x3da)) {
if (((port >= 0xcf8) && (port <= 0xcff)) || ((port >= 0xc000) && (port <= 0xcfff))) {
io_log("[%04X:%08X] (%i, %i, %04i) in b(%04X) = %02X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret);
}
return ret; return ret;
} }
@@ -362,14 +375,21 @@ outb(uint16_t port, uint8_t val)
} }
if (!found) { if (!found) {
cycles -= io_delay; if (is286)
cycles -= io_delay;
else
sub_cycles(io_delay);
#ifdef USE_DYNAREC #ifdef USE_DYNAREC
if (cpu_use_dynarec && ((port == 0xeb) || (port == 0xed))) if (cpu_use_dynarec && ((port == 0xeb) || (port == 0xed)))
update_tsc(); update_tsc();
#endif #endif
} }
io_log("[%04X:%08X] (%i, %i, %04i) outb(%04X, %02X)\n", CS, cpu_state.pc, in_smm, found, qfound, port, val); // if ((port != 0x43) && (port != 0xea)) {
if (((port >= 0xcf8) && (port <= 0xcff)) || ((port >= 0xc000) && (port <= 0xcfff))) {
io_log("[%04X:%08X] (%i, %i, %04i) outb(%04X, %02X)\n", CS, cpu_state.pc, in_smm, found, qfound, port, val);
}
return; return;
} }
@@ -430,10 +450,16 @@ inw(uint16_t port)
amstrad_latch = AMSTRAD_SW9 | 0x80000000; amstrad_latch = AMSTRAD_SW9 | 0x80000000;
} }
if (!found) if (!found) {
cycles -= io_delay; if (is286)
cycles -= io_delay;
else
sub_cycles(io_delay);
}
io_log("[%04X:%08X] (%i, %i, %04i) in w(%04X) = %04X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret); if (((port >= 0xcf8) && (port <= 0xcff)) || ((port >= 0xc000) && (port <= 0xcfff))) {
io_log("[%04X:%08X] (%i, %i, %04i) in w(%04X) = %04X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret);
}
return ret; return ret;
} }
@@ -481,14 +507,21 @@ outw(uint16_t port, uint16_t val)
} }
if (!found) { if (!found) {
cycles -= io_delay; if (is286)
cycles -= io_delay;
else
sub_cycles(io_delay);
#ifdef USE_DYNAREC #ifdef USE_DYNAREC
if (cpu_use_dynarec && ((port == 0xeb) || (port == 0xed))) if (cpu_use_dynarec && ((port == 0xeb) || (port == 0xed)))
update_tsc(); update_tsc();
#endif #endif
} }
io_log("[%04X:%08X] (%i, %i, %04i) outw(%04X, %04X)\n", CS, cpu_state.pc, in_smm, found, qfound, port, val); // if (port != 0xea) {
if (((port >= 0xcf8) && (port <= 0xcff)) || ((port >= 0xc000) && (port <= 0xcfff))) {
io_log("[%04X:%08X] (%i, %i, %04i) outw(%04X, %04X)\n", CS, cpu_state.pc, in_smm, found, qfound, port, val);
}
return; return;
} }
@@ -580,7 +613,9 @@ inl(uint16_t port)
if (!found) if (!found)
cycles -= io_delay; cycles -= io_delay;
io_log("[%04X:%08X] (%i, %i, %04i) in l(%04X) = %08X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret); if (((port >= 0xcf8) && (port <= 0xcff)) || ((port >= 0xc000) && (port <= 0xcfff))) {
io_log("[%04X:%08X] (%i, %i, %04i) in l(%04X) = %08X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret);
}
return ret; return ret;
} }
@@ -651,7 +686,9 @@ outl(uint16_t port, uint32_t val)
#endif #endif
} }
io_log("[%04X:%08X] (%i, %i, %04i) outl(%04X, %08X)\n", CS, cpu_state.pc, in_smm, found, qfound, port, val); if (((port >= 0xcf8) && (port <= 0xcff)) || ((port >= 0xc000) && (port <= 0xcfff))) {
io_log("[%04X:%08X] (%i, %i, %04i) outl(%04X, %08X)\n", CS, cpu_state.pc, in_smm, found, qfound, port, val);
}
return; return;
} }

View File

@@ -37,21 +37,6 @@ static std::vector<std::pair<int, libevdev *>> evdev_mice;
static std::atomic<bool> stopped = false; static std::atomic<bool> stopped = false;
static QThread *evdev_thread; static QThread *evdev_thread;
static std::atomic<int> evdev_mouse_rel_x = 0, evdev_mouse_rel_y = 0;
void
evdev_mouse_poll()
{
if (!evdev_mice.size() || !mouse_capture) {
evdev_mouse_rel_x = 0;
evdev_mouse_rel_y = 0;
return;
}
mouse_x = evdev_mouse_rel_x;
mouse_y = evdev_mouse_rel_y;
evdev_mouse_rel_x = evdev_mouse_rel_y = 0;
}
void void
evdev_thread_func() evdev_thread_func()
{ {
@@ -67,11 +52,11 @@ evdev_thread_func()
struct input_event ev; struct input_event ev;
if (pfds[i].revents & POLLIN) { if (pfds[i].revents & POLLIN) {
while (libevdev_next_event(evdev_mice[i].second, LIBEVDEV_READ_FLAG_NORMAL, &ev) == 0) { while (libevdev_next_event(evdev_mice[i].second, LIBEVDEV_READ_FLAG_NORMAL, &ev) == 0) {
if (ev.type == EV_REL && mouse_capture) { if (evdev_mice.size() && (ev.type == EV_REL) && mouse_capture) {
if (ev.code == REL_X) if (ev.code == REL_X)
evdev_mouse_rel_x += ev.value; mouse_scale_x(ev.value);
if (ev.code == REL_Y) if (ev.code == REL_Y)
evdev_mouse_rel_y += ev.value; mouse_scale_y(ev.value);
} }
} }
} }

View File

@@ -1,4 +1,3 @@
#ifdef EVDEV_INPUT #ifdef EVDEV_INPUT
void evdev_init(); void evdev_init();
void evdev_mouse_poll();
#endif #endif

View File

@@ -17,13 +17,6 @@ extern int mouse_capture;
extern void plat_mouse_capture(int); extern void plat_mouse_capture(int);
} }
typedef struct mouseinputdata {
int deltax, deltay, deltaz;
int mousebuttons;
} mouseinputdata;
static mouseinputdata mousedata;
CocoaEventFilter::~CocoaEventFilter() CocoaEventFilter::~CocoaEventFilter()
{ {
} }
@@ -31,6 +24,8 @@ CocoaEventFilter::~CocoaEventFilter()
bool bool
CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, result_t *result) CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, result_t *result)
{ {
int b = 0;
if (mouse_capture) { if (mouse_capture) {
if (eventType == "mac_generic_NSEvent") { if (eventType == "mac_generic_NSEvent") {
NSEvent *event = (NSEvent *) message; NSEvent *event = (NSEvent *) message;
@@ -38,12 +33,11 @@ CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message,
|| [event type] == NSEventTypeLeftMouseDragged || [event type] == NSEventTypeLeftMouseDragged
|| [event type] == NSEventTypeRightMouseDragged || [event type] == NSEventTypeRightMouseDragged
|| [event type] == NSEventTypeOtherMouseDragged) { || [event type] == NSEventTypeOtherMouseDragged) {
mousedata.deltax += [event deltaX]; mouse_scale([event deltaX], [event deltaY]);
mousedata.deltay += [event deltaY];
return true; return true;
} }
if ([event type] == NSEventTypeScrollWheel) { if ([event type] == NSEventTypeScrollWheel) {
mousedata.deltaz += [event deltaY]; mouse_set_z([event deltaY]);
return true; return true;
} }
switch ([event type]) { switch ([event type]) {
@@ -51,27 +45,32 @@ CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message,
return false; return false;
case NSEventTypeLeftMouseDown: case NSEventTypeLeftMouseDown:
{ {
mousedata.mousebuttons |= 1; b = mouse_get_buttons_ex() | 1;
mouse_set_buttons_ex(b);
break; break;
} }
case NSEventTypeLeftMouseUp: case NSEventTypeLeftMouseUp:
{ {
mousedata.mousebuttons &= ~1; b = mouse_get_buttons_ex() & ~1;
mouse_set_buttons_ex(b);
break; break;
} }
case NSEventTypeRightMouseDown: case NSEventTypeRightMouseDown:
{ {
mousedata.mousebuttons |= 2; b = mouse_get_buttons_ex() | 2;
mouse_set_buttons_ex(b);
break; break;
} }
case NSEventTypeRightMouseUp: case NSEventTypeRightMouseUp:
{ {
mousedata.mousebuttons &= ~2; b = mouse_get_buttons_ex() & ~2;
mouse_set_buttons_ex(b);
break; break;
} }
case NSEventTypeOtherMouseDown: case NSEventTypeOtherMouseDown:
{ {
mousedata.mousebuttons |= 4; b = mouse_get_buttons_ex() | 4;
mouse_set_buttons_ex(b);
break; break;
} }
case NSEventTypeOtherMouseUp: case NSEventTypeOtherMouseUp:
@@ -80,7 +79,8 @@ CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message,
plat_mouse_capture(0); plat_mouse_capture(0);
return true; return true;
} }
mousedata.mousebuttons &= ~4; b = mouse_get_buttons_ex() & ~4;
mouse_set_buttons_ex(b);
break; break;
} }
} }
@@ -89,13 +89,3 @@ CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message,
} }
return false; return false;
} }
extern "C" void
macos_poll_mouse()
{
mouse_x = mousedata.deltax;
mouse_y = mousedata.deltay;
mouse_z = mousedata.deltaz;
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
mouse_buttons = mousedata.mousebuttons;
}

View File

@@ -256,7 +256,6 @@ main(int argc, char *argv[])
auto rawInputFilter = WindowsRawInputFilter::Register(main_window); auto rawInputFilter = WindowsRawInputFilter::Register(main_window);
if (rawInputFilter) { if (rawInputFilter) {
app.installNativeEventFilter(rawInputFilter.get()); app.installNativeEventFilter(rawInputFilter.get());
QObject::connect(main_window, &MainWindow::pollMouse, (WindowsRawInputFilter *) rawInputFilter.get(), &WindowsRawInputFilter::mousePoll, Qt::DirectConnection);
main_window->setSendKeyboardInput(false); main_window->setSendKeyboardInput(false);
} }
#endif #endif

View File

@@ -253,8 +253,6 @@ MainWindow::MainWindow(QWidget *parent)
emit updateMenuResizeOptions(); emit updateMenuResizeOptions();
connect(this, &MainWindow::pollMouse, ui->stackedWidget, &RendererStack::mousePoll, Qt::DirectConnection);
connect(this, &MainWindow::setMouseCapture, this, [this](bool state) { connect(this, &MainWindow::setMouseCapture, this, [this](bool state) {
mouse_capture = state ? 1 : 0; mouse_capture = state ? 1 : 0;
qt_mouse_capture(mouse_capture); qt_mouse_capture(mouse_capture);
@@ -764,7 +762,6 @@ MainWindow::initRendererMonitorSlot(int monitor_index)
secondaryRenderer->switchRenderer((RendererStack::Renderer) vid_api); secondaryRenderer->switchRenderer((RendererStack::Renderer) vid_api);
secondaryRenderer->setMouseTracking(true); secondaryRenderer->setMouseTracking(true);
} }
connect(this, &MainWindow::pollMouse, secondaryRenderer.get(), &RendererStack::mousePoll, Qt::DirectConnection);
} }
} }
@@ -890,6 +887,9 @@ MainWindow::on_actionSettings_triggered()
Settings settings(this); Settings settings(this);
settings.setModal(true); settings.setModal(true);
settings.setWindowModality(Qt::WindowModal); settings.setWindowModality(Qt::WindowModal);
settings.setWindowFlag(Qt::CustomizeWindowHint, true);
settings.setWindowFlag(Qt::WindowTitleHint, true);
settings.setWindowFlag(Qt::WindowSystemMenuHint, false);
settings.exec(); settings.exec();
switch (settings.result()) { switch (settings.result()) {

View File

@@ -39,7 +39,6 @@ signals:
void paint(const QImage &image); void paint(const QImage &image);
void resizeContents(int w, int h); void resizeContents(int w, int h);
void resizeContentsMonitor(int w, int h, int monitor_index); void resizeContentsMonitor(int w, int h, int monitor_index);
void pollMouse();
void statusBarMessage(const QString &msg); void statusBarMessage(const QString &msg);
void updateStatusBarPanes(); void updateStatusBarPanes();
void updateStatusBarActivity(int tag, bool active); void updateStatusBarActivity(int tag, bool active);

View File

@@ -49,26 +49,19 @@
extern "C" { extern "C" {
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/config.h> #include <86box/config.h>
#include <86box/mouse.h>
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/video.h> #include <86box/video.h>
#include <86box/mouse.h>
double mouse_sensitivity = 1.0;
double mouse_x_error = 0.0, mouse_y_error = 0.0;
} }
struct mouseinputdata { struct mouseinputdata {
atomic_int deltax;
atomic_int deltay;
atomic_int deltaz;
atomic_int mousebuttons;
atomic_bool mouse_tablet_in_proximity; atomic_bool mouse_tablet_in_proximity;
std::atomic<double> x_abs; std::atomic<double> x_abs;
std::atomic<double> y_abs; std::atomic<double> y_abs;
}; };
static mouseinputdata mousedata; static mouseinputdata mousedata;
extern "C" void macos_poll_mouse();
extern MainWindow *main_window; extern MainWindow *main_window;
RendererStack::RendererStack(QWidget *parent, int monitor_index) RendererStack::RendererStack(QWidget *parent, int monitor_index)
: QStackedWidget(parent) : QStackedWidget(parent)
@@ -94,29 +87,21 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index)
# ifdef WAYLAND # ifdef WAYLAND
if (!stricmp(mouse_type, "wayland")) { if (!stricmp(mouse_type, "wayland")) {
wl_init(); wl_init();
this->mouse_poll_func = wl_mouse_poll;
this->mouse_capture_func = wl_mouse_capture; this->mouse_capture_func = wl_mouse_capture;
this->mouse_uncapture_func = wl_mouse_uncapture; this->mouse_uncapture_func = wl_mouse_uncapture;
} }
# endif # endif
# ifdef EVDEV_INPUT # ifdef EVDEV_INPUT
if (!stricmp(mouse_type, "evdev")) { if (!stricmp(mouse_type, "evdev"))
evdev_init(); evdev_init();
this->mouse_poll_func = evdev_mouse_poll;
}
# endif # endif
if (!stricmp(mouse_type, "xinput2")) { if (!stricmp(mouse_type, "xinput2")) {
extern void xinput2_init(); extern void xinput2_init();
extern void xinput2_poll();
extern void xinput2_exit(); extern void xinput2_exit();
xinput2_init(); xinput2_init();
this->mouse_poll_func = xinput2_poll;
this->mouse_exit_func = xinput2_exit; this->mouse_exit_func = xinput2_exit;
} }
#endif #endif
#ifdef __APPLE__
this->mouse_poll_func = macos_poll_mouse;
#endif
} }
RendererStack::~RendererStack() RendererStack::~RendererStack()
@@ -149,49 +134,25 @@ RendererStack::mousePoll()
{ {
if (m_monitor_index >= 1) { if (m_monitor_index >= 1) {
if (mouse_mode >= 1) { if (mouse_mode >= 1) {
mouse_x_abs = mousedata.x_abs; mouse_x_abs = mousedata.x_abs;
mouse_y_abs = mousedata.y_abs; mouse_y_abs = mousedata.y_abs;
if (!mouse_tablet_in_proximity) { if (!mouse_tablet_in_proximity)
mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity;
}
if (mousedata.mouse_tablet_in_proximity) {
mouse_buttons = mousedata.mousebuttons;
}
} }
return; return;
} }
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
if (mouse_mode == 0) { if (mouse_mode == 0) {
mouse_x_abs = mousedata.x_abs; mouse_x_abs = mousedata.x_abs;
mouse_y_abs = mousedata.y_abs; mouse_y_abs = mousedata.y_abs;
return; return;
} }
#endif #endif
#ifndef __APPLE__
mouse_x = mousedata.deltax;
mouse_y = mousedata.deltay;
mouse_z = mousedata.deltaz;
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
mouse_buttons = mousedata.mousebuttons;
if (this->mouse_poll_func)
#endif
this->mouse_poll_func();
mouse_x_abs = mousedata.x_abs; mouse_x_abs = mousedata.x_abs;
mouse_y_abs = mousedata.y_abs; mouse_y_abs = mousedata.y_abs;
mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity;
double scaled_x = mouse_x * mouse_sensitivity + mouse_x_error;
double scaled_y = mouse_y * mouse_sensitivity + mouse_y_error;
mouse_x = static_cast<int>(scaled_x);
mouse_y = static_cast<int>(scaled_y);
mouse_x_error = scaled_x - mouse_x;
mouse_y_error = scaled_y - mouse_y;
} }
int ignoreNextMouseEvent = 1; int ignoreNextMouseEvent = 1;
@@ -212,8 +173,9 @@ RendererStack::mouseReleaseEvent(QMouseEvent *event)
isMouseDown &= ~1; isMouseDown &= ~1;
return; return;
} }
if (mouse_capture || mouse_mode >= 1) { if (mouse_capture || (mouse_mode >= 1)) {
mousedata.mousebuttons &= ~event->button(); if ((mouse_mode >= 1) && ((m_monitor_index < 1) || mousedata.mouse_tablet_in_proximity))
mouse_set_buttons_ex(mouse_get_buttons_ex() & ~event->button());
} }
isMouseDown &= ~1; isMouseDown &= ~1;
} }
@@ -222,8 +184,9 @@ void
RendererStack::mousePressEvent(QMouseEvent *event) RendererStack::mousePressEvent(QMouseEvent *event)
{ {
isMouseDown |= 1; isMouseDown |= 1;
if (mouse_capture || mouse_mode >= 1) { if (mouse_capture || (mouse_mode >= 1)) {
mousedata.mousebuttons |= event->button(); if ((mouse_mode >= 1) && ((m_monitor_index < 1) || mousedata.mouse_tablet_in_proximity))
mouse_set_buttons_ex(mouse_get_buttons_ex() | event->button());
} }
event->accept(); event->accept();
} }
@@ -231,9 +194,7 @@ RendererStack::mousePressEvent(QMouseEvent *event)
void void
RendererStack::wheelEvent(QWheelEvent *event) RendererStack::wheelEvent(QWheelEvent *event)
{ {
if (mouse_capture) { mouse_set_z(event->pixelDelta().y());
mousedata.deltaz += event->pixelDelta().y();
}
} }
void void
@@ -258,8 +219,12 @@ RendererStack::mouseMoveEvent(QMouseEvent *event)
event->accept(); event->accept();
return; return;
} }
mousedata.deltax += event->pos().x() - oldPos.x();
mousedata.deltay += event->pos().y() - oldPos.y(); #if defined __unix__ && !defined __HAIKU__
if (!stricmp(mouse_type, "wayland"))
mouse_scale(event->pos().x() - oldPos.x(), event->pos().y() - oldPos.y());
#endif
if (QApplication::platformName() == "eglfs") { if (QApplication::platformName() == "eglfs") {
leaveEvent((QEvent *) event); leaveEvent((QEvent *) event);
ignoreNextMouseEvent--; ignoreNextMouseEvent--;

View File

@@ -82,9 +82,9 @@ public:
rendererWindow->onResize(width, height); rendererWindow->onResize(width, height);
} }
void (*mouse_poll_func)() = nullptr;
void (*mouse_capture_func)(QWindow *window) = nullptr; void (*mouse_capture_func)(QWindow *window) = nullptr;
void (*mouse_uncapture_func)() = nullptr; void (*mouse_uncapture_func)() = nullptr;
void (*mouse_exit_func)() = nullptr; void (*mouse_exit_func)() = nullptr;
signals: signals:

View File

@@ -198,12 +198,6 @@ static const uint16_t sdl_to_xt[0x200] = {
[SDL_SCANCODE_NONUSBACKSLASH] = 0x56, [SDL_SCANCODE_NONUSBACKSLASH] = 0x56,
}; };
typedef struct mouseinputdata {
int deltax, deltay, deltaz;
int mousebuttons;
} mouseinputdata;
static mouseinputdata mousedata;
// #define ENABLE_SDL_LOG 3 // #define ENABLE_SDL_LOG 3
#ifdef ENABLE_SDL_LOG #ifdef ENABLE_SDL_LOG
int sdl_do_log = ENABLE_SDL_LOG; int sdl_do_log = ENABLE_SDL_LOG;
@@ -620,16 +614,14 @@ sdl_main()
event.wheel.x *= -1; event.wheel.x *= -1;
event.wheel.y *= -1; event.wheel.y *= -1;
} }
mousedata.deltaz = event.wheel.y; mouse_set_z(event.wheel.y);
} }
break; break;
} }
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
{ {
if (mouse_capture || video_fullscreen) { if (mouse_capture || video_fullscreen)
mousedata.deltax += event.motion.xrel; mouse_scale(event.motion.xrel, event.motion.yrel);
mousedata.deltay += event.motion.yrel;
}
break; break;
} }
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@@ -660,10 +652,10 @@ sdl_main()
buttonmask = 4; buttonmask = 4;
break; break;
} }
if (event.button.state == SDL_PRESSED) { if (event.button.state == SDL_PRESSED)
mousedata.mousebuttons |= buttonmask; mouse_set_buttons_ex(mouse_get_buttons_ex() | buttonmask);
} else else
mousedata.mousebuttons &= ~buttonmask; mouse_set_buttons_ex(mouse_get_buttons_ex() & ~buttonmask);
} }
break; break;
} }
@@ -714,13 +706,3 @@ sdl_mouse_capture(int on)
{ {
SDL_SetRelativeMouseMode((SDL_bool) on); SDL_SetRelativeMouseMode((SDL_bool) on);
} }
void
sdl_mouse_poll()
{
mouse_x = mousedata.deltax;
mouse_y = mousedata.deltay;
mouse_z = mousedata.deltaz;
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
mouse_buttons = mousedata.mousebuttons;
}

View File

@@ -68,6 +68,5 @@ enum sdl_main_status {
extern enum sdl_main_status sdl_main(); extern enum sdl_main_status sdl_main();
extern void sdl_mouse_capture(int on); extern void sdl_mouse_capture(int on);
extern void sdl_mouse_poll();
#endif /*WIN_SDL_H*/ #endif /*WIN_SDL_H*/

View File

@@ -88,12 +88,6 @@ qt_blit(int x, int y, int w, int h, int monitor_index)
main_window->blitToWidget(x, y, w, h, monitor_index); main_window->blitToWidget(x, y, w, h, monitor_index);
} }
void
mouse_poll()
{
main_window->pollMouse();
}
extern "C" int vid_resize; extern "C" int vid_resize;
void void
plat_resize_request(int w, int h, int monitor_index) plat_resize_request(int w, int h, int monitor_index)

View File

@@ -35,6 +35,8 @@
#include <QMenuBar> #include <QMenuBar>
#include <atomic>
#include <windows.h> #include <windows.h>
#include <86box/keyboard.h> #include <86box/keyboard.h>
@@ -338,85 +340,73 @@ void
WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) WindowsRawInputFilter::mouse_handle(PRAWINPUT raw)
{ {
RAWMOUSE state = raw->data.mouse; RAWMOUSE state = raw->data.mouse;
static int x; static int x, delta_x;
static int y; static int y, delta_y;
static int b, delta_z;
pclog("WindowsRawInputFilter::mouse_handle()\n");
b = mouse_get_buttons_ex();
/* read mouse buttons and wheel */ /* read mouse buttons and wheel */
if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
buttons |= 1; b |= 1;
else if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP)
buttons &= ~1; b &= ~1;
if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)
buttons |= 4; b |= 4;
else if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP)
buttons &= ~4; b &= ~4;
if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN)
buttons |= 2; b |= 2;
else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP)
buttons &= ~2; b &= ~2;
if (state.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) if (state.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
buttons |= 8; b |= 8;
else if (state.usButtonFlags & RI_MOUSE_BUTTON_4_UP) else if (state.usButtonFlags & RI_MOUSE_BUTTON_4_UP)
buttons &= ~8; b &= ~8;
if (state.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) if (state.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
buttons |= 16; b |= 16;
else if (state.usButtonFlags & RI_MOUSE_BUTTON_5_UP) else if (state.usButtonFlags & RI_MOUSE_BUTTON_5_UP)
buttons &= ~16; b &= ~16;
mouse_set_buttons_ex(b);
if (state.usButtonFlags & RI_MOUSE_WHEEL) { if (state.usButtonFlags & RI_MOUSE_WHEEL) {
dwheel += (SHORT) state.usButtonData / 120; delta_z = (SHORT) state.usButtonData / 120;
} mouse_set_z(delta_z);
} else
delta_z = 0;
if (state.usFlags & MOUSE_MOVE_ABSOLUTE) { if (state.usFlags & MOUSE_MOVE_ABSOLUTE) {
/* absolute mouse, i.e. RDP or VNC /* absolute mouse, i.e. RDP or VNC
* seems to work fine for RDP on Windows 10 * seems to work fine for RDP on Windows 10
* Not sure about other environments. * Not sure about other environments.
*/ */
dx += (state.lLastX - x) / 25; delta_x = (state.lLastX - x) / 25;
dy += (state.lLastY - y) / 25; delta_y = (state.lLastY - y) / 25;
x = state.lLastX; x = state.lLastX;
y = state.lLastY; y = state.lLastY;
} else { } else {
/* relative mouse, i.e. regular mouse */ /* relative mouse, i.e. regular mouse */
dx += state.lLastX; delta_x = state.lLastX;
dy += state.lLastY; delta_y = state.lLastY;
} }
HWND wnd = (HWND) window->winId();
mouse_scale(delta_x, delta_y);
HWND wnd = (HWND)window->winId();
RECT rect; RECT rect;
GetWindowRect(wnd, &rect); GetWindowRect(wnd, &rect);
int left = rect.left + (rect.right - rect.left) / 2; int left = rect.left + (rect.right - rect.left) / 2;
int top = rect.top + (rect.bottom - rect.top) / 2; int top = rect.top + (rect.bottom - rect.top) / 2;
SetCursorPos(left, top); SetCursorPos(left, top);
} }
void
WindowsRawInputFilter::mousePoll()
{
if (mouse_mode >= 1) return;
if (mouse_capture || video_fullscreen) {
static int b = 0;
if (dx != 0 || dy != 0 || dwheel != 0) {
mouse_x += dx;
mouse_y += dy;
mouse_z = dwheel;
dx = 0;
dy = 0;
dwheel = 0;
}
if (b != buttons) {
mouse_buttons = buttons;
b = buttons;
}
}
}

View File

@@ -59,9 +59,6 @@ public:
~WindowsRawInputFilter(); ~WindowsRawInputFilter();
public slots:
void mousePoll();
private: private:
MainWindow *window; MainWindow *window;
uint16_t scancode_map[768]; uint16_t scancode_map[768];

View File

@@ -26,6 +26,7 @@
#include <QGuiApplication> #include <QGuiApplication>
extern "C" { extern "C" {
#include <86box/mouse.h>
#include <86box/plat.h> #include <86box/plat.h>
} }
@@ -34,28 +35,12 @@ static zwp_relative_pointer_v1 *rel_pointer = nullptr;
static zwp_pointer_constraints_v1 *conf_pointer_interface = nullptr; static zwp_pointer_constraints_v1 *conf_pointer_interface = nullptr;
static zwp_locked_pointer_v1 *conf_pointer = nullptr; static zwp_locked_pointer_v1 *conf_pointer = nullptr;
static int rel_mouse_x = 0;
static int rel_mouse_y = 0;
static bool wl_init_ok = false; static bool wl_init_ok = false;
void void
rel_mouse_event(void *data, zwp_relative_pointer_v1 *zwp_relative_pointer_v1, uint32_t tstmp, uint32_t tstmpl, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_real, wl_fixed_t dy_real) rel_mouse_event(void *data, zwp_relative_pointer_v1 *zwp_relative_pointer_v1, uint32_t tstmp, uint32_t tstmpl, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_real, wl_fixed_t dy_real)
{ {
rel_mouse_x += wl_fixed_to_int(dx_real); mouse_scale(wl_fixed_to_int(dx_real), wl_fixed_to_int(dy_real));
rel_mouse_y += wl_fixed_to_int(dy_real);
}
extern "C" {
extern int mouse_x, mouse_y;
}
void
wl_mouse_poll()
{
mouse_x = rel_mouse_x;
mouse_y = rel_mouse_y;
rel_mouse_x = 0;
rel_mouse_y = 0;
} }
static struct zwp_relative_pointer_v1_listener rel_listener = { static struct zwp_relative_pointer_v1_listener rel_listener = {

View File

@@ -1,5 +1,4 @@
class QWindow; class QWindow;
void wl_mouse_capture(QWindow *window); void wl_mouse_capture(QWindow *window);
void wl_mouse_uncapture(); void wl_mouse_uncapture();
void wl_mouse_poll();
void wl_init(); void wl_init();

View File

@@ -48,7 +48,7 @@ static Display *disp = nullptr;
static QThread *procThread = nullptr; static QThread *procThread = nullptr;
static XIEventMask ximask; static XIEventMask ximask;
static std::atomic<bool> exitfromthread = false; static std::atomic<bool> exitfromthread = false;
static std::atomic<double> xi2_mouse_x = 0, xi2_mouse_y = 0, xi2_mouse_abs_x = 0, xi2_mouse_abs_y = 0; static std::atomic<double> xi2_mouse_abs_x = 0, xi2_mouse_abs_y = 0;
static int xi2opcode = 0; static int xi2opcode = 0;
static double prev_coords[2] = { 0.0 }; static double prev_coords[2] = { 0.0 };
static Time prev_time = 0; static Time prev_time = 0;
@@ -168,9 +168,9 @@ common_motion:
if ((v->mode == XIModeRelative) && (rawev->sourceid != xtest_pointer)) { if ((v->mode == XIModeRelative) && (rawev->sourceid != xtest_pointer)) {
/* Set relative coordinates. */ /* Set relative coordinates. */
if (axis == 0) if (axis == 0)
xi2_mouse_x = xi2_mouse_x + coords[axis]; mouse_scale_x(coords[axis]);
else else
xi2_mouse_y = xi2_mouse_y + coords[axis]; mouse_scale_y(coords[axis]);
} else { } else {
/* Convert absolute value range to pixel granularity, then to relative coordinates. */ /* Convert absolute value range to pixel granularity, then to relative coordinates. */
int disp_screen = XDefaultScreen(disp); int disp_screen = XDefaultScreen(disp);
@@ -188,7 +188,7 @@ common_motion:
} }
if (xi2_mouse_abs_x != 0) if (xi2_mouse_abs_x != 0)
xi2_mouse_x = xi2_mouse_x + (abs_div - xi2_mouse_abs_x); mouse_scale_x(abs_div - xi2_mouse_abs_x);
xi2_mouse_abs_x = abs_div; xi2_mouse_abs_x = abs_div;
} else { } else {
if (v->mode == XIModeRelative) { if (v->mode == XIModeRelative) {
@@ -202,7 +202,7 @@ common_motion:
} }
if (xi2_mouse_abs_y != 0) if (xi2_mouse_abs_y != 0)
xi2_mouse_y = xi2_mouse_y + (abs_div - xi2_mouse_abs_y); mouse_scale_y(abs_div - xi2_mouse_abs_y);
xi2_mouse_abs_y = abs_div; xi2_mouse_abs_y = abs_div;
} }
} }
@@ -273,14 +273,3 @@ xinput2_init()
} }
} }
} }
void
xinput2_poll()
{
if (procThread && mouse_capture) {
mouse_x = xi2_mouse_x;
mouse_y = xi2_mouse_y;
}
xi2_mouse_x = 0;
xi2_mouse_y = 0;
}

View File

@@ -699,19 +699,6 @@ typedef struct mouseinputdata {
int mousebuttons; int mousebuttons;
} mouseinputdata; } mouseinputdata;
SDL_mutex *mousemutex; SDL_mutex *mousemutex;
static mouseinputdata mousedata;
void
mouse_poll(void)
{
SDL_LockMutex(mousemutex);
mouse_x = mousedata.deltax;
mouse_y = mousedata.deltay;
mouse_z = mousedata.deltaz;
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
mouse_buttons = mousedata.mousebuttons;
SDL_UnlockMutex(mousemutex);
}
int real_sdl_w; int real_sdl_w;
int real_sdl_h; int real_sdl_h;
void void
@@ -1182,7 +1169,7 @@ main(int argc, char **argv)
event.wheel.y *= -1; event.wheel.y *= -1;
} }
SDL_LockMutex(mousemutex); SDL_LockMutex(mousemutex);
mousedata.deltaz = event.wheel.y; mouse_set_z(event.wheel.y);
SDL_UnlockMutex(mousemutex); SDL_UnlockMutex(mousemutex);
} }
break; break;
@@ -1191,8 +1178,7 @@ main(int argc, char **argv)
{ {
if (mouse_capture || video_fullscreen) { if (mouse_capture || video_fullscreen) {
SDL_LockMutex(mousemutex); SDL_LockMutex(mousemutex);
mousedata.deltax += event.motion.xrel; mouse_scale(event.motion.xrel, event.motion.yrel);
mousedata.deltay += event.motion.yrel;
SDL_UnlockMutex(mousemutex); SDL_UnlockMutex(mousemutex);
} }
break; break;
@@ -1232,10 +1218,10 @@ main(int argc, char **argv)
break; break;
} }
SDL_LockMutex(mousemutex); SDL_LockMutex(mousemutex);
if (event.button.state == SDL_PRESSED) { if (event.button.state == SDL_PRESSED)
mousedata.mousebuttons |= buttonmask; mouse_set_buttons_ex(mouse_get_buttons_ex() | buttonmask);
} else else
mousedata.mousebuttons &= ~buttonmask; mouse_set_buttons_ex(mouse_get_buttons_ex() & ~buttonmask);
SDL_UnlockMutex(mousemutex); SDL_UnlockMutex(mousemutex);
} }
break; break;

View File

@@ -21,17 +21,16 @@
*/ */
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
#include <stdatomic.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/mouse.h> #include <86box/mouse.h>
#include <86box/pic.h>
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/win.h> #include <86box/win.h>
int mouse_capture; int mouse_capture;
double mouse_sensitivity = 1.0; /* Unused. */
double mouse_x_error = 0.0; /* Unused. */
double mouse_y_error = 0.0; /* Unused. */
typedef struct { typedef struct {
int buttons; int buttons;
@@ -65,53 +64,62 @@ void
win_mouse_handle(PRAWINPUT raw) win_mouse_handle(PRAWINPUT raw)
{ {
RAWMOUSE state = raw->data.mouse; RAWMOUSE state = raw->data.mouse;
static int x; static int x, delta_x;
static int y; static int y, delta_y;
static int b, delta_z;
b = mouse_get_buttons_ex();
/* read mouse buttons and wheel */ /* read mouse buttons and wheel */
if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
mousestate.buttons |= 1; b |= 1;
else if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP)
mousestate.buttons &= ~1; b &= ~1;
if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)
mousestate.buttons |= 4; b |= 4;
else if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP)
mousestate.buttons &= ~4; b &= ~4;
if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN)
mousestate.buttons |= 2; b |= 2;
else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP)
mousestate.buttons &= ~2; b &= ~2;
if (state.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) if (state.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
mousestate.buttons |= 8; b |= 8;
else if (state.usButtonFlags & RI_MOUSE_BUTTON_4_UP) else if (state.usButtonFlags & RI_MOUSE_BUTTON_4_UP)
mousestate.buttons &= ~8; b &= ~8;
if (state.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) if (state.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
mousestate.buttons |= 16; b |= 16;
else if (state.usButtonFlags & RI_MOUSE_BUTTON_5_UP) else if (state.usButtonFlags & RI_MOUSE_BUTTON_5_UP)
mousestate.buttons &= ~16; b &= ~16;
mouse_set_buttons_ex(b);
if (state.usButtonFlags & RI_MOUSE_WHEEL) { if (state.usButtonFlags & RI_MOUSE_WHEEL) {
mousestate.dwheel += (SHORT) state.usButtonData / 120; delta_z = (SHORT) state.usButtonData / 120;
} mouse_set_z(delta_z);
} else
delta_z = 0;
if (state.usFlags & MOUSE_MOVE_ABSOLUTE) { if (state.usFlags & MOUSE_MOVE_ABSOLUTE) {
/* absolute mouse, i.e. RDP or VNC /* absolute mouse, i.e. RDP or VNC
* seems to work fine for RDP on Windows 10 * seems to work fine for RDP on Windows 10
* Not sure about other environments. * Not sure about other environments.
*/ */
mousestate.dx += (state.lLastX - x) / 25; delta_x = (state.lLastX - x) / 25;
mousestate.dy += (state.lLastY - y) / 25; delta_y = (state.lLastY - y) / 25;
x = state.lLastX; x = state.lLastX;
y = state.lLastY; y = state.lLastY;
} else { } else {
/* relative mouse, i.e. regular mouse */ /* relative mouse, i.e. regular mouse */
mousestate.dx += state.lLastX; delta_x = state.lLastX;
mousestate.dy += state.lLastY; delta_y = state.lLastY;
} }
mouse_scale(delta_x, delta_y);
} }
void void
@@ -124,27 +132,3 @@ win_mouse_close(void)
ridev.usUsage = 0x02; ridev.usUsage = 0x02;
RegisterRawInputDevices(&ridev, 1, sizeof(ridev)); RegisterRawInputDevices(&ridev, 1, sizeof(ridev));
} }
void
mouse_poll(void)
{
static int b = 0;
if (mouse_capture || video_fullscreen) {
if (mousestate.dx != 0 || mousestate.dy != 0 || mousestate.dwheel != 0) {
mouse_x += mousestate.dx;
mouse_y += mousestate.dy;
mouse_z = mousestate.dwheel;
mousestate.dx = 0;
mousestate.dy = 0;
mousestate.dwheel = 0;
// pclog("dx=%d, dy=%d, dwheel=%d\n", mouse_x, mouse_y, mouse_z);
}
if (b != mousestate.buttons) {
mouse_buttons = mousestate.buttons;
b = mousestate.buttons;
}
}
}