Make all users of DOSVM_Enter explicitly set V86 flag.
[wine/wine-kai.git] / dlls / winedos / int33.c
blob32c436607b654b89a30baf7d57971111b1005789
1 /*
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
21 #include <stdlib.h>
22 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "miscemu.h"
29 #include "dosexe.h"
30 #include "vga.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(int);
35 static struct
37 DWORD x, y, but;
38 WORD lbcount, rbcount, rlastx, rlasty, llastx, llasty;
39 FARPROC16 callback;
40 WORD callmask;
41 WORD VMPratio, HMPratio, oldx, oldy;
42 } mouse_info;
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)) {
52 case 0x00:
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;
60 break;
61 case 0x01:
62 FIXME("Show mouse cursor\n");
63 break;
64 case 0x02:
65 FIXME("Hide mouse cursor\n");
66 break;
67 case 0x03:
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 );
73 break;
74 case 0x04:
75 FIXME("Position mouse cursor\n");
76 break;
77 case 0x05:
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 );
85 } else {
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 );
92 break;
93 case 0x07:
94 FIXME("Define horizontal mouse cursor range %d..%d\n",
95 CX_reg(context), DX_reg(context));
96 break;
97 case 0x08:
98 FIXME("Define vertical mouse cursor range %d..%d\n",
99 CX_reg(context), DX_reg(context));
100 break;
101 case 0x09:
102 FIXME("Define graphics mouse cursor\n");
103 break;
104 case 0x0A:
105 FIXME("Define text mouse cursor\n");
106 break;
107 case 0x0B:
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;
113 break;
114 case 0x0C:
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));
118 break;
119 case 0x0F:
120 TRACE("Set mickey/pixel ratio\n");
121 mouse_info.HMPratio = CX_reg(context);
122 mouse_info.VMPratio = DX_reg(context);
123 break;
124 case 0x10:
125 FIXME("Define screen region for update\n");
126 break;
127 default:
128 INT_BARF(context,0x33);
132 typedef struct {
133 FARPROC16 proc;
134 WORD mask,but,x,y,mx,my;
135 } MCALLDATA;
137 static void MouseRelay(CONTEXT86 *context,void *mdata)
139 MCALLDATA *data = (MCALLDATA *)mdata;
140 CONTEXT86 ctx = *context;
142 if (!ISV86(&ctx))
144 ctx.EFlags |= V86_FLAG;
145 ctx.SegSs = 0; /* Allocate new stack. */
148 ctx.Eax = data->mask;
149 ctx.Ebx = data->but;
150 ctx.Ecx = data->x;
151 ctx.Edx = data->y;
152 ctx.Esi = data->mx;
153 ctx.Edi = data->my;
154 ctx.SegCs = SELECTOROF(data->proc);
155 ctx.Eip = OFFSETOF(data->proc);
156 free(data);
157 DPMI_CallRMProc(&ctx, NULL, 0, 0);
160 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
162 mouse_info.x = mx;
163 mouse_info.y = my;
165 /* Left button down */
166 if(mask & 0x02) {
167 mouse_info.but |= 0x01;
168 mouse_info.llastx = mx;
169 mouse_info.llasty = my;
170 mouse_info.lbcount++;
173 /* Left button up */
174 if(mask & 0x04) {
175 mouse_info.but &= ~0x01;
178 /* Right button down */
179 if(mask & 0x08) {
180 mouse_info.but |= 0x02;
181 mouse_info.rlastx = mx;
182 mouse_info.rlasty = my;
183 mouse_info.rbcount++;
186 /* Right button up */
187 if(mask & 0x10) {
188 mouse_info.but &= ~0x02;
191 /* Middle button down */
192 if(mask & 0x20) {
193 mouse_info.but |= 0x04;
196 /* Middle button up */
197 if(mask & 0x40) {
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;
208 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
212 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
214 WORD mask = 0;
215 unsigned Height, Width, SX=1, SY=1;
217 if (!VGA_GetMode(&Height,&Width,NULL)) {
218 /* may need to do some coordinate scaling */
219 if (Width)
220 SX = 640/Width;
221 if (!SX) SX=1;
224 switch (message) {
225 case WM_MOUSEMOVE:
226 mask |= 0x01;
227 break;
228 case WM_LBUTTONDOWN:
229 case WM_LBUTTONDBLCLK:
230 mask |= 0x02;
231 break;
232 case WM_LBUTTONUP:
233 mask |= 0x04;
234 break;
235 case WM_RBUTTONDOWN:
236 case WM_RBUTTONDBLCLK:
237 mask |= 0x08;
238 break;
239 case WM_RBUTTONUP:
240 mask |= 0x10;
241 break;
242 case WM_MBUTTONDOWN:
243 case WM_MBUTTONDBLCLK:
244 mask |= 0x20;
245 break;
246 case WM_MBUTTONUP:
247 mask |= 0x40;
248 break;
251 QueueMouseRelay(LOWORD(lParam) * SX,
252 HIWORD(lParam) * SY,
253 mask);
256 void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
258 unsigned Height, Width;
259 WORD mask = 0;
260 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
261 BOOL oldLeftButton = mouse_info.but & 0x01;
262 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
263 BOOL oldRightButton = mouse_info.but & 0x02;
264 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
265 BOOL oldMiddleButton = mouse_info.but & 0x04;
267 if(newLeftButton && !oldLeftButton)
268 mask |= 0x02;
269 else if(!newLeftButton && oldLeftButton)
270 mask |= 0x04;
272 if(newRightButton && !oldRightButton)
273 mask |= 0x08;
274 else if(!newRightButton && oldRightButton)
275 mask |= 0x10;
277 if(newMiddleButton && !oldMiddleButton)
278 mask |= 0x20;
279 else if(!newMiddleButton && oldMiddleButton)
280 mask |= 0x40;
282 if (VGA_GetAlphaMode(&Width, &Height))
283 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
284 200 / Height * record->dwMousePosition.Y,
285 mask );