aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--int33.h36
-rw-r--r--lfn.h82
-rw-r--r--makefile2
-rw-r--r--mousetsr.c77
-rw-r--r--mousetsr.h13
-rw-r--r--mousew16.c152
-rw-r--r--mousew16.h34
-rw-r--r--mousew16.lnk1
-rw-r--r--mousmain.c8
-rw-r--r--moustest.c58
-rw-r--r--sermouse.h2
-rw-r--r--sftsr.c5
-rw-r--r--utils.h37
-rw-r--r--vboxshfl.h24
-rw-r--r--version.h2
15 files changed, 384 insertions, 149 deletions
diff --git a/int33.h b/int33.h
index df870be..f9191ce 100644
--- a/int33.h
+++ b/int33.h
@@ -114,12 +114,38 @@ enum INT33_API {
INT33_SAVE_MOUSE_STATUS = 0x16,
INT33_LOAD_MOUSE_STATUS = 0x17,
- /** Sets both speed and speed-doubling threshold in one call.
- * @param bx horizontal speed, cx vertical speed
- * @param dx doubling threshold (mickeys per second). */
+ /** Sets both sensitivity and speed-doubling threshold in one call.
+ * @param bx horizontal sensitivity, cx vertical sensitivity
+ * these are values from 5..100.
+ * @param dx speed doubling threshold (mickeys per second?).
+ * Unlike set_mouse_speed, this value is persistent, and survives a reset.
+ * MS doesn't define what "sensitivity" means here, however MSD does print
+ * a table of common sensitivity values and their equivalent "factor",
+ * which is applied to the mouse deltas:
+ * 100 - 3.5 (i.e. mouse is 3.5x faster)
+ * 95 - 3.25
+ * 90 - 3
+ * 85 - 2.75
+ * 80 - 2.5
+ * 75 - 2.25
+ * 70 - 2
+ * 65 - 1.75
+ * 60 - 1.5
+ * 55 - 1.25
+ * 50 - 1 (default value, mouse is 1x)
+ * 45 - 0.875
+ * 40 - 0.75
+ * 35 - 0.625
+ * 30 - 0.5
+ * 25 - 0.375
+ * 20 - 0.25
+ * 15 - 0.125
+ * 10 - 0.062
+ * 5 - 0.031 (MSD prints 0.31 though? looks buggy as hell).
+ * @todo verify if the doubling threshold here is in the same units. */
INT33_SET_MOUSE_SENSITIVITY = 0x1A,
- /** Gets current speed and speed-doubling threshold.
- * @return bx horizontal speed, cx vertical speed
+ /** Gets current sensitivity and speed-doubling threshold.
+ * @return bx horizontal sensitivity, cx vertical sensitivity
* @return dx doubling threshold (mickeys per second). */
INT33_GET_MOUSE_SENSITIVITY = 0x1B,
diff --git a/lfn.h b/lfn.h
index 94c8c1a..3f25330 100644
--- a/lfn.h
+++ b/lfn.h
@@ -31,8 +31,9 @@ static inline bool translate_filename_from_host(SHFLSTRING *, bool, bool);
static bool matches_8_3_wildcard(const char __far *, const char __far *);
static int my_strrchr(const char __far *, char);
-/** Private buffer for resolving VirtualBox long filenames. */
-static SHFLSTRING_WITH_BUF(shflstrlfn, SHFL_MAX_LEN);
+/** Private buffer that we use for calling VirtualBox to list candidate files,
+ * when resolving long filenames. */
+static SHFLDIRINFO_WITH_NAME_BUF(lfndirinfo, SHFL_MAX_LEN);
static char fcb_name[12];
@@ -251,6 +252,8 @@ static inline bool match_to_8_3_filename(const char __far *dos_filename, const c
return false;
}
+/** Given path and (short) filename, returns the corresponding matching host filename.
+ * It will do this by listing all possibly matching filenames in the host and comparing hashes. */
static inline char *find_real_name(
TSRDATAPTR data,
int drive,
@@ -263,83 +266,76 @@ static inline char *find_real_name(
{
SHFLROOT root = data->drives[drive].root;
uint8_t hash_chars = data->drives[drive].opt.hash_chars;
+ SHFLSTRING *shflstr = &lfndirinfo.dirinfo.name; // reuse the lfndirinfo string buffer
vboxerr err;
dprintf("find_real_name path=%Fs filename=%Fs\n", path, filename);
memset(&parms.create, 0, sizeof(SHFLCREATEPARMS));
parms.create.CreateFlags = SHFL_CF_DIRECTORY | SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW | SHFL_CF_ACCESS_READ;
- shflstring_strcpy(&shflstrlfn.shflstr, path);
+ shflstring_strcpy(shflstr, path);
- err = vbox_shfl_open(&data->vb, data->hgcm_client_id, root, &shflstrlfn.shflstr, &parms.create);
+ err = vbox_shfl_open(&data->vb, data->hgcm_client_id, root, shflstr, &parms.create);
if (err)
{
dputs("open search dir failed");
goto not_found;
}
- // Check there is room for appending "\*" to the path
- if (shflstrlfn.shflstr.u16Size < shflstrlfn.shflstr.u16Length + 2)
- {
- dputs("path too long");
- vbox_shfl_close(&data->vb, data->hgcm_client_id, root, parms.create.Handle);
- goto not_found;
- }
-
- *(uint16_t *)&shflstrlfn.shflstr.ach[shflstrlfn.shflstr.u16Length] = '*\\';
- shflstrlfn.shflstr.u16Length += 2;
- shflstrlfn.shflstr.ach[shflstrlfn.shflstr.u16Length] = '\0';
+ // Build the search pattern. We use the full path (already in shflstr and '/' terminated)
+ // + "prefix*" where prefix is the part of the filename before the hash (i.e. xxxx~nnn.txt)
+ // This prevents at least enumerating the entire list of files each time,
+ // instead we only enumerate files starting with the prefix.
+ shflstring_strncat(shflstr, filename, 8 - 1 - hash_chars);
+ shflstring_append(shflstr, '*');
+ dprintf("find_real_name pattern=%s\n", shflstr->ach);
- for (;;)
- {
- unsigned size = sizeof(shfldirinfo), resume = 0, count = 0;
+ while (1) {
+ unsigned size = sizeof(lfndirinfo), resume = 0, count = 0;
char *d;
uint32_t hash;
- bool valid;
err = vbox_shfl_list(&data->vb, data->hgcm_client_id, root, parms.create.Handle,
- SHFL_LIST_RETURN_ONE, &size, &shflstrlfn.shflstr, &shfldirinfo.dirinfo,
+ SHFL_LIST_RETURN_ONE, &size, shflstr, &lfndirinfo.dirinfo,
&resume, &count);
- // Reset the size of the buffer
- shfldirinfo.dirinfo.name.u16Size = sizeof(shfldirinfo.buf);
+ // shflstr not needed anymore, and besides it is now used as lfndirinfo
+ shflstr = NULL;
+ // Reset the size of the buffer (see find_next_from_vbox)
+ lfndirinfo.dirinfo.name.u16Size = sizeof(lfndirinfo.buf);
- if (err)
- {
+ if (err) {
dputs("vbox_shfl_list() failed");
vbox_shfl_close(&data->vb, data->hgcm_client_id, root, parms.create.Handle);
break;
}
- // Calculate hash using host file name
- hash = lfn_name_hash(shfldirinfo.dirinfo.name.ach, shfldirinfo.dirinfo.name.u16Length, hash_chars);
-
- // Copy now, because translate_filename_from_host() converts fName to DOS codepage
- //
- if (shfldirinfo.dirinfo.name.u16Length > bufsiz)
- {
+ // Store the long file name now, because we are about to mangle it into a short one
+ if (lfndirinfo.dirinfo.name.u16Length > bufsiz) {
vbox_shfl_close(&data->vb, data->hgcm_client_id, root, parms.create.Handle);
- return (char *)0;
+ return NULL;
}
- d = _fstrcpy_local(dest, &shfldirinfo.dirinfo.name.ach);
+ d = _fstrcpy_local(dest, &lfndirinfo.dirinfo.name.ach);
- translate_filename_from_host(&shfldirinfo.dirinfo.name, false, true);
- mangle_to_8_3_filename(hash, hash_chars, fcb_name, &shfldirinfo.dirinfo.name);
+ // Calculate the hash of this host file name
+ hash = lfn_name_hash(lfndirinfo.dirinfo.name.ach, lfndirinfo.dirinfo.name.u16Length, hash_chars);
- if (match_to_8_3_filename(filename, fcb_name))
- {
+ // Now convert long file name into a short one
+ translate_filename_from_host(&lfndirinfo.dirinfo.name, false, true);
+ mangle_to_8_3_filename(hash, hash_chars, fcb_name, &lfndirinfo.dirinfo.name);
+
+ // And check if it matches with the one we were searching for
+ if (match_to_8_3_filename(filename, fcb_name)) {
vbox_shfl_close(&data->vb, data->hgcm_client_id, root, parms.create.Handle);
return d;
}
}
not_found:
- if (namelen > bufsiz)
- {
- return (char *)0;
- }
- else
- {
+ // Matching host long file name not found: pass the short filename back unchanged
+ if (namelen > bufsiz) {
+ return NULL;
+ } else {
return _fstrcpy_local(dest, filename);
}
}
diff --git a/makefile b/makefile
index efa98a3..ec8ee8a 100644
--- a/makefile
+++ b/makefile
@@ -123,7 +123,7 @@ flp: vbados.flp $(bins) $(infs) .SYMBOLIC
mcopy -i vbados.flp -o $(bins) $(infs) ::
# Build a zip with the driver binaries
-zip: vbmouse.exe vbmouse.drv oemsetup.inf vbsf.exe .SYMBOLIC
+zip: $(bins) $(infs) .SYMBOLIC
zip --DOS-names -fz- vbados.zip $(bins) $(infs)
srczip: .SYMBOLIC
diff --git a/mousetsr.c b/mousetsr.c
index 16c84df..e1fb1b9 100644
--- a/mousetsr.c
+++ b/mousetsr.c
@@ -60,6 +60,24 @@ static void bound_position_to_window(void)
if (data.pos.y > data.max.y) data.pos.y = data.max.y;
}
+/** Apply sensitivity to a raw mouse delta.
+ * @param sens value [5..100] given to set_mouse_sensitivity.
+ * @param x mouse delta in mickeys
+ * @return mouse delta scaled by sensitivity
+ *
+ * Note this is not acceleration, we are still multiplying the delta by a
+ * linear factor supposedly derived from the sensivitity [5..100] value.
+ * Every mouse driver seems to use their own formula for computing this factor.
+ * I am going with f(x) = x(x+32)/4096 since it looks round and fits decently,
+ * even with integer math (we don't divide by 4096 until after multiplying by delta).
+ * @see INT33_SET_MOUSE_SENSITIVITY for what the factor should look like. */
+int16_t apply_sensitivity(int16_t x, uint8_t sens, int16_t *rem)
+{
+ uint16_t factor = (sens * (sens + 32));
+ // TODO Actually use a shift instead of division
+ return scalei_rem(x, 4096, factor, rem);
+}
+
/** Constraints coordinate value to the desired granularity,
* which must be a power of two. */
static inline int16_t snap_to_grid(int16_t val, int16_t granularity)
@@ -72,7 +90,8 @@ static void hide_text_cursor(void)
{
// Restore the character under the old position of the cursor
uint16_t __far *ch = get_video_char(&data.video_mode,
- data.cursor_pos.x / 8, data.cursor_pos.y / 8);
+ data.cursor_pos.x / (data.screen_scale.x * 8),
+ data.cursor_pos.y / (data.screen_scale.y * 8));
*ch = data.cursor_prev_char;
data.cursor_visible = false;
}
@@ -80,7 +99,8 @@ static void hide_text_cursor(void)
static void show_text_cursor(void)
{
uint16_t __far *ch = get_video_char(&data.video_mode,
- data.pos.x / 8, data.pos.y / 8);
+ data.pos.x / (data.screen_scale.x * 8),
+ data.pos.y / (data.screen_scale.y * 8));
data.cursor_prev_char = *ch;
data.cursor_pos = data.pos;
*ch = (*ch & data.cursor_text_and_mask) ^ data.cursor_text_xor_mask;
@@ -624,8 +644,10 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch
// Set the new absolute position
data.pos.x = x;
data.pos.y = y;
- data.pos_frac.x = 0;
- data.pos_frac.y = 0;
+ data.pos_pixel_frac.x = 0;
+ data.pos_pixel_frac.y = 0;
+ data.pos_sens_frac.x = 0;
+ data.pos_sens_frac.y = 0;
}
} else if (x || y) {
// Relative movement: x,y are in mickeys
@@ -639,13 +661,17 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch
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);
+ dprintf("mouse speed = %u / threshold = %u total_motion in last %u ticks = %u\n", data.cur_speed, data.double_speed_threshold * data.double_speed_threshold, elapsed_ticks, data.total_motion);
#endif
data.total_motion = 0;
data.last_motion_ticks = cur_ticks;
}
data.total_motion += ax * ax + ay * ay;
+ // Apply sensitivity now, since unlike acceleration/speed, it affects the raw mickey counters
+ x = apply_sensitivity(x, data.sensitivity_x, &data.pos_sens_frac.x);
+ y = apply_sensitivity(y, data.sensitivity_y, &data.pos_sens_frac.y);
+
// Update the raw mickey counters
data.delta.x += x;
data.delta.y += y;
@@ -654,18 +680,18 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch
data.abs_pos.x = -1;
data.abs_pos.y = -1;
- // Convert mickeys into pixels, applying speed, sensitivity and acceleration
+ // Convert mickeys into pixels, applying speed 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) {
+ if (data.cur_speed > data.double_speed_threshold * data.double_speed_threshold) {
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);
+ data.pos.x += scalei_rem(x, data.mickeysPerLine.x, 8, &data.pos_pixel_frac.x);
+ data.pos.y += scalei_rem(y, data.mickeysPerLine.y, 8, &data.pos_pixel_frac.y);
}
bound_position_to_window();
@@ -1172,7 +1198,7 @@ static void reset_mouse_settings()
data.mickeysPerLine.x = 8;
data.mickeysPerLine.y = 16;
- data.doubleSpeedThreshold = 64;
+ data.double_speed_threshold = 64;
data.min.x = 0;
data.max.x = data.screen_max.x;
data.min.y = 0;
@@ -1185,6 +1211,10 @@ static void reset_mouse_settings()
data.cursor_hotspot.y = 0;
memcpy(data.cursor_graphic, default_cursor_graphic, sizeof(data.cursor_graphic));
+ // Sensitivity is persisted through resets, but ensure we init it with 50 if 0.
+ if (data.sensitivity_x == 0) data.sensitivity_x = 50;
+ if (data.sensitivity_y == 0) data.sensitivity_y = 50;
+
refresh_cursor(); // This will hide the cursor and update data.cursor_visible
}
@@ -1194,8 +1224,10 @@ static void reset_mouse_state()
int i;
data.pos.x = data.min.x + (data.max.x - data.min.x) / 2;
data.pos.y = data.min.y + (data.max.y - data.min.y) / 2;
- data.pos_frac.x = 0;
- data.pos_frac.y = 0;
+ data.pos_pixel_frac.x = 0;
+ data.pos_pixel_frac.y = 0;
+ data.pos_sens_frac.x = 0;
+ data.pos_sens_frac.y = 0;
data.delta.x = 0;
data.delta.y = 0;
data.abs_pos.x = -1;
@@ -1316,8 +1348,10 @@ static void int33_handler(union INTPACK r)
#endif
data.pos.x = r.w.cx;
data.pos.y = r.w.dx;
- data.pos_frac.x = 0;
- data.pos_frac.y = 0;
+ data.pos_pixel_frac.x = 0;
+ data.pos_pixel_frac.y = 0;
+ data.pos_sens_frac.x = 0;
+ data.pos_sens_frac.y = 0;
data.delta.x = 0;
data.delta.y = 0;
bound_position_to_window();
@@ -1414,7 +1448,7 @@ static void int33_handler(union INTPACK r)
break;
case INT33_SET_SPEED_DOUBLE_THRESHOLD:
dprintf("Mouse set speed double threshold=%d\n", r.w.dx);
- data.doubleSpeedThreshold = r.w.dx;
+ data.double_speed_threshold = r.w.dx;
break;
case INT33_EXCHANGE_EVENT_HANDLER:
dputs("Mouse exchange event handler");
@@ -1446,15 +1480,14 @@ static void int33_handler(union INTPACK r)
case INT33_SET_MOUSE_SENSITIVITY:
dprintf("Mouse set sensitivity x=%d y=%d threshold=%d\n",
r.w.bx, r.w.cx, r.w.dx);
- // TODO According to cutemouse, sensitivity != mickeysPerLine
- data.mickeysPerLine.x = r.w.bx;
- data.mickeysPerLine.y = r.w.cx;
- data.doubleSpeedThreshold = r.w.dx;
+ data.sensitivity_x = BOUND(r.w.bx, 1, 100);
+ data.sensitivity_y = BOUND(r.w.cx, 1, 100);
+ data.double_speed_threshold = r.w.dx;
break;
case INT33_GET_MOUSE_SENSITIVITY:
- r.w.bx = data.mickeysPerLine.x;
- r.w.cx = data.mickeysPerLine.y;
- r.w.dx = data.doubleSpeedThreshold;
+ r.w.bx = data.sensitivity_x;
+ r.w.cx = data.sensitivity_y;
+ r.w.dx = data.double_speed_threshold;
break;
case INT33_RESET_SETTINGS:
dputs("Mouse reset settings");
diff --git a/mousetsr.h b/mousetsr.h
index 9b8fdf8..8904437 100644
--- a/mousetsr.h
+++ b/mousetsr.h
@@ -59,7 +59,7 @@
#define MAX_PACKET_SIZE 4
/** Maximum number of 55ms ticks that may pass between two bytes of the same packet */
-#define MAX_PACKET_DELAY 2
+#define MAX_PACKET_DELAY 6
/** Maximum COMn port. */
#define MAX_PORTS 4
@@ -161,8 +161,12 @@ typedef struct tsrdata {
// Current mouse settings
/** Mouse speed, in mickeys per "line" (aka 8 pixels). */
struct point mickeysPerLine;
+ /** Mouse sensitivity, in 1..100. */
+ uint8_t sensitivity_x, sensitivity_y;
+ /** Mouse sensitivity factor, precalculated. */
+ struct point sensitivity_factor;
/** Mouse acceleration "double-speed threshold", in mickeys per second. */
- uint16_t doubleSpeedThreshold;
+ uint16_t double_speed_threshold;
/** Current window min coordinates. */
struct point min;
/** Current window max coordinates. */
@@ -188,7 +192,10 @@ typedef struct tsrdata {
struct point pos;
/** Current remainder of movement that does not yet translate to an entire pixel
* (8ths of pixel). */
- struct point pos_frac;
+ struct point pos_pixel_frac;
+ /** Current remainder of movement that does not yet translate to one sensitivity unit (4096)
+ * @see apply_sensitivity */
+ struct point pos_sens_frac;
/** Current delta movement (in mickeys) since the last report. */
struct point delta;
/** Last absolute position (to compute a delta for relative motion emulation). Using -1 for "none". */
diff --git a/mousew16.c b/mousew16.c
index 13cf310..ee940d1 100644
--- a/mousew16.c
+++ b/mousew16.c
@@ -39,8 +39,8 @@
/** Number of lines to scroll per (vertical) wheel event. */
#define WHEEL_SCROLL_LINES 2
-/** Windows 3.x only supports 1-2 mouse buttons anyway. */
-#define MOUSE_NUM_BUTTONS 2
+/** Max number of mouse buttons supported. */
+#define MOUSE_MAX_BUTTONS 3
/** Prefix for debug messages. */
#define DPREFIX "mousew16: "
@@ -60,6 +60,8 @@ static struct {
bool has_win386 : 1;
#endif
} flags;
+/** Current mouse number of buttons. */
+static unsigned short num_buttons;
/** Previous deltaX, deltaY from the int33 mouse callback (for relative motion) */
static short prev_delta_x, prev_delta_y;
/** Maximum X and Y coordinates expected from the int33 driver. */
@@ -67,18 +69,28 @@ static unsigned short max_x, max_y;
#if USE_WHEEL
/** Some delay-loaded functions from USER.EXE to provide wheel mouse events. */
static struct {
+ /** Handle to the USER module itself. */
HINSTANCE hUser;
- void WINAPI (*GetCursorPos)( POINT FAR * );
- HWND WINAPI (*WindowFromPoint)( POINT );
- HWND WINAPI (*GetParent)( HWND );
+ BOOL WINAPI (*EnumChildWindows)( HWND, WNDENUMPROC, LPARAM );
+ LRESULT WINAPI (*DefHookProc)( int, WPARAM, LPARAM, HOOKPROC FAR * );
+ HWND WINAPI (*GetActiveWindow)( void );
int WINAPI (*GetClassName)( HWND, LPSTR, int );
- int WINAPI (*GetWindowText)( HWND, LPSTR, int );
+ HWND WINAPI (*GetParent)( HWND );
LONG WINAPI (*GetWindowLong)( HWND, int );
+ int WINAPI (*GetWindowText)( HWND, LPSTR, int );
BOOL WINAPI (*IsWindowEnabled)( HWND );
- BOOL WINAPI (*EnumChildWindows)( HWND, WNDENUMPROC, LPARAM );
BOOL WINAPI (*PostMessage)( HWND, UINT, WPARAM, LPARAM );
+ UINT WINAPI (*RegisterWindowMessage)( LPCSTR );
+ HOOKPROC WINAPI (*SetWindowsHook)( int, HOOKPROC );
+ BOOL WINAPI (*UnhookWindowsHook)( int, HOOKPROC );
+ HWND WINAPI (*WindowFromPoint)( POINT );
} userapi;
-#endif
+/** This is the private message that we send on wheel movement and is
+ * going to be intercepted by the hook, which will translate into scroll msgs. */
+static UINT wheel_msg_private;
+/** The hook that comes after ours. */
+static HOOKPROC wheel_hook_proc_next;
+#endif /* USE_WHEEL */
#if USE_WIN386
/** Previous int2f handler. */
static LPFN prev_int2f_handler;
@@ -86,8 +98,8 @@ static LPFN prev_int2f_handler;
/* This is how events are delivered to Windows */
-static void send_event(unsigned short Status, short deltaX, short deltaY, short ButtonCount, short extra1, short extra2);
-#pragma aux (MOUSEEVENTPROC) send_event = \
+static void post_event(unsigned short Status, short deltaX, short deltaY, short ButtonCount, short extra1, short extra2);
+#pragma aux (MOUSEEVENTPROC) post_event = \
"call dword ptr [eventproc]"
/* Our "CALLBACKS" segment which is fixed and non-relocatable. */
@@ -198,23 +210,20 @@ static void post_scroll_msg(HWND hWnd, UINT msg, int z, HWND hScrollBar)
userapi.PostMessage(hWnd, msg, SB_ENDSCROLL, lParam);
}
-/** Send wheel scrolling events to the most likely candidate window. */
-static void send_wheel_movement(int8_t z, BOOL horizontal)
+/** Send wheel scrolling events to the most likely candidate window.
+ @param cursor the cursor position at the time the wheel event occured */
+static void post_simulated_scroll_msgs(POINT cursor, int z, BOOL horizontal)
{
- POINT point;
HWND hWnd;
#if TRACE_WHEEL
- dprintf(DPREFIX "wheel=%d %s\n", z, horizontal ? "horiz" : "vert");
+ dprintf(DPREFIX "%s @%d,%d z=%d %s\n",
+ __func__, cursor.x, cursor.y,
+ z, horizontal ? "horiz" : "vert");
#endif
- // TODO It's highly unlikely that we can call this many functions from
- // an interrupt handler without causing a re-entrancy issue somewhere.
- // Likely it would be better to just move all of this into a hook .DLL
-
- // Find current window below the mosue cursor
- userapi.GetCursorPos(&point);
- hWnd = userapi.WindowFromPoint(point);
+ // Find current window below the mouse cursor
+ hWnd = userapi.WindowFromPoint(cursor);
#if TRACE_WHEEL
dprintf(DPREFIX "initial hWnd=0x%x\n", hWnd);
@@ -282,9 +291,63 @@ static void send_wheel_movement(int8_t z, BOOL horizontal)
}
#if TRACE_WHEEL
- dprintf(DPREFIX "wheel end\n");
+ dprintf(DPREFIX "%s end\n", __func__);
#endif
}
+
+/** GetMsgProc hook, called for every message before being returned by GetMessage. */
+LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam)
+{
+ if (code >= 0) {
+ // TODO Unclear if on win9x PeekMessage will also call this hook
+ MSG FAR *msg = (MSG FAR *)lParam;
+ if (msg->message == wheel_msg_private) {
+ // This is our private `wheel_msg`
+ BOOL horizontal = msg->wParam;
+ int z = msg->lParam;
+
+ // TODO In theory we could try sending "native" MSH_MOUSEWHEEL msg here
+ // which some early nt/95 software supports (in addition to 98's WM_MOUSEWHEEL)
+ // but I think the fake scroll messages work well enough.
+ // To properly send MSH_MOUSEWHEEL, we'd need to thunk into 32-bit
+ // SendMessage because such win95 software will expect 32-bit WPARAM.
+
+ post_simulated_scroll_msgs(msg->pt, z, horizontal);
+
+ // Prevent us from intercepting this message if fwd'd
+ msg->message = WM_NULL;
+ }
+ }
+
+ return userapi.DefHookProc(code, wParam, lParam, &wheel_hook_proc_next);
+}
+
+/** Post a wheel_msg_private to the active window.
+ * The idea here is this function may be called during interrupt time,
+ * and very few winapi functions are safely callable at this point.
+ * So, we post a message, which will be captured by our WheelHookProc,
+ * at which point we will simulate all the necessary scrolling events. */
+static void post_wheel_msg(int z, BOOL horizontal)
+{
+ HWND hWnd;
+ POINT cursorpos;
+
+ hWnd = userapi.GetActiveWindow();
+ if (!hWnd) return;
+
+#if TRACE_WHEEL
+ dprintf(DPREFIX "post wheel_msg=0x%x to hWnd=0x%x : z=%d %s\n",
+ wheel_msg_private, hWnd, z, horizontal ? "horiz" : "vert");
+#endif
+
+ userapi.PostMessage(hWnd, wheel_msg_private, horizontal, z);
+}
+#else
+LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam) {
+ // Required since we export this symbol, but not use it
+ (void)code; (void) wParam; (void) lParam;
+ return 0;
+}
#endif /* USE_WHEEL */
/** Called by the int33 mouse driver. */
@@ -298,10 +361,12 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
events, buttons, x, y, delta_x, delta_y);
#endif
- if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) status |= SF_B1_DOWN;
- if (events & INT33_EVENT_MASK_LEFT_BUTTON_RELEASED) status |= SF_B1_UP;
- if (events & INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED) status |= SF_B2_DOWN;
- if (events & INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED) status |= SF_B2_UP;
+ if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) status |= SF_B1_DOWN;
+ if (events & INT33_EVENT_MASK_LEFT_BUTTON_RELEASED) status |= SF_B1_UP;
+ if (events & INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED) status |= SF_B2_DOWN;
+ if (events & INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED) status |= SF_B2_UP;
+ if (events & INT33_EVENT_MASK_CENTER_BUTTON_PRESSED) status |= SF_B3_DOWN;
+ if (events & INT33_EVENT_MASK_CENTER_BUTTON_RELEASED) status |= SF_B3_UP;
if (events & INT33_EVENT_MASK_MOVEMENT) {
status |= SF_MOVEMENT;
@@ -313,7 +378,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
int8_t z = (buttons & 0xFF00) >> 8;
BOOL horizontal = !!(events & INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT);
if (z) {
- send_wheel_movement(z, horizontal);
+ post_wheel_msg(z, horizontal);
}
}
#endif
@@ -346,7 +411,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
}
#if TRACE_EVENTS
- dprintf(DPREFIX "post status=0x%x ", status);
+ dprintf(DPREFIX "post nb=%u status=0x%x ", num_buttons, status);
if (status & SF_ABSOLUTE) {
dprintf("x=%u y=%u\n", x, y);
} else {
@@ -354,7 +419,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
}
#endif
- send_event(status, x, y, MOUSE_NUM_BUTTONS, 0, 0);
+ post_event(status, x, y, num_buttons, 0, 0);
}
#if USE_WIN386
@@ -484,7 +549,7 @@ WORD FAR PASCAL Inquire(LPMOUSEINFO lpMouseInfo)
{
lpMouseInfo->msExist = TRUE;
lpMouseInfo->msRelative = 0;
- lpMouseInfo->msNumButtons = MOUSE_NUM_BUTTONS;
+ lpMouseInfo->msNumButtons = MOUSE_MAX_BUTTONS;
lpMouseInfo->msRate = 80;
return sizeof(MOUSEINFO);
}
@@ -499,7 +564,8 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
_enable();
if (!flags.enabled) {
- int33_reset();
+ int33_reset_get_buttons(&num_buttons);
+ num_buttons = BOUND(num_buttons, 2, MOUSE_MAX_BUTTONS);
#if USE_WIN386
// If we are running under win386, hook int2f now.
@@ -515,16 +581,25 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
// Detect whether the int33 driver has wheel support
flags.wheel = int33_get_capabilities() & 1;
if (flags.wheel) {
+ // Initialize functions we need
userapi.hUser = (HINSTANCE) GetModuleHandle("USER");
- userapi.GetCursorPos = (LPVOID) GetProcAddress(userapi.hUser, "GetCursorPos");
- userapi.WindowFromPoint = (LPVOID) GetProcAddress(userapi.hUser, "WindowFromPoint");
- userapi.GetParent = (LPVOID) GetProcAddress(userapi.hUser, "GetParent");
+ userapi.EnumChildWindows = (LPVOID) GetProcAddress(userapi.hUser, "EnumChildWindows");
+ userapi.DefHookProc = (LPVOID) GetProcAddress(userapi.hUser, "DefHookProc");
+ userapi.GetActiveWindow = (LPVOID) GetProcAddress(userapi.hUser, "GetActiveWindow");
userapi.GetClassName = (LPVOID) GetProcAddress(userapi.hUser, "GetClassName");
- userapi.GetWindowText = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowText");
+ userapi.GetParent = (LPVOID) GetProcAddress(userapi.hUser, "GetParent");
userapi.GetWindowLong = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowLong");
+ userapi.GetWindowText = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowText");
userapi.IsWindowEnabled = (LPVOID) GetProcAddress(userapi.hUser, "IsWindowEnabled");
- userapi.EnumChildWindows = (LPVOID) GetProcAddress(userapi.hUser, "EnumChildWindows");
userapi.PostMessage = (LPVOID) GetProcAddress(userapi.hUser, "PostMessage");
+ userapi.RegisterWindowMessage = (LPVOID) GetProcAddress(userapi.hUser, "RegisterWindowMessage");
+ userapi.SetWindowsHook = (LPVOID) GetProcAddress(userapi.hUser, "SetWindowsHook");
+ userapi.UnhookWindowsHook = (LPVOID) GetProcAddress(userapi.hUser, "UnhookWindowsHook");
+ userapi.WindowFromPoint = (LPVOID) GetProcAddress(userapi.hUser, "WindowFromPoint");
+
+ wheel_msg_private = userapi.RegisterWindowMessage("VBMOUSE_WHEEL");
+
+ wheel_hook_proc_next = userapi.SetWindowsHook(WH_GETMESSAGE, (HOOKPROC)WheelHookProc);
}
#endif
@@ -557,6 +632,11 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
VOID FAR PASCAL Disable(VOID)
{
if (flags.enabled) {
+#if USE_WHEEL
+ if (flags.wheel) {
+ userapi.UnhookWindowsHook(WH_GETMESSAGE, (HOOKPROC)WheelHookProc);
+ }
+#endif
#if USE_WIN386
if (flags.has_win386) {
// When Windows is shutting down, it's not that important to correctly
diff --git a/mousew16.h b/mousew16.h
index 54b262f..42ecf04 100644
--- a/mousew16.h
+++ b/mousew16.h
@@ -27,18 +27,28 @@ typedef _Packed struct MOUSEINFO
} MOUSEINFO;
typedef MOUSEINFO __far *LPMOUSEINFO;
-/** Movement occurred. */
-#define SF_MOVEMENT 0x0001
-/** Button 1 changed to down. */
-#define SF_B1_DOWN 0x0002
-/** Button 1 changed to up. */
-#define SF_B1_UP 0x0004
-/** Button 2 changed to down. */
-#define SF_B2_DOWN 0x0008
-/** Button 2 changed to up. */
-#define SF_B2_UP 0x0010
-/** Event coordinates are absolute instead of relative. */
-#define SF_ABSOLUTE 0x8000
+/** Status flag when posting mouse events to Windows (mouse_event func). */
+enum MOUSESTATUSFLAGS {
+ /** Movement occurred. */
+ SF_MOVEMENT = 0x0001,
+ /** Button 1 changed to down. */
+ SF_B1_DOWN = 0x0002,
+ /** Button 1 changed to up. */
+ SF_B1_UP = 0x0004,
+ /** Button 2 changed to down. */
+ SF_B2_DOWN = 0x0008,
+ /** Button 2 changed to up. */
+ SF_B2_UP = 0x0010,
+ /** Event coordinates are absolute instead of relative. */
+ SF_ABSOLUTE = 0x8000,
+
+ // The following may only work with win95 up.
+ /** Button 3 changed to down. */
+ SF_B3_DOWN = 0x0020,
+ /** Button 3 changed to up. */
+ SF_B3_UP = 0x0040,
+};
+
/** Driver should call this callback when there are new mouse events to report.
* @param Status What happened. Combination of SF_MOVEMENT, SF_ABSOLUTE, etc.
diff --git a/mousew16.lnk b/mousew16.lnk
index ad6ac85..4e379ef 100644
--- a/mousew16.lnk
+++ b/mousew16.lnk
@@ -13,3 +13,4 @@ export Inquire.1
export Enable.2
export Disable.3
export MouseGetIntVect.4
+export WheelHookProc
diff --git a/mousmain.c b/mousmain.c
index 24801b7..f9e31b6 100644
--- a/mousmain.c
+++ b/mousmain.c
@@ -354,8 +354,8 @@ static int configure_driver_serial(LPTSRDATA data, int port, unsigned iobase)
serial_set_modem_control(iobase, SERIAL_MCR_DTR | SERIAL_MCR_RTS);
dputs("DTR ON, RTS ON");
- // Wait up to 10 ticks (550ms) for the mouse to send something we understand
- for (delay = 10; delay > 0; delay--) {
+ // Wait up to 11 ticks (~600ms) for the mouse to send something we understand
+ for (delay = 11; delay > 0; delay--) {
while (serial_data_ready(iobase)) {
uint8_t car = serial_read_data(iobase);
@@ -429,7 +429,7 @@ static int configure_driver_serial(LPTSRDATA data, int port, unsigned iobase)
}
#endif
-/// Auto-configure the TSR. Try to detect which mouse we have connected and enable all possible integrations.
+/// Configure the TSR. Try to detect which mouse we have connected and enable all possible integrations.
static int configure_driver(LPTSRDATA data, unsigned num_ports, int ports[])
{
int errs[MAX_PORTS+1] = {0};
@@ -647,7 +647,7 @@ static void uninstall_driver(LPTSRDATA data)
printf(_(1, 18, "Driver uninstalled\n"));
}
-static int driver_reset(void)
+static bool driver_reset(void)
{
printf(_(1, 19, "Reset mouse driver\n"));
return int33_reset() == INT33_MOUSE_FOUND;
diff --git a/moustest.c b/moustest.c
index 3270c9c..c53dcfd 100644
--- a/moustest.c
+++ b/moustest.c
@@ -142,7 +142,7 @@ void gui_draw_title()
const int cols = vidconf.numtextcols;
gui_draw_textwindow(1, 1, 1, cols, GUI_COLOR_BAR);
- gui_print(GUI_COLOR_BAR, "MOUSTEST ESC to exit, 'm'ode, 'r'eset, 's'how, 'h'ide, s'p'eed");
+ gui_print(GUI_COLOR_BAR, "MOUSTEST ESC to exit, 'm'ode, 'r'eset, 's'how, 'h'ide, s'p'eed, sensi't'");
}
void gui_draw_status()
@@ -280,6 +280,19 @@ void console_leave()
_wrapon(_GWRAPOFF);
}
+void console_backspace()
+{
+ _disable();
+ console_enter();
+ if (ctextpos.col > 0) {
+ _settextposition(ctextpos.row, ctextpos.col - 1);
+ _outtext(" ");
+ _settextposition(ctextpos.row, ctextpos.col - 1);
+ }
+ console_leave();
+ _enable();
+}
+
void console_print(char __far *str)
{
_disable();
@@ -313,6 +326,12 @@ int console_getline(char *buffer, int maxlen)
case 0: // Extended: consume and ignore
c = getch();
break;
+ case 8: // Backspace
+ if (bufpos > 0) {
+ bufpos--;
+ console_backspace();
+ }
+ break;
case 27: // ESC
console_print("\n");
return -1;
@@ -585,6 +604,35 @@ void mouse_report()
void mouse_speed()
{
+ uint16_t speed_x = 8, speed_y = 16;
+ bool update = false;
+ char buffer[16] = {'\0'};
+ int ret;
+
+ console_printf("X speed [default=8] ? ");
+ ret = console_getline(buffer, sizeof(buffer)-1);
+ if (ret > 0) {
+ speed_x = atoi(buffer);
+ update = true;
+ }
+
+ console_printf("Y speed [default=16] ? ");
+ ret = console_getline(buffer, sizeof(buffer)-1);
+ if (ret > 0) {
+ speed_y = atoi(buffer);
+ update = true;
+ }
+
+ if (update) {
+ int33_set_mouse_speed(speed_x, speed_y);
+ console_printf("Values updated: %u %u\n", speed_x, speed_y);
+ } else {
+ console_printf("No values changed\n");
+ }
+}
+
+void mouse_sensitivity()
+{
uint16_t speed_x, speed_y, double_speed_threshold;
bool update = false;
char buffer[16] = {'\0'};
@@ -592,14 +640,14 @@ void mouse_speed()
int33_get_sensitivity(&speed_x, &speed_y, &double_speed_threshold);
- console_printf("X speed [default=8, current=%u] ? ", speed_x);
+ console_printf("X sensitivity [default=50, current=%u] ? ", speed_x);
ret = console_getline(buffer, sizeof(buffer)-1);
if (ret > 0) {
speed_x = atoi(buffer);
update = true;
}
- console_printf("Y speed [default=16, current=%u] ? ", speed_y);
+ console_printf("Y sensitivity [default=50, current=%u] ? ", speed_y);
ret = console_getline(buffer, sizeof(buffer)-1);
if (ret > 0) {
speed_y = atoi(buffer);
@@ -797,6 +845,10 @@ int main(int argc, const char *argv[])
break;
case 'p':
mouse_speed();
+ break;
+ case 't':
+ mouse_sensitivity();
+ break;
case 'd':
mouse_debug();
break;
diff --git a/sermouse.h b/sermouse.h
index fb2184d..eccce5b 100644
--- a/sermouse.h
+++ b/sermouse.h
@@ -42,7 +42,7 @@ enum SERMOUSE_PROTOCOL_MS {
SERMOUSE_MS_Y_HI_SHIFT = 4,
// 4th byte:
- SERMOUSE_MS_BUTTON_CENTER = 1 << 5,
+ SERMOUSE_MS_BUTTON_CENTER = 1 << 4,
SERMOUSE_MS_Z_LO_MASK = 0xF,
SERMOUSE_MS_Z_LO_SHIFT = 0
};
diff --git a/sftsr.c b/sftsr.c
index 0e9915f..6db709e 100644
--- a/sftsr.c
+++ b/sftsr.c
@@ -1040,9 +1040,8 @@ static vboxerr find_next_from_vbox(unsigned openfile, char __far *path)
}
} else {
drive = sdb->drive & DOS_SDB_DRIVE_MASK;
- // For find next calls, it's not really important what we pass here,
- // as long as it's not empty.
- shflstring_strcpy(&shflstr.shflstr, " ");
+ // For find next calls, it's not really important what we pass here.
+ shflstring_clear(&shflstr.shflstr);
}
diff --git a/utils.h b/utils.h
index 9b9db2a..7d9a15b 100644
--- a/utils.h
+++ b/utils.h
@@ -54,43 +54,52 @@ static inline uint32_t linear_addr(const void __far * ptr)
/** Map x linearly from range [0, srcmax] to [0, dstmax].
* Equivalent of (x * dstmax) / srcmax but with 32-bit unsigned precision. */
-static unsigned scaleu(unsigned x, unsigned srcmax, unsigned dstmax);
+static uint16_t scaleu(uint16_t x, uint16_t srcmax, uint16_t dstmax);
#pragma aux scaleu = \
"mul cx" /* dx:ax = x * dstmax */\
"div bx" /* ax = dx:ax / srcmax */\
__parm [ax] [bx] [cx] \
__value [ax] \
- __modify [ax dx]
+ __modify exact [ax dx]
+
+/** Map x linearly from range [0, 2^srcmax_bits] to [0, dstmax].
+ * Equivalent to above, but uses shift instead of division. */
+static uint16_t scaleu_shift(uint16_t x, uint8_t srcmax_bits, uint16_t dstmax);
+#pragma aux scaleu_shift = \
+ "mul dx" /* dx:ax = x * dstmax */ \
+ "shrd ax, dx, cl" /* ax = dx:ax / 2^srcmax_bits */ \
+ __parm [ax] [cl] [dx] \
+ __value [ax] \
+ __modify exact [ax dx]
-/** Map x linearly from range [0, srcmax] to [0, dstmax].
+/** Map x linearly from range [-srcmax, srcmax] to [-dstmax, dstmax].
* Equivalent of (x * dstmax) / srcmax but with 32-bit signed precision. */
-static int scalei(int x, int srcmax, int dstmax);
+static int16_t scalei(int16_t x, int16_t srcmax, int16_t dstmax);
#pragma aux scalei = \
"imul cx" /* dx:ax = x * dstmax */ \
"idiv bx" /* ax = dx:ax / srcmax */ \
__parm [ax] [bx] [cx] \
__value [ax] \
- __modify [ax dx]
+ __modify exact [ax dx]
-/** Map x linearly from range [0, srcmax] to [0, dstmax].
- * Equivalent of (x * dstmax) / srcmax but with 32-bit signed precision.
- * Division remainder is returned in rem, which should be reused
- * in future calls to reduce rounding error. */
-static int scalei_rem(int x, int srcmax, int dstmax, short *rem);
+/** Map x linearly from range [-srcmax, srcmax] to [-dstmax, dstmax].
+ * Equivalent to scalei, but the division remainder is returned in rem,
+ * which can be reused in future calls to reduce rounding error. */
+static int16_t scalei_rem(int16_t x, int16_t srcmax, int16_t dstmax, int16_t *rem);
#pragma aux scalei_rem = \
"imul cx" /* dx:ax = x * dstmax */ \
"mov cx, [si]" /* cx = rem */ \
"test cx, cx" \
- "setns cl" /* cl = 1 if rem positive, 0 if negative */ \
+ "setns cl" /* cl = 1 if rem sign positive, 0 if negative */ \
"movzx cx, cl" \
- "dec cx" /* cx = 0 if rem positive, -1 if negative */ \
+ "dec cx" /* cx = 0 if rem positive, -1 if negative => rem sign extended */ \
"add ax, [si]" /* ax += *rem */ \
- "adc dx, cx" /* dx += 1 if carry and rem positive, 0 if carry and rem negative (aka. signed addition) */ \
+ "adc dx, cx" /* dx += "upper part of rem" +cf */ \
"idiv bx" /* ax = dx:ax / srcmax, dx = new remainder */ \
"mov [si], dx" /* store the new remainder */ \
__parm [ax] [bx] [cx] [si] \
__value [ax] \
- __modify [ax cx dx si]
+ __modify [ax cx dx]
/** Sign extend x from b bits to 16. */
static inline int16_t sign_extend(int16_t x, int b)
diff --git a/vboxshfl.h b/vboxshfl.h
index 412709a..276add4 100644
--- a/vboxshfl.h
+++ b/vboxshfl.h
@@ -43,18 +43,21 @@ static inline unsigned shflstring_size_with_buf(const SHFLSTRING *str)
static inline unsigned shflstring_size_optional_in(const SHFLSTRING *str)
{
- if (str->u16Length > 0) {
+ if (str && str->u16Length > 0) {
return sizeof(SHFLSTRING) + str->u16Size;
} else {
return 0;
}
}
+/** Set str to the empty string. */
static inline void shflstring_clear(SHFLSTRING *str)
{
str->u16Length = 0;
+ str->ach[str->u16Length] = '\0';
}
+/** Initialize str by copying src. */
static void shflstring_strcpy(SHFLSTRING *str, const char __far *src)
{
str->u16Length = MIN(_fstrlen(src), str->u16Size - 1);
@@ -62,6 +65,7 @@ static void shflstring_strcpy(SHFLSTRING *str, const char __far *src)
str->ach[str->u16Length] = '\0';
}
+/** Initialize str by copying len first characters of src. */
static void shflstring_strncpy(SHFLSTRING *str, const char __far *src, unsigned len)
{
str->u16Length = MIN(len, str->u16Size - 1);
@@ -69,6 +73,24 @@ static void shflstring_strncpy(SHFLSTRING *str, const char __far *src, unsigned
str->ach[str->u16Length] = '\0';
}
+/** Append single character to str (if space) */
+static void shflstring_append(SHFLSTRING *str, char c)
+{
+ if (str->u16Length < str->u16Size - 1) {
+ str->ach[str->u16Length++] = c;
+ str->ach[str->u16Length] = '\0';
+ }
+}
+
+/** Append len characters of src to str. */
+static void shflstring_strncat(SHFLSTRING *str, const char __far *src, unsigned len)
+{
+ len = MIN(len, (str->u16Size - 1) - str->u16Length);
+ _fmemcpy(&str->ach[str->u16Length], src, len);
+ str->u16Length += len;
+ str->ach[str->u16Length] = '\0';
+}
+
static inline void vbox_hgcm_set_parameter_shflroot(VMMDevHGCMCall __far *req, unsigned arg, SHFLROOT root)
{
vbox_hgcm_set_parameter_uint32(req, arg, root);
diff --git a/version.h b/version.h
index 1df35fd..b756585 100644
--- a/version.h
+++ b/version.h
@@ -2,6 +2,6 @@
#define VERSION_H
#define VERSION_MAJOR 0
-#define VERSION_MINOR 0x71
+#define VERSION_MINOR 0x70
#endif // VERSION_H