diff options
| author | Javier <dev.git@javispedro.com> | 2026-09-23 22:51:08 +0200 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2026-09-23 22:51:08 +0200 |
| commit | b73c038b18e2e838366f389d81038344b917eb56 (patch) | |
| tree | 48dbe428305400ce9736bff158102a397a5549ca | |
| parent | d481d4d4ac9b8bb8c8e3fa5a159268f5a0767353 (diff) | |
| download | vbados-b73c038b18e2e838366f389d81038344b917eb56.tar.gz vbados-b73c038b18e2e838366f389d81038344b917eb56.zip | |
rework how acceleration works and avoid acceleration influencing raw mickey counts (as given to e.g. windows)HEADmaster
| -rw-r--r-- | mousetsr.c | 43 | ||||
| -rw-r--r-- | mousetsr.h | 15 |
2 files changed, 32 insertions, 26 deletions
@@ -629,33 +629,41 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch } } else if (x || y) { // Relative movement: x,y are in mickeys - uint16_t ticks = bda_get_tick_count_lo(); + uint16_t cur_ticks = bda_get_tick_count_lo(); unsigned ax = abs(x), ay = abs(y); events |= INT33_EVENT_MASK_MOVEMENT; - // Check if around one second has passed - if ((ticks - data.last_motion_ticks) >= 18) { + // Check if a tick has passed, if so update speed + if (data.last_motion_ticks != cur_ticks) { + uint16_t elapsed_ticks = cur_ticks - data.last_motion_ticks; + data.cur_speed = (data.total_motion / elapsed_ticks) * 18; // Extrapolate speed from movement in this tick +#if TRACE_EVENTS + dprintf("mouse speed = %u / threshold = %u total_motion in last %u ticks = %u\n", data.cur_speed, data.doubleSpeedThreshold * data.doubleSpeedThreshold, elapsed_ticks, data.total_motion); +#endif data.total_motion = 0; - data.last_motion_ticks = ticks; + data.last_motion_ticks = cur_ticks; } - - // If more than the double speed threshold has been moved in the last second, - // double the speed data.total_motion += ax * ax + ay * ay; - if (data.total_motion > data.doubleSpeedThreshold * data.doubleSpeedThreshold) { - x *= 2; - y *= 2; - } + // Update the raw mickey counters data.delta.x += x; data.delta.y += y; - data.delta_frac.x = 0; - data.delta_frac.y = 0; + + // Invalidate last abs position data.abs_pos.x = -1; data.abs_pos.y = -1; - // Convert mickeys into pixels + // Convert mickeys into pixels, applying speed, sensitivity and acceleration + + // If more than the double speed threshold has been moved in the last second, + // double the speed + if (data.cur_speed > data.doubleSpeedThreshold * data.doubleSpeedThreshold) { + x *= 2; + y *= 2; + } + + // Apply mickeysPerLine. Keep the fractional part for the next movement! data.pos.x += scalei_rem(x, data.mickeysPerLine.x, 8, &data.pos_frac.x); data.pos.y += scalei_rem(y, data.mickeysPerLine.y, 8, &data.pos_frac.y); } @@ -1190,11 +1198,12 @@ static void reset_mouse_state() data.pos_frac.y = 0; data.delta.x = 0; data.delta.y = 0; - data.delta_frac.x = 0; - data.delta_frac.y = 0; data.abs_pos.x = -1; data.abs_pos.y = -1; data.buttons = 0; + data.cur_speed = 0; + data.total_motion = 0; + data.last_motion_ticks = bda_get_tick_count_lo(); for (i = 0; i < MAX_BUTTONS; i++) { data.button[i].pressed.count = 0; data.button[i].pressed.last.x = 0; @@ -1311,8 +1320,6 @@ static void int33_handler(union INTPACK r) data.pos_frac.y = 0; data.delta.x = 0; data.delta.y = 0; - data.delta_frac.x = 0; - data.delta_frac.y = 0; bound_position_to_window(); break; case INT33_GET_BUTTON_PRESSED_COUNTER: @@ -159,10 +159,10 @@ typedef struct tsrdata { uint8_t port_irq; // Current mouse settings - /** Mouse sensitivity/speed. */ - struct point mickeysPerLine; // mickeys per 8 pixels - /** Mouse acceleration "double-speed threshold". */ - uint16_t doubleSpeedThreshold; // mickeys + /** Mouse speed, in mickeys per "line" (aka 8 pixels). */ + struct point mickeysPerLine; + /** Mouse acceleration "double-speed threshold", in mickeys per second. */ + uint16_t doubleSpeedThreshold; /** Current window min coordinates. */ struct point min; /** Current window max coordinates. */ @@ -191,12 +191,11 @@ typedef struct tsrdata { struct point pos_frac; /** Current delta movement (in mickeys) since the last report. */ struct point delta; - /** Current remainder of delta movement that does not yet translate to an entire mickey - * Usually only when mickeysPerLine is not a multiple of 8. */ - struct point delta_frac; /** Last absolute position (to compute a delta for relative motion emulation). Using -1 for "none". */ struct point abs_pos; - /** Total mickeys moved in the last second. */ + /** Current calculated mouse speed (in mickeys/second) */ + uint16_t cur_speed; + /** Total mickeys moved in the last tick. */ uint16_t total_motion; /** Ticks when the above value was last reset. */ uint16_t last_motion_ticks; |
