4 * Copyright 1997 Andreas Mohr
6 * nearly all joystick functions can be regarded as obsolete,
7 * as Linux (2.1.x) now supports extended joysticks
8 * with a completely new joystick driver interface
9 * new driver's docu says:
10 * "For backward compatibility the old interface is still included,
11 * but will be dropped in the future."
12 * Thus we should implement the new interface and at most keep the old
13 * routines for backward compatibility.
21 #include <sys/ioctl.h>
22 #include <sys/errno.h>
30 #define MAXJOYDRIVERS 4
32 static int count_use[MAXJOYDRIVERS] = {0, 0, 0, 0};
34 static int joy_nr_open = 0;
35 static BOOL16 joyCaptured = FALSE;
36 static HWND16 CaptureWnd[MAXJOYDRIVERS] = {0, 0};
37 static int joy_dev[MAXJOYDRIVERS] = {-1, -1,-1,-1};
38 static JOYINFO16 joyCapData[MAXJOYDRIVERS];
39 static unsigned int joy_threshold[MAXJOYDRIVERS] = {0, 0, 0, 0};
49 /**************************************************************************
50 * joyOpenDriver [internal]
52 BOOL16 joyOpenDriver(WORD wID)
54 char dev_name[] = "/dev/js%d";
57 if (joy_dev[wID] >= 0) return TRUE;
58 sprintf(buf,dev_name,wID);
59 if ((joy_dev[wID] = open(buf, O_RDONLY)) >= 0) {
66 /**************************************************************************
67 * joyCloseDriver [internal]
69 void joyCloseDriver(WORD wID)
71 if (joy_dev[wID] >= 0) {
78 /**************************************************************************
79 * joySendMessages [internal]
81 void joySendMessages(void)
87 for (joy=0; joy < MAXJOYDRIVERS; joy++)
88 if (joy_dev[joy] >= 0) {
89 if (count_use[joy] > 250) {
96 if (joyCaptured == FALSE) return;
98 TRACE(mmsys, " --\n");
100 for (joy=0; joy < MAXJOYDRIVERS; joy++) {
101 if (joyOpenDriver(joy) == FALSE) continue;
102 dev_stat = read(joy_dev[joy], &js, sizeof(js));
103 if (dev_stat == sizeof(js)) {
106 if ((joyCapData[joy].wXpos != js.x) || (joyCapData[joy].wYpos != js.y)) {
107 SendMessage32A(CaptureWnd[joy], MM_JOY1MOVE + joy, js.buttons, MAKELONG(js.x, js.y));
108 joyCapData[joy].wXpos = js.x;
109 joyCapData[joy].wYpos = js.y;
111 if (joyCapData[joy].wButtons != js.buttons) {
112 unsigned int ButtonChanged = (WORD)(joyCapData[joy].wButtons ^ js.buttons)<<8;
113 if (joyCapData[joy].wButtons < js.buttons)
114 SendMessage32A(CaptureWnd[joy], MM_JOY1BUTTONDOWN + joy, ButtonChanged, MAKELONG(js.x, js.y));
116 if (joyCapData[joy].wButtons > js.buttons)
117 SendMessage32A(CaptureWnd[joy], MM_JOY1BUTTONUP
118 + joy, ButtonChanged, MAKELONG(js.x, js.y));
119 joyCapData[joy].wButtons = js.buttons;
126 /**************************************************************************
127 * JoyGetNumDevs [MMSYSTEM.101]
129 UINT32 WINAPI joyGetNumDevs32(void)
131 return joyGetNumDevs16();
134 /**************************************************************************
135 * JoyGetNumDevs [MMSYSTEM.101]
137 UINT16 WINAPI joyGetNumDevs16(void)
142 for (joy=0; joy<MAXJOYDRIVERS; joy++)
143 if (joyOpenDriver(joy) == TRUE) {
147 TRACE(mmsys, "returning %d\n", joy_cnt);
148 if (!joy_cnt) ERR(mmsys, "No joystick found - "
149 "perhaps get joystick-0.8.0.tar.gz and load"
150 "it as module or use Linux >= 2.1.45 to be "
151 "able to use joysticks.\n");
155 /**************************************************************************
156 * JoyGetDevCaps [WINMM.27]
158 MMRESULT32 WINAPI joyGetDevCaps32A(UINT32 wID, LPJOYCAPS32A lpCaps,UINT32 wSize)
161 MMRESULT16 ret = joyGetDevCaps16(wID,&jc16,sizeof(jc16));
163 lpCaps->wMid = jc16.wMid;
164 lpCaps->wPid = jc16.wPid;
165 lstrcpy32A(lpCaps->szPname,jc16.szPname);
166 lpCaps->wXmin = jc16.wXmin;
167 lpCaps->wXmax = jc16.wXmax;
168 lpCaps->wYmin = jc16.wYmin;
169 lpCaps->wYmax = jc16.wYmax;
170 lpCaps->wZmin = jc16.wZmin;
171 lpCaps->wZmax = jc16.wZmax;
172 lpCaps->wNumButtons = jc16.wNumButtons;
173 lpCaps->wPeriodMin = jc16.wPeriodMin;
174 lpCaps->wPeriodMax = jc16.wPeriodMax;
176 lpCaps->wRmin = jc16.wRmin;
177 lpCaps->wRmax = jc16.wRmax;
178 lpCaps->wUmin = jc16.wUmin;
179 lpCaps->wUmax = jc16.wUmax;
180 lpCaps->wVmin = jc16.wVmin;
181 lpCaps->wVmax = jc16.wVmax;
182 lpCaps->wCaps = jc16.wCaps;
183 lpCaps->wMaxAxes = jc16.wMaxAxes;
184 lpCaps->wNumAxes = jc16.wNumAxes;
185 lpCaps->wMaxButtons = jc16.wMaxButtons;
186 lstrcpy32A(lpCaps->szRegKey,jc16.szRegKey);
187 lstrcpy32A(lpCaps->szOEMVxD,jc16.szOEMVxD);
191 /**************************************************************************
192 * JoyGetDevCaps [WINMM.28]
194 MMRESULT32 WINAPI joyGetDevCaps32W(UINT32 wID, LPJOYCAPS32W lpCaps,UINT32 wSize)
197 MMRESULT16 ret = joyGetDevCaps16(wID,&jc16,sizeof(jc16));
199 lpCaps->wMid = jc16.wMid;
200 lpCaps->wPid = jc16.wPid;
201 lstrcpyAtoW(lpCaps->szPname,jc16.szPname);
202 lpCaps->wXmin = jc16.wXmin;
203 lpCaps->wXmax = jc16.wXmax;
204 lpCaps->wYmin = jc16.wYmin;
205 lpCaps->wYmax = jc16.wYmax;
206 lpCaps->wZmin = jc16.wZmin;
207 lpCaps->wZmax = jc16.wZmax;
208 lpCaps->wNumButtons = jc16.wNumButtons;
209 lpCaps->wPeriodMin = jc16.wPeriodMin;
210 lpCaps->wPeriodMax = jc16.wPeriodMax;
212 lpCaps->wRmin = jc16.wRmin;
213 lpCaps->wRmax = jc16.wRmax;
214 lpCaps->wUmin = jc16.wUmin;
215 lpCaps->wUmax = jc16.wUmax;
216 lpCaps->wVmin = jc16.wVmin;
217 lpCaps->wVmax = jc16.wVmax;
218 lpCaps->wCaps = jc16.wCaps;
219 lpCaps->wMaxAxes = jc16.wMaxAxes;
220 lpCaps->wNumAxes = jc16.wNumAxes;
221 lpCaps->wMaxButtons = jc16.wMaxButtons;
222 lstrcpyAtoW(lpCaps->szRegKey,jc16.szRegKey);
223 lstrcpyAtoW(lpCaps->szOEMVxD,jc16.szOEMVxD);
226 /**************************************************************************
227 * JoyGetDevCaps [MMSYSTEM.102]
229 MMRESULT16 WINAPI joyGetDevCaps16(UINT16 wID, LPJOYCAPS16 lpCaps, UINT16 wSize)
231 TRACE(mmsys, "(%04X, %p, %d);\n",
233 if (joyOpenDriver(wID) == TRUE) {
234 lpCaps->wMid = MM_MICROSOFT;
235 lpCaps->wPid = MM_PC_JOYSTICK;
236 strcpy(lpCaps->szPname, "WineJoy"); /* joystick product name */
237 lpCaps->wXmin = 0; /* FIXME */
238 lpCaps->wXmax = 0xffff;
240 lpCaps->wYmax = 0xffff;
242 lpCaps->wZmax = 0xffff;
243 lpCaps->wNumButtons = 2;
244 lpCaps->wPeriodMin = 0;
245 lpCaps->wPeriodMax = 50; /* FIXME end */
246 if (wSize == sizeof(JOYCAPS16)) {
247 /* complete 95 structure */
249 lpCaps->wRmax = 0xffff;
251 lpCaps->wUmax = 0xffff;
253 lpCaps->wVmax = 0xffff;
255 lpCaps->wMaxAxes = 6;
256 lpCaps->wNumAxes = 2;
257 lpCaps->wMaxButtons = 3;
258 strcpy(lpCaps->szRegKey,"");
259 strcpy(lpCaps->szOEMVxD,"");
262 return JOYERR_NOERROR;
265 return MMSYSERR_NODRIVER;
268 /**************************************************************************
269 * JoyGetPosEx [WINMM.31]
271 MMRESULT32 WINAPI joyGetPosEx(UINT32 wID, LPJOYINFOEX lpInfo)
273 /* FIXME: implement it */
274 return MMSYSERR_NODRIVER;
277 /**************************************************************************
278 * JoyGetPos [WINMM.30]
280 MMRESULT32 WINAPI joyGetPos32(UINT32 wID, LPJOYINFO32 lpInfo)
283 MMRESULT16 ret = joyGetPos16(wID,&ji);
285 lpInfo->wXpos = ji.wXpos;
286 lpInfo->wYpos = ji.wYpos;
287 lpInfo->wZpos = ji.wZpos;
288 lpInfo->wButtons = ji.wButtons;
292 /**************************************************************************
293 * JoyGetPos [MMSYSTEM.103]
295 MMRESULT16 WINAPI joyGetPos16(UINT16 wID, LPJOYINFO16 lpInfo)
299 TRACE(mmsys, "(%04X, %p)\n", wID, lpInfo);
300 if (joyOpenDriver(wID) == FALSE) return MMSYSERR_NODRIVER;
301 dev_stat = read(joy_dev[wID], &js, sizeof(js));
302 if (dev_stat != sizeof(js)) {
304 return JOYERR_UNPLUGGED; /* FIXME: perhaps wrong, but what should I return else ? */
309 lpInfo->wXpos = js.x; /* FIXME: perhaps multiply it somehow ? */
310 lpInfo->wYpos = js.y;
311 lpInfo->wZpos = 0; /* FIXME: Don't know what to do with this value as joystick driver doesn't provide a Z value */
312 lpInfo->wButtons = js.buttons;
313 TRACE(mmsys, "x: %d, y: %d, buttons: %d\n", js.x, js.y, js.buttons);
314 return JOYERR_NOERROR;
317 /**************************************************************************
318 * JoyGetThreshold [WINMM.32]
320 MMRESULT32 WINAPI joyGetThreshold32(UINT32 wID, LPUINT32 lpThreshold)
323 MMRESULT16 ret = joyGetThreshold16(wID,&thresh);
325 *lpThreshold = thresh;
329 /**************************************************************************
330 * JoyGetThreshold [MMSYSTEM.104]
332 MMRESULT16 WINAPI joyGetThreshold16(UINT16 wID, LPUINT16 lpThreshold)
334 TRACE(mmsys, "(%04X, %p);\n", wID, lpThreshold);
335 if (wID >= MAXJOYDRIVERS) return JOYERR_PARMS;
336 *lpThreshold = joy_threshold[wID];
337 return JOYERR_NOERROR;
340 /**************************************************************************
341 * JoyReleaseCapture [WINMM.33]
343 MMRESULT32 WINAPI joyReleaseCapture32(UINT32 wID)
345 return joyReleaseCapture16(wID);
348 /**************************************************************************
349 * JoyReleaseCapture [MMSYSTEM.105]
351 MMRESULT16 WINAPI joyReleaseCapture16(UINT16 wID)
353 TRACE(mmsys, "(%04X);\n", wID);
358 return JOYERR_NOERROR;
361 /**************************************************************************
362 * JoySetCapture [MMSYSTEM.106]
364 MMRESULT32 WINAPI joySetCapture32(HWND32 hWnd,UINT32 wID,UINT32 wPeriod,BOOL32 bChanged)
366 return joySetCapture16(hWnd,wID,wPeriod,bChanged);
369 /**************************************************************************
370 * JoySetCapture [MMSYSTEM.106]
372 MMRESULT16 WINAPI joySetCapture16(HWND16 hWnd,UINT16 wID,UINT16 wPeriod,BOOL16 bChanged)
375 TRACE(mmsys, "(%04X, %04X, %d, %d);\n",
376 hWnd, wID, wPeriod, bChanged);
378 if (!CaptureWnd[wID]) {
379 if (joyOpenDriver(wID) == FALSE) return MMSYSERR_NODRIVER;
381 CaptureWnd[wID] = hWnd;
382 return JOYERR_NOERROR;
385 return JOYERR_NOCANDO; /* FIXME: what should be returned ? */
388 /**************************************************************************
389 * JoySetThreshold [WINMM.35]
391 MMRESULT32 WINAPI joySetThreshold32(UINT32 wID, UINT32 wThreshold)
393 return joySetThreshold16(wID,wThreshold);
395 /**************************************************************************
396 * JoySetThreshold [MMSYSTEM.107]
398 MMRESULT16 WINAPI joySetThreshold16(UINT16 wID, UINT16 wThreshold)
400 TRACE(mmsys, "(%04X, %d);\n", wID, wThreshold);
402 if (wID > 3) return JOYERR_PARMS;
403 joy_threshold[wID] = wThreshold;
404 return JOYERR_NOERROR;
407 /**************************************************************************
408 * JoySetCalibration [MMSYSTEM.109]
410 MMRESULT16 WINAPI joySetCalibration16(UINT16 wID)
412 FIXME(mmsys, "(%04X): stub.\n", wID);
413 return JOYERR_NOCANDO;