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\n");
97 FIXME("Define vertical mouse cursor range\n");
100 FIXME("Define graphics mouse cursor\n");
103 FIXME("Define text mouse cursor\n");
106 TRACE("Read Mouse motion counters\n");
107 SET_CX( context, (mouse_info.x - mouse_info.oldx) * (mouse_info.HMPratio / 8) );
108 SET_DX( context, (mouse_info.y - mouse_info.oldy) * (mouse_info.VMPratio / 8) );
109 mouse_info.oldx = mouse_info.x;
110 mouse_info.oldy = mouse_info.y;
113 TRACE("Define mouse interrupt subroutine\n");
114 mouse_info.callmask = CX_reg(context);
115 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs, LOWORD(context->Edx));
118 TRACE("Set mickey/pixel ratio\n");
119 mouse_info.HMPratio = CX_reg(context);
120 mouse_info.VMPratio = DX_reg(context);
123 FIXME("Define screen region for update\n");
126 INT_BARF(context,0x33);
132 WORD mask,but,x,y,mx,my;
135 static void MouseRelay(CONTEXT86 *context,void *mdata)
137 MCALLDATA *data = (MCALLDATA *)mdata;
138 CONTEXT86 ctx = *context;
140 ctx.Eax = data->mask;
146 ctx.SegCs = SELECTOROF(data->proc);
147 ctx.Eip = OFFSETOF(data->proc);
149 DPMI_CallRMProc(&ctx, NULL, 0, 0);
152 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
157 /* Left button down */
159 mouse_info.but |= 0x01;
160 mouse_info.llastx = mx;
161 mouse_info.llasty = my;
162 mouse_info.lbcount++;
167 mouse_info.but &= ~0x01;
170 /* Right button down */
172 mouse_info.but |= 0x02;
173 mouse_info.rlastx = mx;
174 mouse_info.rlasty = my;
175 mouse_info.rbcount++;
178 /* Right button up */
180 mouse_info.but &= ~0x02;
183 /* Middle button down */
185 mouse_info.but |= 0x04;
188 /* Middle button up */
190 mouse_info.but &= ~0x04;
193 if ((mask & mouse_info.callmask) && mouse_info.callback) {
194 MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
195 data->proc = mouse_info.callback;
196 data->mask = mask & mouse_info.callmask;
197 data->but = mouse_info.but;
198 data->x = mouse_info.x;
199 data->y = mouse_info.y;
200 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
204 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
207 unsigned Height, Width, SX=1, SY=1;
209 if (!VGA_GetMode(&Height,&Width,NULL)) {
210 /* may need to do some coordinate scaling */
221 case WM_LBUTTONDBLCLK:
228 case WM_RBUTTONDBLCLK:
235 case WM_MBUTTONDBLCLK:
243 QueueMouseRelay(LOWORD(lParam) * SX,
248 void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
250 unsigned Height, Width;
252 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
253 BOOL oldLeftButton = mouse_info.but & 0x01;
254 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
255 BOOL oldRightButton = mouse_info.but & 0x02;
256 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
257 BOOL oldMiddleButton = mouse_info.but & 0x04;
259 if(newLeftButton && !oldLeftButton)
261 else if(!newLeftButton && oldLeftButton)
264 if(newRightButton && !oldRightButton)
266 else if(!newRightButton && oldRightButton)
269 if(newMiddleButton && !oldMiddleButton)
271 else if(!newMiddleButton && oldMiddleButton)
274 if (VGA_GetAlphaMode(&Width, &Height))
275 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
276 200 / Height * record->dwMousePosition.Y,