annotate src/joystick/win32/SDL_dxjoystick.c @ 2528:50414589501e gsoc2008_force_feedback

Fixed some typos.
author Edgar Simo <bobbens@gmail.com>
date Fri, 18 Jul 2008 08:06:06 +0000
parents fe19afb86473
children 034440120c38 e1da92da346c 0906692aa6a4
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"
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
41
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
42 #define WIN32_LEAN_AND_MEAN
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
43 #include <windows.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
44
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
45 #define DIRECTINPUT_VERSION 0x0500
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
46 #include <dinput.h>
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
47 #ifdef _MSC_VER
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
48 /* Used for the c_dfDIJoystick2 symbol (no imports are used) */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
49 # pragma comment (lib, "dinput.lib")
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
50 #endif
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
51 #include <dxerr9.h> /* From DirectX SDK 9c */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
52 #ifdef _MSC_VER
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
53 # pragma comment (lib, "dxerr9.lib")
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
54 #endif
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
55
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
56 /* 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
57 #ifdef _MSC_VER
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
58 #define snprintf _snprintf
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
59 #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
60
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
61 #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
62 #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
63 #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
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
64 #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
65 #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
66 #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
67
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
68 /* external variables referenced. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
69 extern HINSTANCE SDL_Instance;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
70 extern HWND SDL_Window;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
71
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
72
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
73 /* local variables */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
74 static LPDIRECTINPUT dinput = NULL;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
75 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
76 LPDIRECTINPUT * ppDI,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
77 LPUNKNOWN punkOuter);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
78 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
79 static int SYS_NumJoysticks;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
80 static HINSTANCE DInputDLL = NULL;
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
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
83 /* local prototypes */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
84 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
85 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
86 pdidInstance, VOID * pContext);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
87 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
88 LPVOID pvRef);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
89 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
90 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
91 Sint16 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
92 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
93 Uint8 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
94 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
95 Uint8 button, Uint8 state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
96
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
97
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
98 /* local types */
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
99 typedef enum Type
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 { BUTTON, AXIS, HAT } Type;
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
101
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 typedef struct input_t
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 {
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 /* DirectInput offset for this input type: */
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
105 DWORD ofs;
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
106
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
107 /* Button, axis or hat: */
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 Type type;
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 /* SDL input offset: */
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
111 Uint8 num;
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
112 } input_t;
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
113
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
114 /* The private structure used to keep track 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
115 struct joystick_hwdata
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
116 {
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
117 LPDIRECTINPUTDEVICE2 InputDevice;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
118 DIDEVCAPS Capabilities;
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
119 int 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
120
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
121 input_t Inputs[MAX_INPUTS];
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
122 int NumInputs;
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
123 };
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
124
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
125 /* 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
126 static void
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
127 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
128 {
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
129 SDL_SetError("%s() [%s]: %s", function,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
130 DXGetErrorString9(code), DXGetErrorDescription9(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
131 }
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
132
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
133
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 /* 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
135 * 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
136 * 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
137 * 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
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 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
140 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
141 {
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
142 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
143
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
144 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
145
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
146 result = CoInitialize(NULL);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
147 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
148 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
149 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
150 }
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
151
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
152 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
153 &IID_IDirectInput, &dinput);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
154
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
155 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
156 SetDIerror("CoCreateInstance", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
157 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
158 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
159
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
160 /* Because we used CoCreateInstance, we need to Initialize it, first. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
161 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
162 IDirectInput_Initialize(dinput, SDL_Instance, DIRECTINPUT_VERSION);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
163
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
164 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
165 SetDIerror("IDirectInput::Initialize", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
166 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
167 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
168
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
169 /* 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
170 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
171 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
172 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
173 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
174
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
175 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
176 }
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
177
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
178 static BOOL CALLBACK
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
179 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
180 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
181 memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
182 sizeof(DIDEVICEINSTANCE));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
183 SYS_NumJoysticks++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
184
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
185 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
186 return DIENUM_STOP;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
187
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
188 return DIENUM_CONTINUE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
189 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
190
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
191 /* 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
192 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
193 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
194 {
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
195 /***-> 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
196 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
197 }
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 /* 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
200 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
201 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
202 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
203 */
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 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
205 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
206 {
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
207 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
208 LPDIRECTINPUTDEVICE device;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
209 DIPROPDWORD dipdw;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
210
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
211 ZeroMemory(&dipdw, sizeof(DIPROPDWORD));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
212 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
213 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
214
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
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 /* 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
217 joystick->hwdata =
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
218 (struct joystick_hwdata *) 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
219 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
220 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
221 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
222 }
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
223 ZeroMemory(joystick->hwdata, 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
224 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
225 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
226
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 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
228 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
229 &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
230 guidInstance, &device, NULL);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
231 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
232 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
233 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
234 }
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
235
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
236 /* 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
237 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
238 &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
239 (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
240 hwdata->InputDevice);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
241 /* 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
242 IDirectInputDevice_Release(device);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
243
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
244 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
245 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
246 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
247 }
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
248
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
249 /* 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
250 * 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
251 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
252 IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
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
253 InputDevice, SDL_Window,
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
254 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
255 DISCL_BACKGROUND);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
256 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
257 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
258 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
259 }
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
260
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
261 /* 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
262 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
263 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
264 &c_dfDIJoystick2);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
265 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
266 SetDIerror("IDirectInputDevice2::SetDataFormat", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
267 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
268 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
269
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
270 /* Get device capabilities */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
271 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
272 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
273 &joystick->hwdata->Capabilities);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
274
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
275 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
276 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
277 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
278 }
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
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
280 /* Force capable? */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
281 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
282
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
283 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
284
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
285 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
286 SetDIerror("IDirectInputDevice2::Acquire", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
287 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
288 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
289
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
290 /* reset all accuators. */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
291 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
292 IDirectInputDevice2_SendForceFeedbackCommand(joystick->hwdata->
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
293 InputDevice,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
294 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
295
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
296 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
297 SetDIerror("IDirectInputDevice2::SendForceFeedbackCommand",
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
298 result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
299 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
300 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
301
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
302 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
303
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
304 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
305 SetDIerror("IDirectInputDevice2::Unacquire", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
306 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
307 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
308
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
309 /* 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
310 * 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
311 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
312 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
313 dipdw.dwData = DIPROPAUTOCENTER_ON;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
314
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
315 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
316 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
317 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
318
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
319 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
320 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
321 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
322 }
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
323 }
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
324
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
325 /* 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
326 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
327 EnumDevObjectsCallback, joystick,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
328 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
329
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
330 dipdw.diph.dwObj = 0;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
331 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
332 dipdw.dwData = INPUT_QSIZE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
333
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
334 /* Set the buffer size */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
335 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
336 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
337 DIPROP_BUFFERSIZE, &dipdw.diph);
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 if (result == DI_POLLEDDEVICE) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
340 /* 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
341 * 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
342 joystick->hwdata->buffered = 0;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
343 } else if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
344 SetDIerror("IDirectInputDevice2::SetProperty", result);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
345 return (-1);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
346 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
347
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
348 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
349 }
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
350
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
351 static BOOL CALLBACK
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
352 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
353 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
354 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
355 HRESULT result;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
356 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
357
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
358 in->ofs = dev->dwOfs;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
359
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
360 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
361 in->type = BUTTON;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
362 in->num = joystick->nbuttons;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
363 joystick->nbuttons++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
364 } 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
365 in->type = HAT;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
366 in->num = joystick->nhats;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
367 joystick->nhats++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
368 } 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
369 DIPROPRANGE diprg;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
370 DIPROPDWORD dilong;
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 in->type = AXIS;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
373 in->num = joystick->naxes;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
374
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
375 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
376 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
377 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
378 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
379 diprg.lMin = AXIS_MIN;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
380 diprg.lMax = AXIS_MAX;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
381
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
382 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
383 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
384 DIPROP_RANGE, &diprg.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
385 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
386 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
387 }
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 /* 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
390 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
391 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
392 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
393 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
394 dilong.dwData = 0;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
395 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
396 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
397 DIPROP_DEADZONE, &dilong.diph);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
398 if (FAILED(result)) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
399 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
400 }
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 joystick->naxes++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
403 } else {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
404 /* 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
405 return DIENUM_CONTINUE;
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
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
408 joystick->hwdata->NumInputs++;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
409
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
410 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
411 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
412 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
413
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
414 return DIENUM_CONTINUE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
415 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
416
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
417 /* 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
418 * 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
419 * 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
420 * 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
421 */
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
422 void
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
423 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
424 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
425 DIJOYSTATE2 state;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
426 HRESULT result;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
427 int i;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
428
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
429 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
430 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
431 sizeof(DIJOYSTATE2), &state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
432 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
433 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
434 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
435 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
436 sizeof(DIJOYSTATE2), &state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
437 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
438
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
439 /* 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
440 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
441 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
442
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
443 switch (in->type) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
444 case AXIS:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
445 switch (in->ofs) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
446 case DIJOFS_X:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
447 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
448 (Sint16) state.lX);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
449 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
450 case DIJOFS_Y:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
451 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
452 (Sint16) state.lY);
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 DIJOFS_Z:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
455 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
456 (Sint16) state.lZ);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
457 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
458 case DIJOFS_RX:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
459 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
460 (Sint16) state.lRx);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
461 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
462 case DIJOFS_RY:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
463 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
464 (Sint16) state.lRy);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
465 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
466 case DIJOFS_RZ:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
467 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
468 (Sint16) state.lRz);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
469 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
470 case DIJOFS_SLIDER(0):
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
471 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
472 (Sint16) state.rglSlider[0]);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
473 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
474 case DIJOFS_SLIDER(1):
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
475 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
476 (Sint16) state.rglSlider[1]);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
477 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
478 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
479
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
480 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
481
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
482 case BUTTON:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
483 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
484 (Uint8) (state.
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
485 rgbButtons[in->ofs -
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
486 DIJOFS_BUTTON0]
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
487 ? SDL_PRESSED :
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
488 SDL_RELEASED));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
489 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
490 case HAT:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
491 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
492 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
493 DIJOFS_POV(0)]);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
494 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
495 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
496 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
497 }
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 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
500
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
501 void
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
502 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
503 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
504 int i;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
505 HRESULT result;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
506 DWORD numevents;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
507 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
508
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
509 numevents = INPUT_QSIZE;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
510 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
511 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
512 sizeof(DIDEVICEOBJECTDATA), evtbuf,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
513 &numevents, 0);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
514 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
515 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
516 result =
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
517 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
518 sizeof(DIDEVICEOBJECTDATA),
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
519 evtbuf, &numevents, 0);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
520 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
521
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
522 /* 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
523 if (FAILED(result))
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
524 return;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
525
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
526 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
527 int j;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
528
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
529 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
530 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
531
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
532 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
533 continue;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
534
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
535 switch (in->type) {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
536 case AXIS:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
537 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
538 (Sint16) evtbuf[i].dwData);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
539 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
540 case BUTTON:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
541 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
542 (Uint8) (evtbuf[i].
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
543 dwData ? SDL_PRESSED :
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
544 SDL_RELEASED));
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
545 break;
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
546 case HAT:
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
547 {
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
548 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
549 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
550 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
551 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
552 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
553 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
554 }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
555
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
556
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
557 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
558 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
559 {
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 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
561 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
562 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
563 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
564 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
565 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
566 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
567 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
568 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
569 };
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 (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
572 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
573
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 /* 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
575 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
576 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
577 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
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 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
580 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
581
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 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
583 }
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
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 /* 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
586 * 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
587 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
588 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
589 {
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 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
591 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
592 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
593 }
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
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 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
596 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
597 {
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 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
599 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
600 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
601 }
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
602
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 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
604 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
605 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
606 {
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 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
608 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
609 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
610 }
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
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 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
613 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
614 {
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 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
616
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
617 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
618 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
619 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
620 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
621 }
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
622
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
623 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
624 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
625 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
626 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
627 }
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
628
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
629 /* 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
630 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
631 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
632 {
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
633 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
634 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
635
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
636 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
637 /* free 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
638 free(joystick->hwdata);
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
639 }
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
640 }
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
641
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
642 /* 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
643 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
644 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
645 {
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
646 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
647 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
648 }
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
649
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
650 #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
651 /* vi: set ts=4 sw=4 expandtab: */