annotate src/joystick/win32/SDL_dxjoystick.c @ 2652:380d926cc5a7 gsoc2008_force_feedback

Fix for mingw compilation of haptic subsystem by Alam.
author Edgar Simo <bobbens@gmail.com>
date Mon, 25 Aug 2008 17:30:39 +0000
parents 9bad8efcb75e
children
rev   line source
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #ifdef SDL_JOYSTICK_DINPUT
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * A. Formiga's WINMM driver.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * Hats and sliders are completely untested; the app I'm writing this for mostly
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * doesn't use them and I don't own any joysticks with them.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 * We don't bother to use event notification here. It doesn't seem to work
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 * let it return 0 events. */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_error.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include "SDL_events.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL_joystick.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "../SDL_sysjoystick.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "../SDL_joystick_c.h"
2616
acd5da848404 Moved the directinput joystick hwdata stuff into a seperate header file.
Edgar Simo <bobbens@gmail.com>
parents: 2580
diff changeset
41 #include "SDL_dxjoystick_c.h"
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
42
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
43 /* an ISO hack for VisualC++ */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
44 #ifdef _MSC_VER
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
45 #define snprintf _snprintf
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
46 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #define MAX_JOYSTICKS 8
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 #define AXIS_MIN -32768 /* minimum value for axis coordinate */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #define AXIS_MAX 32767 /* maximum value for axis coordinate */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
54 /* external variables referenced. */
2580
64fa227c01ce Added the concept of the HelperWindow to help with DirectInput.
Edgar Simo <bobbens@gmail.com>
parents: 2579
diff changeset
55 extern HWND SDL_HelperWindow;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
56
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
57
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
58 /* local variables */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
59 static LPDIRECTINPUT dinput = NULL;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
60 extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
61 LPDIRECTINPUT * ppDI,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
62 LPUNKNOWN punkOuter);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
63 static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; /* array to hold joystick ID values */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
64 static int SYS_NumJoysticks;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
65 static HINSTANCE DInputDLL = NULL;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
66
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
67
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
68 /* local prototypes */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
69 static void SetDIerror(const char *function, HRESULT code);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
70 static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
71 pdidInstance, VOID * pContext);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
72 static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
73 LPVOID pvRef);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
74 static Uint8 TranslatePOV(DWORD value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
75 static int SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
76 Sint16 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
77 static int SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
78 Uint8 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
79 static int SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
80 Uint8 button, Uint8 state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
81
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
82
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 /* Convert a DirectInput return code to a text message */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 static void
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
85 SetDIerror(const char *function, HRESULT code)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 {
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
87 SDL_SetError("%s() [%s]: %s", function,
2652
380d926cc5a7 Fix for mingw compilation of haptic subsystem by Alam.
Edgar Simo <bobbens@gmail.com>
parents: 2625
diff changeset
88 DXGetErrorString8A(code), DXGetErrorDescription8A(code));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 /* Function to scan the system for joysticks.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 * This function should set SDL_numjoysticks to the number of available
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 * joysticks. Joystick 0 should be the system default joystick.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 * It should return 0, or -1 on an unrecoverable fatal error.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 SDL_SYS_JoystickInit(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 HRESULT result;
2625
9bad8efcb75e Forgot to declare instance.
Edgar Simo <bobbens@gmail.com>
parents: 2623
diff changeset
101 HINSTANCE instance;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 SYS_NumJoysticks = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
105 result = CoInitialize(NULL);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
106 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
107 SetDIerror("CoInitialize", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
111 result = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
112 &IID_IDirectInput, &dinput);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
113
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
114 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
115 SetDIerror("CoCreateInstance", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
116 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
117 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
118
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
119 /* Because we used CoCreateInstance, we need to Initialize it, first. */
2623
6deba05725ac This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
Edgar Simo <bobbens@gmail.com>
parents: 2616
diff changeset
120 instance = GetModuleHandle(NULL);
6deba05725ac This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
Edgar Simo <bobbens@gmail.com>
parents: 2616
diff changeset
121 if (instance == NULL) {
6deba05725ac This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
Edgar Simo <bobbens@gmail.com>
parents: 2616
diff changeset
122 SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError());
6deba05725ac This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
Edgar Simo <bobbens@gmail.com>
parents: 2616
diff changeset
123 return (-1);
6deba05725ac This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
Edgar Simo <bobbens@gmail.com>
parents: 2616
diff changeset
124 }
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
125 result =
2623
6deba05725ac This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
Edgar Simo <bobbens@gmail.com>
parents: 2616
diff changeset
126 IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
127
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
128 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
129 SetDIerror("IDirectInput::Initialize", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
130 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
131 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
132
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
133 /* Look for joysticks, wheels, head trackers, gamepads, etc.. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 result = IDirectInput_EnumDevices(dinput,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 DIDEVTYPE_JOYSTICK,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 EnumJoysticksCallback,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 NULL, DIEDFL_ATTACHEDONLY);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 return SYS_NumJoysticks;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
142 static BOOL CALLBACK
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
143 EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
144 {
2576
034440120c38 Converted some functions to SDL_mem*.
Edgar Simo <bobbens@gmail.com>
parents: 2198
diff changeset
145 SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
146 sizeof(DIDEVICEINSTANCE));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
147 SYS_NumJoysticks++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
148
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
149 if (SYS_NumJoysticks >= MAX_JOYSTICKS)
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
150 return DIENUM_STOP;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
151
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
152 return DIENUM_CONTINUE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
153 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
154
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 /* Function to get the device-dependent name of a joystick */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 const char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 SDL_SYS_JoystickName(int index)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 /***-> test for invalid index ? */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 return (SYS_Joystick[index].tszProductName);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 /* Function to open a joystick for use.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 The joystick to open is specified by the index field of the joystick.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 This should fill the nbuttons and naxes fields of the joystick structure.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 It returns 0, or -1 if there is an error.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 HRESULT result;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 LPDIRECTINPUTDEVICE device;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
173 DIPROPDWORD dipdw;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
174
2576
034440120c38 Converted some functions to SDL_mem*.
Edgar Simo <bobbens@gmail.com>
parents: 2198
diff changeset
175 SDL_memset(&dipdw, 0, sizeof(DIPROPDWORD));
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
176 dipdw.diph.dwSize = sizeof(DIPROPDWORD);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
177 dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
178
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 /* allocate memory for system specific hardware data */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 joystick->hwdata =
2577
72b17d80b426 Fixed some lone malloc and free.
Edgar Simo <bobbens@gmail.com>
parents: 2576
diff changeset
182 (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if (joystick->hwdata == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 }
2576
034440120c38 Converted some functions to SDL_mem*.
Edgar Simo <bobbens@gmail.com>
parents: 2198
diff changeset
187 SDL_memset(joystick->hwdata, 0, sizeof(struct joystick_hwdata));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 joystick->hwdata->buffered = 1;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
189 joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 result =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 IDirectInput_CreateDevice(dinput,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 &SYS_Joystick[joystick->index].
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 guidInstance, &device, NULL);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
195 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
196 SetDIerror("IDirectInput::CreateDevice", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
200 /* Now get the IDirectInputDevice2 interface, instead. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 result = IDirectInputDevice_QueryInterface(device,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 &IID_IDirectInputDevice2,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 (LPVOID *) & joystick->
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 hwdata->InputDevice);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
205 /* We are done with this object. Use the stored one from now on. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 IDirectInputDevice_Release(device);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
207
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
208 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
209 SetDIerror("IDirectInputDevice::QueryInterface", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
213 /* Aquire shared access. Exclusive access is required for forces,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
214 * though. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 result =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
2580
64fa227c01ce Added the concept of the HelperWindow to help with DirectInput.
Edgar Simo <bobbens@gmail.com>
parents: 2579
diff changeset
217 InputDevice, SDL_HelperWindow,
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
218 DISCL_EXCLUSIVE |
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 DISCL_BACKGROUND);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
220 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
221 SetDIerror("IDirectInputDevice2::SetCooperativeLevel", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
225 /* Use the extended data structure: DIJOYSTATE2. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 result =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice,
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
228 &c_dfDIJoystick2);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
229 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
230 SetDIerror("IDirectInputDevice2::SetDataFormat", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
231 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
232 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
233
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
234 /* Get device capabilities */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
235 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
236 IDirectInputDevice2_GetCapabilities(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
237 &joystick->hwdata->Capabilities);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
238
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
239 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
240 SetDIerror("IDirectInputDevice2::GetCapabilities", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
244 /* Force capable? */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
245 if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
246
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
247 result = IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
248
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
249 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
250 SetDIerror("IDirectInputDevice2::Acquire", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
251 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
252 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
253
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
254 /* reset all accuators. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
255 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
256 IDirectInputDevice2_SendForceFeedbackCommand(joystick->hwdata->
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
257 InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
258 DISFFC_RESET);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
260 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
261 SetDIerror("IDirectInputDevice2::SendForceFeedbackCommand",
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
262 result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
263 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
264 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
265
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
266 result = IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
267
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
268 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
269 SetDIerror("IDirectInputDevice2::Unacquire", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
270 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
271 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
272
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
273 /* Turn on auto-centering for a ForceFeedback device (until told
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
274 * otherwise). */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 dipdw.diph.dwObj = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 dipdw.diph.dwHow = DIPH_DEVICE;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
277 dipdw.dwData = DIPROPAUTOCENTER_ON;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
278
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 result =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
281 DIPROP_AUTOCENTER, &dipdw.diph);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
283 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
284 SetDIerror("IDirectInputDevice2::SetProperty", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
289 /* What buttons and axes does it have? */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
290 IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
291 EnumDevObjectsCallback, joystick,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
292 DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
293
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
294 dipdw.diph.dwObj = 0;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
295 dipdw.diph.dwHow = DIPH_DEVICE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
296 dipdw.dwData = INPUT_QSIZE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
297
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
298 /* Set the buffer size */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
299 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
300 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
301 DIPROP_BUFFERSIZE, &dipdw.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
302
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
303 if (result == DI_POLLEDDEVICE) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
304 /* This device doesn't support buffering, so we're forced
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
305 * to use less reliable polling. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
306 joystick->hwdata->buffered = 0;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
307 } else if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
308 SetDIerror("IDirectInputDevice2::SetProperty", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
309 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
310 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
311
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 return (0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
315 static BOOL CALLBACK
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
316 EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
317 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
318 SDL_Joystick *joystick = (SDL_Joystick *) pvRef;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
319 HRESULT result;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
320 input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
321
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
322 in->ofs = dev->dwOfs;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
323
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
324 if (dev->dwType & DIDFT_BUTTON) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
325 in->type = BUTTON;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
326 in->num = joystick->nbuttons;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
327 joystick->nbuttons++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
328 } else if (dev->dwType & DIDFT_POV) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
329 in->type = HAT;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
330 in->num = joystick->nhats;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
331 joystick->nhats++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
332 } else if (dev->dwType & DIDFT_AXIS) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
333 DIPROPRANGE diprg;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
334 DIPROPDWORD dilong;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
335
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
336 in->type = AXIS;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
337 in->num = joystick->naxes;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
338
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
339 diprg.diph.dwSize = sizeof(diprg);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
340 diprg.diph.dwHeaderSize = sizeof(diprg.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
341 diprg.diph.dwObj = dev->dwOfs;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
342 diprg.diph.dwHow = DIPH_BYOFFSET;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
343 diprg.lMin = AXIS_MIN;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
344 diprg.lMax = AXIS_MAX;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
345
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
346 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
347 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
348 DIPROP_RANGE, &diprg.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
349 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
350 return DIENUM_CONTINUE; /* don't use this axis */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
351 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
352
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
353 /* Set dead zone to 0. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
354 dilong.diph.dwSize = sizeof(dilong);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
355 dilong.diph.dwHeaderSize = sizeof(dilong.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
356 dilong.diph.dwObj = dev->dwOfs;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
357 dilong.diph.dwHow = DIPH_BYOFFSET;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
358 dilong.dwData = 0;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
359 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
360 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
361 DIPROP_DEADZONE, &dilong.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
362 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
363 return DIENUM_CONTINUE; /* don't use this axis */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
364 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
365
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
366 joystick->naxes++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
367 } else {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
368 /* not supported at this time */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
369 return DIENUM_CONTINUE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
370 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
371
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
372 joystick->hwdata->NumInputs++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
373
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
374 if (joystick->hwdata->NumInputs == MAX_INPUTS) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
375 return DIENUM_STOP; /* too many */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
376 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
377
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
378 return DIENUM_CONTINUE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
379 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
380
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
381 /* Function to update the state of a joystick - called as a device poll.
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
382 * This function shouldn't update the joystick structure directly,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
383 * but instead should call SDL_PrivateJoystick*() to deliver events
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
384 * and update joystick device state.
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
385 */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
386 void
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
387 SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick)
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
388 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
389 DIJOYSTATE2 state;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
390 HRESULT result;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
391 int i;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
392
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
393 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
394 IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
395 sizeof(DIJOYSTATE2), &state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
396 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
397 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
398 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
399 IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
400 sizeof(DIJOYSTATE2), &state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
401 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
402
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
403 /* Set each known axis, button and POV. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
404 for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
405 const input_t *in = &joystick->hwdata->Inputs[i];
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
406
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
407 switch (in->type) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
408 case AXIS:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
409 switch (in->ofs) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
410 case DIJOFS_X:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
411 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
412 (Sint16) state.lX);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
413 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
414 case DIJOFS_Y:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
415 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
416 (Sint16) state.lY);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
417 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
418 case DIJOFS_Z:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
419 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
420 (Sint16) state.lZ);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
421 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
422 case DIJOFS_RX:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
423 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
424 (Sint16) state.lRx);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
425 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
426 case DIJOFS_RY:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
427 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
428 (Sint16) state.lRy);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
429 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
430 case DIJOFS_RZ:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
431 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
432 (Sint16) state.lRz);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
433 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
434 case DIJOFS_SLIDER(0):
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
435 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
436 (Sint16) state.rglSlider[0]);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
437 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
438 case DIJOFS_SLIDER(1):
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
439 SDL_PrivateJoystickAxis_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
440 (Sint16) state.rglSlider[1]);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
441 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
442 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
443
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
444 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
445
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
446 case BUTTON:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
447 SDL_PrivateJoystickButton_Int(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
448 (Uint8) (state.
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
449 rgbButtons[in->ofs -
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
450 DIJOFS_BUTTON0]
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
451 ? SDL_PRESSED :
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
452 SDL_RELEASED));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
453 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
454 case HAT:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
455 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
456 Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs -
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
457 DIJOFS_POV(0)]);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
458 SDL_PrivateJoystickHat_Int(joystick, in->num, pos);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
459 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
460 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
461 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
462 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
463 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
464
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
465 void
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
466 SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick)
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
467 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
468 int i;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
469 HRESULT result;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
470 DWORD numevents;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
471 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
472
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
473 numevents = INPUT_QSIZE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
474 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
475 IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
476 sizeof(DIDEVICEOBJECTDATA), evtbuf,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
477 &numevents, 0);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
478 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
479 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
480 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
481 IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
482 sizeof(DIDEVICEOBJECTDATA),
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
483 evtbuf, &numevents, 0);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
484 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
485
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
486 /* Handle the events or punt */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
487 if (FAILED(result))
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
488 return;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
489
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
490 for (i = 0; i < (int) numevents; ++i) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
491 int j;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
492
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
493 for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
494 const input_t *in = &joystick->hwdata->Inputs[j];
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
495
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
496 if (evtbuf[i].dwOfs != in->ofs)
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
497 continue;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
498
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
499 switch (in->type) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
500 case AXIS:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
501 SDL_PrivateJoystickAxis(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
502 (Sint16) evtbuf[i].dwData);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
503 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
504 case BUTTON:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
505 SDL_PrivateJoystickButton(joystick, in->num,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
506 (Uint8) (evtbuf[i].
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
507 dwData ? SDL_PRESSED :
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
508 SDL_RELEASED));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
509 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
510 case HAT:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
511 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
512 Uint8 pos = TranslatePOV(evtbuf[i].dwData);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
513 SDL_PrivateJoystickHat(joystick, in->num, pos);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
514 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
515 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
516 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
517 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
518 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
519
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
520
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 static Uint8
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 TranslatePOV(DWORD value)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 const int HAT_VALS[] = {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 SDL_HAT_UP,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 SDL_HAT_UP | SDL_HAT_RIGHT,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 SDL_HAT_RIGHT,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 SDL_HAT_DOWN | SDL_HAT_RIGHT,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 SDL_HAT_DOWN,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 SDL_HAT_DOWN | SDL_HAT_LEFT,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 SDL_HAT_LEFT,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 SDL_HAT_UP | SDL_HAT_LEFT
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 };
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 if (LOWORD(value) == 0xFFFF)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 return SDL_HAT_CENTERED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 /* Round the value up: */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 value += 4500 / 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 value %= 36000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 value /= 4500;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 if (value >= 8)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 return SDL_HAT_CENTERED; /* shouldn't happen */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 return HAT_VALS[value];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 * do it. */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 if (joystick->axes[axis] != value)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 return SDL_PrivateJoystickAxis(joystick, axis, value);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat, Uint8 value)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 if (joystick->hats[hat] != value)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 return SDL_PrivateJoystickHat(joystick, hat, value);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, Uint8 button,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 Uint8 state)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 if (joystick->buttons[button] != state)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 return SDL_PrivateJoystickButton(joystick, button, state);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 HRESULT result;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 result = IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 if (joystick->hwdata->buffered)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 SDL_SYS_JoystickUpdate_Buffered(joystick);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 SDL_SYS_JoystickUpdate_Polled(joystick);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 /* Function to close a joystick after use */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 IDirectInputDevice2_Release(joystick->hwdata->InputDevice);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 if (joystick->hwdata != NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 /* free system specific hardware data */
2577
72b17d80b426 Fixed some lone malloc and free.
Edgar Simo <bobbens@gmail.com>
parents: 2576
diff changeset
602 SDL_free(joystick->hwdata);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 /* Function to perform any system-specific joystick related cleanup */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 SDL_SYS_JoystickQuit(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 IDirectInput_Release(dinput);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 dinput = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 #endif /* SDL_JOYSTICK_DINPUT */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 /* vi: set ts=4 sw=4 expandtab: */