From 0ebcd2c1c9148e8647a5b2f89654949435403058 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Mar 2022 00:43:23 +0100 Subject: let VMD know the mouse type --- int2fwin.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 +- mousew16.c | 11 ++++++++++- ps2.h | 5 +++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/int2fwin.h b/int2fwin.h index 8d79211..7845293 100644 --- a/int2fwin.h +++ b/int2fwin.h @@ -32,6 +32,11 @@ enum int2f_functions INT2F_NOTIFY_FOREGROUND_SWITCH = 0x4002 }; +enum vxd_device_ids +{ + VMD_DEVICE_ID = 0xC +}; + static bool windows_386_enhanced_mode(void); #pragma aux windows_386_enhanced_mode = \ "mov ax, 0x1600" \ @@ -41,6 +46,49 @@ static bool windows_386_enhanced_mode(void); __value [al] \ __modify [ax] +static LPFN win_get_vxd_api_entry(uint16_t devid); +#pragma aux win_get_vxd_api_entry = \ + "mov ax, 0x1684" /* Get Device Entry Point Address */ \ + "int 0x2F" \ + __parm [bx] \ + __value [es di] \ + __modify [ax] + +/* VMD (Virtual Mouse Device) API */ + +enum vmd_apis { + VMD_GET_VERSION = 0x0, + VMD_SET_MOUSE_TYPE = 0x100, +}; + +enum vmd_mouse_type { + VMD_TYPE_UNDEFINED = 0, + VMD_TYPE_BUS = 1, + VMD_TYPE_SERIAL = 2, + VMD_TYPE_INPORT = 3, + VMD_TYPE_PS2 = 4, + VMD_TYPE_HP = 5 +}; + +static inline int vmd_get_version(LPFN *vmd_entry); +#pragma aux vmd_get_version = \ + "mov ax, 0x000" \ + "call dword ptr es:[di]" \ + __parm [es di] \ + __value [ax] + +static inline bool vmd_set_mouse_type(LPFN *vmd_entry, uint8_t mousetype, int8_t interrupt, int8_t com_port); +#pragma aux vmd_set_mouse_type = \ + "stc" /* If nothing happens, assume failure */ \ + "mov ax, 0x100" \ + "call dword ptr es:[di]" \ + "setnc al" \ + __parm [es di] [bl] [bh] [cl] \ + __value [al] \ + __modify [ax] + +/* Miscelaneous helpers. */ + static inline void hook_int2f(LPFN *prev, LPFN new) { *prev = _dos_getvect(0x2F); diff --git a/makefile b/makefile index 9cd59d6..c677d4d 100644 --- a/makefile +++ b/makefile @@ -6,7 +6,7 @@ set include=$(%watcom)/h/win;$(%watcom)/h # The main driver file -vbmouse.drv: mousew16.c mousew16.h vbox.c vbox.h vboxdev.h ps2.h pci.h vds.h +vbmouse.drv: mousew16.c mousew16.h vbox.c vbox.h vboxdev.h ps2.h pci.h vds.h int2fwin.h # -bd to build DLL # -mc to use compact memory model (far data pointers, since ss != ds) # -zu for DLL calling convention (ss != ds) diff --git a/mousew16.c b/mousew16.c index f2e22ab..45c0266 100644 --- a/mousew16.c +++ b/mousew16.c @@ -212,6 +212,15 @@ BOOL FAR PASCAL LibMain(HINSTANCE hInstance, WORD wDataSegment, } #endif + // When running under protected mode Windows, let's tell VMD (the mouse virtualizer) + // what type of mouse we are going to be using + if (mouseflags & MOUSEFLAGS_HAS_WIN386) { + LPFN vmd_entry = win_get_vxd_api_entry(VMD_DEVICE_ID); + if (vmd_entry) { + vmd_set_mouse_type(&vmd_entry, VMD_TYPE_PS2, PS2_MOUSE_INT_VECTOR, 0); + } + } + return 1; } @@ -317,6 +326,6 @@ VOID FAR PASCAL Disable(VOID) /** Called by Window to retrieve the interrupt vector number used by this driver, or -1. */ int FAR PASCAL MouseGetIntVect(VOID) { - return 0x74; /* This corresponds to IRQ12, the PS/2 IRQ. At least in VirtualBox. */ + return PS2_MOUSE_INT_VECTOR; } diff --git a/ps2.h b/ps2.h index 0ff154b..6fcb1ec 100644 --- a/ps2.h +++ b/ps2.h @@ -23,6 +23,11 @@ #include #include +/** Standard PS/2 mouse IRQ. At least on VirtualBox. */ +#define PS2_MOUSE_IRQ 12 +/** The corresponding interrupt vector for IRQ 12. */ +#define PS2_MOUSE_INT_VECTOR 0x74 + enum { PS2M_STATUS_BUTTON_1 = 1 << 0, PS2M_STATUS_BUTTON_2 = 1 << 1, -- cgit v1.2.3