Commit fd65aaa9a86410083673d057c65e214f10362069

Ozkan Sezer 2021-01-23T17:30:50

move outdated winmm and psp joystick codes to struct _SDL_JoystickDriver build-tested only. (bug #5472.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 37eda1e..1cae14a 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -62,6 +62,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
 #if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
     &SDL_WINDOWS_JoystickDriver,
 #endif
+#if defined(SDL_JOYSTICK_WINMM)
+    &SDL_WINMM_JoystickDriver,
+#endif
 #ifdef SDL_JOYSTICK_LINUX
     &SDL_LINUX_JoystickDriver,
 #endif
@@ -86,6 +89,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
 #ifdef SDL_JOYSTICK_OS2
     &SDL_OS2_JoystickDriver,
 #endif
+#ifdef SDL_JOYSTICK_PSP
+    &SDL_PSP_JoystickDriver,
+#endif
 #ifdef SDL_JOYSTICK_VIRTUAL
     &SDL_VIRTUAL_JoystickDriver,
 #endif
@@ -343,7 +349,7 @@ SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
     Uint32 id = MAKE_VIDPID(SDL_JoystickGetVendor(joystick),
                             SDL_JoystickGetProduct(joystick));
 
-/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
+    /*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
 
     if (joystick->naxes == 2) {
         /* Assume D-pad or thumbstick style axes are centered at 0 */
@@ -1249,7 +1255,6 @@ SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
             SDL_PrivateJoystickTouchpad(joystick, i, j, SDL_RELEASED, 0.0f, 0.0f, 0.0f);
         }
     }
-
 }
 
 void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index 2de9cd3..1ba6775 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -24,7 +24,6 @@
 #define SDL_sysjoystick_h_
 
 /* This is the system specific header for the SDL joystick API */
-
 #include "SDL_joystick.h"
 #include "SDL_joystick_c.h"
 
@@ -204,7 +203,9 @@ extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
 extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
 extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
 extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
+extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
 extern SDL_JoystickDriver SDL_OS2_JoystickDriver;
+extern SDL_JoystickDriver SDL_PSP_JoystickDriver;
 
 #endif /* SDL_sysjoystick_h_ */
 
diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c
index 8208869..f806465 100644
--- a/src/joystick/psp/SDL_sysjoystick.c
+++ b/src/joystick/psp/SDL_sysjoystick.c
@@ -103,7 +103,7 @@ int JoystickUpdate(void *data)
  * Joystick 0 should be the system default joystick.
  * It should return number of joysticks, or -1 on an unrecoverable fatal error.
  */
-int SDL_SYS_JoystickInit(void)
+static int PSP_JoystickInit(void)
 {
     int i;
 
@@ -132,35 +132,55 @@ int SDL_SYS_JoystickInit(void)
     return 1;
 }
 
-int SDL_SYS_NumJoysticks(void)
+static int PSP_NumJoysticks(void)
 {
     return 1;
 }
 
-void SDL_SYS_JoystickDetect(void)
+static void PSP_JoystickDetect(void)
 {
 }
 
+#if 0
 /* Function to get the device-dependent name of a joystick */
-const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+static const char *PSP_JoystickName(int idx)
+{
+    if (idx == 0) return "PSP controller";
+    SDL_SetError("No joystick available with that index");
+    return NULL;
+}
+#endif
+
+/* Function to get the device-dependent name of a joystick */
+static const char *PSP_JoystickGetDeviceName(int device_index)
 {
     return "PSP builtin joypad";
 }
 
-/* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+static int PSP_JoystickGetDevicePlayerIndex(int device_index)
 {
-    return device_index;
+    return -1;
 }
 
-/* Function to get the device-dependent name of a joystick */
-const char *SDL_SYS_JoystickName(int index)
+static void
+PSP_JoystickSetDevicePlayerIndex(int device_index, int player_index)
 {
-    if (index == 0)
-        return "PSP controller";
+}
 
-    SDL_SetError("No joystick available with that index");
-    return(NULL);
+static SDL_JoystickGUID PSP_JoystickGetDeviceGUID(int device_index)
+{
+    SDL_JoystickGUID guid;
+    /* the GUID is just the first 16 chars of the name for now */
+    const char *name = PSP_JoystickGetDeviceName(device_index);
+    SDL_zero(guid);
+    SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
+    return guid;
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+static SDL_JoystickID PSP_JoystickGetDeviceInstanceID(int device_index)
+{
+    return device_index;
 }
 
 /* Function to open a joystick for use.
@@ -168,7 +188,7 @@ const char *SDL_SYS_JoystickName(int index)
    This should fill the nbuttons and naxes fields of the joystick structure.
    It returns 0, or -1 if there is an error.
  */
-int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
+static int PSP_JoystickOpen(SDL_Joystick *joystick, int device_index)
 {
     joystick->nbuttons = 14;
     joystick->naxes = 2;
@@ -177,12 +197,40 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
     return 0;
 }
 
+static int
+PSP_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+    return SDL_Unsupported();
+}
+
+static int
+PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+    return SDL_Unsupported();
+}
+
+static SDL_bool PSP_JoystickHasLED(SDL_Joystick *joystick)
+{
+    return SDL_FALSE;
+}
+
+static int
+PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+    return SDL_Unsupported();
+}
+
+static int PSP_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
+{
+    return SDL_Unsupported();
+}
+
 /* Function to update the state of a joystick - called as a device poll.
  * This function shouldn't update the joystick structure directly,
  * but instead should call SDL_PrivateJoystick*() to deliver events
  * and update joystick device state.
  */
-void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
+static void PSP_JoystickUpdate(SDL_Joystick *joystick)
 {
     int i;
     enum PspCtrlButtons buttons;
@@ -225,12 +273,12 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
 }
 
 /* Function to close a joystick after use */
-void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
+static void PSP_JoystickClose(SDL_Joystick *joystick)
 {
 }
 
 /* Function to perform any system-specific joystick related cleanup */
-void SDL_SYS_JoystickQuit(void)
+static void PSP_JoystickQuit(void)
 {
     /* Cleanup Threads and Semaphore. */
     running = 0;
@@ -238,25 +286,33 @@ void SDL_SYS_JoystickQuit(void)
     SDL_DestroySemaphore(pad_sem);
 }
 
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+static SDL_bool
+PSP_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
 {
-    SDL_JoystickGUID guid;
-    /* the GUID is just the first 16 chars of the name for now */
-    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
-    SDL_zero( guid );
-    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
-    return guid;
+    return SDL_FALSE;
 }
 
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+SDL_JoystickDriver SDL_PSP_JoystickDriver =
 {
-    SDL_JoystickGUID guid;
-    /* the GUID is just the first 16 chars of the name for now */
-    const char *name = joystick->name;
-    SDL_zero( guid );
-    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
-    return guid;
-}
+    PSP_JoystickInit,
+    PSP_NumJoysticks,
+    PSP_JoystickDetect,
+    PSP_JoystickGetDeviceName,
+    PSP_JoystickGetDevicePlayerIndex,
+    PSP_JoystickSetDevicePlayerIndex,
+    PSP_JoystickGetDeviceGUID,
+    PSP_JoystickGetDeviceInstanceID,
+    PSP_JoystickOpen,
+    PSP_JoystickRumble,
+    PSP_JoystickRumbleTriggers,
+    PSP_JoystickHasLED,
+    PSP_JoystickSetLED,
+    PSP_JoystickSetSensorsEnabled,
+    PSP_JoystickUpdate,
+    PSP_JoystickClose,
+    PSP_JoystickQuit,
+    PSP_JoystickGetGamepadMapping
+};
 
 #endif /* SDL_JOYSTICK_PSP */
 
diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c
index 2c37383..79ac67f 100644
--- a/src/joystick/windows/SDL_mmjoystick.c
+++ b/src/joystick/windows/SDL_mmjoystick.c
@@ -146,14 +146,14 @@ GetJoystickName(int index, const char *szRegKey)
     return (name);
 }
 
-static int SDL_SYS_numjoysticks = 0;
+static int numjoysticks = 0;
 
 /* Function to scan the system for joysticks.
  * Joystick 0 should be the system default joystick.
  * It should return 0, or -1 on an unrecoverable fatal error.
  */
-int
-SDL_SYS_JoystickInit(void)
+static int
+WINMM_JoystickInit(void)
 {
     int i;
     int maxdevs;
@@ -168,9 +168,9 @@ SDL_SYS_JoystickInit(void)
     }
 
     /* Loop over all potential joystick devices */
-    SDL_SYS_numjoysticks = 0;
+    numjoysticks = 0;
     maxdevs = joyGetNumDevs();
-    for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++i) {
+    for (i = JOYSTICKID1; i < maxdevs && numjoysticks < MAX_JOYSTICKS; ++i) {
 
         joyinfo.dwSize = sizeof(joyinfo);
         joyinfo.dwFlags = JOY_RETURNALL;
@@ -178,31 +178,31 @@ SDL_SYS_JoystickInit(void)
         if (result == JOYERR_NOERROR) {
             result = joyGetDevCapsA(i, &joycaps, sizeof(joycaps));
             if (result == JOYERR_NOERROR) {
-                SYS_JoystickID[SDL_SYS_numjoysticks] = i;
-                SYS_Joystick[SDL_SYS_numjoysticks] = joycaps;
-                SYS_JoystickName[SDL_SYS_numjoysticks] =
+                SYS_JoystickID[numjoysticks] = i;
+                SYS_Joystick[numjoysticks] = joycaps;
+                SYS_JoystickName[numjoysticks] =
                     GetJoystickName(i, joycaps.szRegKey);
-                SDL_SYS_numjoysticks++;
+                numjoysticks++;
             }
         }
     }
-    return (SDL_SYS_numjoysticks);
+    return numjoysticks;
 }
 
-int
-SDL_SYS_NumJoysticks(void)
+static int
+WINMM_NumJoysticks(void)
 {
-    return SDL_SYS_numjoysticks;
+    return numjoysticks;
 }
 
-void
-SDL_SYS_JoystickDetect(void)
+static void
+WINMM_JoystickDetect(void)
 {
 }
 
 /* Function to get the device-dependent name of a joystick */
-const char *
-SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+static const char *
+WINMM_JoystickGetDeviceName(int device_index)
 {
     if (SYS_JoystickName[device_index] != NULL) {
         return (SYS_JoystickName[device_index]);
@@ -211,8 +211,29 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
     }
 }
 
+static int
+WINMM_JoystickGetDevicePlayerIndex(int device_index)
+{
+    return -1;
+}
+
+static void
+WINMM_JoystickSetDevicePlayerIndex(int device_index, int player_index)
+{
+}
+
+static SDL_JoystickGUID WINMM_JoystickGetDeviceGUID(int device_index)
+{
+    SDL_JoystickGUID guid;
+    /* the GUID is just the first 16 chars of the name for now */
+    const char *name = WINMM_JoystickGetDeviceName(device_index);
+    SDL_zero(guid);
+    SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
+    return guid;
+}
+
 /* Function to perform the mapping from device index to the instance id for this index */
-SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+static SDL_JoystickID WINMM_JoystickGetDeviceInstanceID(int device_index)
 {
     return device_index;
 }
@@ -222,15 +243,14 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    This should fill the nbuttons and naxes fields of the joystick structure.
    It returns 0, or -1 if there is an error.
  */
-int
-SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+static int
+WINMM_JoystickOpen(SDL_Joystick * joystick, int device_index)
 {
     int index, i;
     int caps_flags[MAX_AXES - 2] =
         { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
     int axis_min[MAX_AXES], axis_max[MAX_AXES];
 
-
     /* shortcut */
     index = device_index;
     axis_min[0] = SYS_Joystick[index].wXmin;
@@ -302,18 +322,46 @@ TranslatePOV(DWORD value)
     return (pos);
 }
 
+static int
+WINMM_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
+{
+    return SDL_Unsupported();
+}
+
+static int
+WINMM_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
+{
+    return SDL_Unsupported();
+}
+
+static SDL_bool WINMM_JoystickHasLED(SDL_Joystick *joystick)
+{
+    return SDL_FALSE;
+}
+
+static int
+WINMM_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
+{
+    return SDL_Unsupported();
+}
+
+static int WINMM_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
+{
+    return SDL_Unsupported();
+}
+
 /* Function to update the state of a joystick - called as a device poll.
  * This function shouldn't update the joystick structure directly,
  * but instead should call SDL_PrivateJoystick*() to deliver events
  * and update joystick device state.
  */
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+static void
+WINMM_JoystickUpdate(SDL_Joystick * joystick)
 {
     MMRESULT result;
     int i;
     DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
-        JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
+                              JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
     };
     DWORD pos[MAX_AXES];
     struct _transaxis *transaxis;
@@ -365,15 +413,15 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
 }
 
 /* Function to close a joystick after use */
-void
-SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+static void
+WINMM_JoystickClose(SDL_Joystick * joystick)
 {
     SDL_free(joystick->hwdata);
 }
 
 /* Function to perform any system-specific joystick related cleanup */
-void
-SDL_SYS_JoystickQuit(void)
+static void
+WINMM_JoystickQuit(void)
 {
     int i;
     for (i = 0; i < MAX_JOYSTICKS; i++) {
@@ -382,24 +430,10 @@ SDL_SYS_JoystickQuit(void)
     }
 }
 
-SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
-{
-    SDL_JoystickGUID guid;
-    /* the GUID is just the first 16 chars of the name for now */
-    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
-    SDL_zero( guid );
-    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
-    return guid;
-}
-
-SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+static SDL_bool
+WINMM_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
 {
-    SDL_JoystickGUID guid;
-    /* the GUID is just the first 16 chars of the name for now */
-    const char *name = joystick->name;
-    SDL_zero( guid );
-    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
-    return guid;
+    return SDL_FALSE;
 }
 
 
@@ -447,6 +481,28 @@ SetMMerror(char *function, int code)
     SDL_SetError("%s", errbuf);
 }
 
+SDL_JoystickDriver SDL_WINMM_JoystickDriver =
+{
+    WINMM_JoystickInit,
+    WINMM_NumJoysticks,
+    WINMM_JoystickDetect,
+    WINMM_JoystickGetDeviceName,
+    WINMM_JoystickGetDevicePlayerIndex,
+    WINMM_JoystickSetDevicePlayerIndex,
+    WINMM_JoystickGetDeviceGUID,
+    WINMM_JoystickGetDeviceInstanceID,
+    WINMM_JoystickOpen,
+    WINMM_JoystickRumble,
+    WINMM_JoystickRumbleTriggers,
+    WINMM_JoystickHasLED,
+    WINMM_JoystickSetLED,
+    WINMM_JoystickSetSensorsEnabled,
+    WINMM_JoystickUpdate,
+    WINMM_JoystickClose,
+    WINMM_JoystickQuit,
+    WINMM_JoystickGetGamepadMapping
+};
+
 #endif /* SDL_JOYSTICK_WINMM */
 
 /* vi: set ts=4 sw=4 expandtab: */