2 * DOS interrupt 33h handler
4 * Copyright 1999 Ove Kåven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(int);
38 WORD lbcount
, rbcount
, rlastx
, rlasty
, llastx
, llasty
;
41 WORD VMPratio
, HMPratio
, oldx
, oldy
;
46 /**********************************************************************
50 * - subfunction 0x00 (reset mouse)
51 * - subfunction 0x21 (software reset)
53 static void INT33_ResetMouse( CONTEXT86
*context
)
55 memset( &mouse_info
, 0, sizeof(mouse_info
) );
57 /* Set the default mickey/pixel ratio */
58 mouse_info
.HMPratio
= 8;
59 mouse_info
.VMPratio
= 16;
61 /* Hide the mouse cursor */
62 mouse_info
.hide_count
= 1;
63 VGA_ShowMouse( FALSE
);
67 SET_AX( context
, 0xFFFF ); /* driver installed */
68 SET_BX( context
, 3 ); /* number of buttons */
73 /**********************************************************************
76 * Handler for int 33h (MS MOUSE).
78 void WINAPI
DOSVM_Int33Handler( CONTEXT86
*context
)
80 switch (AX_reg(context
))
83 TRACE("Reset mouse driver and request status\n");
84 INT33_ResetMouse( context
);
88 TRACE("Show mouse cursor, old hide count: %d\n",
89 mouse_info
.hide_count
);
90 if (mouse_info
.hide_count
>= 1)
91 mouse_info
.hide_count
--;
92 if (!mouse_info
.hide_count
)
93 VGA_ShowMouse( TRUE
);
97 TRACE("Hide mouse cursor, old hide count: %d\n",
98 mouse_info
.hide_count
);
99 if(!mouse_info
.hide_count
)
100 VGA_ShowMouse( FALSE
);
101 mouse_info
.hide_count
++;
105 TRACE("Return mouse position and button status: (%d,%d) and %d\n",
106 mouse_info
.x
, mouse_info
.y
, mouse_info
.but
);
107 SET_BX( context
, mouse_info
.but
);
108 SET_CX( context
, mouse_info
.x
);
109 SET_DX( context
, mouse_info
.y
);
113 FIXME("Position mouse cursor\n");
117 TRACE("Return Mouse button press Information for %s mouse button\n",
118 BX_reg(context
) ? "right" : "left");
121 SET_BX( context
, mouse_info
.rbcount
);
122 mouse_info
.rbcount
= 0;
123 SET_CX( context
, mouse_info
.rlastx
);
124 SET_DX( context
, mouse_info
.rlasty
);
128 SET_BX( context
, mouse_info
.lbcount
);
129 mouse_info
.lbcount
= 0;
130 SET_CX( context
, mouse_info
.llastx
);
131 SET_DX( context
, mouse_info
.llasty
);
133 SET_AX( context
, mouse_info
.but
);
137 FIXME("Define horizontal mouse cursor range %d..%d\n",
138 CX_reg(context
), DX_reg(context
));
142 FIXME("Define vertical mouse cursor range %d..%d\n",
143 CX_reg(context
), DX_reg(context
));
147 FIXME("Define graphics mouse cursor\n");
151 FIXME("Define text mouse cursor\n");
155 TRACE("Read Mouse motion counters\n");
157 int dx
= ((int)mouse_info
.x
- (int)mouse_info
.oldx
)
158 * (mouse_info
.HMPratio
/ 8);
159 int dy
= ((int)mouse_info
.y
- (int)mouse_info
.oldy
)
160 * (mouse_info
.VMPratio
/ 8);
162 SET_CX( context
, (WORD
)dx
);
163 SET_DX( context
, (WORD
)dy
);
165 mouse_info
.oldx
= mouse_info
.x
;
166 mouse_info
.oldy
= mouse_info
.y
;
171 TRACE("Define mouse interrupt subroutine\n");
172 mouse_info
.callmask
= CX_reg(context
);
173 mouse_info
.callback
= (FARPROC16
)MAKESEGPTR(context
->SegEs
,
178 TRACE("Set mickey/pixel ratio\n");
179 mouse_info
.HMPratio
= CX_reg(context
);
180 mouse_info
.VMPratio
= DX_reg(context
);
184 FIXME("Define screen region for update\n");
188 TRACE("Software reset\n");
189 INT33_ResetMouse( context
);
193 INT_BARF(context
,0x33);
199 WORD mask
,but
,x
,y
,mx
,my
;
202 static void MouseRelay(CONTEXT86
*context
,void *mdata
)
204 MCALLDATA
*data
= mdata
;
205 CONTEXT86 ctx
= *context
;
209 ctx
.EFlags
|= V86_FLAG
;
210 ctx
.SegSs
= 0; /* Allocate new stack. */
213 ctx
.Eax
= data
->mask
;
219 ctx
.SegCs
= SELECTOROF(data
->proc
);
220 ctx
.Eip
= OFFSETOF(data
->proc
);
221 HeapFree(GetProcessHeap(), 0, data
);
222 DPMI_CallRMProc(&ctx
, NULL
, 0, 0);
225 static void QueueMouseRelay(DWORD mx
, DWORD my
, WORD mask
)
230 /* Left button down */
232 mouse_info
.but
|= 0x01;
233 mouse_info
.llastx
= mx
;
234 mouse_info
.llasty
= my
;
235 mouse_info
.lbcount
++;
240 mouse_info
.but
&= ~0x01;
243 /* Right button down */
245 mouse_info
.but
|= 0x02;
246 mouse_info
.rlastx
= mx
;
247 mouse_info
.rlasty
= my
;
248 mouse_info
.rbcount
++;
251 /* Right button up */
253 mouse_info
.but
&= ~0x02;
256 /* Middle button down */
258 mouse_info
.but
|= 0x04;
261 /* Middle button up */
263 mouse_info
.but
&= ~0x04;
266 if ((mask
& mouse_info
.callmask
) && mouse_info
.callback
) {
267 MCALLDATA
*data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MCALLDATA
));
268 data
->proc
= mouse_info
.callback
;
269 data
->mask
= mask
& mouse_info
.callmask
;
270 data
->but
= mouse_info
.but
;
271 data
->x
= mouse_info
.x
;
272 data
->y
= mouse_info
.y
;
277 * FIXME: This is not entirely correct. If mouse if moved to the edge
278 * of the screen, mouse will stop moving and mickeys won't
279 * be updated even though they should be.
281 data
->mx
= mouse_info
.x
* (mouse_info
.HMPratio
/ 8);
282 data
->my
= mouse_info
.y
* (mouse_info
.VMPratio
/ 8);
284 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE
, MouseRelay
, data
);
288 void DOSVM_Int33Message(UINT message
,WPARAM wParam
,LPARAM lParam
)
291 unsigned Height
, Width
, SX
=1, SY
=1;
293 if (!VGA_GetMode(&Height
,&Width
,NULL
)) {
294 /* may need to do some coordinate scaling */
305 case WM_LBUTTONDBLCLK
:
312 case WM_RBUTTONDBLCLK
:
319 case WM_MBUTTONDBLCLK
:
327 QueueMouseRelay(LOWORD(lParam
) * SX
,
332 void DOSVM_Int33Console(MOUSE_EVENT_RECORD
*record
)
334 unsigned Height
, Width
;
336 BOOL newLeftButton
= record
->dwButtonState
& FROM_LEFT_1ST_BUTTON_PRESSED
;
337 BOOL oldLeftButton
= mouse_info
.but
& 0x01;
338 BOOL newRightButton
= record
->dwButtonState
& RIGHTMOST_BUTTON_PRESSED
;
339 BOOL oldRightButton
= mouse_info
.but
& 0x02;
340 BOOL newMiddleButton
= record
->dwButtonState
& FROM_LEFT_2ND_BUTTON_PRESSED
;
341 BOOL oldMiddleButton
= mouse_info
.but
& 0x04;
343 if(newLeftButton
&& !oldLeftButton
)
345 else if(!newLeftButton
&& oldLeftButton
)
348 if(newRightButton
&& !oldRightButton
)
350 else if(!newRightButton
&& oldRightButton
)
353 if(newMiddleButton
&& !oldMiddleButton
)
355 else if(!newMiddleButton
&& oldMiddleButton
)
358 if (VGA_GetAlphaMode(&Width
, &Height
))
359 QueueMouseRelay( 640 / Width
* record
->dwMousePosition
.X
,
360 200 / Height
* record
->dwMousePosition
.Y
,