int33 21h is identical to int33 00h.
[wine/multimedia.git] / dlls / winedos / int33.c
blob55264535d71479d17a06c1bfb03be678781ebbfa
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 case 0x21:
54 TRACE("Reset mouse driver and request status\n");
55 SET_AX( context, 0xFFFF ); /* installed */
56 SET_BX( context, 3 ); /* # of buttons */
57 memset( &mouse_info, 0, sizeof(mouse_info) );
58 /* Set the default mickey/pixel ratio */
59 mouse_info.HMPratio = 8;
60 mouse_info.VMPratio = 16;
61 break;
62 case 0x01:
63 FIXME("Show mouse cursor\n");
64 break;
65 case 0x02:
66 FIXME("Hide mouse cursor\n");
67 break;
68 case 0x03:
69 TRACE("Return mouse position and button status: (%ld,%ld) and %ld\n",
70 mouse_info.x, mouse_info.y, mouse_info.but);
71 SET_BX( context, mouse_info.but );
72 SET_CX( context, mouse_info.x );
73 SET_DX( context, mouse_info.y );
74 break;
75 case 0x04:
76 FIXME("Position mouse cursor\n");
77 break;
78 case 0x05:
79 TRACE("Return Mouse button press Information for %s mouse button\n",
80 BX_reg(context) ? "right" : "left");
81 if (BX_reg(context)) {
82 SET_BX( context, mouse_info.rbcount );
83 mouse_info.rbcount = 0;
84 SET_CX( context, mouse_info.rlastx );
85 SET_DX( context, mouse_info.rlasty );
86 } else {
87 SET_BX( context, mouse_info.lbcount );
88 mouse_info.lbcount = 0;
89 SET_CX( context, mouse_info.llastx );
90 SET_DX( context, mouse_info.llasty );
92 SET_AX( context, mouse_info.but );
93 break;
94 case 0x07:
95 FIXME("Define horizontal mouse cursor range %d..%d\n",
96 CX_reg(context), DX_reg(context));
97 break;
98 case 0x08:
99 FIXME("Define vertical mouse cursor range %d..%d\n",
100 CX_reg(context), DX_reg(context));
101 break;
102 case 0x09:
103 FIXME("Define graphics mouse cursor\n");
104 break;
105 case 0x0A:
106 FIXME("Define text mouse cursor\n");
107 break;
108 case 0x0B:
109 TRACE("Read Mouse motion counters\n");
110 SET_CX( context, (mouse_info.x - mouse_info.oldx) * (mouse_info.HMPratio / 8) );
111 SET_DX( context, (mouse_info.y - mouse_info.oldy) * (mouse_info.VMPratio / 8) );
112 mouse_info.oldx = mouse_info.x;
113 mouse_info.oldy = mouse_info.y;
114 break;
115 case 0x0C:
116 TRACE("Define mouse interrupt subroutine\n");
117 mouse_info.callmask = CX_reg(context);
118 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs, LOWORD(context->Edx));
119 break;
120 case 0x0F:
121 TRACE("Set mickey/pixel ratio\n");
122 mouse_info.HMPratio = CX_reg(context);
123 mouse_info.VMPratio = DX_reg(context);
124 break;
125 case 0x10:
126 FIXME("Define screen region for update\n");
127 break;
128 default:
129 INT_BARF(context,0x33);
133 typedef struct {
134 FARPROC16 proc;
135 WORD mask,but,x,y,mx,my;
136 } MCALLDATA;
138 static void MouseRelay(CONTEXT86 *context,void *mdata)
140 MCALLDATA *data = (MCALLDATA *)mdata;
141 CONTEXT86 ctx = *context;
143 if (!ISV86(&ctx))
145 ctx.EFlags |= V86_FLAG;
146 ctx.SegSs = 0; /* Allocate new stack. */
149 ctx.Eax = data->mask;
150 ctx.Ebx = data->but;
151 ctx.Ecx = data->x;
152 ctx.Edx = data->y;
153 ctx.Esi = data->mx;
154 ctx.Edi = data->my;
155 ctx.SegCs = SELECTOROF(data->proc);
156 ctx.Eip = OFFSETOF(data->proc);
157 free(data);
158 DPMI_CallRMProc(&ctx, NULL, 0, 0);
161 static void QueueMouseRelay(DWORD mx, DWORD my, WORD mask)
163 mouse_info.x = mx;
164 mouse_info.y = my;
166 /* Left button down */
167 if(mask & 0x02) {
168 mouse_info.but |= 0x01;
169 mouse_info.llastx = mx;
170 mouse_info.llasty = my;
171 mouse_info.lbcount++;
174 /* Left button up */
175 if(mask & 0x04) {
176 mouse_info.but &= ~0x01;
179 /* Right button down */
180 if(mask & 0x08) {
181 mouse_info.but |= 0x02;
182 mouse_info.rlastx = mx;
183 mouse_info.rlasty = my;
184 mouse_info.rbcount++;
187 /* Right button up */
188 if(mask & 0x10) {
189 mouse_info.but &= ~0x02;
192 /* Middle button down */
193 if(mask & 0x20) {
194 mouse_info.but |= 0x04;
197 /* Middle button up */
198 if(mask & 0x40) {
199 mouse_info.but &= ~0x04;
202 if ((mask & mouse_info.callmask) && mouse_info.callback) {
203 MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
204 data->proc = mouse_info.callback;
205 data->mask = mask & mouse_info.callmask;
206 data->but = mouse_info.but;
207 data->x = mouse_info.x;
208 data->y = mouse_info.y;
211 * Fake mickeys.
213 * FIXME: This is not entirely correct. If mouse if moved to the edge
214 * of the screen, mouse will stop moving and mickeys won't
215 * be updated even though they should be.
217 data->mx = mouse_info.x * (mouse_info.HMPratio / 8);
218 data->my = mouse_info.y * (mouse_info.VMPratio / 8);
220 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
224 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
226 WORD mask = 0;
227 unsigned Height, Width, SX=1, SY=1;
229 if (!VGA_GetMode(&Height,&Width,NULL)) {
230 /* may need to do some coordinate scaling */
231 if (Width)
232 SX = 640/Width;
233 if (!SX) SX=1;
236 switch (message) {
237 case WM_MOUSEMOVE:
238 mask |= 0x01;
239 break;
240 case WM_LBUTTONDOWN:
241 case WM_LBUTTONDBLCLK:
242 mask |= 0x02;
243 break;
244 case WM_LBUTTONUP:
245 mask |= 0x04;
246 break;
247 case WM_RBUTTONDOWN:
248 case WM_RBUTTONDBLCLK:
249 mask |= 0x08;
250 break;
251 case WM_RBUTTONUP:
252 mask |= 0x10;
253 break;
254 case WM_MBUTTONDOWN:
255 case WM_MBUTTONDBLCLK:
256 mask |= 0x20;
257 break;
258 case WM_MBUTTONUP:
259 mask |= 0x40;
260 break;
263 QueueMouseRelay(LOWORD(lParam) * SX,
264 HIWORD(lParam) * SY,
265 mask);
268 void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD *record)
270 unsigned Height, Width;
271 WORD mask = 0;
272 BOOL newLeftButton = record->dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED;
273 BOOL oldLeftButton = mouse_info.but & 0x01;
274 BOOL newRightButton = record->dwButtonState & RIGHTMOST_BUTTON_PRESSED;
275 BOOL oldRightButton = mouse_info.but & 0x02;
276 BOOL newMiddleButton = record->dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED;
277 BOOL oldMiddleButton = mouse_info.but & 0x04;
279 if(newLeftButton && !oldLeftButton)
280 mask |= 0x02;
281 else if(!newLeftButton && oldLeftButton)
282 mask |= 0x04;
284 if(newRightButton && !oldRightButton)
285 mask |= 0x08;
286 else if(!newRightButton && oldRightButton)
287 mask |= 0x10;
289 if(newMiddleButton && !oldMiddleButton)
290 mask |= 0x20;
291 else if(!newMiddleButton && oldMiddleButton)
292 mask |= 0x40;
294 if (VGA_GetAlphaMode(&Width, &Height))
295 QueueMouseRelay( 640 / Width * record->dwMousePosition.X,
296 200 / Height * record->dwMousePosition.Y,
297 mask );