1 /* DirectInput Joystick device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/port.h"
31 #ifdef HAVE_LINUX_22_JOYSTICK_API
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
44 #include <sys/fcntl.h>
45 #ifdef HAVE_SYS_IOCTL_H
46 # include <sys/ioctl.h>
49 #ifdef HAVE_SYS_ERRNO_H
50 # include <sys/errno.h>
52 #ifdef HAVE_LINUX_IOCTL_H
53 # include <linux/ioctl.h>
55 #ifdef HAVE_LINUX_JOYSTICK_H
56 # include <linux/joystick.h>
58 #define JOYDEV "/dev/js"
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
68 #include "dinput_private.h"
69 #include "device_private.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
85 typedef struct JoystickImpl JoystickImpl;
86 static IDirectInputDevice8AVtbl JoystickAvt;
87 static IDirectInputDevice8WVtbl JoystickWvt;
95 /* The 'parent' DInput */
96 IDirectInputImpl *dinput;
98 /* joystick private */
100 DIJOYSTATE2 js; /* wine data */
101 LPDIDATAFORMAT user_df; /* user defined format */
102 DataFormat *transform; /* wine to user format converter */
103 int *offsets; /* object offsets */
106 LPDIDEVICEOBJECTDATA data_queue;
107 int queue_head, queue_tail, queue_len;
116 CRITICAL_SECTION crit;
120 static GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
124 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
127 static void _dump_DIDEVCAPS(LPDIDEVCAPS lpDIDevCaps)
129 TRACE("dwSize: %ld\n", lpDIDevCaps->dwSize);
130 TRACE("dwFlags: %08lx\n",lpDIDevCaps->dwFlags);
131 TRACE("dwDevType: %08lx %s\n", lpDIDevCaps->dwDevType,
132 lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
133 lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
134 lpDIDevCaps->dwDevType == DIDEVTYPE_MOUSE ? "DIDEVTYPE_MOUSE" :
135 lpDIDevCaps->dwDevType == DIDEVTYPE_KEYBOARD ? "DIDEVTYPE_KEYBOARD" :
136 lpDIDevCaps->dwDevType == DIDEVTYPE_JOYSTICK ? "DIDEVTYPE_JOYSTICK" :
137 lpDIDevCaps->dwDevType == DIDEVTYPE_HID ? "DIDEVTYPE_HID" : "UNKNOWN");
138 TRACE("dwAxes: %ld\n",lpDIDevCaps->dwAxes);
139 TRACE("dwButtons: %ld\n",lpDIDevCaps->dwButtons);
140 TRACE("dwPOVs: %ld\n",lpDIDevCaps->dwPOVs);
141 if (lpDIDevCaps->dwSize > sizeof(DIDEVCAPS_DX3)) {
142 TRACE("dwFFSamplePeriod: %ld\n",lpDIDevCaps->dwFFSamplePeriod);
143 TRACE("dwFFMinTimeResolution: %ld\n",lpDIDevCaps->dwFFMinTimeResolution);
144 TRACE("dwFirmwareRevision: %ld\n",lpDIDevCaps->dwFirmwareRevision);
145 TRACE("dwHardwareRevision: %ld\n",lpDIDevCaps->dwHardwareRevision);
146 TRACE("dwFFDriverVersion: %ld\n",lpDIDevCaps->dwFFDriverVersion);
150 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version, int id)
155 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
156 WARN("force feedback not supported\n");
160 if ((dwDevType == 0) ||
161 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 8)) ||
162 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 8))) {
163 /* check whether we have a joystick */
164 sprintf(dev, "%s%d", JOYDEV, id);
165 if ((fd = open(dev,O_RDONLY)) < 0) {
166 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
170 /* Return joystick */
171 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
172 lpddi->guidInstance.Data3 = id;
173 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
174 /* we only support traditional joysticks for now */
176 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
178 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
179 sprintf(lpddi->tszInstanceName, "Joystick %d", id);
180 #if defined(JSIOCGNAME)
181 if (ioctl(fd,JSIOCGNAME(sizeof(lpddi->tszProductName)),lpddi->tszProductName) < 0) {
182 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
183 strcpy(lpddi->tszProductName, "Wine Joystick");
186 strcpy(lpddi->tszProductName, "Wine Joystick");
189 lpddi->guidFFDriver = GUID_NULL;
191 TRACE("Enumerating the linux Joystick device: %s (%s)\n", dev, lpddi->tszProductName);
198 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id)
205 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
206 WARN("force feedback not supported\n");
210 if ((dwDevType == 0) ||
211 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 8)) ||
212 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 8))) {
213 /* check whether we have a joystick */
214 sprintf(dev, "%s%d", JOYDEV, id);
215 if ((fd = open(dev,O_RDONLY)) < 0) {
216 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
220 /* Return joystick */
221 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
222 lpddi->guidInstance.Data3 = id;
223 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
224 /* we only support traditional joysticks for now */
226 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
228 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
229 sprintf(friendly, "Joystick %d", id);
230 MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
231 #if defined(JSIOCGNAME)
232 if (ioctl(fd,JSIOCGNAME(sizeof(name)),name) < 0) {
233 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
234 strcpy(name, "Wine Joystick");
237 strcpy(name, "Wine Joystick");
239 MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
240 lpddi->guidFFDriver = GUID_NULL;
242 TRACE("Enumerating the linux Joystick device: %s (%s)\n",dev,name);
250 * Get a config key from either the app-specific or the default config
253 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
254 char *buffer, DWORD size )
256 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, buffer, &size ))
259 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, buffer, &size ))
262 return ERROR_FILE_NOT_FOUND;
266 * Setup the dinput options.
269 static HRESULT setup_dinput_options(JoystickImpl * device)
271 char buffer[MAX_PATH+1];
272 HKEY hkey, appkey = 0;
275 buffer[MAX_PATH]='\0';
277 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\dinput", &hkey)) hkey = 0;
279 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
280 if (len && len < MAX_PATH) {
283 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\AppDefaults", &tmpkey )) {
284 char appname[MAX_PATH+16];
285 char *p = strrchr( buffer, '\\' );
288 strcat(appname,"\\dinput");
289 TRACE("appname = [%s] \n",appname);
290 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
292 RegCloseKey( tmpkey );
298 if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) {
299 device->deadzone = atoi(buffer);
300 TRACE("setting default deadzone to: \"%s\" %ld\n", buffer, device->deadzone);
303 if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) {
309 TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
311 device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
312 if (device->axis_map == 0)
313 return DIERR_OUTOFMEMORY;
315 if ((ptr = strtok(buffer, delim)) != NULL) {
317 if (strcmp(ptr, "X") == 0) {
318 device->axis_map[tokens] = 0;
320 } else if (strcmp(ptr, "Y") == 0) {
321 device->axis_map[tokens] = 1;
323 } else if (strcmp(ptr, "Z") == 0) {
324 device->axis_map[tokens] = 2;
326 } else if (strcmp(ptr, "Rx") == 0) {
327 device->axis_map[tokens] = 3;
329 } else if (strcmp(ptr, "Ry") == 0) {
330 device->axis_map[tokens] = 4;
332 } else if (strcmp(ptr, "Rz") == 0) {
333 device->axis_map[tokens] = 5;
335 } else if (strcmp(ptr, "Slider1") == 0) {
336 device->axis_map[tokens] = 6;
338 } else if (strcmp(ptr, "Slider2") == 0) {
339 device->axis_map[tokens] = 7;
341 } else if (strcmp(ptr, "POV1") == 0) {
342 device->axis_map[tokens++] = 8;
343 device->axis_map[tokens] = 8;
345 } else if (strcmp(ptr, "POV2") == 0) {
346 device->axis_map[tokens++] = 9;
347 device->axis_map[tokens] = 9;
349 } else if (strcmp(ptr, "POV3") == 0) {
350 device->axis_map[tokens++] = 10;
351 device->axis_map[tokens] = 10;
353 } else if (strcmp(ptr, "POV4") == 0) {
354 device->axis_map[tokens++] = 11;
355 device->axis_map[tokens] = 11;
358 ERR("invalid joystick axis type: %s\n", ptr);
359 device->axis_map[tokens] = tokens;
364 } while ((ptr = strtok(NULL, delim)) != NULL);
366 if (tokens != device->devcaps.dwAxes) {
367 ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens);
368 while (tokens < device->axes) {
369 device->axis_map[tokens] = tokens;
375 device->devcaps.dwAxes = axis;
376 device->devcaps.dwPOVs = pov;
380 RegCloseKey( appkey );
388 void calculate_ids(JoystickImpl* device)
398 /* Make two passes over the format. The first counts the number
399 * for each type and the second sets the id */
400 for (i = 0; i < device->user_df->dwNumObjs; i++) {
401 if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS)
403 else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV)
405 else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
411 button_base = axis + pov;
417 for (i = 0; i < device->user_df->dwNumObjs; i++) {
419 if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS) {
421 type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
422 DIDFT_MAKEINSTANCE(axis + axis_base);
423 TRACE("axis type = 0x%08lx\n", type);
424 } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV) {
426 type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
427 DIDFT_MAKEINSTANCE(pov + pov_base);
428 TRACE("POV type = 0x%08lx\n", type);
429 } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON) {
431 type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
432 DIDFT_MAKEINSTANCE(button + button_base);
433 TRACE("button type = 0x%08lx\n", type);
435 device->user_df->rgodf[i].dwType = type;
439 static HRESULT alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *dinput, LPDIRECTINPUTDEVICEA* pdev)
442 JoystickImpl* newDevice;
446 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
447 if (newDevice == 0) {
448 WARN("out of memory\n");
450 return DIERR_OUTOFMEMORY;
453 sprintf(newDevice->dev, "%s%d", JOYDEV, rguid->Data3);
455 if ((newDevice->joyfd = open(newDevice->dev,O_RDONLY)) < 0) {
456 WARN("open(%s,O_RDONLY) failed: %s\n", newDevice->dev, strerror(errno));
457 HeapFree(GetProcessHeap(), 0, newDevice);
458 return DIERR_DEVICENOTREG;
461 /* get the device name */
462 #if defined(JSIOCGNAME)
463 if (ioctl(newDevice->joyfd,JSIOCGNAME(MAX_PATH),name) < 0) {
464 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice->dev, strerror(errno));
465 strcpy(name, "Wine Joystick");
468 strcpy(name, "Wine Joystick");
471 /* copy the device name */
472 newDevice->name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
473 strcpy(newDevice->name, name);
476 if (ioctl(newDevice->joyfd,JSIOCGAXES,&newDevice->axes) < 0) {
477 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
482 if (ioctl(newDevice->joyfd,JSIOCGBUTTONS,&newDevice->buttons) < 0) {
483 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
484 newDevice->buttons = 2;
488 newDevice->lpVtbl = jvt;
490 newDevice->dinput = dinput;
491 newDevice->acquired = FALSE;
492 newDevice->overflow = FALSE;
493 CopyMemory(&(newDevice->guid),rguid,sizeof(*rguid));
495 /* setup_dinput_options may change these */
496 newDevice->deadzone = 5000;
497 newDevice->devcaps.dwButtons = newDevice->buttons;
498 newDevice->devcaps.dwAxes = newDevice->axes;
499 newDevice->devcaps.dwPOVs = 0;
501 /* do any user specified configuration */
502 hr = setup_dinput_options(newDevice);
506 if (newDevice->axis_map == 0) {
507 newDevice->axis_map = HeapAlloc(GetProcessHeap(), 0, newDevice->axes * sizeof(int));
508 if (newDevice->axis_map == 0)
511 for (i = 0; i < newDevice->axes; i++)
512 newDevice->axis_map[i] = i;
515 /* wine uses DIJOYSTATE2 as it's internal format so copy
516 * the already defined format c_dfDIJoystick2 */
517 newDevice->user_df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
518 if (newDevice->user_df == 0)
521 CopyMemory(newDevice->user_df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
523 /* copy default objects */
524 newDevice->user_df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
525 if (newDevice->user_df->rgodf == 0)
528 CopyMemory(newDevice->user_df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
530 /* create default properties */
531 newDevice->props = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*sizeof(ObjProps));
532 if (newDevice->props == 0)
535 /* initialize default properties */
536 for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
537 newDevice->props[i].lMin = 0;
538 newDevice->props[i].lMax = 0xffff;
539 newDevice->props[i].lDeadZone = newDevice->deadzone; /* % * 1000 */
540 newDevice->props[i].lSaturation = 0;
543 /* create an offsets array */
544 newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
545 if (newDevice->offsets == 0)
548 /* create the default transform filter */
549 newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->user_df, newDevice->offsets);
551 calculate_ids(newDevice);
553 IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
554 InitializeCriticalSection(&(newDevice->crit));
555 newDevice->crit.DebugInfo->Spare[1] = (DWORD)"DINPUT_Mouse";
557 newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
558 newDevice->devcaps.dwFlags = DIDC_ATTACHED;
559 if (newDevice->dinput->version >= 8)
560 newDevice->devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
562 newDevice->devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
563 newDevice->devcaps.dwFFSamplePeriod = 0;
564 newDevice->devcaps.dwFFMinTimeResolution = 0;
565 newDevice->devcaps.dwFirmwareRevision = 0;
566 newDevice->devcaps.dwHardwareRevision = 0;
567 newDevice->devcaps.dwFFDriverVersion = 0;
569 if (TRACE_ON(dinput)) {
570 _dump_DIDATAFORMAT(newDevice->user_df);
571 for (i = 0; i < (newDevice->axes); i++)
572 TRACE("axis_map[%ld] = %d\n", i, newDevice->axis_map[i]);
573 _dump_DIDEVCAPS(&newDevice->devcaps);
576 *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
581 hr = DIERR_OUTOFMEMORY;
583 HeapFree(GetProcessHeap(),0,newDevice->axis_map);
584 HeapFree(GetProcessHeap(),0,newDevice->name);
585 HeapFree(GetProcessHeap(),0,newDevice->props);
586 HeapFree(GetProcessHeap(),0,newDevice->user_df->rgodf);
587 HeapFree(GetProcessHeap(),0,newDevice->user_df);
588 HeapFree(GetProcessHeap(),0,newDevice);
594 static BOOL IsJoystickGUID(REFGUID guid)
596 GUID wine_joystick = DInput_Wine_Joystick_GUID;
597 GUID dev_guid = *guid;
599 wine_joystick.Data3 = 0;
602 return IsEqualGUID(&wine_joystick, &dev_guid);
605 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
607 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
608 (IsJoystickGUID(rguid))) {
609 if ((riid == NULL) ||
610 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
611 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
612 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
613 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
614 return alloc_device(rguid, &JoystickAvt, dinput, pdev);
616 WARN("no interface\n");
618 return DIERR_NOINTERFACE;
622 WARN("invalid device GUID\n");
624 return DIERR_DEVICENOTREG;
627 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
629 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
630 (IsJoystickGUID(rguid))) {
631 if ((riid == NULL) ||
632 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
633 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
634 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
635 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
636 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev);
638 WARN("no interface\n");
640 return DIERR_NOINTERFACE;
644 WARN("invalid device GUID\n");
646 return DIERR_DEVICENOTREG;
649 static dinput_device joydev = {
651 "Wine Linux joystick driver",
654 joydev_create_deviceA,
655 joydev_create_deviceW
658 DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
660 /******************************************************************************
663 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
665 JoystickImpl *This = (JoystickImpl *)iface;
668 ref = InterlockedDecrement((&This->ref));
672 /* Free the device name */
673 HeapFree(GetProcessHeap(),0,This->name);
675 /* Free the axis map */
676 HeapFree(GetProcessHeap(),0,This->axis_map);
678 /* Free the data queue */
679 HeapFree(GetProcessHeap(),0,This->data_queue);
681 /* Free the DataFormat */
682 HeapFree(GetProcessHeap(), 0, This->user_df->rgodf);
683 HeapFree(GetProcessHeap(), 0, This->user_df);
685 /* Free the properties */
686 HeapFree(GetProcessHeap(), 0, This->props);
688 /* Free the offsets array */
689 HeapFree(GetProcessHeap(),0,This->offsets);
691 /* release the data transform filter */
692 release_DataFormat(This->transform);
694 This->crit.DebugInfo->Spare[1] = 0;
695 DeleteCriticalSection(&(This->crit));
696 IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
698 HeapFree(GetProcessHeap(),0,This);
702 /******************************************************************************
703 * SetDataFormat : the application can choose the format of the data
704 * the device driver sends back with GetDeviceState.
706 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
707 LPDIRECTINPUTDEVICE8A iface,
710 JoystickImpl *This = (JoystickImpl *)iface;
712 LPDIDATAFORMAT new_df = 0;
713 LPDIOBJECTDATAFORMAT new_rgodf = 0;
714 ObjProps * new_props = 0;
716 TRACE("(%p,%p)\n",This,df);
718 if (This->acquired) {
720 return DIERR_ACQUIRED;
723 if (TRACE_ON(dinput))
724 _dump_DIDATAFORMAT(df);
726 /* Store the new data format */
727 new_df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
731 new_rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
735 new_props = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*sizeof(ObjProps));
739 HeapFree(GetProcessHeap(),0,This->user_df);
740 HeapFree(GetProcessHeap(),0,This->user_df->rgodf);
741 HeapFree(GetProcessHeap(),0,This->props);
742 release_DataFormat(This->transform);
744 This->user_df = new_df;
745 CopyMemory(This->user_df, df, df->dwSize);
746 This->user_df->rgodf = new_rgodf;
747 CopyMemory(This->user_df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
748 This->props = new_props;
749 for (i = 0; i < df->dwNumObjs; i++) {
750 This->props[i].lMin = 0;
751 This->props[i].lMax = 0xffff;
752 This->props[i].lDeadZone = 1000;
753 This->props[i].lSaturation = 0;
755 This->transform = create_DataFormat(&c_dfDIJoystick2, This->user_df, This->offsets);
762 WARN("out of memory\n");
763 HeapFree(GetProcessHeap(),0,new_props);
764 HeapFree(GetProcessHeap(),0,new_rgodf);
765 HeapFree(GetProcessHeap(),0,new_df);
766 return DIERR_OUTOFMEMORY;
769 /******************************************************************************
770 * Acquire : gets exclusive control of the joystick
772 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
774 JoystickImpl *This = (JoystickImpl *)iface;
776 TRACE("(%p)\n",This);
778 if (This->acquired) {
779 WARN("already acquired\n");
783 /* open the joystick device */
784 if (This->joyfd==-1) {
785 TRACE("opening joystick device %s\n", This->dev);
787 This->joyfd=open(This->dev,O_RDONLY);
788 if (This->joyfd==-1) {
789 ERR("open(%s) failed: %s\n", This->dev, strerror(errno));
790 return DIERR_NOTFOUND;
794 This->acquired = TRUE;
799 /******************************************************************************
800 * Unacquire : frees the joystick
802 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
804 JoystickImpl *This = (JoystickImpl *)iface;
806 TRACE("(%p)\n",This);
808 if (!This->acquired) {
809 WARN("not acquired\n");
810 return DIERR_NOTACQUIRED;
813 if (This->joyfd!=-1) {
814 TRACE("closing joystick device\n");
817 This->acquired = FALSE;
821 This->acquired = FALSE;
826 LONG map_axis(JoystickImpl * This, short val, short index)
829 double fmin = This->props[index].lMin;
830 double fmax = This->props[index].lMax;
833 fret = (((fval + 32767.0) * (fmax - fmin)) / (32767.0*2.0)) + fmin;
843 /* convert wine format offset to user format object index */
844 int offset_to_object(JoystickImpl *This, int offset)
848 for (i = 0; i < This->user_df->dwNumObjs; i++) {
849 if (This->user_df->rgodf[i].dwOfs == offset)
856 static LONG calculate_pov(JoystickImpl *This, int index)
858 if (This->povs[index].lX < 16384) {
859 if (This->povs[index].lY < 16384)
860 This->js.rgdwPOV[index] = 31500;
861 else if (This->povs[index].lY > 49150)
862 This->js.rgdwPOV[index] = 22500;
864 This->js.rgdwPOV[index] = 27000;
865 } else if (This->povs[index].lX > 49150) {
866 if (This->povs[index].lY < 16384)
867 This->js.rgdwPOV[index] = 4500;
868 else if (This->povs[index].lY > 49150)
869 This->js.rgdwPOV[index] = 13500;
871 This->js.rgdwPOV[index] = 9000;
873 if (This->povs[index].lY < 16384)
874 This->js.rgdwPOV[index] = 0;
875 else if (This->povs[index].lY > 49150)
876 This->js.rgdwPOV[index] = 18000;
878 This->js.rgdwPOV[index] = -1;
881 return This->js.rgdwPOV[index];
884 static void joy_polldev(JoystickImpl *This) {
888 TRACE("(%p)\n", This);
890 if (This->joyfd==-1) {
895 memset(&tv,0,sizeof(tv));
896 FD_ZERO(&readfds);FD_SET(This->joyfd,&readfds);
897 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
899 /* we have one event, so we can read */
900 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
903 TRACE("js_event: type 0x%x, number %d, value %d\n",
904 jse.type,jse.number,jse.value);
905 if (jse.type & JS_EVENT_BUTTON) {
906 int offset = This->offsets[jse.number + 12];
907 int value = jse.value?0x80:0x00;
909 This->js.rgbButtons[jse.number] = value;
910 GEN_EVENT(offset,value,jse.time,(This->dinput->evsequence)++);
911 } else if (jse.type & JS_EVENT_AXIS) {
912 int number = This->axis_map[jse.number]; /* wine format object index */
914 int offset = This->offsets[number];
915 int index = offset_to_object(This, offset);
916 LONG value = map_axis(This, jse.value, index);
918 /* FIXME do deadzone and saturation here */
920 TRACE("changing axis %d => %d\n", jse.number, number);
932 This->js.lRx = value;
935 This->js.lRy = value;
938 This->js.lRz = value;
941 This->js.rglSlider[0] = value;
944 This->js.rglSlider[1] = value;
947 /* FIXME don't go off array */
948 if (This->axis_map[jse.number + 1] == number)
949 This->povs[0].lX = value;
950 else if (This->axis_map[jse.number - 1] == number)
951 This->povs[0].lY = value;
952 value = calculate_pov(This, 0);
955 if (This->axis_map[jse.number + 1] == number)
956 This->povs[1].lX = value;
957 else if (This->axis_map[jse.number - 1] == number)
958 This->povs[1].lY = value;
959 value = calculate_pov(This, 1);
962 if (This->axis_map[jse.number + 1] == number)
963 This->povs[2].lX = value;
964 else if (This->axis_map[jse.number - 1] == number)
965 This->povs[2].lY = value;
966 value = calculate_pov(This, 2);
969 if (This->axis_map[jse.number + 1] == number)
970 This->povs[3].lX = value;
971 else if (This->axis_map[jse.number - 1] == number)
972 This->povs[3].lY = value;
973 value = calculate_pov(This, 3);
977 GEN_EVENT(offset,value,jse.time,(This->dinput->evsequence)++);
979 WARN("axis %d not supported\n", number);
984 /******************************************************************************
985 * GetDeviceState : returns the "state" of the joystick.
988 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
989 LPDIRECTINPUTDEVICE8A iface,
993 JoystickImpl *This = (JoystickImpl *)iface;
995 TRACE("(%p,0x%08lx,%p)\n",This,len,ptr);
997 if (!This->acquired) {
998 WARN("not acquired\n");
999 return DIERR_NOTACQUIRED;
1002 /* update joystick state */
1005 /* convert and copy data to user supplied buffer */
1006 fill_DataFormat(ptr, &This->js, This->transform);
1011 /******************************************************************************
1012 * GetDeviceData : gets buffered input data.
1014 static HRESULT WINAPI JoystickAImpl_GetDeviceData(
1015 LPDIRECTINPUTDEVICE8A iface,
1017 LPDIDEVICEOBJECTDATA dod,
1021 JoystickImpl *This = (JoystickImpl *)iface;
1026 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This,dodsize,*entries,flags);
1028 if (!This->acquired) {
1029 WARN("not acquired\n");
1030 return DIERR_NOTACQUIRED;
1033 EnterCriticalSection(&(This->crit));
1037 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
1038 + (This->queue_head - This->queue_tail);
1044 TRACE("Application discarding %ld event(s).\n", len);
1047 nqtail = This->queue_tail + len;
1048 while (nqtail >= This->queue_len)
1049 nqtail -= This->queue_len;
1051 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
1052 ERR("Wrong structure size !\n");
1053 LeaveCriticalSection(&(This->crit));
1054 return DIERR_INVALIDPARAM;
1058 TRACE("Application retrieving %ld event(s).\n", len);
1061 nqtail = This->queue_tail;
1063 DWORD span = ((This->queue_head < nqtail) ? This->queue_len : This->queue_head) - nqtail;
1067 /* Copy the buffered data into the application queue */
1068 memcpy(dod + *entries, This->data_queue + nqtail, span * dodsize);
1069 /* Advance position */
1071 if (nqtail >= This->queue_len)
1072 nqtail -= This->queue_len;
1078 if (This->overflow) {
1079 hr = DI_BUFFEROVERFLOW;
1080 if (!(flags & DIGDD_PEEK)) {
1081 This->overflow = FALSE;
1085 if (!(flags & DIGDD_PEEK))
1086 This->queue_tail = nqtail;
1088 LeaveCriticalSection(&(This->crit));
1093 int find_property(JoystickImpl * This, LPCDIPROPHEADER ph)
1096 if (ph->dwHow == DIPH_BYOFFSET) {
1097 return offset_to_object(This, ph->dwObj);
1098 } else if (ph->dwHow == DIPH_BYID) {
1099 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1100 if ((This->user_df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
1109 /******************************************************************************
1110 * SetProperty : change input device properties
1112 static HRESULT WINAPI JoystickAImpl_SetProperty(
1113 LPDIRECTINPUTDEVICE8A iface,
1117 JoystickImpl *This = (JoystickImpl *)iface;
1120 TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
1122 if (TRACE_ON(dinput))
1123 _dump_DIPROPHEADER(ph);
1125 if (!HIWORD(rguid)) {
1126 switch ((DWORD)rguid) {
1127 case (DWORD) DIPROP_BUFFERSIZE: {
1128 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1129 TRACE("buffersize = %ld\n",pd->dwData);
1130 if (This->data_queue)
1131 This->data_queue = HeapReAlloc(GetProcessHeap(),0, This->data_queue, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1133 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1134 This->queue_head = 0;
1135 This->queue_tail = 0;
1136 This->queue_len = pd->dwData;
1139 case (DWORD)DIPROP_RANGE: {
1140 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
1141 if (ph->dwHow == DIPH_DEVICE) {
1142 TRACE("proprange(%ld,%ld) all\n",pr->lMin,pr->lMax);
1143 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1144 This->props[i].lMin = pr->lMin;
1145 This->props[i].lMax = pr->lMax;
1148 int obj = find_property(This, ph);
1149 TRACE("proprange(%ld,%ld) obj=%d\n",pr->lMin,pr->lMax,obj);
1151 This->props[obj].lMin = pr->lMin;
1152 This->props[obj].lMax = pr->lMax;
1158 case (DWORD)DIPROP_DEADZONE: {
1159 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1160 if (ph->dwHow == DIPH_DEVICE) {
1161 TRACE("deadzone(%ld) all\n",pd->dwData);
1162 for (i = 0; i < This->user_df->dwNumObjs; i++)
1163 This->props[i].lDeadZone = pd->dwData;
1165 int obj = find_property(This, ph);
1166 TRACE("deadzone(%ld) obj=%d\n",pd->dwData,obj);
1168 This->props[obj].lDeadZone = pd->dwData;
1174 case (DWORD)DIPROP_SATURATION: {
1175 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1176 if (ph->dwHow == DIPH_DEVICE) {
1177 TRACE("saturation(%ld) all\n",pd->dwData);
1178 for (i = 0; i < This->user_df->dwNumObjs; i++)
1179 This->props[i].lSaturation = pd->dwData;
1181 int obj = find_property(This, ph);
1182 TRACE("saturation(%ld) obj=%d\n",pd->dwData,obj);
1184 This->props[obj].lSaturation = pd->dwData;
1191 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1199 /******************************************************************************
1200 * SetEventNotification : specifies event to be sent on state change
1202 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
1203 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
1205 JoystickImpl *This = (JoystickImpl *)iface;
1207 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
1212 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
1213 LPDIRECTINPUTDEVICE8A iface,
1214 LPDIDEVCAPS lpDIDevCaps)
1216 JoystickImpl *This = (JoystickImpl *)iface;
1219 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
1221 if (lpDIDevCaps == NULL) {
1222 WARN("invalid parameter: lpDIDevCaps = NULL\n");
1223 return DIERR_INVALIDPARAM;
1226 size = lpDIDevCaps->dwSize;
1227 CopyMemory(lpDIDevCaps, &This->devcaps, size);
1228 lpDIDevCaps->dwSize = size;
1230 if (TRACE_ON(dinput))
1231 _dump_DIDEVCAPS(lpDIDevCaps);
1236 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1238 JoystickImpl *This = (JoystickImpl *)iface;
1240 TRACE("(%p)\n",This);
1242 if (!This->acquired) {
1243 WARN("not acquired\n");
1244 return DIERR_NOTACQUIRED;
1251 /******************************************************************************
1252 * EnumObjects : enumerate the different buttons and axis...
1254 static HRESULT WINAPI JoystickAImpl_EnumObjects(
1255 LPDIRECTINPUTDEVICE8A iface,
1256 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1260 JoystickImpl *This = (JoystickImpl *)iface;
1261 DIDEVICEOBJECTINSTANCEA ddoi;
1266 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
1267 if (TRACE_ON(dinput)) {
1268 TRACE(" - flags = ");
1269 _dump_EnumObjects_flags(dwFlags);
1273 /* Only the fields till dwFFMaxForce are relevant */
1274 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1276 /* For the joystick, do as is done in the GetCapabilities function */
1277 if ((dwFlags == DIDFT_ALL) ||
1278 (dwFlags & DIDFT_AXIS) ||
1279 (dwFlags & DIDFT_POV)) {
1280 int pov[4] = { 0, 0, 0, 0 };
1284 for (i = 0; i < This->axes; i++) {
1285 int wine_obj = This->axis_map[i];
1290 ddoi.guidType = GUID_XAxis;
1293 ddoi.guidType = GUID_YAxis;
1296 ddoi.guidType = GUID_ZAxis;
1299 ddoi.guidType = GUID_RxAxis;
1302 ddoi.guidType = GUID_RyAxis;
1305 ddoi.guidType = GUID_RzAxis;
1308 ddoi.guidType = GUID_Slider;
1311 ddoi.guidType = GUID_Slider;
1315 ddoi.guidType = GUID_POV;
1319 ddoi.guidType = GUID_POV;
1323 ddoi.guidType = GUID_POV;
1327 ddoi.guidType = GUID_POV;
1330 ddoi.guidType = GUID_Unknown;
1333 user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
1334 user_object = offset_to_object(This, user_offset);
1336 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1337 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1338 sprintf(ddoi.tszName, "Axis %d", axes);
1341 if (pov[wine_obj - 8] < 2) {
1342 user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
1343 user_object = offset_to_object(This, user_offset);
1345 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1346 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1347 sprintf(ddoi.tszName, "POV %d", povs);
1353 _dump_OBJECTINSTANCEA(&ddoi);
1354 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
1360 if ((dwFlags == DIDFT_ALL) ||
1361 (dwFlags & DIDFT_BUTTON)) {
1363 /* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
1364 ddoi.guidType = GUID_Button;
1366 for (i = 0; i < This->buttons; i++) {
1367 user_offset = This->offsets[i + 12]; /* get user offset from wine index */
1368 user_object = offset_to_object(This, user_offset);
1369 ddoi.guidType = GUID_Button;
1370 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1371 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1372 sprintf(ddoi.tszName, "Button %d", i);
1373 _dump_OBJECTINSTANCEA(&ddoi);
1374 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1381 /******************************************************************************
1382 * EnumObjects : enumerate the different buttons and axis...
1384 static HRESULT WINAPI JoystickWImpl_EnumObjects(
1385 LPDIRECTINPUTDEVICE8W iface,
1386 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1390 JoystickImpl *This = (JoystickImpl *)iface;
1392 device_enumobjects_AtoWcb_data data;
1394 data.lpCallBack = lpCallback;
1395 data.lpvRef = lpvRef;
1397 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1400 /******************************************************************************
1401 * GetProperty : get input device properties
1403 static HRESULT WINAPI JoystickAImpl_GetProperty(
1404 LPDIRECTINPUTDEVICE8A iface,
1406 LPDIPROPHEADER pdiph)
1408 JoystickImpl *This = (JoystickImpl *)iface;
1410 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
1412 if (TRACE_ON(dinput))
1413 _dump_DIPROPHEADER(pdiph);
1415 if (!HIWORD(rguid)) {
1416 switch ((DWORD)rguid) {
1417 case (DWORD) DIPROP_BUFFERSIZE: {
1418 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1419 TRACE(" return buffersize = %d\n",This->queue_len);
1420 pd->dwData = This->queue_len;
1423 case (DWORD) DIPROP_RANGE: {
1424 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1425 int obj = find_property(This, pdiph);
1426 /* The app is querying the current range of the axis
1427 * return the lMin and lMax values */
1429 pr->lMin = This->props[obj].lMin;
1430 pr->lMax = This->props[obj].lMax;
1431 TRACE("range(%ld, %ld) obj=%d\n", pr->lMin, pr->lMax, obj);
1436 case (DWORD) DIPROP_DEADZONE: {
1437 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1438 int obj = find_property(This, pdiph);
1440 pd->dwData = This->props[obj].lDeadZone;
1441 TRACE("deadzone(%ld) obj=%d\n", pd->dwData, obj);
1446 case (DWORD) DIPROP_SATURATION: {
1447 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1448 int obj = find_property(This, pdiph);
1450 pd->dwData = This->props[obj].lSaturation;
1451 TRACE("saturation(%ld) obj=%d\n", pd->dwData, obj);
1457 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1465 /******************************************************************************
1466 * GetObjectInfo : get object info
1468 HRESULT WINAPI JoystickAImpl_GetObjectInfo(
1469 LPDIRECTINPUTDEVICE8A iface,
1470 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1474 JoystickImpl *This = (JoystickImpl *)iface;
1475 DIDEVICEOBJECTINSTANCEA didoiA;
1478 TRACE("(%p,%p,%ld,0x%08lx(%s))\n",
1479 iface, pdidoi, dwObj, dwHow,
1480 dwHow == DIPH_BYOFFSET ? "DIPH_BYOFFSET" :
1481 dwHow == DIPH_BYID ? "DIPH_BYID" :
1482 dwHow == DIPH_BYUSAGE ? "DIPH_BYUSAGE" :
1485 if (pdidoi == NULL) {
1486 WARN("invalid parameter: pdidoi = NULL\n");
1487 return DIERR_INVALIDPARAM;
1490 if ((pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA)) &&
1491 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A))) {
1492 WARN("invalid parameter: pdidoi->dwSize = %ld != %d or %d\n",
1493 pdidoi->dwSize, sizeof(DIDEVICEOBJECTINSTANCEA),
1494 sizeof(DIDEVICEOBJECTINSTANCE_DX3A));
1495 return DIERR_INVALIDPARAM;
1498 ZeroMemory(&didoiA, sizeof(didoiA));
1499 didoiA.dwSize = pdidoi->dwSize;
1502 case DIPH_BYOFFSET: {
1506 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1507 if (This->user_df->rgodf[i].dwOfs == dwObj) {
1508 if (This->user_df->rgodf[i].pguid)
1509 didoiA.guidType = *This->user_df->rgodf[i].pguid;
1511 didoiA.guidType = GUID_NULL;
1513 didoiA.dwOfs = dwObj;
1514 didoiA.dwType = This->user_df->rgodf[i].dwType;
1515 didoiA.dwFlags = This->user_df->rgodf[i].dwFlags;
1517 if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_AXIS)
1518 sprintf(didoiA.tszName, "Axis %d", axis);
1519 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_POV)
1520 sprintf(didoiA.tszName, "POV %d", pov);
1521 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
1522 sprintf(didoiA.tszName, "Button %d", button);
1524 CopyMemory(pdidoi, &didoiA, pdidoi->dwSize);
1528 if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_AXIS)
1530 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_POV)
1532 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
1538 FIXME("dwHow = DIPH_BYID not implemented\n");
1541 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1544 WARN("invalid parameter: dwHow = %08lx\n", dwHow);
1545 return DIERR_INVALIDPARAM;
1548 CopyMemory(pdidoi, &didoiA, pdidoi->dwSize);
1553 /******************************************************************************
1554 * GetDeviceInfo : get information about a device's identity
1556 HRESULT WINAPI JoystickAImpl_GetDeviceInfo(
1557 LPDIRECTINPUTDEVICE8A iface,
1558 LPDIDEVICEINSTANCEA pdidi)
1560 JoystickImpl *This = (JoystickImpl *)iface;
1562 TRACE("(%p,%p)\n", iface, pdidi);
1564 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1565 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
1566 WARN("invalid parameter: pdidi->dwSize = %ld != %d or %d\n",
1567 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3A),
1568 sizeof(DIDEVICEINSTANCEA));
1569 return DIERR_INVALIDPARAM;
1572 /* Return joystick */
1573 pdidi->guidInstance = GUID_Joystick;
1574 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1575 /* we only support traditional joysticks for now */
1576 pdidi->dwDevType = This->devcaps.dwDevType;
1577 strcpy(pdidi->tszInstanceName, "Joystick");
1578 strcpy(pdidi->tszProductName, This->name);
1579 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
1580 pdidi->guidFFDriver = GUID_NULL;
1581 pdidi->wUsagePage = 0;
1588 /******************************************************************************
1589 * GetDeviceInfo : get information about a device's identity
1591 HRESULT WINAPI JoystickWImpl_GetDeviceInfo(
1592 LPDIRECTINPUTDEVICE8W iface,
1593 LPDIDEVICEINSTANCEW pdidi)
1595 JoystickImpl *This = (JoystickImpl *)iface;
1597 TRACE("(%p,%p)\n", iface, pdidi);
1599 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1600 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW))) {
1601 WARN("invalid parameter: pdidi->dwSize = %ld != %d or %d\n",
1602 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3W),
1603 sizeof(DIDEVICEINSTANCEW));
1604 return DIERR_INVALIDPARAM;
1607 /* Return joystick */
1608 pdidi->guidInstance = GUID_Joystick;
1609 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1610 /* we only support traditional joysticks for now */
1611 pdidi->dwDevType = This->devcaps.dwDevType;
1612 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, pdidi->tszInstanceName, MAX_PATH);
1613 MultiByteToWideChar(CP_ACP, 0, This->name, -1, pdidi->tszProductName, MAX_PATH);
1614 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3W)) {
1615 pdidi->guidFFDriver = GUID_NULL;
1616 pdidi->wUsagePage = 0;
1623 static IDirectInputDevice8AVtbl JoystickAvt =
1625 IDirectInputDevice2AImpl_QueryInterface,
1626 IDirectInputDevice2AImpl_AddRef,
1627 JoystickAImpl_Release,
1628 JoystickAImpl_GetCapabilities,
1629 JoystickAImpl_EnumObjects,
1630 JoystickAImpl_GetProperty,
1631 JoystickAImpl_SetProperty,
1632 JoystickAImpl_Acquire,
1633 JoystickAImpl_Unacquire,
1634 JoystickAImpl_GetDeviceState,
1635 JoystickAImpl_GetDeviceData,
1636 JoystickAImpl_SetDataFormat,
1637 JoystickAImpl_SetEventNotification,
1638 IDirectInputDevice2AImpl_SetCooperativeLevel,
1639 JoystickAImpl_GetObjectInfo,
1640 JoystickAImpl_GetDeviceInfo,
1641 IDirectInputDevice2AImpl_RunControlPanel,
1642 IDirectInputDevice2AImpl_Initialize,
1643 IDirectInputDevice2AImpl_CreateEffect,
1644 IDirectInputDevice2AImpl_EnumEffects,
1645 IDirectInputDevice2AImpl_GetEffectInfo,
1646 IDirectInputDevice2AImpl_GetForceFeedbackState,
1647 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1648 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1649 IDirectInputDevice2AImpl_Escape,
1651 IDirectInputDevice2AImpl_SendDeviceData,
1652 IDirectInputDevice7AImpl_EnumEffectsInFile,
1653 IDirectInputDevice7AImpl_WriteEffectToFile,
1654 IDirectInputDevice8AImpl_BuildActionMap,
1655 IDirectInputDevice8AImpl_SetActionMap,
1656 IDirectInputDevice8AImpl_GetImageInfo
1659 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1660 # define XCAST(fun) (typeof(SysJoystickWvt.fun))
1662 # define XCAST(fun) (void*)
1665 static IDirectInputDevice8WVtbl SysJoystickWvt =
1667 IDirectInputDevice2WImpl_QueryInterface,
1668 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1669 XCAST(Release)JoystickAImpl_Release,
1670 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1671 JoystickWImpl_EnumObjects,
1672 XCAST(GetProperty)JoystickAImpl_GetProperty,
1673 XCAST(SetProperty)JoystickAImpl_SetProperty,
1674 XCAST(Acquire)JoystickAImpl_Acquire,
1675 XCAST(Unacquire)JoystickAImpl_Unacquire,
1676 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1677 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1678 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1679 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1680 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1681 IDirectInputDevice2WImpl_GetObjectInfo,
1682 JoystickWImpl_GetDeviceInfo,
1683 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1684 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1685 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1686 IDirectInputDevice2WImpl_EnumEffects,
1687 IDirectInputDevice2WImpl_GetEffectInfo,
1688 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1689 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1690 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1691 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1692 XCAST(Poll)JoystickAImpl_Poll,
1693 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1694 IDirectInputDevice7WImpl_EnumEffectsInFile,
1695 IDirectInputDevice7WImpl_WriteEffectToFile,
1696 IDirectInputDevice8WImpl_BuildActionMap,
1697 IDirectInputDevice8WImpl_SetActionMap,
1698 IDirectInputDevice8WImpl_GetImageInfo
1702 #endif /* HAVE_LINUX_22_JOYSTICK_API */