Implement function number 0x5 (Return mouse button press information).
[wine/testsucceed.git] / dlls / winedos / int33.c
blobf97ebbc296d461be38ba2d0635d9f7425474bb95
1 /*
2 * DOS interrupt 33h handler
3 */
5 #include <stdlib.h>
6 #include <string.h>
8 #include "windef.h"
9 #include "winbase.h"
10 #include "wingdi.h"
11 #include "winuser.h"
12 #include "miscemu.h"
13 #include "dosexe.h"
14 #include "vga.h"
15 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(int);
19 static struct
21 DWORD x, y, but;
22 WORD lbcount, rbcount, rlastx, rlasty, llastx, llasty;
23 FARPROC16 callback;
24 WORD callmask;
25 } mouse_info;
27 /**********************************************************************
28 * DOSVM_Int33Handler
30 * Handler for int 33h (MS MOUSE).
32 void WINAPI DOSVM_Int33Handler( CONTEXT86 *context )
34 switch (LOWORD(context->Eax)) {
35 case 0x00:
36 TRACE("Reset mouse driver and request status\n");
37 AX_reg(context) = 0xFFFF; /* installed */
38 BX_reg(context) = 3; /* # of buttons */
39 memset( &mouse_info, 0, sizeof(mouse_info) );
40 break;
41 case 0x01:
42 FIXME("Show mouse cursor\n");
43 break;
44 case 0x02:
45 FIXME("Hide mouse cursor\n");
46 break;
47 case 0x03:
48 TRACE("Return mouse position and button status\n");
49 BX_reg(context) = mouse_info.but;
50 CX_reg(context) = mouse_info.x;
51 DX_reg(context) = mouse_info.y;
52 break;
53 case 0x04:
54 FIXME("Position mouse cursor\n");
55 break;
56 case 0x05:
57 TRACE("Return Mouse button press Information for %s mouse button\n",
58 BX_reg(context) ? "right" : "left");
59 if (BX_reg(context)) {
60 BX_reg(context) = mouse_info.rbcount;
61 mouse_info.rbcount = 0;
62 CX_reg(context) = mouse_info.rlastx;
63 DX_reg(context) = mouse_info.rlasty;
64 } else {
65 BX_reg(context) = mouse_info.lbcount;
66 mouse_info.lbcount = 0;
67 CX_reg(context) = mouse_info.llastx;
68 DX_reg(context) = mouse_info.llasty;
70 AX_reg(context) = mouse_info.but;
71 break;
72 case 0x07:
73 FIXME("Define horizontal mouse cursor range\n");
74 break;
75 case 0x08:
76 FIXME("Define vertical mouse cursor range\n");
77 break;
78 case 0x09:
79 FIXME("Define graphics mouse cursor\n");
80 break;
81 case 0x0A:
82 FIXME("Define text mouse cursor\n");
83 break;
84 case 0x0C:
85 TRACE("Define mouse interrupt subroutine\n");
86 mouse_info.callmask = CX_reg(context);
87 mouse_info.callback = (FARPROC16)MAKESEGPTR(context->SegEs, LOWORD(context->Edx));
88 break;
89 case 0x10:
90 FIXME("Define screen region for update\n");
91 break;
92 default:
93 INT_BARF(context,0x33);
97 typedef struct {
98 FARPROC16 proc;
99 WORD mask,but,x,y,mx,my;
100 } MCALLDATA;
102 static void MouseRelay(CONTEXT86 *context,void *mdata)
104 MCALLDATA *data = (MCALLDATA *)mdata;
105 CONTEXT86 ctx = *context;
107 ctx.Eax = data->mask;
108 ctx.Ebx = data->but;
109 ctx.Ecx = data->x;
110 ctx.Edx = data->y;
111 ctx.Esi = data->mx;
112 ctx.Edi = data->my;
113 ctx.SegCs = SELECTOROF(data->proc);
114 ctx.Eip = OFFSETOF(data->proc);
115 free(data);
116 DPMI_CallRMProc(&ctx, NULL, 0, 0);
119 void WINAPI DOSVM_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
121 WORD mask = 0;
122 unsigned Height, Width, SX=1, SY=1;
124 if (!VGA_GetMode(&Height,&Width,NULL)) {
125 /* may need to do some coordinate scaling */
126 if (Width)
127 SX = 640/Width;
128 if (!SX) SX=1;
130 mouse_info.x = LOWORD(lParam) * SX;
131 mouse_info.y = HIWORD(lParam) * SY;
132 switch (message) {
133 case WM_MOUSEMOVE:
134 mask |= 0x01;
135 break;
136 case WM_LBUTTONDOWN:
137 case WM_LBUTTONDBLCLK:
138 mouse_info.but |= 0x01;
139 mask |= 0x02;
140 mouse_info.llastx = mouse_info.x;
141 mouse_info.llasty = mouse_info.y;
142 mouse_info.lbcount++;
143 break;
144 case WM_LBUTTONUP:
145 mouse_info.but &= ~0x01;
146 mask |= 0x04;
147 break;
148 case WM_RBUTTONDOWN:
149 case WM_RBUTTONDBLCLK:
150 mouse_info.but |= 0x02;
151 mask |= 0x08;
152 mouse_info.rlastx = mouse_info.x;
153 mouse_info.rlasty = mouse_info.y;
154 mouse_info.rbcount++;
155 break;
156 case WM_RBUTTONUP:
157 mouse_info.but &= ~0x02;
158 mask |= 0x10;
159 break;
160 case WM_MBUTTONDOWN:
161 case WM_MBUTTONDBLCLK:
162 mouse_info.but |= 0x04;
163 mask |= 0x20;
164 break;
165 case WM_MBUTTONUP:
166 mouse_info.but &= ~0x04;
167 mask |= 0x40;
168 break;
171 if ((mask & mouse_info.callmask) && mouse_info.callback) {
172 MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
173 data->proc = mouse_info.callback;
174 data->mask = mask & mouse_info.callmask;
175 data->but = mouse_info.but;
176 data->x = mouse_info.x;
177 data->y = mouse_info.y;
178 DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);