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;
47 /**********************************************************************
51 * - subfunction 0x00 (reset mouse)
52 * - subfunction 0x21 (software reset)
54 static void INT33_ResetMouse( CONTEXT86 *context )
56 memset( &mouse_info, 0, sizeof(mouse_info) );
58 /* Set the default mickey/pixel ratio */
59 mouse_info.HMPratio = 8;
60 mouse_info.VMPratio = 16;
62 /* Hide the mouse cursor */
63 mouse_info.hide_count = 1;
64 VGA_ShowMouse( FALSE );
68 SET_AX( context, 0xFFFF ); /* driver installed */
69 SET_BX( context, 3 ); /* number of buttons */
74 /**********************************************************************
75 * DOSVM_Int33Handler (WINEDOS16.151)
77 * Handler for int 33h (MS MOUSE).
79 void WINAPI DOSVM_Int33Handler( CONTEXT86 *context )
81 switch (AX_reg(context))
84 TRACE("Reset mouse driver and request status\n");
85 INT33_ResetMouse( context );
89 TRACE("Show mouse cursor, old hide count: %d\n",
90 mouse_info.hide_count);
91 if (mouse_info.hide_count >= 1)
92 mouse_info.hide_count--;
93 if (!mouse_info.hide_count)
94 VGA_ShowMouse( TRUE );
98 TRACE("Hide mouse cursor, old hide count: %d\n",
99 mouse_info.hide_count);
100 if(!mouse_info.hide_count)
101 VGA_ShowMouse( FALSE );
102 mouse_info.hide_count++;
106 TRACE("Return mouse position and button status: (%d,%d) and %d\n",
107 mouse_info.x, mouse_info.y, mouse_info.but);
108 SET_BX( context, mouse_info.but );
109 SET_CX( context, mouse_info.x );
110 SET_DX( context, mouse_info.y );
114 FIXME("Position mouse cursor\n");
118 TRACE("Return Mouse button press Information for %s mouse button\n",
119 BX_reg(context) ? "right" : "left");
122 SET_BX( context, mouse_info.rbcount );
123 mouse_info.rbcount = 0;
124 SET_CX( context, mouse_info.rlastx );
125 SET_DX( context, mouse_info.rlasty );
129 SET_BX( context, mouse_info.lbcount );
130 mouse_info.lbcount = 0;
131 SET_CX( context, mouse_info.llastx );
132 SET_DX( context, mouse_info.llasty );
134 SET_AX( context, mouse_info.but );
138 FIXME("Define horizontal mouse cursor range %d..%d\n",
139 CX_reg(context), DX_reg(context));
143 FIXME("Define vertical mouse cursor range %d..%d\n",
144 CX_reg(context), DX_reg(context));
148 FIXME("Define graphics mouse cursor\n");
152 FIXME("Define text mouse cursor\n");
156 TRACE("Read Mouse motion counters\n");
158 int dx = ((int)mouse_info.x - (int)mouse_info.oldx)
159 * (mouse_info.HMPratio / 8);
160 int dy = ((int)mouse_info.y - (int)mouse_info.oldy)
161 * (mouse_info.VMPratio / 8);
163 SET_CX( context, (WORD)dx );
164 SET_DX( context, (WORD)dy );
166 mouse_info.oldx = mouse_info.x;
167 mouse_info.oldy = mouse_info.y;
172 TRACE("Define mouse interrupt subroutine\n");
173 mouse_info.callmask = CX_reg(context);
174 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs,
179 TRACE("Set mickey/pixel ratio\n");
180 mouse_info.HMPratio = CX_reg(context);
181 mouse_info.VMPratio = DX_reg(context);
185 FIXME("Define screen region for update\n");
189 TRACE("Software reset\n");
190 INT33_ResetMouse( context );
194 INT_BARF(context,0x33);
200 WORD mask,but,x,y,mx,my;
203 static void MouseRelay(CONTEXT86 *context,void *mdata)
205 MCALLDATA *data = (MCALLDATA *)mdata;
206 CONTEXT86 ctx = *context;
210 ctx.EFlags |= V86_FLAG;
211 ctx.SegSs = 0; /* Allocate new stack. */
214 ctx.Eax = data->mask;
220 ctx.SegCs = SELECTOROF(data->proc);
221 ctx.Eip = OFFSETOF(data->proc);
223 DPMI_CallRMProc(&ctx, NULL, 0, 0);
226 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
231 /* Left button down */
233 mouse_info.but |= 0x01;
234 mouse_info.llastx = mx;
235 mouse_info.llasty = my;
236 mouse_info.lbcount++;
241 mouse_info.but &= ~0x01;
244 /* Right button down */
246 mouse_info.but |= 0x02;
247 mouse_info.rlastx = mx;
248 mouse_info.rlasty = my;
249 mouse_info.rbcount++;
252 /* Right button up */
254 mouse_info.but &= ~0x02;
257 /* Middle button down */
259 mouse_info.but |= 0x04;
262 /* Middle button up */
264 mouse_info.but &= ~0x04;
267 if ((mask & mouse_info.callmask) && mouse_info.callback) {
268 MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
269 data->proc = mouse_info.callback;
270 data->mask = mask & mouse_info.callmask;
271 data->but = mouse_info.but;
272 data->x = mouse_info.x;
273 data->y = mouse_info.y;
278 * FIXME: This is not entirely correct. If mouse if moved to the edge
279 * of the screen, mouse will stop moving and mickeys won't
280 * be updated even though they should be.
282 data->mx = mouse_info.x * (mouse_info.HMPratio / 8);
283 data->my = mouse_info.y * (mouse_info.VMPratio / 8);
285 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
289 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
292 unsigned Height, Width, SX=1, SY=1;
294 if (!VGA_GetMode(&Height,&Width,NULL)) {
295 /* may need to do some coordinate scaling */
306 case WM_LBUTTONDBLCLK:
313 case WM_RBUTTONDBLCLK:
320 case WM_MBUTTONDBLCLK:
328 QueueMouseRelay(LOWORD(lParam) * SX,
333 void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
335 unsigned Height, Width;
337 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
338 BOOL oldLeftButton = mouse_info.but & 0x01;
339 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
340 BOOL oldRightButton = mouse_info.but & 0x02;
341 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
342 BOOL oldMiddleButton = mouse_info.but & 0x04;
344 if(newLeftButton && !oldLeftButton)
346 else if(!newLeftButton && oldLeftButton)
349 if(newRightButton && !oldRightButton)
351 else if(!newRightButton && oldRightButton)
354 if(newMiddleButton && !oldMiddleButton)
356 else if(!newMiddleButton && oldMiddleButton)
359 if (VGA_GetAlphaMode(&Width, &Height))
360 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
361 200 / Height * record->dwMousePosition.Y,