1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1997 Andreas Mohr
6 * 2000 Wolfgang Schwotzer
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/ioctl.h>
39 #include "wine/mmsystem16.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mmsys
);
46 #define MAXJOYSTICK (JOYSTICKID2 + 1)
47 #define JOY_PERIOD_MIN (10) /* min Capture time period */
48 #define JOY_PERIOD_MAX (1000) /* max Capture time period */
50 typedef struct tagWINE_JOYSTICK
{
59 static WINE_JOYSTICK JOY_Sticks
[MAXJOYSTICK
];
61 /**************************************************************************
62 * JOY_LoadDriver [internal]
64 static BOOL
JOY_LoadDriver(DWORD dwJoyID
)
66 if (dwJoyID
>= MAXJOYSTICK
)
68 if (JOY_Sticks
[dwJoyID
].hDriver
)
71 return JOY_Sticks
[dwJoyID
].hDriver
= OpenDriverA("joystick.drv", 0, dwJoyID
);
74 /**************************************************************************
75 * JOY_Timer [internal]
77 static void CALLBACK
JOY_Timer(HWND hWnd
, UINT wMsg
, UINT wTimer
, DWORD dwTime
)
83 unsigned buttonChange
;
85 for (i
= 0; i
< MAXJOYSTICK
; i
++) {
88 if (joy
->hCapture
!= hWnd
) continue;
91 pos
= MAKELONG(ji
.wXpos
, ji
.wYpos
);
94 abs(joy
->ji
.wXpos
- ji
.wXpos
) > joy
->threshold
||
95 abs(joy
->ji
.wYpos
- ji
.wYpos
) > joy
->threshold
) {
96 SendMessageA(joy
->hCapture
, MM_JOY1MOVE
+ i
, ji
.wButtons
, pos
);
97 joy
->ji
.wXpos
= ji
.wXpos
;
98 joy
->ji
.wYpos
= ji
.wYpos
;
100 if (!joy
->bChanged
||
101 abs(joy
->ji
.wZpos
- ji
.wZpos
) > joy
->threshold
) {
102 SendMessageA(joy
->hCapture
, MM_JOY1ZMOVE
+ i
, ji
.wButtons
, pos
);
103 joy
->ji
.wZpos
= ji
.wZpos
;
105 if ((buttonChange
= joy
->ji
.wButtons
^ ji
.wButtons
) != 0) {
106 if (ji
.wButtons
& buttonChange
)
107 SendMessageA(joy
->hCapture
, MM_JOY1BUTTONDOWN
+ i
,
108 (buttonChange
<< 8) | (ji
.wButtons
& buttonChange
), pos
);
109 if (joy
->ji
.wButtons
& buttonChange
)
110 SendMessageA(joy
->hCapture
, MM_JOY1BUTTONUP
+ i
,
111 (buttonChange
<< 8) | (joy
->ji
.wButtons
& buttonChange
), pos
);
112 joy
->ji
.wButtons
= ji
.wButtons
;
117 /**************************************************************************
118 * joyGetNumDevs [WINMM.@]
120 UINT WINAPI
joyGetNumDevs(void)
125 for (i
= 0; i
< MAXJOYSTICK
; i
++) {
126 if (JOY_LoadDriver(i
)) {
127 ret
+= SendDriverMessage(JOY_Sticks
[i
].hDriver
, JDD_GETNUMDEVS
, 0L, 0L);
133 /**************************************************************************
134 * joyGetNumDevs [MMSYSTEM.101]
136 UINT16 WINAPI
joyGetNumDevs16(void)
138 return joyGetNumDevs();
141 /**************************************************************************
142 * joyGetDevCapsA [WINMM.@]
144 MMRESULT WINAPI
joyGetDevCapsA(UINT wID
, LPJOYCAPSA lpCaps
, UINT wSize
)
146 if (wID
>= MAXJOYSTICK
) return JOYERR_PARMS
;
147 if (!JOY_LoadDriver(wID
)) return MMSYSERR_NODRIVER
;
149 lpCaps
->wPeriodMin
= JOY_PERIOD_MIN
; /* FIXME */
150 lpCaps
->wPeriodMax
= JOY_PERIOD_MAX
; /* FIXME (same as MS Joystick Driver) */
152 return SendDriverMessage(JOY_Sticks
[wID
].hDriver
, JDD_GETDEVCAPS
, (DWORD
)lpCaps
, wSize
);
155 /**************************************************************************
156 * joyGetDevCapsW [WINMM.@]
158 MMRESULT WINAPI
joyGetDevCapsW(UINT wID
, LPJOYCAPSW lpCaps
, UINT wSize
)
161 MMRESULT ret
= joyGetDevCapsA(wID
, &jca
, sizeof(jca
));
163 if (ret
!= JOYERR_NOERROR
) return ret
;
164 lpCaps
->wMid
= jca
.wMid
;
165 lpCaps
->wPid
= jca
.wPid
;
166 MultiByteToWideChar( CP_ACP
, 0, jca
.szPname
, -1, lpCaps
->szPname
,
167 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
168 lpCaps
->wXmin
= jca
.wXmin
;
169 lpCaps
->wXmax
= jca
.wXmax
;
170 lpCaps
->wYmin
= jca
.wYmin
;
171 lpCaps
->wYmax
= jca
.wYmax
;
172 lpCaps
->wZmin
= jca
.wZmin
;
173 lpCaps
->wZmax
= jca
.wZmax
;
174 lpCaps
->wNumButtons
= jca
.wNumButtons
;
175 lpCaps
->wPeriodMin
= jca
.wPeriodMin
;
176 lpCaps
->wPeriodMax
= jca
.wPeriodMax
;
178 if (wSize
>= sizeof(JOYCAPSW
)) { /* Win95 extensions ? */
179 lpCaps
->wRmin
= jca
.wRmin
;
180 lpCaps
->wRmax
= jca
.wRmax
;
181 lpCaps
->wUmin
= jca
.wUmin
;
182 lpCaps
->wUmax
= jca
.wUmax
;
183 lpCaps
->wVmin
= jca
.wVmin
;
184 lpCaps
->wVmax
= jca
.wVmax
;
185 lpCaps
->wCaps
= jca
.wCaps
;
186 lpCaps
->wMaxAxes
= jca
.wMaxAxes
;
187 lpCaps
->wNumAxes
= jca
.wNumAxes
;
188 lpCaps
->wMaxButtons
= jca
.wMaxButtons
;
189 MultiByteToWideChar( CP_ACP
, 0, jca
.szRegKey
, -1, lpCaps
->szRegKey
,
190 sizeof(lpCaps
->szRegKey
)/sizeof(WCHAR
) );
191 MultiByteToWideChar( CP_ACP
, 0, jca
.szOEMVxD
, -1, lpCaps
->szOEMVxD
,
192 sizeof(lpCaps
->szOEMVxD
)/sizeof(WCHAR
) );
198 /**************************************************************************
199 * joyGetDevCaps [MMSYSTEM.102]
201 MMRESULT16 WINAPI
joyGetDevCaps16(UINT16 wID
, LPJOYCAPS16 lpCaps
, UINT16 wSize
)
204 MMRESULT ret
= joyGetDevCapsA(wID
, &jca
, sizeof(jca
));
206 if (ret
!= JOYERR_NOERROR
) return ret
;
207 lpCaps
->wMid
= jca
.wMid
;
208 lpCaps
->wPid
= jca
.wPid
;
209 strcpy(lpCaps
->szPname
, jca
.szPname
);
210 lpCaps
->wXmin
= jca
.wXmin
;
211 lpCaps
->wXmax
= jca
.wXmax
;
212 lpCaps
->wYmin
= jca
.wYmin
;
213 lpCaps
->wYmax
= jca
.wYmax
;
214 lpCaps
->wZmin
= jca
.wZmin
;
215 lpCaps
->wZmax
= jca
.wZmax
;
216 lpCaps
->wNumButtons
= jca
.wNumButtons
;
217 lpCaps
->wPeriodMin
= jca
.wPeriodMin
;
218 lpCaps
->wPeriodMax
= jca
.wPeriodMax
;
220 if (wSize
>= sizeof(JOYCAPS16
)) { /* Win95 extensions ? */
221 lpCaps
->wRmin
= jca
.wRmin
;
222 lpCaps
->wRmax
= jca
.wRmax
;
223 lpCaps
->wUmin
= jca
.wUmin
;
224 lpCaps
->wUmax
= jca
.wUmax
;
225 lpCaps
->wVmin
= jca
.wVmin
;
226 lpCaps
->wVmax
= jca
.wVmax
;
227 lpCaps
->wCaps
= jca
.wCaps
;
228 lpCaps
->wMaxAxes
= jca
.wMaxAxes
;
229 lpCaps
->wNumAxes
= jca
.wNumAxes
;
230 lpCaps
->wMaxButtons
= jca
.wMaxButtons
;
231 strcpy(lpCaps
->szRegKey
, jca
.szRegKey
);
232 strcpy(lpCaps
->szOEMVxD
, jca
.szOEMVxD
);
238 /**************************************************************************
239 * joyGetPosEx [WINMM.@]
241 MMRESULT WINAPI
joyGetPosEx(UINT wID
, LPJOYINFOEX lpInfo
)
243 TRACE("(%d, %p);\n", wID
, lpInfo
);
245 if (wID
>= MAXJOYSTICK
) return JOYERR_PARMS
;
246 if (!JOY_LoadDriver(wID
)) return MMSYSERR_NODRIVER
;
254 lpInfo
->dwButtons
= 0;
255 lpInfo
->dwButtonNumber
= 0;
257 lpInfo
->dwReserved1
= 0;
258 lpInfo
->dwReserved2
= 0;
260 return SendDriverMessage(JOY_Sticks
[wID
].hDriver
, JDD_GETPOSEX
, (DWORD
)lpInfo
, 0L);
263 /**************************************************************************
264 * joyGetPosEx [MMSYSTEM.110]
266 MMRESULT16 WINAPI
joyGetPosEx16(UINT16 wID
, LPJOYINFOEX lpInfo
)
268 return joyGetPosEx(wID
, lpInfo
);
271 /**************************************************************************
272 * joyGetPos [WINMM.@]
274 MMRESULT WINAPI
joyGetPos(UINT wID
, LPJOYINFO lpInfo
)
276 TRACE("(%d, %p);\n", wID
, lpInfo
);
278 if (wID
>= MAXJOYSTICK
) return JOYERR_PARMS
;
279 if (!JOY_LoadDriver(wID
)) return MMSYSERR_NODRIVER
;
284 lpInfo
->wButtons
= 0;
286 return SendDriverMessage(JOY_Sticks
[wID
].hDriver
, JDD_GETPOS
, (DWORD
)lpInfo
, 0L);
289 /**************************************************************************
290 * joyGetPos [MMSYSTEM.103]
292 MMRESULT16 WINAPI
joyGetPos16(UINT16 wID
, LPJOYINFO16 lpInfo
)
297 TRACE("(%d, %p);\n", wID
, lpInfo
);
299 if ((ret
= joyGetPos(wID
, &ji
)) == JOYERR_NOERROR
) {
300 lpInfo
->wXpos
= ji
.wXpos
;
301 lpInfo
->wYpos
= ji
.wYpos
;
302 lpInfo
->wZpos
= ji
.wZpos
;
303 lpInfo
->wButtons
= ji
.wButtons
;
308 /**************************************************************************
309 * joyGetThreshold [WINMM.@]
311 MMRESULT WINAPI
joyGetThreshold(UINT wID
, LPUINT lpThreshold
)
313 TRACE("(%04X, %p);\n", wID
, lpThreshold
);
315 if (wID
>= MAXJOYSTICK
) return JOYERR_PARMS
;
317 *lpThreshold
= JOY_Sticks
[wID
].threshold
;
318 return JOYERR_NOERROR
;
321 /**************************************************************************
322 * joyGetThreshold [MMSYSTEM.104]
324 MMRESULT16 WINAPI
joyGetThreshold16(UINT16 wID
, LPUINT16 lpThreshold
)
326 TRACE("(%04X, %p);\n", wID
, lpThreshold
);
328 if (wID
>= MAXJOYSTICK
) return JOYERR_PARMS
;
330 *lpThreshold
= JOY_Sticks
[wID
].threshold
;
331 return JOYERR_NOERROR
;
334 /**************************************************************************
335 * joyReleaseCapture [WINMM.@]
337 MMRESULT WINAPI
joyReleaseCapture(UINT wID
)
339 TRACE("(%04X);\n", wID
);
341 if (wID
>= MAXJOYSTICK
) return JOYERR_PARMS
;
342 if (!JOY_LoadDriver(wID
)) return MMSYSERR_NODRIVER
;
343 if (!JOY_Sticks
[wID
].hCapture
) return JOYERR_NOCANDO
;
345 KillTimer(JOY_Sticks
[wID
].hCapture
, JOY_Sticks
[wID
].wTimer
);
346 JOY_Sticks
[wID
].hCapture
= 0;
347 JOY_Sticks
[wID
].wTimer
= 0;
349 return JOYERR_NOERROR
;
352 /**************************************************************************
353 * joyReleaseCapture [MMSYSTEM.105]
355 MMRESULT16 WINAPI
joyReleaseCapture16(UINT16 wID
)
357 return joyReleaseCapture(wID
);
360 /**************************************************************************
361 * joySetCapture [WINMM.@]
363 MMRESULT WINAPI
joySetCapture(HWND hWnd
, UINT wID
, UINT wPeriod
, BOOL bChanged
)
365 TRACE("(%04X, %04X, %d, %d);\n", hWnd
, wID
, wPeriod
, bChanged
);
367 if (wID
>= MAXJOYSTICK
|| hWnd
== 0) return JOYERR_PARMS
;
368 if (wPeriod
<JOY_PERIOD_MIN
|| wPeriod
>JOY_PERIOD_MAX
) return JOYERR_PARMS
;
369 if (!JOY_LoadDriver(wID
)) return MMSYSERR_NODRIVER
;
371 if (JOY_Sticks
[wID
].hCapture
|| !IsWindow(hWnd
))
372 return JOYERR_NOCANDO
; /* FIXME: what should be returned ? */
374 if (joyGetPos(wID
, &JOY_Sticks
[wID
].ji
) != JOYERR_NOERROR
)
375 return JOYERR_UNPLUGGED
;
377 if ((JOY_Sticks
[wID
].wTimer
= SetTimer(hWnd
, 0, wPeriod
, JOY_Timer
)) == 0)
378 return JOYERR_NOCANDO
;
380 JOY_Sticks
[wID
].hCapture
= hWnd
;
381 JOY_Sticks
[wID
].bChanged
= bChanged
;
383 return JOYERR_NOERROR
;
386 /**************************************************************************
387 * joySetCapture [MMSYSTEM.106]
389 MMRESULT16 WINAPI
joySetCapture16(HWND16 hWnd
, UINT16 wID
, UINT16 wPeriod
, BOOL16 bChanged
)
391 return joySetCapture16(hWnd
, wID
, wPeriod
, bChanged
);
394 /**************************************************************************
395 * joySetThreshold [WINMM.@]
397 MMRESULT WINAPI
joySetThreshold(UINT wID
, UINT wThreshold
)
399 TRACE("(%04X, %d);\n", wID
, wThreshold
);
401 if (wID
>= MAXJOYSTICK
) return MMSYSERR_INVALPARAM
;
403 JOY_Sticks
[wID
].threshold
= wThreshold
;
405 return JOYERR_NOERROR
;
408 /**************************************************************************
409 * joySetThreshold [MMSYSTEM.107]
411 MMRESULT16 WINAPI
joySetThreshold16(UINT16 wID
, UINT16 wThreshold
)
413 return joySetThreshold16(wID
,wThreshold
);
416 /**************************************************************************
417 * joySetCalibration [MMSYSTEM.109]
419 MMRESULT16 WINAPI
joySetCalibration16(UINT16 wID
)
421 FIXME("(%04X): stub.\n", wID
);
422 return JOYERR_NOCANDO
;