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
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
;
44 /**********************************************************************
45 * DOSVM_Int33Handler (WINEDOS16.151)
47 * Handler for int 33h (MS MOUSE).
49 void WINAPI
DOSVM_Int33Handler( CONTEXT86
*context
)
51 switch (LOWORD(context
->Eax
)) {
54 TRACE("Reset mouse driver and request status\n");
55 SET_AX( context
, 0xFFFF ); /* installed */
56 SET_BX( context
, 3 ); /* # of buttons */
57 memset( &mouse_info
, 0, sizeof(mouse_info
) );
58 /* Set the default mickey/pixel ratio */
59 mouse_info
.HMPratio
= 8;
60 mouse_info
.VMPratio
= 16;
63 FIXME("Show mouse cursor\n");
66 FIXME("Hide mouse cursor\n");
69 TRACE("Return mouse position and button status: (%ld,%ld) and %ld\n",
70 mouse_info
.x
, mouse_info
.y
, mouse_info
.but
);
71 SET_BX( context
, mouse_info
.but
);
72 SET_CX( context
, mouse_info
.x
);
73 SET_DX( context
, mouse_info
.y
);
76 FIXME("Position mouse cursor\n");
79 TRACE("Return Mouse button press Information for %s mouse button\n",
80 BX_reg(context
) ? "right" : "left");
81 if (BX_reg(context
)) {
82 SET_BX( context
, mouse_info
.rbcount
);
83 mouse_info
.rbcount
= 0;
84 SET_CX( context
, mouse_info
.rlastx
);
85 SET_DX( context
, mouse_info
.rlasty
);
87 SET_BX( context
, mouse_info
.lbcount
);
88 mouse_info
.lbcount
= 0;
89 SET_CX( context
, mouse_info
.llastx
);
90 SET_DX( context
, mouse_info
.llasty
);
92 SET_AX( context
, mouse_info
.but
);
95 FIXME("Define horizontal mouse cursor range %d..%d\n",
96 CX_reg(context
), DX_reg(context
));
99 FIXME("Define vertical mouse cursor range %d..%d\n",
100 CX_reg(context
), DX_reg(context
));
103 FIXME("Define graphics mouse cursor\n");
106 FIXME("Define text mouse cursor\n");
109 TRACE("Read Mouse motion counters\n");
110 SET_CX( context
, (mouse_info
.x
- mouse_info
.oldx
) * (mouse_info
.HMPratio
/ 8) );
111 SET_DX( context
, (mouse_info
.y
- mouse_info
.oldy
) * (mouse_info
.VMPratio
/ 8) );
112 mouse_info
.oldx
= mouse_info
.x
;
113 mouse_info
.oldy
= mouse_info
.y
;
116 TRACE("Define mouse interrupt subroutine\n");
117 mouse_info
.callmask
= CX_reg(context
);
118 mouse_info
.callback
= (FARPROC16
)MAKESEGPTR(context
->SegEs
, LOWORD(context
->Edx
));
121 TRACE("Set mickey/pixel ratio\n");
122 mouse_info
.HMPratio
= CX_reg(context
);
123 mouse_info
.VMPratio
= DX_reg(context
);
126 FIXME("Define screen region for update\n");
129 INT_BARF(context
,0x33);
135 WORD mask
,but
,x
,y
,mx
,my
;
138 static void MouseRelay(CONTEXT86
*context
,void *mdata
)
140 MCALLDATA
*data
= (MCALLDATA
*)mdata
;
141 CONTEXT86 ctx
= *context
;
145 ctx
.EFlags
|= V86_FLAG
;
146 ctx
.SegSs
= 0; /* Allocate new stack. */
149 ctx
.Eax
= data
->mask
;
155 ctx
.SegCs
= SELECTOROF(data
->proc
);
156 ctx
.Eip
= OFFSETOF(data
->proc
);
158 DPMI_CallRMProc(&ctx
, NULL
, 0, 0);
161 static void QueueMouseRelay(DWORD mx
, DWORD my
, WORD mask
)
166 /* Left button down */
168 mouse_info
.but
|= 0x01;
169 mouse_info
.llastx
= mx
;
170 mouse_info
.llasty
= my
;
171 mouse_info
.lbcount
++;
176 mouse_info
.but
&= ~0x01;
179 /* Right button down */
181 mouse_info
.but
|= 0x02;
182 mouse_info
.rlastx
= mx
;
183 mouse_info
.rlasty
= my
;
184 mouse_info
.rbcount
++;
187 /* Right button up */
189 mouse_info
.but
&= ~0x02;
192 /* Middle button down */
194 mouse_info
.but
|= 0x04;
197 /* Middle button up */
199 mouse_info
.but
&= ~0x04;
202 if ((mask
& mouse_info
.callmask
) && mouse_info
.callback
) {
203 MCALLDATA
*data
= calloc(1,sizeof(MCALLDATA
));
204 data
->proc
= mouse_info
.callback
;
205 data
->mask
= mask
& mouse_info
.callmask
;
206 data
->but
= mouse_info
.but
;
207 data
->x
= mouse_info
.x
;
208 data
->y
= mouse_info
.y
;
213 * FIXME: This is not entirely correct. If mouse if moved to the edge
214 * of the screen, mouse will stop moving and mickeys won't
215 * be updated even though they should be.
217 data
->mx
= mouse_info
.x
* (mouse_info
.HMPratio
/ 8);
218 data
->my
= mouse_info
.y
* (mouse_info
.VMPratio
/ 8);
220 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE
, MouseRelay
, data
);
224 void WINAPI
DOSVM_Int33Message(UINT message
,WPARAM wParam
,LPARAM lParam
)
227 unsigned Height
, Width
, SX
=1, SY
=1;
229 if (!VGA_GetMode(&Height
,&Width
,NULL
)) {
230 /* may need to do some coordinate scaling */
241 case WM_LBUTTONDBLCLK
:
248 case WM_RBUTTONDBLCLK
:
255 case WM_MBUTTONDBLCLK
:
263 QueueMouseRelay(LOWORD(lParam
) * SX
,
268 void WINAPI
DOSVM_Int33Console(MOUSE_EVENT_RECORD
*record
)
270 unsigned Height
, Width
;
272 BOOL newLeftButton
= record
->dwButtonState
& FROM_LEFT_1ST_BUTTON_PRESSED
;
273 BOOL oldLeftButton
= mouse_info
.but
& 0x01;
274 BOOL newRightButton
= record
->dwButtonState
& RIGHTMOST_BUTTON_PRESSED
;
275 BOOL oldRightButton
= mouse_info
.but
& 0x02;
276 BOOL newMiddleButton
= record
->dwButtonState
& FROM_LEFT_2ND_BUTTON_PRESSED
;
277 BOOL oldMiddleButton
= mouse_info
.but
& 0x04;
279 if(newLeftButton
&& !oldLeftButton
)
281 else if(!newLeftButton
&& oldLeftButton
)
284 if(newRightButton
&& !oldRightButton
)
286 else if(!newRightButton
&& oldRightButton
)
289 if(newMiddleButton
&& !oldMiddleButton
)
291 else if(!newMiddleButton
&& oldMiddleButton
)
294 if (VGA_GetAlphaMode(&Width
, &Height
))
295 QueueMouseRelay( 640 / Width
* record
->dwMousePosition
.X
,
296 200 / Height
* record
->dwMousePosition
.Y
,