Added a first-cut version of MapVirtualKeyExW() that has the same
[wine] / msdos / int33.c
1 /*
2  * DOS interrupt 33h handler
3  */
4
5 #include <stdlib.h>
6 #include "windef.h"
7 #include "wingdi.h"
8 #include "winuser.h"
9 #include "miscemu.h"
10 #include "dosexe.h"
11 #include "vga.h"
12 #include "debugtools.h"
13
14 DEFAULT_DEBUG_CHANNEL(int);
15
16 static struct
17 {
18   DWORD x, y, but;
19   FARPROC16 callback;
20   WORD callmask;
21 } mouse_info;
22
23 /**********************************************************************
24  *          INT_Int33Handler
25  *
26  * Handler for int 33h (MS MOUSE).
27  */
28 void WINAPI INT_Int33Handler( CONTEXT86 *context )
29 {
30   switch (LOWORD(context->Eax)) {
31   case 0x00:
32     TRACE("Reset mouse driver and request status\n");
33     AX_reg(context) = 0xFFFF; /* installed */
34     BX_reg(context) = 3;      /* # of buttons */
35     memset( &mouse_info, 0, sizeof(mouse_info) );
36     break;
37   case 0x01:
38     FIXME("Show mouse cursor\n");
39     break;
40   case 0x02:
41     FIXME("Hide mouse cursor\n");
42     break;
43   case 0x03:
44     TRACE("Return mouse position and button status\n");
45     BX_reg(context) = mouse_info.but;
46     CX_reg(context) = mouse_info.x;
47     DX_reg(context) = mouse_info.y;
48     break;
49   case 0x04:
50     FIXME("Position mouse cursor\n");
51     break;
52   case 0x07:
53     FIXME("Define horizontal mouse cursor range\n");
54     break;
55   case 0x08:
56     FIXME("Define vertical mouse cursor range\n");
57     break;
58   case 0x09:
59     FIXME("Define graphics mouse cursor\n");
60     break;
61   case 0x0A:
62     FIXME("Define text mouse cursor\n");
63     break;
64   case 0x0C:
65     TRACE("Define mouse interrupt subroutine\n");
66     mouse_info.callmask = CX_reg(context);
67     mouse_info.callback = (FARPROC16)PTR_SEG_OFF_TO_SEGPTR(context->SegEs, LOWORD(context->Edx));
68     break;
69   case 0x10:
70     FIXME("Define screen region for update\n");
71     break;
72   default:
73     INT_BARF(context,0x33);
74   }
75 }
76
77 typedef struct {
78   FARPROC16 proc;
79   WORD mask,but,x,y,mx,my;
80 } MCALLDATA;
81
82 static void MouseRelay(CONTEXT86 *context,void *mdata)
83 {
84   MCALLDATA *data = (MCALLDATA *)mdata;
85   CONTEXT86 ctx = *context;
86
87   ctx.Eax   = data->mask;
88   ctx.Ebx   = data->but;
89   ctx.Ecx   = data->x;
90   ctx.Edx   = data->y;
91   ctx.Esi   = data->mx;
92   ctx.Edi   = data->my;
93   ctx.SegCs = SELECTOROF(data->proc);
94   ctx.Eip   = OFFSETOF(data->proc);
95   free(data);
96   DPMI_CallRMProc(&ctx, NULL, 0, 0);
97 }
98
99 void WINAPI INT_Int33Message(UINT message,WPARAM wParam,LPARAM lParam)
100 {
101   WORD mask = 0;
102   unsigned Height, Width, SX=1, SY=1;
103
104   if (!VGA_GetMode(&Height,&Width,NULL)) {
105     /* may need to do some coordinate scaling */
106     SX = 640/Width;
107     if (!SX) SX=1;
108   }
109   mouse_info.x = LOWORD(lParam) * SX;
110   mouse_info.y = HIWORD(lParam) * SY;
111   switch (message) {
112   case WM_MOUSEMOVE:
113     mask |= 0x01;
114     break;
115   case WM_LBUTTONDOWN:
116   case WM_LBUTTONDBLCLK:
117     mouse_info.but |= 0x01;
118     mask |= 0x02;
119     break;
120   case WM_LBUTTONUP:
121     mouse_info.but &= ~0x01;
122     mask |= 0x04;
123     break;
124   case WM_RBUTTONDOWN:
125   case WM_RBUTTONDBLCLK:
126     mouse_info.but |= 0x02;
127     mask |= 0x08;
128     break;
129   case WM_RBUTTONUP:
130     mouse_info.but &= ~0x02;
131     mask |= 0x10;
132     break;
133   case WM_MBUTTONDOWN:
134   case WM_MBUTTONDBLCLK:
135     mouse_info.but |= 0x04;
136     mask |= 0x20;
137     break;
138   case WM_MBUTTONUP:
139     mouse_info.but &= ~0x04;
140     mask |= 0x40;
141     break;
142   }
143
144   if ((mask & mouse_info.callmask) && mouse_info.callback) {
145     MCALLDATA *data = calloc(1,sizeof(MCALLDATA));
146     data->proc = mouse_info.callback;
147     data->mask = mask & mouse_info.callmask;
148     data->but = mouse_info.but;
149     data->x = mouse_info.x;
150     data->y = mouse_info.y;
151     DOSVM_QueueEvent(-1, DOS_PRIORITY_MOUSE, MouseRelay, data);
152   }
153 }