3
* An Idea and Atari version: LK Avalon, Janusz Pelc, 1989
4
* Linux Code: Arkadiusz Lipiec, 2002-2009
5
* <arkadiusz.lipiec@gmail.com>
7
* <thunorsif@hotmail.com>
9
* GNU Robbo is free software - you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* GNU Robbo is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the impled warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with GNU CC; see the file COPYING. If not, write to the
21
* Free Software Foundation, 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
30
#define DEBUG_CONTROLS
32
#define JOYDEADZONE (32767 * joystick_dead_zone / 100)
35
#define GP2X_JOY_N 0x00
36
#define GP2X_JOY_NW 0x01
37
#define GP2X_JOY_W 0x02
38
#define GP2X_JOY_SW 0x03
39
#define GP2X_JOY_S 0x04
40
#define GP2X_JOY_SE 0x05
41
#define GP2X_JOY_E 0x06
42
#define GP2X_JOY_NE 0x07
43
#define GP2X_START 0x08
44
#define GP2X_SELECT 0x09
45
#define GP2X_LTRIG 0x0A
46
#define GP2X_RTRIG 0x0B
47
#define GP2X_BTN_A 0x0C
48
#define GP2X_BTN_B 0x0D
49
#define GP2X_BTN_X 0x0E
50
#define GP2X_BTN_Y 0x0F
51
#define GP2X_VOL_UP 0x10
52
#define GP2X_VOL_DN 0x11
53
#define GP2X_BTN_JOY 0x12
55
/* Zaurus button IDs */
56
#define ZAURUS_UP SDLK_UP
57
#define ZAURUS_DOWN SDLK_DOWN
58
#define ZAURUS_LEFT SDLK_LEFT
59
#define ZAURUS_RIGHT SDLK_RIGHT
60
#define ZAURUS_SPACE SDLK_SPACE
61
#define ZAURUS_CANCEL SDLK_ESCAPE
63
#define ZAURUS_CALENDAR SDLK_F9
64
#define ZAURUS_ADDRESS SDLK_F10
65
#define ZAURUS_HOME SDLK_F12
66
#define ZAURUS_MENU SDLK_F11
67
#define ZAURUS_EMAIL SDLK_F13
72
/* Function prototypes */
73
void show_user_action(int *action_found);
74
int set_key_repeat(int delay, int interval);
77
/***************************************************************************
78
* Get User Action v5 *
79
***************************************************************************/
80
/* This reports whether an action has been triggered via user input.
81
Controls with modifiers take precedence over single key controls.
82
Controls must be unique although you can combine actions in your code.
83
Mixing of input devices and control reconfiguration is trivial.
84
user_controls holds all the controls. Each control has its pressed state
85
recorded so you won't need to do it yourself. It's also possible to
86
gain access to the device, id and state of individual events but in normal
87
operation you should only need to know the action triggered.
88
This function manages key/button repeat which can be different for each
89
control. If you don't want key/button repeat then set delay to -1.
90
It's designed to be called every TICK_INTERVAL because it counts in
91
TICK_INTERVAL units for key/button repeat calculation.
92
The event loop code in END SCREEN in main is almost empty and makes a good
93
template. Enable DEBUG to see the ACTIONs firing.
95
UPDATE: Joystick axis support added. Axes are converted into additional
96
virtual buttons (two per axis) and require a dead zone to be set up which
97
should be user configurable. For example, if a joystick has 10 physical
98
buttons then axis0 will be virtual buttons 10 and 11, axis1 12 and 13 etc.
101
int device; Keyboard or joystick
102
int id; Key or button id
103
int mod; Modifier control
104
int state; Pressed or released
105
int cyclesactive; How many cycles this has been pressed for
106
int delay; The initial delay in cycles before repeating - 0 disables the delay
107
int interval; The repeat interval in cycles - 0 disables the interval
109
struct control user_controls[USER_CONTROLS]; Holds the assignment of user controls
111
On entry: actionid will hold any actionid found
112
pollall = TRUE to poll all events
113
pollall = FALSE to poll one event (used to retrieve the device, id and state for each polled event)
114
device will hold the device of the last event or UNDEFINED (-1)
115
id will hold the id of the last event or UNDEFINED
116
state will hold the state of the last event or UNDEFINED
117
On exit: actionid will contain an actionid or UNDEFINED
118
returns 1 on SDL_QUIT else 0 */
120
int get_user_action(int *actionid, int pollall, int *device, int *id, int *state) {
121
int count, found = FALSE, axisplus, quitfound = 0;
122
static int axisvalues[10 * 2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* I doubt there exists a joystick with more than 10 axes */
124
*actionid = UNDEFINED;
126
while (SDL_PollEvent(&event)) {
127
*device = *id = *state = UNDEFINED;
128
switch (event.type) {
131
*device = DEVICE_KEYBOARD;
132
*id = event.key.keysym.sym;
133
*state = event.key.state;
135
case SDL_JOYBUTTONUP:
136
case SDL_JOYBUTTONDOWN:
137
*device = DEVICE_JOYSTICK;
138
*id = event.jbutton.button;
139
*state = event.jbutton.state;
141
case SDL_JOYAXISMOTION:
142
/* Identify which end of the axis we are going to work with */
143
axisplus = 0; /* -32767 to 0 */
144
if (event.jaxis.value > 0 || (event.jaxis.value == 0 && axisvalues[event.jaxis.axis * 2 + 1] >= JOYDEADZONE)) axisplus = 1; /* 0 to +32767 */
145
/* Does anything need to be reported as pressed or released? */
146
if ((abs(event.jaxis.value) >= JOYDEADZONE && axisvalues[event.jaxis.axis * 2 + axisplus] < JOYDEADZONE) || (abs(event.jaxis.value) < JOYDEADZONE && axisvalues[event.jaxis.axis * 2 + axisplus] >= JOYDEADZONE)) {
147
*device = DEVICE_JOYSTICK;
148
*id = event.jaxis.axis * 2 + axisplus + SDL_JoystickNumButtons(joystick);
149
*state = (abs(event.jaxis.value) >= JOYDEADZONE && axisvalues[event.jaxis.axis * 2 + axisplus] < JOYDEADZONE)? SDL_PRESSED: SDL_RELEASED;
150
axisvalues[event.jaxis.axis * 2 + axisplus] = abs(event.jaxis.value);
160
/* Iterate through user_controls and record the state for all matching controls */
161
if (*device != UNDEFINED) {
162
#ifdef DEBUG_CONTROLS
163
printf("device=%i; id=%03i; state=%i; all control states:", *device, *id, *state);
165
for (count = 0; count < USER_CONTROLS; count++) {
166
if (user_controls[count].device == *device && user_controls[count].id == *id) user_controls[count].state = *state;
167
if (*state == SDL_RELEASED) user_controls[count].cyclesactive = 0;
168
#ifdef DEBUG_CONTROLS
169
printf(" %i", user_controls[count].state);
172
#ifdef DEBUG_CONTROLS
181
/* Now we know what's pressed we can see if an action has been triggered */
182
/* Controls with modifiers take precedence so search for these first */
183
for (count = 0; count < USER_CONTROLS; count++) {
184
if (user_controls[count].state == SDL_PRESSED && user_controls[count].mod != UNDEFINED && user_controls[user_controls[count].mod].state == SDL_PRESSED) {
187
#ifdef DEBUG_CONTROLS
188
show_user_action(actionid);
194
/* Now search for controls without modifiers */
195
for (count = 0; count < USER_CONTROLS; count++) {
196
if (user_controls[count].state == SDL_PRESSED && user_controls[count].mod == UNDEFINED) {
199
#ifdef DEBUG_CONTROLS
200
show_user_action(actionid);
207
/* Because this function is called every TICK_INTERVAL, if the user is pressing a
208
control then it would trigger an action every TICK_INTERVAL. cyclesactive, delay
209
and interval are used to decide the frequency of individual key/button repeats */
211
if (user_controls[*actionid].cyclesactive == 0) {
212
/* Allow this action */
213
} else if (user_controls[*actionid].cyclesactive == user_controls[*actionid].delay) {
214
/* Allow this action */
215
} else if (user_controls[*actionid].cyclesactive > user_controls[*actionid].delay) {
216
if (user_controls[*actionid].interval == 0) {
217
/* Allow this action */
218
} else if ((user_controls[*actionid].cyclesactive - user_controls[*actionid].delay) % user_controls[*actionid].interval == 0) {
219
/* Allow this action */
226
user_controls[*actionid].cyclesactive++;
227
if (!found) *actionid = UNDEFINED;
233
/***************************************************************************
235
***************************************************************************/
236
/* Used for debugging */
238
void show_user_action(int *actionid) {
244
printf("ACTION_DOWN");
247
printf("ACTION_LEFT");
250
printf("ACTION_RIGHT");
252
case ACTION_SHOOT_UP:
253
printf("ACTION_SHOOT_UP");
255
case ACTION_SHOOT_DOWN:
256
printf("ACTION_SHOOT_DOWN");
258
case ACTION_SHOOT_LEFT:
259
printf("ACTION_SHOOT_LEFT");
261
case ACTION_SHOOT_RIGHT:
262
printf("ACTION_SHOOT_RIGHT");
265
printf("ACTION_SELECT");
268
printf("ACTION_EXIT");
271
printf("ACTION_HELP");
274
printf("ACTION_OPTIONS");
277
printf("ACTION_RESTART");
279
case ACTION_PREVIOUS_LEVEL:
280
printf("ACTION_PREVIOUS_LEVEL");
282
case ACTION_NEXT_LEVEL:
283
printf("ACTION_NEXT_LEVEL");
285
case ACTION_PREVIOUS_PACK:
286
printf("ACTION_PREVIOUS_PACK");
288
case ACTION_NEXT_PACK:
289
printf("ACTION_NEXT_PACK");
291
case ACTION_MODIFIER1:
292
printf("ACTION_MODIFIER1");
294
case ACTION_MODIFIER2:
295
printf("ACTION_MODIFIER2");
297
case ACTION_TOGGLE_FULLSCREEN:
298
printf("ACTION_TOGGLE_FULLSCREEN");
301
printf("ACTION_HOME");
304
printf("ACTION_END");
307
printf("ACTION_PAGEUP");
309
case ACTION_PAGEDOWN:
310
printf("ACTION_PAGEDOWN");
313
printf("ACTION_VOLUP");
316
printf("ACTION_VOLDOWN");
318
case ACTION_NOT_USED1:
319
printf("ACTION_NOT_USED1");
325
printf("Unknown action");
328
printf(": %i\n", user_controls[*actionid].cyclesactive);
331
/***************************************************************************
332
* Set Default User Controls *
333
***************************************************************************/
335
void set_default_user_controls(struct control user_controls[USER_CONTROLS]) {
338
/* Set some defaults */
339
for (count = 0; count < USER_CONTROLS; count++) {
340
#if defined(PLATFORM_GP2X)
341
user_controls[count].device = DEVICE_JOYSTICK;
342
#elif defined(PLATFORM_ZAURUS)
343
user_controls[count].device = DEVICE_KEYBOARD;
344
#elif defined(PLATFORM_PC)
345
user_controls[count].device = DEVICE_KEYBOARD;
347
user_controls[count].id = UNDEFINED;
348
user_controls[count].mod = UNDEFINED;
349
user_controls[count].state = SDL_RELEASED;
350
user_controls[count].cyclesactive = 0;
351
user_controls[count].delay = KEY_REPEAT_DELAY;
352
user_controls[count].interval = KEY_REPEAT_INTERVAL;
355
/* Now tune to a platform */
356
#if defined(PLATFORM_GP2X)
357
user_controls[ACTION_UP].id = GP2X_JOY_N;
358
user_controls[ACTION_DOWN].id = GP2X_JOY_S;
359
user_controls[ACTION_LEFT].id = GP2X_JOY_W;
360
user_controls[ACTION_RIGHT].id = GP2X_JOY_E;
361
user_controls[ACTION_SHOOT_UP].id = GP2X_JOY_N;
362
user_controls[ACTION_SHOOT_UP].mod = ACTION_MODIFIER1;
363
user_controls[ACTION_SHOOT_DOWN].id = GP2X_JOY_S;
364
user_controls[ACTION_SHOOT_DOWN].mod = ACTION_MODIFIER1;
365
user_controls[ACTION_SHOOT_LEFT].id = GP2X_JOY_W;
366
user_controls[ACTION_SHOOT_LEFT].mod = ACTION_MODIFIER1;
367
user_controls[ACTION_SHOOT_RIGHT].id = GP2X_JOY_E;
368
user_controls[ACTION_SHOOT_RIGHT].mod = ACTION_MODIFIER1;
369
user_controls[ACTION_SELECT].id = GP2X_BTN_B;
370
user_controls[ACTION_EXIT].id = GP2X_BTN_X;
371
user_controls[ACTION_HELP].id = GP2X_BTN_Y;
372
user_controls[ACTION_HELP].mod = ACTION_MODIFIER1;
373
user_controls[ACTION_OPTIONS].id = GP2X_START;
374
user_controls[ACTION_RESTART].id = GP2X_SELECT;
375
user_controls[ACTION_PREVIOUS_LEVEL].id = GP2X_LTRIG;
376
user_controls[ACTION_PREVIOUS_LEVEL].mod = ACTION_MODIFIER1;
377
user_controls[ACTION_NEXT_LEVEL].id = GP2X_RTRIG;
378
user_controls[ACTION_NEXT_LEVEL].mod = ACTION_MODIFIER1;
379
user_controls[ACTION_PREVIOUS_PACK].id = GP2X_LTRIG;
380
user_controls[ACTION_PREVIOUS_PACK].mod = ACTION_MODIFIER2;
381
user_controls[ACTION_NEXT_PACK].id = GP2X_RTRIG;
382
user_controls[ACTION_NEXT_PACK].mod = ACTION_MODIFIER2;
383
user_controls[ACTION_MODIFIER1].id = GP2X_BTN_A;
384
user_controls[ACTION_MODIFIER2].id = GP2X_BTN_Y;
385
user_controls[ACTION_TOGGLE_FULLSCREEN].device = UNDEFINED;
386
user_controls[ACTION_HOME].id = GP2X_VOL_DN;
387
user_controls[ACTION_HOME].mod = ACTION_MODIFIER1;
388
user_controls[ACTION_END].id = GP2X_VOL_UP;
389
user_controls[ACTION_END].mod = ACTION_MODIFIER1;
390
user_controls[ACTION_PAGEUP].id = GP2X_LTRIG;
391
user_controls[ACTION_PAGEDOWN].id = GP2X_RTRIG;
392
user_controls[ACTION_VOLUP].id = GP2X_VOL_UP;
393
user_controls[ACTION_VOLDOWN].id = GP2X_VOL_DN;
394
user_controls[ACTION_NOT_USED1].device = UNDEFINED;
395
#elif defined(PLATFORM_ZAURUS)
396
user_controls[ACTION_UP].id = ZAURUS_UP;
397
user_controls[ACTION_DOWN].id = ZAURUS_DOWN;
398
user_controls[ACTION_LEFT].id = ZAURUS_LEFT;
399
user_controls[ACTION_RIGHT].id = ZAURUS_RIGHT;
400
user_controls[ACTION_SHOOT_UP].id = ZAURUS_UP;
401
user_controls[ACTION_SHOOT_UP].mod = ACTION_MODIFIER1;
402
user_controls[ACTION_SHOOT_DOWN].id = ZAURUS_DOWN;
403
user_controls[ACTION_SHOOT_DOWN].mod = ACTION_MODIFIER1;
404
user_controls[ACTION_SHOOT_LEFT].id = ZAURUS_LEFT;
405
user_controls[ACTION_SHOOT_LEFT].mod = ACTION_MODIFIER1;
406
user_controls[ACTION_SHOOT_RIGHT].id = ZAURUS_RIGHT;
407
user_controls[ACTION_SHOOT_RIGHT].mod = ACTION_MODIFIER1;
408
user_controls[ACTION_SELECT].id = ZAURUS_OK;
409
user_controls[ACTION_EXIT].id = ZAURUS_CANCEL;
410
user_controls[ACTION_HELP].id = UNDEFINED;
411
user_controls[ACTION_OPTIONS].id = ZAURUS_ADDRESS;
412
user_controls[ACTION_RESTART].id = ZAURUS_HOME;
413
user_controls[ACTION_PREVIOUS_LEVEL].id = UNDEFINED;
414
user_controls[ACTION_NEXT_LEVEL].id = UNDEFINED;
415
user_controls[ACTION_PREVIOUS_PACK].id = UNDEFINED;
416
user_controls[ACTION_NEXT_PACK].id = UNDEFINED;
417
user_controls[ACTION_MODIFIER1].id = ZAURUS_SPACE;
418
user_controls[ACTION_MODIFIER2].id = UNDEFINED;
419
user_controls[ACTION_TOGGLE_FULLSCREEN].id = UNDEFINED;
420
user_controls[ACTION_HOME].id = UNDEFINED;
421
user_controls[ACTION_END].id = UNDEFINED;
422
user_controls[ACTION_PAGEUP].id = UNDEFINED;
423
user_controls[ACTION_PAGEDOWN].id = UNDEFINED;
424
user_controls[ACTION_VOLUP].id = UNDEFINED;
425
user_controls[ACTION_VOLDOWN].id = UNDEFINED;
426
user_controls[ACTION_NOT_USED1].device = UNDEFINED;
427
#elif defined(PLATFORM_PC)
428
user_controls[ACTION_UP].id = SDLK_UP;
429
user_controls[ACTION_DOWN].id = SDLK_DOWN;
430
user_controls[ACTION_LEFT].id = SDLK_LEFT;
431
user_controls[ACTION_RIGHT].id = SDLK_RIGHT;
432
user_controls[ACTION_SHOOT_UP].id = SDLK_UP;
433
user_controls[ACTION_SHOOT_UP].mod = ACTION_MODIFIER2;
434
user_controls[ACTION_SHOOT_DOWN].id = SDLK_DOWN;
435
user_controls[ACTION_SHOOT_DOWN].mod = ACTION_MODIFIER2;
436
user_controls[ACTION_SHOOT_LEFT].id = SDLK_LEFT;
437
user_controls[ACTION_SHOOT_LEFT].mod = ACTION_MODIFIER2;
438
user_controls[ACTION_SHOOT_RIGHT].id = SDLK_RIGHT;
439
user_controls[ACTION_SHOOT_RIGHT].mod = ACTION_MODIFIER2;
440
user_controls[ACTION_SELECT].id = SDLK_RETURN;
441
user_controls[ACTION_EXIT].id = SDLK_ESCAPE;
442
user_controls[ACTION_HELP].id = SDLK_F1;
443
user_controls[ACTION_OPTIONS].id = SDLK_F4;
444
user_controls[ACTION_RESTART].id = SDLK_r;
445
user_controls[ACTION_PREVIOUS_LEVEL].id = SDLK_F5;
446
user_controls[ACTION_NEXT_LEVEL].id = SDLK_F6;
447
user_controls[ACTION_PREVIOUS_PACK].id = SDLK_F7;
448
user_controls[ACTION_NEXT_PACK].id = SDLK_F8;
449
user_controls[ACTION_MODIFIER1].id = SDLK_LALT;
450
user_controls[ACTION_MODIFIER2].id = SDLK_RSHIFT;
451
user_controls[ACTION_TOGGLE_FULLSCREEN].id = SDLK_RETURN;
452
user_controls[ACTION_TOGGLE_FULLSCREEN].mod = ACTION_MODIFIER1;
453
user_controls[ACTION_HOME].id = SDLK_HOME;
454
user_controls[ACTION_END].id = SDLK_END;
455
user_controls[ACTION_PAGEUP].id = SDLK_PAGEUP;
456
user_controls[ACTION_PAGEDOWN].id = SDLK_PAGEDOWN;
457
user_controls[ACTION_VOLUP].id = SDLK_EQUALS;
458
user_controls[ACTION_VOLDOWN].id = SDLK_MINUS;
459
user_controls[ACTION_NOT_USED1].device = UNDEFINED;
464
/***************************************************************************
466
***************************************************************************/
467
/* Enable or disable keyboard key repeat (not used in this project anymore)
469
On entry: delay = the delay before repeating or 0 to disable
470
interval = the repeat interval
471
On exit: returns 1 on error else 0 */
473
int set_key_repeat(int delay, int interval) {
475
if (SDL_EnableKeyRepeat(delay, interval) != 0) {
476
fprintf(stdout, "Error setting key repeat: %s\n", SDL_GetError());
483
/***************************************************************************
484
* Initialise Joystick *
485
***************************************************************************/
486
/* Enable a joystick for input. It's designed so that it's possible to restore
487
a saved joyid and joyname from an rc file and attempt to match them up
488
taking into account somebody might have two joysticks that may have been
491
On entry: joyid = UNDEFINED (-1) for any joystick with joyname irrelevant
492
joyid = 0 to n for a specific joystick by joyid only (joyname = "-1")
493
joyid = 0 to n for a specific joystick by joyid and/or joyname with joyname taking priority (joyname != "-1")
494
show = TRUE to dump output to the terminal
495
On exit: returns the joyid if successful (zero based) with joyname = joystick name
496
returns UNDEFINED (-1) if unsuccessful with joyname = "-1" */
498
int initialise_joystick(int joyid, char *joyname, int show) {
499
int count, number_found, found = FALSE;
501
number_found = SDL_NumJoysticks(); /* Get number of joysticks attached */
503
/* Are any joysticks available? */
504
if (number_found > 0) {
506
/* WARNING: attempting to close joystick 0 on the GP2X causes a seg fault
507
and it'll probably do the same on other similar devices */
508
#if defined(PLATFORM_GP2X)
509
if ((joystick) && ((SDL_JoystickIndex(joystick)) > 0)) {
510
#elif defined(PLATFORM_ZAURUS)
512
#elif defined(PLATFORM_PC)
515
if (show) fprintf(stdout, "Joystick closed: %i:%s\n", SDL_JoystickIndex(joystick), SDL_JoystickName(SDL_JoystickIndex(joystick)));
516
SDL_JoystickClose(joystick);
519
/* Enable joystick event processing */
520
SDL_JoystickEventState(SDL_ENABLE);
522
/* Enable any joystick? */
523
if (joyid == UNDEFINED) {
524
for (count = 0; count < number_found; count++) {
525
if ((joystick = SDL_JoystickOpen(count))) {
526
if (show) fprintf(stdout, "Joystick opened: %i:%s\n", count, SDL_JoystickName(count));
531
if (show) fprintf(stdout, "Couldn't open joystick %i:%s!\n", count, SDL_JoystickName(count));
535
if (show) fprintf(stdout, "Couldn't open any of %i joystick(s)!\n", number_found);
539
/* Enable a joystick by joyid only? */
540
} else if (!strcmp(joyname, "-1")) {
541
if ((joystick = SDL_JoystickOpen(joyid))) {
542
if (show) fprintf(stdout, "Joystick opened: %i:%s\n", joyid, SDL_JoystickName(joyid));
544
if (show) fprintf(stdout, "Couldn't open joystick %i\n", joyid);
548
/* Enable a joystick by joyid and/or joyname */
550
/* First attempt to find an exact match on joyid and joyname */
551
for (count = 0; count < number_found; count++) {
552
if ((joystick = SDL_JoystickOpen(count))) {
553
if (joyid == count && !strcmp(joyname, SDL_JoystickName(count))) {
554
if (show) fprintf(stdout, "Joystick opened: %i:%s\n", count, SDL_JoystickName(count));
562
/* Exact match not found so search for joyname only */
563
for (count = 0; count < number_found; count++) {
564
if ((joystick = SDL_JoystickOpen(count))) {
565
if (!strcmp(joyname, SDL_JoystickName(count))) {
566
if (show) fprintf(stdout, "Joystick opened: %i:%s\n", count, SDL_JoystickName(count));
574
if (show) fprintf(stdout, "Couldn't find joystick %i:%s\n", joyid, joyname);
581
if (show) fprintf(stdout, "There is no joystick to initialise\n");
585
if (joystick) while (SDL_PollEvent(&event)); /* Flush events as opening a joystick releases all the buttons */
586
get_joystick_name(joyid, joyname);
590
/***************************************************************************
591
* Get Joystick Name *
592
***************************************************************************/
593
/* Gets a joystick name that isn't NULL ;) It's also truncated to
594
MAX_JOYSTICK_NAME_LENGTH which is currently 256 characters.
596
On entry: joyid = 0 to n for a specific joystick
597
On exit: returns 0 if successful with joyname = joystick name
598
returns 1 on error with joyname = "-1" */
600
int get_joystick_name(int joyid, char *joyname) {
602
if (SDL_JoystickName(joyid) != NULL) {
603
strncpy(joyname, SDL_JoystickName(joyid), MAX_JOYSTICK_NAME_LENGTH);
604
joyname[MAX_JOYSTICK_NAME_LENGTH - 1] = '\0'; /* If max characters were copied then the string won't be null terminated */
607
strcpy(joyname, "-1");
612
/***************************************************************************
613
* Get Joystick List *
614
***************************************************************************/
615
/* Get a list of attached joysticks if any. I have found that SDL does not
616
update the list if you subsequently plug or unplug a joystick.
618
On entry: joystick_list is an array of strings
619
show = TRUE to dump output to the terminal
620
On exit: returns number of joysticks found */
622
int get_joystick_list(char joystick_list[MAX_JOYSTICKS][MAX_JOYSTICK_NAME_LENGTH], int show) {
623
int count, number_found;
625
for (count = 0; count < MAX_JOYSTICKS; count++) strcpy(joystick_list[count], "");
627
number_found = SDL_NumJoysticks(); /* Get number of joysticks attached */
628
if (number_found > MAX_JOYSTICKS) number_found = MAX_JOYSTICKS;
631
SDL_JoystickEventState(SDL_ENABLE); /* Enable joystick event processing */
633
/* Initialise joystick_list */
634
for (count = 0; count < number_found; count++) {
635
get_joystick_name(count, joystick_list[count]);
636
if (show) fprintf(stdout, "Joystick found: %i:%s\n", count, joystick_list[count]);
640
if (show) fprintf(stdout, "No joystick found\n");
643
#ifdef DEBUG_CONTROLS
644
strcpy(joystick_list[number_found++], "Micro Shaft Pretend Joystick");
645
strcpy(joystick_list[number_found++], "Grevious Gamepad Pro");
646
strcpy(joystick_list[number_found++], "Cheapo Joypad");
652
/***************************************************************************
653
* Get Key/Joystick Button Text *
654
***************************************************************************/
655
/* Translates an SDLKey value into a string for display in Options.
657
On entry: device = input device
659
joyname = a string containing a possible joystick name
660
text = the return string
661
On exit: text = either a key/button legend or the id in text */
663
void get_keyjbtn_text(int device, int id, char *joyname, char *text) {
664
if (device == DEVICE_KEYBOARD) {
667
strcpy(text, "SDLUnknown");
670
strcpy(text, txt_key_Backspace);
673
strcpy(text, txt_key_Tab);
676
strcpy(text, txt_key_Clear);
679
strcpy(text, txt_key_Return);
682
strcpy(text, txt_key_Pause);
685
strcpy(text, txt_key_Escape);
688
strcpy(text, txt_key_Space);
711
case SDLK_RIGHTPAREN:
783
case SDLK_LEFTBRACKET:
789
case SDLK_RIGHTBRACKET:
795
case SDLK_UNDERSCORE:
880
strcpy(text, txt_key_Delete);
883
sprintf(text, "%s0", txt_key_KP);
886
sprintf(text, "%s1", txt_key_KP);
889
sprintf(text, "%s2", txt_key_KP);
892
sprintf(text, "%s3", txt_key_KP);
895
sprintf(text, "%s4", txt_key_KP);
898
sprintf(text, "%s5", txt_key_KP);
901
sprintf(text, "%s6", txt_key_KP);
904
sprintf(text, "%s7", txt_key_KP);
907
sprintf(text, "%s8", txt_key_KP);
910
sprintf(text, "%s9", txt_key_KP);
913
sprintf(text, "%s.", txt_key_KP);
916
sprintf(text, "%s/", txt_key_KP);
918
case SDLK_KP_MULTIPLY:
919
sprintf(text, "%s*", txt_key_KP);
922
sprintf(text, "%s-", txt_key_KP);
925
sprintf(text, "%s+", txt_key_KP);
928
sprintf(text, "%sEnter", txt_key_KP);
931
sprintf(text, "%s=", txt_key_KP);
934
strcpy(text, txt_key_Up);
937
strcpy(text, txt_key_Down);
940
strcpy(text, txt_key_Right);
943
strcpy(text, txt_key_Left);
946
strcpy(text, txt_key_Insert);
949
strcpy(text, txt_key_Home);
952
strcpy(text, txt_key_End);
955
strcpy(text, txt_key_PgUp);
958
strcpy(text, txt_key_PgDn);
1000
strcpy(text, "F14");
1003
strcpy(text, "F15");
1006
strcpy(text, txt_key_NumLk);
1009
strcpy(text, txt_key_CapsLk);
1011
case SDLK_SCROLLOCK:
1012
strcpy(text, txt_key_ScrlLk);
1015
strcpy(text, txt_key_RShift);
1018
strcpy(text, txt_key_LShift);
1021
strcpy(text, txt_key_RCtrl);
1024
strcpy(text, txt_key_LCtrl);
1027
strcpy(text, txt_key_RAlt);
1030
strcpy(text, txt_key_LAlt);
1033
strcpy(text, txt_key_RMeta);
1036
strcpy(text, txt_key_LMeta);
1039
strcpy(text, txt_key_LSuper);
1042
strcpy(text, txt_key_RSuper);
1045
strcpy(text, txt_key_AltGr);
1048
strcpy(text, txt_key_Compose);
1051
strcpy(text, txt_key_Help);
1054
strcpy(text, txt_key_PrScr);
1057
strcpy(text, txt_key_SysRq);
1060
strcpy(text, txt_key_Break);
1063
strcpy(text, txt_key_Menu);
1066
strcpy(text, txt_key_Power);
1069
strcpy(text, txt_key_Euro);
1072
strcpy(text, txt_key_Undo);
1075
sprintf(text, "%i", id);
1076
/*strcpy(text, "Unknown");*/
1079
} else if (device == DEVICE_JOYSTICK) {
1080
if ((strcmp(joyname, "Microsoft SideWinder Game Pad Pro USB version 1.0")) == 0) { /* My own joystick :) */
1101
strcpy(text, "LTrig");
1104
strcpy(text, "RTrig");
1107
strcpy(text, "Shift");
1110
strcpy(text, "Left");
1113
strcpy(text, "Right");
1119
strcpy(text, "Down");
1122
sprintf(text, "%i", id);
1123
/*strcpy(text, "Unknown");*/
1126
} else if ((strcmp(joyname, "PEP Joy")) == 0) { /* GP2X F100 joystick */
1132
strcpy(text, "UpLeft");
1135
strcpy(text, "Left");
1138
strcpy(text, "DownLeft");
1141
strcpy(text, "Down");
1144
strcpy(text, "DownRight");
1147
strcpy(text, "Right");
1150
strcpy(text, "UpRight");
1153
strcpy(text, "Start");
1156
strcpy(text, "Select");
1159
strcpy(text, "LTrig");
1162
strcpy(text, "RTrig");
1177
strcpy(text, "VolUp");
1180
strcpy(text, "VolDn");
1183
strcpy(text, "JoyPush");
1186
sprintf(text, "%i", id);
1187
/*strcpy(text, "Unknown");*/
1191
sprintf(text, "%i", id);