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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(int);
39 WORD lbcount
, rbcount
, rlastx
, rlasty
, llastx
, llasty
;
42 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;
63 SET_AX( context
, 0xFFFF ); /* driver installed */
64 SET_BX( context
, 3 ); /* number of buttons */
69 /**********************************************************************
70 * DOSVM_Int33Handler (WINEDOS16.151)
72 * Handler for int 33h (MS MOUSE).
74 void WINAPI
DOSVM_Int33Handler( CONTEXT86
*context
)
76 switch (AX_reg(context
))
79 TRACE("Reset mouse driver and request status\n");
80 INT33_ResetMouse( context
);
84 FIXME("Show mouse cursor\n");
88 FIXME("Hide mouse cursor\n");
92 TRACE("Return mouse position and button status: (%d,%d) and %d\n",
93 mouse_info
.x
, mouse_info
.y
, mouse_info
.but
);
94 SET_BX( context
, mouse_info
.but
);
95 SET_CX( context
, mouse_info
.x
);
96 SET_DX( context
, mouse_info
.y
);
100 FIXME("Position mouse cursor\n");
104 TRACE("Return Mouse button press Information for %s mouse button\n",
105 BX_reg(context
) ? "right" : "left");
108 SET_BX( context
, mouse_info
.rbcount
);
109 mouse_info
.rbcount
= 0;
110 SET_CX( context
, mouse_info
.rlastx
);
111 SET_DX( context
, mouse_info
.rlasty
);
115 SET_BX( context
, mouse_info
.lbcount
);
116 mouse_info
.lbcount
= 0;
117 SET_CX( context
, mouse_info
.llastx
);
118 SET_DX( context
, mouse_info
.llasty
);
120 SET_AX( context
, mouse_info
.but
);
124 FIXME("Define horizontal mouse cursor range %d..%d\n",
125 CX_reg(context
), DX_reg(context
));
129 FIXME("Define vertical mouse cursor range %d..%d\n",
130 CX_reg(context
), DX_reg(context
));
134 FIXME("Define graphics mouse cursor\n");
138 FIXME("Define text mouse cursor\n");
142 TRACE("Read Mouse motion counters\n");
144 int dx
= ((int)mouse_info
.x
- (int)mouse_info
.oldx
)
145 * (mouse_info
.HMPratio
/ 8);
146 int dy
= ((int)mouse_info
.y
- (int)mouse_info
.oldy
)
147 * (mouse_info
.VMPratio
/ 8);
149 SET_CX( context
, (WORD
)dx
);
150 SET_DX( context
, (WORD
)dy
);
152 mouse_info
.oldx
= mouse_info
.x
;
153 mouse_info
.oldy
= mouse_info
.y
;
158 TRACE("Define mouse interrupt subroutine\n");
159 mouse_info
.callmask
= CX_reg(context
);
160 mouse_info
.callback
= (FARPROC16
)MAKESEGPTR(context
->SegEs
,
165 TRACE("Set mickey/pixel ratio\n");
166 mouse_info
.HMPratio
= CX_reg(context
);
167 mouse_info
.VMPratio
= DX_reg(context
);
171 FIXME("Define screen region for update\n");
175 TRACE("Software reset\n");
176 INT33_ResetMouse( context
);
180 INT_BARF(context
,0x33);
186 WORD mask
,but
,x
,y
,mx
,my
;
189 static void MouseRelay(CONTEXT86
*context
,void *mdata
)
191 MCALLDATA
*data
= (MCALLDATA
*)mdata
;
192 CONTEXT86 ctx
= *context
;
196 ctx
.EFlags
|= V86_FLAG
;
197 ctx
.SegSs
= 0; /* Allocate new stack. */
200 ctx
.Eax
= data
->mask
;
206 ctx
.SegCs
= SELECTOROF(data
->proc
);
207 ctx
.Eip
= OFFSETOF(data
->proc
);
209 DPMI_CallRMProc(&ctx
, NULL
, 0, 0);
212 static void QueueMouseRelay(DWORD mx
, DWORD my
, WORD mask
)
217 /* Left button down */
219 mouse_info
.but
|= 0x01;
220 mouse_info
.llastx
= mx
;
221 mouse_info
.llasty
= my
;
222 mouse_info
.lbcount
++;
227 mouse_info
.but
&= ~0x01;
230 /* Right button down */
232 mouse_info
.but
|= 0x02;
233 mouse_info
.rlastx
= mx
;
234 mouse_info
.rlasty
= my
;
235 mouse_info
.rbcount
++;
238 /* Right button up */
240 mouse_info
.but
&= ~0x02;
243 /* Middle button down */
245 mouse_info
.but
|= 0x04;
248 /* Middle button up */
250 mouse_info
.but
&= ~0x04;
253 if ((mask
& mouse_info
.callmask
) && mouse_info
.callback
) {
254 MCALLDATA
*data
= calloc(1,sizeof(MCALLDATA
));
255 data
->proc
= mouse_info
.callback
;
256 data
->mask
= mask
& mouse_info
.callmask
;
257 data
->but
= mouse_info
.but
;
258 data
->x
= mouse_info
.x
;
259 data
->y
= mouse_info
.y
;
264 * FIXME: This is not entirely correct. If mouse if moved to the edge
265 * of the screen, mouse will stop moving and mickeys won't
266 * be updated even though they should be.
268 data
->mx
= mouse_info
.x
* (mouse_info
.HMPratio
/ 8);
269 data
->my
= mouse_info
.y
* (mouse_info
.VMPratio
/ 8);
271 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE
, MouseRelay
, data
);
275 void WINAPI
DOSVM_Int33Message(UINT message
,WPARAM wParam
,LPARAM lParam
)
278 unsigned Height
, Width
, SX
=1, SY
=1;
280 if (!VGA_GetMode(&Height
,&Width
,NULL
)) {
281 /* may need to do some coordinate scaling */
292 case WM_LBUTTONDBLCLK
:
299 case WM_RBUTTONDBLCLK
:
306 case WM_MBUTTONDBLCLK
:
314 QueueMouseRelay(LOWORD(lParam
) * SX
,
319 void WINAPI
DOSVM_Int33Console(MOUSE_EVENT_RECORD
*record
)
321 unsigned Height
, Width
;
323 BOOL newLeftButton
= record
->dwButtonState
& FROM_LEFT_1ST_BUTTON_PRESSED
;
324 BOOL oldLeftButton
= mouse_info
.but
& 0x01;
325 BOOL newRightButton
= record
->dwButtonState
& RIGHTMOST_BUTTON_PRESSED
;
326 BOOL oldRightButton
= mouse_info
.but
& 0x02;
327 BOOL newMiddleButton
= record
->dwButtonState
& FROM_LEFT_2ND_BUTTON_PRESSED
;
328 BOOL oldMiddleButton
= mouse_info
.but
& 0x04;
330 if(newLeftButton
&& !oldLeftButton
)
332 else if(!newLeftButton
&& oldLeftButton
)
335 if(newRightButton
&& !oldRightButton
)
337 else if(!newRightButton
&& oldRightButton
)
340 if(newMiddleButton
&& !oldMiddleButton
)
342 else if(!newMiddleButton
&& oldMiddleButton
)
345 if (VGA_GetAlphaMode(&Width
, &Height
))
346 QueueMouseRelay( 640 / Width
* record
->dwMousePosition
.X
,
347 200 / Height
* record
->dwMousePosition
.Y
,