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)) {
53 TRACE("Reset mouse driver and request status\n");
54 SET_AX( context, 0xFFFF ); /* installed */
55 SET_BX( context, 3 ); /* # of buttons */
56 memset( &mouse_info, 0, sizeof(mouse_info) );
57 /* Set the default mickey/pixel ratio */
58 mouse_info.HMPratio = 8;
59 mouse_info.VMPratio = 16;
62 FIXME("Show mouse cursor\n");
65 FIXME("Hide mouse cursor\n");
68 TRACE("Return mouse position and button status: (%ld,%ld) and %ld\n",
69 mouse_info.x, mouse_info.y, mouse_info.but);
70 SET_BX( context, mouse_info.but );
71 SET_CX( context, mouse_info.x );
72 SET_DX( context, mouse_info.y );
75 FIXME("Position mouse cursor\n");
78 TRACE("Return Mouse button press Information for %s mouse button\n",
79 BX_reg(context) ? "right" : "left");
80 if (BX_reg(context)) {
81 SET_BX( context, mouse_info.rbcount );
82 mouse_info.rbcount = 0;
83 SET_CX( context, mouse_info.rlastx );
84 SET_DX( context, mouse_info.rlasty );
86 SET_BX( context, mouse_info.lbcount );
87 mouse_info.lbcount = 0;
88 SET_CX( context, mouse_info.llastx );
89 SET_DX( context, mouse_info.llasty );
91 SET_AX( context, mouse_info.but );
94 FIXME("Define horizontal mouse cursor range %d..%d\n",
95 CX_reg(context), DX_reg(context));
98 FIXME("Define vertical mouse cursor range %d..%d\n",
99 CX_reg(context), DX_reg(context));
102 FIXME("Define graphics mouse cursor\n");
105 FIXME("Define text mouse cursor\n");
108 TRACE("Read Mouse motion counters\n");
109 SET_CX( context, (mouse_info.x - mouse_info.oldx) * (mouse_info.HMPratio / 8) );
110 SET_DX( context, (mouse_info.y - mouse_info.oldy) * (mouse_info.VMPratio / 8) );
111 mouse_info.oldx = mouse_info.x;
112 mouse_info.oldy = mouse_info.y;
115 TRACE("Define mouse interrupt subroutine\n");
116 mouse_info.callmask = CX_reg(context);
117 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs, LOWORD(context->Edx));
120 TRACE("Set mickey/pixel ratio\n");
121 mouse_info.HMPratio = CX_reg(context);
122 mouse_info.VMPratio = DX_reg(context);
125 FIXME("Define screen region for update\n");
128 INT_BARF(context,0x33);
134 WORD mask,but,x,y,mx,my;
137 static void MouseRelay(CONTEXT86 *context,void *mdata)
139 MCALLDATA *data = (MCALLDATA *)mdata;
140 CONTEXT86 ctx = *context;
144 ctx.EFlags |= V86_FLAG;
145 ctx.SegSs = 0; /* Allocate new stack. */
148 ctx.Eax = data->mask;
154 ctx.SegCs = SELECTOROF(data->proc);
155 ctx.Eip = OFFSETOF(data->proc);
157 DPMI_CallRMProc(&ctx, NULL, 0, 0);
160 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
165 /* Left button down */
167 mouse_info.but |= 0x01;
168 mouse_info.llastx = mx;
169 mouse_info.llasty = my;
170 mouse_info.lbcount++;
175 mouse_info.but &= ~0x01;
178 /* Right button down */
180 mouse_info.but |= 0x02;
181 mouse_info.rlastx = mx;
182 mouse_info.rlasty = my;
183 mouse_info.rbcount++;
186 /* Right button up */
188 mouse_info.but &= ~0x02;
191 /* Middle button down */
193 mouse_info.but |= 0x04;
196 /* Middle button up */
198 mouse_info.but &= ~0x04;
201 if ((mask & mouse_info.callmask) && mouse_info.callback) {
202 MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
203 data->proc = mouse_info.callback;
204 data->mask = mask & mouse_info.callmask;
205 data->but = mouse_info.but;
206 data->x = mouse_info.x;
207 data->y = mouse_info.y;
212 * FIXME: This is not entirely correct. If mouse if moved to the edge
213 * of the screen, mouse will stop moving and mickeys won't
214 * be updated even though they should be.
216 data->mx = mouse_info.x * (mouse_info.HMPratio / 8);
217 data->my = mouse_info.y * (mouse_info.VMPratio / 8);
219 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
223 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
226 unsigned Height, Width, SX=1, SY=1;
228 if (!VGA_GetMode(&Height,&Width,NULL)) {
229 /* may need to do some coordinate scaling */
240 case WM_LBUTTONDBLCLK:
247 case WM_RBUTTONDBLCLK:
254 case WM_MBUTTONDBLCLK:
262 QueueMouseRelay(LOWORD(lParam) * SX,
267 void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
269 unsigned Height, Width;
271 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
272 BOOL oldLeftButton = mouse_info.but & 0x01;
273 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
274 BOOL oldRightButton = mouse_info.but & 0x02;
275 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
276 BOOL oldMiddleButton = mouse_info.but & 0x04;
278 if(newLeftButton && !oldLeftButton)
280 else if(!newLeftButton && oldLeftButton)
283 if(newRightButton && !oldRightButton)
285 else if(!newRightButton && oldRightButton)
288 if(newMiddleButton && !oldMiddleButton)
290 else if(!newMiddleButton && oldMiddleButton)
293 if (VGA_GetAlphaMode(&Width, &Height))
294 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
295 200 / Height * record->dwMousePosition.Y,