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( CONTEXT
*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( CONTEXT
*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("Get mouse driver state and memory requirements\n");
189 SET_BX(context
, sizeof(mouse_info
));
193 TRACE("Software reset\n");
194 INT33_ResetMouse( context
);
198 INT_BARF(context
,0x33);
204 WORD mask
,but
,x
,y
,mx
,my
;
207 static void MouseRelay(CONTEXT
*context
,void *mdata
)
209 MCALLDATA
*data
= mdata
;
210 CONTEXT ctx
= *context
;
214 ctx
.EFlags
|= V86_FLAG
;
215 ctx
.SegSs
= 0; /* Allocate new stack. */
218 ctx
.Eax
= data
->mask
;
224 ctx
.SegCs
= SELECTOROF(data
->proc
);
225 ctx
.Eip
= OFFSETOF(data
->proc
);
226 HeapFree(GetProcessHeap(), 0, data
);
227 DPMI_CallRMProc(&ctx
, NULL
, 0, 0);
230 static void QueueMouseRelay(DWORD mx
, DWORD my
, WORD mask
)
235 /* Left button down */
237 mouse_info
.but
|= 0x01;
238 mouse_info
.llastx
= mx
;
239 mouse_info
.llasty
= my
;
240 mouse_info
.lbcount
++;
245 mouse_info
.but
&= ~0x01;
248 /* Right button down */
250 mouse_info
.but
|= 0x02;
251 mouse_info
.rlastx
= mx
;
252 mouse_info
.rlasty
= my
;
253 mouse_info
.rbcount
++;
256 /* Right button up */
258 mouse_info
.but
&= ~0x02;
261 /* Middle button down */
263 mouse_info
.but
|= 0x04;
266 /* Middle button up */
268 mouse_info
.but
&= ~0x04;
271 if ((mask
& mouse_info
.callmask
) && mouse_info
.callback
) {
272 MCALLDATA
*data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MCALLDATA
));
273 data
->proc
= mouse_info
.callback
;
274 data
->mask
= mask
& mouse_info
.callmask
;
275 data
->but
= mouse_info
.but
;
276 data
->x
= mouse_info
.x
;
277 data
->y
= mouse_info
.y
;
282 * FIXME: This is not entirely correct. If mouse if moved to the edge
283 * of the screen, mouse will stop moving and mickeys won't
284 * be updated even though they should be.
286 data
->mx
= mouse_info
.x
* (mouse_info
.HMPratio
/ 8);
287 data
->my
= mouse_info
.y
* (mouse_info
.VMPratio
/ 8);
289 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE
, MouseRelay
, data
);
293 void DOSVM_Int33Message(UINT message
,WPARAM wParam
,LPARAM lParam
)
296 unsigned Height
, Width
, SX
=1, SY
=1;
298 if (VGA_GetMode(&Height
, &Width
, NULL
)) {
299 /* may need to do some coordinate scaling */
310 case WM_LBUTTONDBLCLK
:
317 case WM_RBUTTONDBLCLK
:
324 case WM_MBUTTONDBLCLK
:
332 QueueMouseRelay(LOWORD(lParam
) * SX
,
337 void DOSVM_Int33Console(MOUSE_EVENT_RECORD
*record
)
339 unsigned Height
, Width
;
341 BOOL newLeftButton
= record
->dwButtonState
& FROM_LEFT_1ST_BUTTON_PRESSED
;
342 BOOL oldLeftButton
= mouse_info
.but
& 0x01;
343 BOOL newRightButton
= record
->dwButtonState
& RIGHTMOST_BUTTON_PRESSED
;
344 BOOL oldRightButton
= mouse_info
.but
& 0x02;
345 BOOL newMiddleButton
= record
->dwButtonState
& FROM_LEFT_2ND_BUTTON_PRESSED
;
346 BOOL oldMiddleButton
= mouse_info
.but
& 0x04;
348 if(newLeftButton
&& !oldLeftButton
)
350 else if(!newLeftButton
&& oldLeftButton
)
353 if(newRightButton
&& !oldRightButton
)
355 else if(!newRightButton
&& oldRightButton
)
358 if(newMiddleButton
&& !oldMiddleButton
)
360 else if(!newMiddleButton
&& oldMiddleButton
)
363 if (VGA_GetAlphaMode(&Width
, &Height
))
364 QueueMouseRelay( 640 / Width
* record
->dwMousePosition
.X
,
365 200 / Height
* record
->dwMousePosition
.Y
,