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;
45 /**********************************************************************
46 * DOSVM_Int33Handler (WINEDOS16.151)
48 * Handler for int 33h (MS MOUSE).
50 void WINAPI DOSVM_Int33Handler( CONTEXT86 *context )
52 switch (LOWORD(context->Eax)) {
55 TRACE("Reset mouse driver and request status\n");
56 SET_AX( context, 0xFFFF ); /* installed */
57 SET_BX( context, 3 ); /* # of buttons */
58 memset( &mouse_info, 0, sizeof(mouse_info) );
59 /* Set the default mickey/pixel ratio */
60 mouse_info.HMPratio = 8;
61 mouse_info.VMPratio = 16;
64 FIXME("Show mouse cursor\n");
67 FIXME("Hide mouse cursor\n");
70 TRACE("Return mouse position and button status: (%ld,%ld) and %ld\n",
71 mouse_info.x, mouse_info.y, mouse_info.but);
72 SET_BX( context, mouse_info.but );
73 SET_CX( context, mouse_info.x );
74 SET_DX( context, mouse_info.y );
77 FIXME("Position mouse cursor\n");
80 TRACE("Return Mouse button press Information for %s mouse button\n",
81 BX_reg(context) ? "right" : "left");
82 if (BX_reg(context)) {
83 SET_BX( context, mouse_info.rbcount );
84 mouse_info.rbcount = 0;
85 SET_CX( context, mouse_info.rlastx );
86 SET_DX( context, mouse_info.rlasty );
88 SET_BX( context, mouse_info.lbcount );
89 mouse_info.lbcount = 0;
90 SET_CX( context, mouse_info.llastx );
91 SET_DX( context, mouse_info.llasty );
93 SET_AX( context, mouse_info.but );
96 FIXME("Define horizontal mouse cursor range %d..%d\n",
97 CX_reg(context), DX_reg(context));
100 FIXME("Define vertical mouse cursor range %d..%d\n",
101 CX_reg(context), DX_reg(context));
104 FIXME("Define graphics mouse cursor\n");
107 FIXME("Define text mouse cursor\n");
110 TRACE("Read Mouse motion counters\n");
111 SET_CX( context, (mouse_info.x - mouse_info.oldx) * (mouse_info.HMPratio / 8) );
112 SET_DX( context, (mouse_info.y - mouse_info.oldy) * (mouse_info.VMPratio / 8) );
113 mouse_info.oldx = mouse_info.x;
114 mouse_info.oldy = mouse_info.y;
117 TRACE("Define mouse interrupt subroutine\n");
118 mouse_info.callmask = CX_reg(context);
119 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs, LOWORD(context->Edx));
122 TRACE("Set mickey/pixel ratio\n");
123 mouse_info.HMPratio = CX_reg(context);
124 mouse_info.VMPratio = DX_reg(context);
127 FIXME("Define screen region for update\n");
130 INT_BARF(context,0x33);
136 WORD mask,but,x,y,mx,my;
139 static void MouseRelay(CONTEXT86 *context,void *mdata)
141 MCALLDATA *data = (MCALLDATA *)mdata;
142 CONTEXT86 ctx = *context;
146 ctx.EFlags |= V86_FLAG;
147 ctx.SegSs = 0; /* Allocate new stack. */
150 ctx.Eax = data->mask;
156 ctx.SegCs = SELECTOROF(data->proc);
157 ctx.Eip = OFFSETOF(data->proc);
159 DPMI_CallRMProc(&ctx, NULL, 0, 0);
162 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
167 /* Left button down */
169 mouse_info.but |= 0x01;
170 mouse_info.llastx = mx;
171 mouse_info.llasty = my;
172 mouse_info.lbcount++;
177 mouse_info.but &= ~0x01;
180 /* Right button down */
182 mouse_info.but |= 0x02;
183 mouse_info.rlastx = mx;
184 mouse_info.rlasty = my;
185 mouse_info.rbcount++;
188 /* Right button up */
190 mouse_info.but &= ~0x02;
193 /* Middle button down */
195 mouse_info.but |= 0x04;
198 /* Middle button up */
200 mouse_info.but &= ~0x04;
203 if ((mask & mouse_info.callmask) && mouse_info.callback) {
204 MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
205 data->proc = mouse_info.callback;
206 data->mask = mask & mouse_info.callmask;
207 data->but = mouse_info.but;
208 data->x = mouse_info.x;
209 data->y = mouse_info.y;
214 * FIXME: This is not entirely correct. If mouse if moved to the edge
215 * of the screen, mouse will stop moving and mickeys won't
216 * be updated even though they should be.
218 data->mx = mouse_info.x * (mouse_info.HMPratio / 8);
219 data->my = mouse_info.y * (mouse_info.VMPratio / 8);
221 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
225 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
228 unsigned Height, Width, SX=1, SY=1;
230 if (!VGA_GetMode(&Height,&Width,NULL)) {
231 /* may need to do some coordinate scaling */
242 case WM_LBUTTONDBLCLK:
249 case WM_RBUTTONDBLCLK:
256 case WM_MBUTTONDBLCLK:
264 QueueMouseRelay(LOWORD(lParam) * SX,
269 void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
271 unsigned Height, Width;
273 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
274 BOOL oldLeftButton = mouse_info.but & 0x01;
275 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
276 BOOL oldRightButton = mouse_info.but & 0x02;
277 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
278 BOOL oldMiddleButton = mouse_info.but & 0x04;
280 if(newLeftButton && !oldLeftButton)
282 else if(!newLeftButton && oldLeftButton)
285 if(newRightButton && !oldRightButton)
287 else if(!newRightButton && oldRightButton)
290 if(newMiddleButton && !oldMiddleButton)
292 else if(!newMiddleButton && oldMiddleButton)
295 if (VGA_GetAlphaMode(&Width, &Height))
296 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
297 200 / Height * record->dwMousePosition.Y,