diff options
Diffstat (limited to 'w16mouse.c')
-rw-r--r-- | w16mouse.c | 137 |
1 files changed, 13 insertions, 124 deletions
@@ -24,27 +24,16 @@ #include "int2fwin.h" #include "w16mouse.h" -#define TRACE_EVENT 1 - -/** If 1, hook int2f to detect fullscreen DOSBoxes and auto-disable this driver. */ -#define HOOK_INT2F 0 +#define TRACE_EVENTS 0 #define MOUSE_NUM_BUTTONS 2 /** The routine Windows gave us which we should use to report events. */ static LPFN_MOUSEEVENT eventproc; -/** Current status of the mouse driver (see MOUSEFLAGS_*). */ -static struct mouseflags { - bool enabled : 1; - bool haswin386 : 1; - bool int2f_hooked : 1; -} flags; +/** Current status of the mouse driver. */ +static bool enabled; /** Previous deltaX, deltaY from the int33 mouse callback (for relative motion) */ static short prev_delta_x, prev_delta_y; -#if HOOK_INT2F -/** Existing interrupt2f handler. */ -static LPFN prev_int2f_handler; -#endif /* This is how events are delivered to Windows */ @@ -52,6 +41,8 @@ static void send_event(unsigned short Status, short deltaX, short deltaY, short #pragma aux (MOUSEEVENTPROC) send_event = \ "call dword ptr [eventproc]" +/* Our "CALLBACKS" segment which is fixed and non-relocatable. */ + #pragma code_seg ( "CALLBACKS" ) #include "dlog.h" @@ -61,7 +52,7 @@ static void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t { int status = 0; -#if TRACE_EVENT_IN +#if TRACE_EVENTS_IN dlog_print("w16mouse: events="); dlog_printx(events); dlog_print(" buttons="); @@ -104,7 +95,7 @@ static void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t // Unused (void) buttons; -#if TRACE_EVENT +#if TRACE_EVENTS dlog_print("w16mouse: event status="); dlog_printx(status); dlog_print(" x="); @@ -117,72 +108,6 @@ static void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t send_event(status, x, (uint16_t)(y), MOUSE_NUM_BUTTONS, 0, 0); } -#if HOOK_INT2F - -static void display_switch_handler(int function) -#pragma aux display_switch_handler parm caller [ax] modify [ax bx cx dx si di] -{ - if (!flags.enabled) { - return; - } - - switch (function) { - case INT2F_NOTIFY_BACKGROUND_SWITCH: - dlog_puts("Going background\n"); - break; - case INT2F_NOTIFY_FOREGROUND_SWITCH: - dlog_puts("Going foreground\n"); - break; - } -} - -/** Interrupt 2F handler, which will be called on some Windows 386 mode events. - * This is more complicated than it should be becaused we have to fetch our DS - * without clobbering any registers whatsoever, and chain back to the previous handler. - * @todo OpenWatcom 2.x insists on calling GETDS from a different code segment, so we can't use __interrupt. */ -static void __declspec(naked) __far int2f_handler(void) -{ - _asm { - ; Preserve data segment - push ds - - ; Load our data segment - push ax - mov ax, SEG prev_int2f_handler ; Let's hope that Windows relocates segments with interrupts disabled - mov ds, ax - pop ax - - ; Check functions we are interested in hooking - cmp ax, 0x4001 ; Notify Background Switch - je handle_it - cmp ax, 0x4002 ; Notify Foreground Switch - je handle_it - - ; Otherwise directly jump to next handler - jmp next_handler - - handle_it: - pushad ; Save and restore 32-bit registers, we may clobber them from C - call display_switch_handler - popad - - next_handler: - ; Store the address of the previous handler - push dword ptr [prev_int2f_handler] - - ; Restore original data segment without touching the stack, - ; since we want to keep the prev handler address at the top - push bp - mov bp, sp - mov ds, [bp + 6] ; Stack looks like 0: bp, 2: prev_int2f_handler, 6: ds - pop bp - - retf 2 - } -} - -#endif /* HOOK_INT2F */ - #pragma code_seg () /* Driver exported functions. */ @@ -196,25 +121,8 @@ BOOL FAR PASCAL LibMain(HINSTANCE hInstance, WORD wDataSegment, WORD wHeapSize, LPSTR lpszCmdLine) #pragma pop (unreferenced); { - // We are not going to bother checking whether a PS2 mouse exists and just assume it does - -#if HOOK_INT2F - // Check now whether we are running under protected mode windows - if (windows_386_enhanced_mode()) { - flags.haswin386 = true; - } -#endif - -#if 0 - // When running under protected mode Windows, let's tell VMD (the mouse virtualizer) - // what type of mouse we are going to be using - if (flags.haswin386) { - LPFN vmd_entry = win_get_vxd_api_entry(VMD_DEVICE_ID); - if (vmd_entry) { - vmd_set_mouse_type(&vmd_entry, VMD_TYPE_PS2, 0x33, 0); - } - } -#endif + // We are not going to bother checking whether the int33 driver exists + // and just assume it does. return 1; } @@ -238,7 +146,7 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc) eventproc = lpEventProc; sti(); - if (!flags.enabled) { + if (!enabled) { int33_reset(); int33_set_horizontal_window(0, 0x7FFF); @@ -246,35 +154,17 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc) int33_set_event_handler(INT33_EVENT_MASK_ALL, int33_mouse_callback); - flags.enabled = true; - -#if HOOK_INT2F - if (flags.haswin386) { - cli(); - hook_int2f(&prev_int2f_handler, int2f_handler); - sti(); - flags.int2f_hooked = true; - } -#endif + enabled = true; } } /** Called by Windows to disable the mouse driver. */ VOID FAR PASCAL Disable(VOID) { - if (flags.enabled) { -#if HOOK_INT2F - if (flags.int2f_hooked) { - cli(); - unhook_int2f(prev_int2f_handler); - sti(); - flags.int2f_hooked = false; - } -#endif - + if (enabled) { int33_reset(); - flags.enabled = false; + enabled = false; } } @@ -283,4 +173,3 @@ int FAR PASCAL MouseGetIntVect(VOID) { return 0x33; } - |