regedit: An English (United States) spelling fix.
[wine/multimedia.git] / dlls / krnl386.exe16 / int33.c
blobb3411a70b01d0793d66dabc09c088c42bffc1a50
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "dosexe.h"
30 #include "vga.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(int);
35 static struct
37 WORD x, y, but;
38 WORD lbcount, rbcount, rlastx, rlasty, llastx, llasty;
39 FARPROC16 callback;
40 WORD callmask;
41 WORD VMPratio, HMPratio, oldx, oldy;
42 WORD hide_count;
43 } mouse_info;
46 /**********************************************************************
47 * INT33_ResetMouse
49 * Handler for:
50 * - subfunction 0x00 (reset mouse)
51 * - subfunction 0x21 (software reset)
53 static void INT33_ResetMouse( CONTEXT *context )
55 memset( &mouse_info, 0, sizeof(mouse_info) );
57 /* Set the default mickey/pixel ratio */
58 mouse_info.HMPratio = 8;
59 mouse_info.VMPratio = 16;
61 /* Hide the mouse cursor */
62 mouse_info.hide_count = 1;
63 VGA_ShowMouse( FALSE );
65 if (context)
67 SET_AX( context, 0xFFFF ); /* driver installed */
68 SET_BX( context, 3 ); /* number of buttons */
73 /**********************************************************************
74 * DOSVM_Int33Handler
76 * Handler for int 33h (MS MOUSE).
78 void WINAPI DOSVM_Int33Handler( CONTEXT *context )
80 switch (AX_reg(context))
82 case 0x0000:
83 TRACE("Reset mouse driver and request status\n");
84 INT33_ResetMouse( context );
85 break;
87 case 0x0001:
88 TRACE("Show mouse cursor, old hide count: %d\n",
89 mouse_info.hide_count);
90 if (mouse_info.hide_count >= 1)
91 mouse_info.hide_count--;
92 if (!mouse_info.hide_count)
93 VGA_ShowMouse( TRUE );
94 break;
96 case 0x0002:
97 TRACE("Hide mouse cursor, old hide count: %d\n",
98 mouse_info.hide_count);
99 if(!mouse_info.hide_count)
100 VGA_ShowMouse( FALSE );
101 mouse_info.hide_count++;
102 break;
104 case 0x0003:
105 TRACE("Return mouse position and button status: (%d,%d) and %d\n",
106 mouse_info.x, mouse_info.y, mouse_info.but);
107 SET_BX( context, mouse_info.but );
108 SET_CX( context, mouse_info.x );
109 SET_DX( context, mouse_info.y );
110 break;
112 case 0x0004:
113 FIXME("Position mouse cursor\n");
114 break;
116 case 0x0005:
117 TRACE("Return Mouse button press Information for %s mouse button\n",
118 BX_reg(context) ? "right" : "left");
119 if (BX_reg(context))
121 SET_BX( context, mouse_info.rbcount );
122 mouse_info.rbcount = 0;
123 SET_CX( context, mouse_info.rlastx );
124 SET_DX( context, mouse_info.rlasty );
126 else
128 SET_BX( context, mouse_info.lbcount );
129 mouse_info.lbcount = 0;
130 SET_CX( context, mouse_info.llastx );
131 SET_DX( context, mouse_info.llasty );
133 SET_AX( context, mouse_info.but );
134 break;
136 case 0x0007:
137 FIXME("Define horizontal mouse cursor range %d..%d\n",
138 CX_reg(context), DX_reg(context));
139 break;
141 case 0x0008:
142 FIXME("Define vertical mouse cursor range %d..%d\n",
143 CX_reg(context), DX_reg(context));
144 break;
146 case 0x0009:
147 FIXME("Define graphics mouse cursor\n");
148 break;
150 case 0x000A:
151 FIXME("Define text mouse cursor\n");
152 break;
154 case 0x000B:
155 TRACE("Read Mouse motion counters\n");
157 int dx = ((int)mouse_info.x - (int)mouse_info.oldx)
158 * (mouse_info.HMPratio / 8);
159 int dy = ((int)mouse_info.y - (int)mouse_info.oldy)
160 * (mouse_info.VMPratio / 8);
162 SET_CX( context, (WORD)dx );
163 SET_DX( context, (WORD)dy );
165 mouse_info.oldx = mouse_info.x;
166 mouse_info.oldy = mouse_info.y;
168 break;
170 case 0x000C:
171 TRACE("Define mouse interrupt subroutine\n");
172 mouse_info.callmask = CX_reg(context);
173 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs,
174 DX_reg(context));
175 break;
177 case 0x000F:
178 TRACE("Set mickey/pixel ratio\n");
179 mouse_info.HMPratio = CX_reg(context);
180 mouse_info.VMPratio = DX_reg(context);
181 break;
183 case 0x0010:
184 FIXME("Define screen region for update\n");
185 break;
187 case 0x0021:
188 TRACE("Software reset\n");
189 INT33_ResetMouse( context );
190 break;
192 default:
193 INT_BARF(context,0x33);
197 typedef struct {
198 FARPROC16 proc;
199 WORD mask,but,x,y,mx,my;
200 } MCALLDATA;
202 static void MouseRelay(CONTEXT *context,void *mdata)
204 MCALLDATA *data = mdata;
205 CONTEXT ctx = *context;
207 if (!ISV86(&ctx))
209 ctx.EFlags |= V86_FLAG;
210 ctx.SegSs = 0; /* Allocate new stack. */
213 ctx.Eax = data->mask;
214 ctx.Ebx = data->but;
215 ctx.Ecx = data->x;
216 ctx.Edx = data->y;
217 ctx.Esi = data->mx;
218 ctx.Edi = data->my;
219 ctx.SegCs = SELECTOROF(data->proc);
220 ctx.Eip = OFFSETOF(data->proc);
221 HeapFree(GetProcessHeap(), 0, data);
222 DPMI_CallRMProc(&ctx, NULL, 0, 0);
225 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
227 mouse_info.x = mx;
228 mouse_info.y = my;
230 /* Left button down */
231 if(mask & 0x02) {
232 mouse_info.but |= 0x01;
233 mouse_info.llastx = mx;
234 mouse_info.llasty = my;
235 mouse_info.lbcount++;
238 /* Left button up */
239 if(mask & 0x04) {
240 mouse_info.but &= ~0x01;
243 /* Right button down */
244 if(mask & 0x08) {
245 mouse_info.but |= 0x02;
246 mouse_info.rlastx = mx;
247 mouse_info.rlasty = my;
248 mouse_info.rbcount++;
251 /* Right button up */
252 if(mask & 0x10) {
253 mouse_info.but &= ~0x02;
256 /* Middle button down */
257 if(mask & 0x20) {
258 mouse_info.but |= 0x04;
261 /* Middle button up */
262 if(mask & 0x40) {
263 mouse_info.but &= ~0x04;
266 if ((mask & mouse_info.callmask) && mouse_info.callback) {
267 MCALLDATA *data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MCALLDATA));
268 data->proc = mouse_info.callback;
269 data->mask = mask & mouse_info.callmask;
270 data->but = mouse_info.but;
271 data->x = mouse_info.x;
272 data->y = mouse_info.y;
275 * Fake mickeys.
277 * FIXME: This is not entirely correct. If mouse if moved to the edge
278 * of the screen, mouse will stop moving and mickeys won't
279 * be updated even though they should be.
281 data->mx = mouse_info.x * (mouse_info.HMPratio / 8);
282 data->my = mouse_info.y * (mouse_info.VMPratio / 8);
284 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
288 void DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
290 WORD mask = 0;
291 unsigned Height, Width, SX=1, SY=1;
293 if (!VGA_GetMode(&Height,&Width,NULL)) {
294 /* may need to do some coordinate scaling */
295 if (Width)
296 SX = 640/Width;
297 if (!SX) SX=1;
300 switch (message) {
301 case WM_MOUSEMOVE:
302 mask |= 0x01;
303 break;
304 case WM_LBUTTONDOWN:
305 case WM_LBUTTONDBLCLK:
306 mask |= 0x02;
307 break;
308 case WM_LBUTTONUP:
309 mask |= 0x04;
310 break;
311 case WM_RBUTTONDOWN:
312 case WM_RBUTTONDBLCLK:
313 mask |= 0x08;
314 break;
315 case WM_RBUTTONUP:
316 mask |= 0x10;
317 break;
318 case WM_MBUTTONDOWN:
319 case WM_MBUTTONDBLCLK:
320 mask |= 0x20;
321 break;
322 case WM_MBUTTONUP:
323 mask |= 0x40;
324 break;
327 QueueMouseRelay(LOWORD(lParam) * SX,
328 HIWORD(lParam) * SY,
329 mask);
332 void DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
334 unsigned Height, Width;
335 WORD mask = 0;
336 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
337 BOOL oldLeftButton = mouse_info.but & 0x01;
338 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
339 BOOL oldRightButton = mouse_info.but & 0x02;
340 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
341 BOOL oldMiddleButton = mouse_info.but & 0x04;
343 if(newLeftButton && !oldLeftButton)
344 mask |= 0x02;
345 else if(!newLeftButton && oldLeftButton)
346 mask |= 0x04;
348 if(newRightButton && !oldRightButton)
349 mask |= 0x08;
350 else if(!newRightButton && oldRightButton)
351 mask |= 0x10;
353 if(newMiddleButton && !oldMiddleButton)
354 mask |= 0x20;
355 else if(!newMiddleButton && oldMiddleButton)
356 mask |= 0x40;
358 if (VGA_GetAlphaMode(&Width, &Height))
359 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
360 200 / Height * record->dwMousePosition.Y,
361 mask );