More mouse fixes (thanks, coldbrewed!), and mitigated IRQ clear spam from serial and AT NVR.

This commit is contained in:
OBattler
2023-08-13 17:25:45 +02:00
parent e7dd8664f2
commit 3e2a31eb97
3 changed files with 73 additions and 42 deletions

View File

@@ -171,8 +171,7 @@ mouse_scale_coord_x(double x, int mul)
double ratio = 1.0; double ratio = 1.0;
if (!mouse_raw) if (!mouse_raw)
ratio = ((double) monitors[0].mon_unscaled_size_x) / ratio = ((double) monitors[0].mon_unscaled_size_x) / monitors[0].mon_res_x;
(monitors[0].mon_res_x * plat_get_dpi());
if (mul) if (mul)
x *= ratio; x *= ratio;
@@ -188,8 +187,7 @@ mouse_scale_coord_y(double y, int mul)
double ratio = 1.0; double ratio = 1.0;
if (!mouse_raw) if (!mouse_raw)
ratio = ((double) monitors[0].mon_efscrnsz_y) / ratio = ((double) monitors[0].mon_efscrnsz_y) / monitors[0].mon_res_y;
(monitors[0].mon_res_y * plat_get_dpi());
if (mul) if (mul)
y *= ratio; y *= ratio;
@@ -198,6 +196,7 @@ mouse_scale_coord_y(double y, int mul)
return y; return y;
} }
void void
mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs) mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs)
{ {
@@ -205,6 +204,8 @@ mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs)
double smax_x; double smax_x;
double rsmin_x; double rsmin_x;
double smin_x; double smin_x;
int ds_x;
int scaled_x;
rsmin_x = mouse_scale_coord_x(min, 0); rsmin_x = mouse_scale_coord_x(min, 0);
if (abs) { if (abs) {
@@ -217,28 +218,39 @@ mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs)
smin_x = rsmin_x; smin_x = rsmin_x;
} }
/* Default the X and Y overflows to 1. */ smax_x = floor(smax_x);
smin_x = ceil(smin_x);
/* Default the X overflow to 1. */
if (o_x != NULL) if (o_x != NULL)
*o_x = 1; *o_x = 1;
ds_x = mouse_scale_coord_x(real_x, 1);
if (ds_x >= 0.0)
scaled_x = (int) floor(mouse_scale_coord_x(real_x, 1));
else
scaled_x = (int) ceil(mouse_scale_coord_x(real_x, 1));
if (real_x > smax_x) { if (real_x > smax_x) {
if (abs) if (abs) {
*delta_x = (int) mouse_scale_coord_x(real_x, 1); *delta_x = scaled_x;
else real_x -= mouse_scale_coord_x((double) scaled_x, 0);
} else {
*delta_x = max; *delta_x = max;
real_x -= smax_x; real_x -= smax_x;
}
} else if (real_x < smin_x) { } else if (real_x < smin_x) {
if (abs) if (abs) {
*delta_x = (int) mouse_scale_coord_x(real_x, 1); *delta_x = scaled_x;
else real_x -= mouse_scale_coord_x((double) scaled_x, 0);
} else {
*delta_x = min; *delta_x = min;
real_x += ABS(smin_x); real_x += ABS(smin_x);
}
} else { } else {
if (abs) *delta_x = scaled_x;
*delta_x = (int) mouse_scale_coord_x(real_x, 1); real_x -= mouse_scale_coord_x((double) scaled_x, 0);
else
*delta_x = (int) mouse_scale_coord_x(real_x, 1);
real_x = 0.0;
if (o_x != NULL) if (o_x != NULL)
*o_x = 0; *o_x = 0;
} }
@@ -259,6 +271,8 @@ mouse_subtract_y(int *delta_y, int *o_y, int min, int max, int invert, int abs)
double smax_y; double smax_y;
double rsmin_y; double rsmin_y;
double smin_y; double smin_y;
int ds_y;
int scaled_y;
if (invert) if (invert)
real_y = -real_y; real_y = -real_y;
@@ -274,28 +288,39 @@ mouse_subtract_y(int *delta_y, int *o_y, int min, int max, int invert, int abs)
smin_y = rsmin_y; smin_y = rsmin_y;
} }
/* Default the X and Y overflows to 1. */ smax_y = floor(smax_y);
smin_y = ceil(smin_y);
/* Default Y overflow to 1. */
if (o_y != NULL) if (o_y != NULL)
*o_y = 1; *o_y = 1;
ds_y = mouse_scale_coord_x(real_y, 1);
if (ds_y >= 0.0)
scaled_y = (int) floor(mouse_scale_coord_x(real_y, 1));
else
scaled_y = (int) ceil(mouse_scale_coord_x(real_y, 1));
if (real_y > smax_y) { if (real_y > smax_y) {
if (abs) if (abs) {
*delta_y = (int) mouse_scale_coord_y(real_y, 1); *delta_y = scaled_y;
else real_y -= mouse_scale_coord_y((double) scaled_y, 0);
} else {
*delta_y = max; *delta_y = max;
real_y -= smax_y; real_y -= smax_y;
}
} else if (real_y < smin_y) { } else if (real_y < smin_y) {
if (abs) if (abs) {
*delta_y = (int) mouse_scale_coord_y(real_y, 1); *delta_y = scaled_y;
else real_y -= mouse_scale_coord_y((double) scaled_y, 0);
} else {
*delta_y = min; *delta_y = min;
real_y += ABS(smin_y); real_y += ABS(smin_y);
}
} else { } else {
if (abs) *delta_y = scaled_y;
*delta_y = (int) mouse_scale_coord_y(real_y, 1); real_y -= mouse_scale_coord_y((double) scaled_y, 0);
else
*delta_y = (int) mouse_scale_coord_y(real_y, 1);
real_y = 0.0;
if (o_y != NULL) if (o_y != NULL)
*o_y = 0; *o_y = 0;
} }
@@ -324,8 +349,8 @@ int
mouse_moved(void) mouse_moved(void)
{ {
/* Convert them to integer so we treat < 1.0 and > -1.0 as 0. */ /* Convert them to integer so we treat < 1.0 and > -1.0 as 0. */
int ret = (((int) floor(atomic_load(&mouse_x)) != 0) || int ret = (((int) floor(mouse_scale_coord_x(atomic_load(&mouse_x), 1)) != 0) ||
((int) floor(atomic_load(&mouse_y)) != 0)); ((int) floor(mouse_scale_coord_x(atomic_load(&mouse_y), 1)) != 0));
return ret; return ret;
} }

View File

@@ -109,8 +109,12 @@ serial_transmit_period(serial_t *dev)
void void
serial_do_irq(serial_t *dev, int set) serial_do_irq(serial_t *dev, int set)
{ {
if (dev->irq != 0xff) if (dev->irq != 0xff) {
picint_common(1 << dev->irq, !!(dev->type >= SERIAL_16450), set, &dev->irq_state); if (set || (dev->irq_state != !!set))
picint_common(1 << dev->irq, !!(dev->type >= SERIAL_16450), set, &dev->irq_state);
if (dev->type >= SERIAL_16450)
dev->irq_state = !!set;
}
} }
void void

View File

@@ -440,12 +440,14 @@ timer_update_irq(nvr_t *nvr)
local_t *local = (local_t *) nvr->data; local_t *local = (local_t *) nvr->data;
uint8_t irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & (REGB_UIE | REGB_AIE | REGB_PIE); uint8_t irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & (REGB_UIE | REGB_AIE | REGB_PIE);
if (irq) { if (irq || (local->irq_state != !!irq)) {
nvr->regs[RTC_REGC] |= REGC_IRQF; if (irq) {
picintlevel(1 << nvr->irq, &local->irq_state); nvr->regs[RTC_REGC] |= REGC_IRQF;
} else { picintlevel(1 << nvr->irq, &local->irq_state);
nvr->regs[RTC_REGC] &= ~REGC_IRQF; } else {
picintclevel(1 << nvr->irq, &local->irq_state); nvr->regs[RTC_REGC] &= ~REGC_IRQF;
picintclevel(1 << nvr->irq, &local->irq_state);
}
} }
} }