~ubuntu-branches/ubuntu/quantal/gnurobbo/quantal

« back to all changes in this revision

Viewing changes to controls.c

  • Committer: Bazaar Package Importer
  • Author(s): Ansgar Burchardt, Ansgar Burchardt, Gonéri Le Bouder
  • Date: 2009-03-14 23:10:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090314231050-70zcgdcmp7177pql
Tags: 0.61-1
[ Ansgar Burchardt ]
* New Upstream Version (LP: #337089)
* Do not dump vm usage information
  + New patch: do-not-dump-vmusage.diff
* Update packaging for debhelper 7
* Update copyright information
* Update Vcs-* fields for the Git repository
* Bump Standards Version to 3.8.0
  + add debian/README.source
* Add watch file

[ Gonéri Le Bouder ]
* Do not install the LICENSE-font files 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  GNU Robbo
 
2
 *  Copyright (C) notes:
 
3
 *  An Idea and Atari version: LK Avalon, Janusz Pelc, 1989
 
4
 *                 Linux Code: Arkadiusz Lipiec, 2002-2009
 
5
 *                                 <arkadiusz.lipiec@gmail.com>
 
6
 *                             Thunor 2007-2009
 
7
 *                                 <thunorsif@hotmail.com>
 
8
 *
 
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)
 
12
 *  any later version.
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 *
 
24
 */
 
25
 
 
26
#include "game.h"
 
27
 
 
28
/* Defines */
 
29
/*
 
30
#define DEBUG_CONTROLS
 
31
*/
 
32
#define JOYDEADZONE (32767 * joystick_dead_zone / 100)
 
33
 
 
34
/* GP2X button IDs */
 
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
 
54
 
 
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
 
62
#define ZAURUS_OK 0
 
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
 
68
 
 
69
/* Variables */
 
70
SDL_Event event;
 
71
 
 
72
/* Function prototypes */
 
73
void show_user_action(int *action_found);
 
74
int set_key_repeat(int delay, int interval);
 
75
 
 
76
 
 
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.
 
94
   
 
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.   
 
99
 
 
100
   struct control {
 
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 
 
108
   };
 
109
   struct control user_controls[USER_CONTROLS];         Holds the assignment of user controls 
 
110
   
 
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 */   
 
119
 
 
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 */
 
123
        
 
124
        *actionid = UNDEFINED;
 
125
 
 
126
        while (SDL_PollEvent(&event)) {
 
127
                *device = *id = *state = UNDEFINED;
 
128
                switch (event.type) {
 
129
                        case SDL_KEYUP:
 
130
                        case SDL_KEYDOWN:
 
131
                                *device = DEVICE_KEYBOARD;
 
132
                                *id = event.key.keysym.sym;
 
133
                                *state = event.key.state;
 
134
                                break;
 
135
                        case SDL_JOYBUTTONUP:
 
136
                        case SDL_JOYBUTTONDOWN:
 
137
                                *device = DEVICE_JOYSTICK;
 
138
                                *id = event.jbutton.button;
 
139
                                *state = event.jbutton.state;
 
140
                                break;
 
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);
 
151
                                }
 
152
                                break;
 
153
                        case SDL_QUIT:
 
154
                                quitfound = 1;
 
155
                                break;
 
156
                        default:
 
157
                                break;
 
158
                }
 
159
 
 
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);
 
164
                        #endif
 
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);
 
170
                                #endif
 
171
                        }
 
172
                        #ifdef DEBUG_CONTROLS
 
173
                                printf("\n");
 
174
                        #endif
 
175
                }
 
176
                
 
177
                if (!pollall) break;
 
178
                
 
179
        }
 
180
 
 
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) {
 
185
                        found = TRUE;
 
186
                        *actionid = count;
 
187
                        #ifdef DEBUG_CONTROLS
 
188
                                show_user_action(actionid);
 
189
                        #endif
 
190
                        break;
 
191
                }
 
192
        }
 
193
        if (!found) {
 
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) {
 
197
                                found = TRUE;
 
198
                                *actionid = count;
 
199
                                #ifdef DEBUG_CONTROLS
 
200
                                        show_user_action(actionid);
 
201
                                #endif
 
202
                                break;
 
203
                        }
 
204
                }
 
205
        }
 
206
        
 
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 */
 
210
        if (found) {
 
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 */
 
220
                        } else {
 
221
                                found = FALSE;
 
222
                        }
 
223
                } else {
 
224
                        found = FALSE;
 
225
                }
 
226
                user_controls[*actionid].cyclesactive++;
 
227
                if (!found) *actionid = UNDEFINED;
 
228
        }
 
229
 
 
230
        return quitfound;
 
231
}
 
232
 
 
233
/***************************************************************************
 
234
 * Show User Action                                                        *
 
235
 ***************************************************************************/
 
236
/* Used for debugging */   
 
237
 
 
238
void show_user_action(int *actionid) {
 
239
        switch (*actionid) {
 
240
                case ACTION_UP:
 
241
                        printf("ACTION_UP");
 
242
                        break;
 
243
                case ACTION_DOWN:
 
244
                        printf("ACTION_DOWN");
 
245
                        break;
 
246
                case ACTION_LEFT:
 
247
                        printf("ACTION_LEFT");
 
248
                        break;
 
249
                case ACTION_RIGHT:
 
250
                        printf("ACTION_RIGHT");
 
251
                        break;
 
252
                case ACTION_SHOOT_UP:
 
253
                        printf("ACTION_SHOOT_UP");
 
254
                        break;
 
255
                case ACTION_SHOOT_DOWN:
 
256
                        printf("ACTION_SHOOT_DOWN");
 
257
                        break;
 
258
                case ACTION_SHOOT_LEFT:
 
259
                        printf("ACTION_SHOOT_LEFT");
 
260
                        break;
 
261
                case ACTION_SHOOT_RIGHT:
 
262
                        printf("ACTION_SHOOT_RIGHT");
 
263
                        break;
 
264
                case ACTION_SELECT:
 
265
                        printf("ACTION_SELECT");
 
266
                        break;
 
267
                case ACTION_EXIT:
 
268
                        printf("ACTION_EXIT");
 
269
                        break;
 
270
                case ACTION_HELP:
 
271
                        printf("ACTION_HELP");
 
272
                        break;
 
273
                case ACTION_OPTIONS:
 
274
                        printf("ACTION_OPTIONS");
 
275
                        break;
 
276
                case ACTION_RESTART:
 
277
                        printf("ACTION_RESTART");
 
278
                        break;
 
279
                case ACTION_PREVIOUS_LEVEL:
 
280
                        printf("ACTION_PREVIOUS_LEVEL");
 
281
                        break;
 
282
                case ACTION_NEXT_LEVEL:
 
283
                        printf("ACTION_NEXT_LEVEL");
 
284
                        break;
 
285
                case ACTION_PREVIOUS_PACK:
 
286
                        printf("ACTION_PREVIOUS_PACK");
 
287
                        break;
 
288
                case ACTION_NEXT_PACK:
 
289
                        printf("ACTION_NEXT_PACK");
 
290
                        break;
 
291
                case ACTION_MODIFIER1:
 
292
                        printf("ACTION_MODIFIER1");
 
293
                        break;
 
294
                case ACTION_MODIFIER2:
 
295
                        printf("ACTION_MODIFIER2");
 
296
                        break;
 
297
                case ACTION_TOGGLE_FULLSCREEN:
 
298
                        printf("ACTION_TOGGLE_FULLSCREEN");
 
299
                        break;
 
300
                case ACTION_HOME:
 
301
                        printf("ACTION_HOME");
 
302
                        break;
 
303
                case ACTION_END:
 
304
                        printf("ACTION_END");
 
305
                        break;
 
306
                case ACTION_PAGEUP:
 
307
                        printf("ACTION_PAGEUP");
 
308
                        break;
 
309
                case ACTION_PAGEDOWN:
 
310
                        printf("ACTION_PAGEDOWN");
 
311
                        break;
 
312
                case ACTION_VOLUP:
 
313
                        printf("ACTION_VOLUP");
 
314
                        break;
 
315
                case ACTION_VOLDOWN:
 
316
                        printf("ACTION_VOLDOWN");
 
317
                        break;
 
318
                case ACTION_NOT_USED1:
 
319
                        printf("ACTION_NOT_USED1");
 
320
                        break;
 
321
                case UNDEFINED:
 
322
                        printf("UNDEFINED");
 
323
                        break;
 
324
                default:
 
325
                        printf("Unknown action");
 
326
                        break;
 
327
        }
 
328
        printf(": %i\n", user_controls[*actionid].cyclesactive);
 
329
}
 
330
 
 
331
/***************************************************************************
 
332
 * Set Default User Controls                                               *
 
333
 ***************************************************************************/
 
334
 
 
335
void set_default_user_controls(struct control user_controls[USER_CONTROLS]) {
 
336
        int count;
 
337
 
 
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;
 
346
                #endif
 
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;
 
353
        }
 
354
        
 
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;
 
460
        #endif
 
461
 
 
462
}
 
463
 
 
464
/***************************************************************************
 
465
 * Set Key Repeat                                                          *
 
466
 ***************************************************************************/
 
467
/* Enable or disable keyboard key repeat (not used in this project anymore)
 
468
 
 
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 */
 
472
                         
 
473
int set_key_repeat(int delay, int interval) {
 
474
 
 
475
        if (SDL_EnableKeyRepeat(delay, interval) != 0) {
 
476
                fprintf(stdout, "Error setting key repeat: %s\n", SDL_GetError());
 
477
                return 1;
 
478
        }
 
479
        
 
480
        return 0;
 
481
}
 
482
 
 
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
 
489
   switched.
 
490
 
 
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" */
 
497
 
 
498
int initialise_joystick(int joyid, char *joyname, int show) {
 
499
        int count, number_found, found = FALSE;
 
500
        
 
501
        number_found = SDL_NumJoysticks();                      /* Get number of joysticks attached */
 
502
 
 
503
        /* Are any joysticks available? */
 
504
        if (number_found > 0) {
 
505
                
 
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)
 
511
                        if (joystick) {
 
512
                #elif defined(PLATFORM_PC)
 
513
                        if (joystick) {
 
514
                #endif
 
515
                        if (show) fprintf(stdout, "Joystick closed: %i:%s\n", SDL_JoystickIndex(joystick), SDL_JoystickName(SDL_JoystickIndex(joystick)));
 
516
                        SDL_JoystickClose(joystick);
 
517
                }
 
518
 
 
519
                /* Enable joystick event processing */
 
520
                SDL_JoystickEventState(SDL_ENABLE);                     
 
521
                
 
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));
 
527
                                        joyid = count;
 
528
                                        found = TRUE;
 
529
                                        break;
 
530
                                } else {
 
531
                                        if (show) fprintf(stdout, "Couldn't open joystick %i:%s!\n", count, SDL_JoystickName(count));
 
532
                                }
 
533
                        }
 
534
                        if (!found) {
 
535
                                if (show) fprintf(stdout, "Couldn't open any of %i joystick(s)!\n", number_found);
 
536
                                joyid = UNDEFINED;
 
537
                        }
 
538
 
 
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));
 
543
                        } else {
 
544
                                if (show) fprintf(stdout, "Couldn't open joystick %i\n", joyid);
 
545
                                joyid = UNDEFINED;
 
546
                        }
 
547
 
 
548
                /* Enable a joystick by joyid and/or joyname */
 
549
                } else {
 
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));
 
555
                                                joyid = count;
 
556
                                                found = TRUE;
 
557
                                                break;
 
558
                                        }
 
559
                                }
 
560
                        }
 
561
                        if (!found) {
 
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));
 
567
                                                        joyid = count;
 
568
                                                        found = TRUE;
 
569
                                                        break;
 
570
                                                }
 
571
                                        }
 
572
                                }
 
573
                                if (!found) {
 
574
                                        if (show) fprintf(stdout, "Couldn't find joystick %i:%s\n", joyid, joyname);
 
575
                                        joyid = UNDEFINED;
 
576
                                }
 
577
                        }
 
578
                }
 
579
 
 
580
        } else {
 
581
                if (show) fprintf(stdout, "There is no joystick to initialise\n");
 
582
                joyid = UNDEFINED;
 
583
        }
 
584
 
 
585
        if (joystick) while (SDL_PollEvent(&event));    /* Flush events as opening a joystick releases all the buttons */
 
586
        get_joystick_name(joyid, joyname);
 
587
        return joyid;
 
588
}
 
589
 
 
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.
 
595
 
 
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" */
 
599
 
 
600
int get_joystick_name(int joyid, char *joyname) {
 
601
        
 
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 */
 
605
                return 0;
 
606
        } else {
 
607
                strcpy(joyname, "-1");
 
608
                return 1;
 
609
        }
 
610
}
 
611
 
 
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.
 
617
 
 
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 */
 
621
 
 
622
int get_joystick_list(char joystick_list[MAX_JOYSTICKS][MAX_JOYSTICK_NAME_LENGTH], int show) {
 
623
        int count, number_found;
 
624
        
 
625
        for (count = 0; count < MAX_JOYSTICKS; count++) strcpy(joystick_list[count], "");
 
626
 
 
627
        number_found = SDL_NumJoysticks();                      /* Get number of joysticks attached */
 
628
        if (number_found > MAX_JOYSTICKS) number_found = MAX_JOYSTICKS;
 
629
 
 
630
        if (number_found) {
 
631
                SDL_JoystickEventState(SDL_ENABLE);             /* Enable joystick event processing */
 
632
                
 
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]);
 
637
                }
 
638
 
 
639
        } else {
 
640
                if (show) fprintf(stdout, "No joystick found\n");
 
641
        }
 
642
        
 
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");
 
647
        #endif
 
648
        
 
649
        return number_found;
 
650
}
 
651
 
 
652
/***************************************************************************
 
653
 * Get Key/Joystick Button Text                                            *
 
654
 ***************************************************************************/
 
655
/* Translates an SDLKey value into a string for display in Options.
 
656
 
 
657
   On entry: device = input device
 
658
                         id = keysym.sym
 
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 */
 
662
 
 
663
void get_keyjbtn_text(int device, int id, char *joyname, char *text) {
 
664
        if (device == DEVICE_KEYBOARD) {
 
665
                switch (id) {
 
666
                        case SDLK_UNKNOWN:
 
667
                                strcpy(text, "SDLUnknown");
 
668
                                break;
 
669
                        case SDLK_BACKSPACE:
 
670
                                strcpy(text, txt_key_Backspace);
 
671
                                break;
 
672
                        case SDLK_TAB:
 
673
                                strcpy(text, txt_key_Tab);
 
674
                                break;
 
675
                        case SDLK_CLEAR:
 
676
                                strcpy(text, txt_key_Clear);
 
677
                                break;
 
678
                        case SDLK_RETURN:
 
679
                                strcpy(text, txt_key_Return);
 
680
                                break;
 
681
                        case SDLK_PAUSE:
 
682
                                strcpy(text, txt_key_Pause);
 
683
                                break;
 
684
                        case SDLK_ESCAPE:
 
685
                                strcpy(text, txt_key_Escape);
 
686
                                break;
 
687
                        case SDLK_SPACE:
 
688
                                strcpy(text, txt_key_Space);
 
689
                                break;
 
690
                        case SDLK_EXCLAIM:
 
691
                                strcpy(text, "!");
 
692
                                break;
 
693
                        case SDLK_QUOTEDBL:
 
694
                                strcpy(text, "\"");
 
695
                                break;
 
696
                        case SDLK_HASH:
 
697
                                strcpy(text, "#");
 
698
                                break;
 
699
                        case SDLK_DOLLAR:
 
700
                                strcpy(text, "$");
 
701
                                break;
 
702
                        case SDLK_AMPERSAND:
 
703
                                strcpy(text, "&");
 
704
                                break;
 
705
                        case SDLK_QUOTE:
 
706
                                strcpy(text, "'");
 
707
                                break;
 
708
                        case SDLK_LEFTPAREN:
 
709
                                strcpy(text, "(");
 
710
                                break;
 
711
                        case SDLK_RIGHTPAREN:
 
712
                                strcpy(text, ")");
 
713
                                break;
 
714
                        case SDLK_ASTERISK:
 
715
                                strcpy(text, "*");
 
716
                                break;
 
717
                        case SDLK_PLUS:
 
718
                                strcpy(text, "+");
 
719
                                break;
 
720
                        case SDLK_COMMA:
 
721
                                strcpy(text, ",");
 
722
                                break;
 
723
                        case SDLK_MINUS:
 
724
                                strcpy(text, "-");
 
725
                                break;
 
726
                        case SDLK_PERIOD:
 
727
                                strcpy(text, ".");
 
728
                                break;
 
729
                        case SDLK_SLASH:
 
730
                                strcpy(text, "/");
 
731
                                break;
 
732
                        case SDLK_0:
 
733
                                strcpy(text, "0");
 
734
                                break;
 
735
                        case SDLK_1:
 
736
                                strcpy(text, "1");
 
737
                                break;
 
738
                        case SDLK_2:
 
739
                                strcpy(text, "2");
 
740
                                break;
 
741
                        case SDLK_3:
 
742
                                strcpy(text, "3");
 
743
                                break;
 
744
                        case SDLK_4:
 
745
                                strcpy(text, "4");
 
746
                                break;
 
747
                        case SDLK_5:
 
748
                                strcpy(text, "5");
 
749
                                break;
 
750
                        case SDLK_6:
 
751
                                strcpy(text, "6");
 
752
                                break;
 
753
                        case SDLK_7:
 
754
                                strcpy(text, "7");
 
755
                                break;
 
756
                        case SDLK_8:
 
757
                                strcpy(text, "8");
 
758
                                break;
 
759
                        case SDLK_9:
 
760
                                strcpy(text, "9");
 
761
                                break;
 
762
                        case SDLK_COLON:
 
763
                                strcpy(text, ":");
 
764
                                break;
 
765
                        case SDLK_SEMICOLON:
 
766
                                strcpy(text, ";");
 
767
                                break;
 
768
                        case SDLK_LESS:
 
769
                                strcpy(text, "<");
 
770
                                break;
 
771
                        case SDLK_EQUALS:
 
772
                                strcpy(text, "=");
 
773
                                break;
 
774
                        case SDLK_GREATER:
 
775
                                strcpy(text, ">");
 
776
                                break;
 
777
                        case SDLK_QUESTION:
 
778
                                strcpy(text, "?");
 
779
                                break;
 
780
                        case SDLK_AT:
 
781
                                strcpy(text, "@");
 
782
                                break;
 
783
                        case SDLK_LEFTBRACKET:
 
784
                                strcpy(text, "[");
 
785
                                break;
 
786
                        case SDLK_BACKSLASH:
 
787
                                strcpy(text, "\\");
 
788
                                break;
 
789
                        case SDLK_RIGHTBRACKET:
 
790
                                strcpy(text, "]");
 
791
                                break;
 
792
                        case SDLK_CARET:
 
793
                                strcpy(text, "^");
 
794
                                break;
 
795
                        case SDLK_UNDERSCORE:
 
796
                                strcpy(text, "_");
 
797
                                break;
 
798
                        case SDLK_BACKQUOTE:
 
799
                                strcpy(text, "`");
 
800
                                break;
 
801
                        case SDLK_a:
 
802
                                strcpy(text, "A");
 
803
                                break;
 
804
                        case SDLK_b:
 
805
                                strcpy(text, "B");
 
806
                                break;
 
807
                        case SDLK_c:
 
808
                                strcpy(text, "C");
 
809
                                break;
 
810
                        case SDLK_d:
 
811
                                strcpy(text, "D");
 
812
                                break;
 
813
                        case SDLK_e:
 
814
                                strcpy(text, "E");
 
815
                                break;
 
816
                        case SDLK_f:
 
817
                                strcpy(text, "F");
 
818
                                break;
 
819
                        case SDLK_g:
 
820
                                strcpy(text, "G");
 
821
                                break;
 
822
                        case SDLK_h:
 
823
                                strcpy(text, "H");
 
824
                                break;
 
825
                        case SDLK_i:
 
826
                                strcpy(text, "I");
 
827
                                break;
 
828
                        case SDLK_j:
 
829
                                strcpy(text, "J");
 
830
                                break;
 
831
                        case SDLK_k:
 
832
                                strcpy(text, "K");
 
833
                                break;
 
834
                        case SDLK_l:
 
835
                                strcpy(text, "L");
 
836
                                break;
 
837
                        case SDLK_m:
 
838
                                strcpy(text, "M");
 
839
                                break;
 
840
                        case SDLK_n:
 
841
                                strcpy(text, "N");
 
842
                                break;
 
843
                        case SDLK_o:
 
844
                                strcpy(text, "O");
 
845
                                break;
 
846
                        case SDLK_p:
 
847
                                strcpy(text, "P");
 
848
                                break;
 
849
                        case SDLK_q:
 
850
                                strcpy(text, "Q");
 
851
                                break;
 
852
                        case SDLK_r:
 
853
                                strcpy(text, "R");
 
854
                                break;
 
855
                        case SDLK_s:
 
856
                                strcpy(text, "S");
 
857
                                break;
 
858
                        case SDLK_t:
 
859
                                strcpy(text, "T");
 
860
                                break;
 
861
                        case SDLK_u:
 
862
                                strcpy(text, "U");
 
863
                                break;
 
864
                        case SDLK_v:
 
865
                                strcpy(text, "V");
 
866
                                break;
 
867
                        case SDLK_w:
 
868
                                strcpy(text, "W");
 
869
                                break;
 
870
                        case SDLK_x:
 
871
                                strcpy(text, "X");
 
872
                                break;
 
873
                        case SDLK_y:
 
874
                                strcpy(text, "Y");
 
875
                                break;
 
876
                        case SDLK_z:
 
877
                                strcpy(text, "Z");
 
878
                                break;
 
879
                        case SDLK_DELETE:
 
880
                                strcpy(text, txt_key_Delete);
 
881
                                break;
 
882
                        case SDLK_KP0:
 
883
                                sprintf(text, "%s0", txt_key_KP);
 
884
                                break;
 
885
                        case SDLK_KP1:
 
886
                                sprintf(text, "%s1", txt_key_KP);
 
887
                                break;
 
888
                        case SDLK_KP2:
 
889
                                sprintf(text, "%s2", txt_key_KP);
 
890
                                break;
 
891
                        case SDLK_KP3:
 
892
                                sprintf(text, "%s3", txt_key_KP);
 
893
                                break;
 
894
                        case SDLK_KP4:
 
895
                                sprintf(text, "%s4", txt_key_KP);
 
896
                                break;
 
897
                        case SDLK_KP5:
 
898
                                sprintf(text, "%s5", txt_key_KP);
 
899
                                break;
 
900
                        case SDLK_KP6:
 
901
                                sprintf(text, "%s6", txt_key_KP);
 
902
                                break;
 
903
                        case SDLK_KP7:
 
904
                                sprintf(text, "%s7", txt_key_KP);
 
905
                                break;
 
906
                        case SDLK_KP8:
 
907
                                sprintf(text, "%s8", txt_key_KP);
 
908
                                break;
 
909
                        case SDLK_KP9:
 
910
                                sprintf(text, "%s9", txt_key_KP);
 
911
                                break;
 
912
                        case SDLK_KP_PERIOD:
 
913
                                sprintf(text, "%s.", txt_key_KP);
 
914
                                break;
 
915
                        case SDLK_KP_DIVIDE:
 
916
                                sprintf(text, "%s/", txt_key_KP);
 
917
                                break;
 
918
                        case SDLK_KP_MULTIPLY:
 
919
                                sprintf(text, "%s*", txt_key_KP);
 
920
                                break;
 
921
                        case SDLK_KP_MINUS:
 
922
                                sprintf(text, "%s-", txt_key_KP);
 
923
                                break;
 
924
                        case SDLK_KP_PLUS:
 
925
                                sprintf(text, "%s+", txt_key_KP);
 
926
                                break;
 
927
                        case SDLK_KP_ENTER:
 
928
                                sprintf(text, "%sEnter", txt_key_KP);
 
929
                                break;
 
930
                        case SDLK_KP_EQUALS:
 
931
                                sprintf(text, "%s=", txt_key_KP);
 
932
                                break;
 
933
                        case SDLK_UP:
 
934
                                strcpy(text, txt_key_Up);
 
935
                                break;
 
936
                        case SDLK_DOWN:
 
937
                                strcpy(text, txt_key_Down);
 
938
                                break;
 
939
                        case SDLK_RIGHT:
 
940
                                strcpy(text, txt_key_Right);
 
941
                                break;
 
942
                        case SDLK_LEFT:
 
943
                                strcpy(text, txt_key_Left);
 
944
                                break;
 
945
                        case SDLK_INSERT:
 
946
                                strcpy(text, txt_key_Insert);
 
947
                                break;
 
948
                        case SDLK_HOME:
 
949
                                strcpy(text, txt_key_Home);
 
950
                                break;
 
951
                        case SDLK_END:
 
952
                                strcpy(text, txt_key_End);
 
953
                                break;
 
954
                        case SDLK_PAGEUP:
 
955
                                strcpy(text, txt_key_PgUp);
 
956
                                break;
 
957
                        case SDLK_PAGEDOWN:
 
958
                                strcpy(text, txt_key_PgDn);
 
959
                                break;
 
960
                        case SDLK_F1:
 
961
                                strcpy(text, "F1");
 
962
                                break;
 
963
                        case SDLK_F2:
 
964
                                strcpy(text, "F2");
 
965
                                break;
 
966
                        case SDLK_F3:
 
967
                                strcpy(text, "F3");
 
968
                                break;
 
969
                        case SDLK_F4:
 
970
                                strcpy(text, "F4");
 
971
                                break;
 
972
                        case SDLK_F5:
 
973
                                strcpy(text, "F5");
 
974
                                break;
 
975
                        case SDLK_F6:
 
976
                                strcpy(text, "F6");
 
977
                                break;
 
978
                        case SDLK_F7:
 
979
                                strcpy(text, "F7");
 
980
                                break;
 
981
                        case SDLK_F8:
 
982
                                strcpy(text, "F8");
 
983
                                break;
 
984
                        case SDLK_F9:
 
985
                                strcpy(text, "F9");
 
986
                                break;
 
987
                        case SDLK_F10:
 
988
                                strcpy(text, "F10");
 
989
                                break;
 
990
                        case SDLK_F11:
 
991
                                strcpy(text, "F11");
 
992
                                break;
 
993
                        case SDLK_F12:
 
994
                                strcpy(text, "F12");
 
995
                                break;
 
996
                        case SDLK_F13:
 
997
                                strcpy(text, "F13");
 
998
                                break;
 
999
                        case SDLK_F14:
 
1000
                                strcpy(text, "F14");
 
1001
                                break;
 
1002
                        case SDLK_F15:
 
1003
                                strcpy(text, "F15");
 
1004
                                break;
 
1005
                        case SDLK_NUMLOCK:
 
1006
                                strcpy(text, txt_key_NumLk);
 
1007
                                break;
 
1008
                        case SDLK_CAPSLOCK:
 
1009
                                strcpy(text, txt_key_CapsLk);
 
1010
                                break;
 
1011
                        case SDLK_SCROLLOCK:
 
1012
                                strcpy(text, txt_key_ScrlLk);
 
1013
                                break;
 
1014
                        case SDLK_RSHIFT:
 
1015
                                strcpy(text, txt_key_RShift);
 
1016
                                break;
 
1017
                        case SDLK_LSHIFT:
 
1018
                                strcpy(text, txt_key_LShift);
 
1019
                                break;
 
1020
                        case SDLK_RCTRL:
 
1021
                                strcpy(text, txt_key_RCtrl);
 
1022
                                break;
 
1023
                        case SDLK_LCTRL:
 
1024
                                strcpy(text, txt_key_LCtrl);
 
1025
                                break;
 
1026
                        case SDLK_RALT:
 
1027
                                strcpy(text, txt_key_RAlt);
 
1028
                                break;
 
1029
                        case SDLK_LALT:
 
1030
                                strcpy(text, txt_key_LAlt);
 
1031
                                break;
 
1032
                        case SDLK_RMETA:
 
1033
                                strcpy(text, txt_key_RMeta);
 
1034
                                break;
 
1035
                        case SDLK_LMETA:
 
1036
                                strcpy(text, txt_key_LMeta);
 
1037
                                break;
 
1038
                        case SDLK_LSUPER:
 
1039
                                strcpy(text, txt_key_LSuper);
 
1040
                                break;
 
1041
                        case SDLK_RSUPER:
 
1042
                                strcpy(text, txt_key_RSuper);
 
1043
                                break;
 
1044
                        case SDLK_MODE:
 
1045
                                strcpy(text, txt_key_AltGr);
 
1046
                                break;
 
1047
                        case SDLK_COMPOSE:
 
1048
                                strcpy(text, txt_key_Compose);
 
1049
                                break;
 
1050
                        case SDLK_HELP:
 
1051
                                strcpy(text, txt_key_Help);
 
1052
                                break;
 
1053
                        case SDLK_PRINT:
 
1054
                                strcpy(text, txt_key_PrScr);
 
1055
                                break;
 
1056
                        case SDLK_SYSREQ:
 
1057
                                strcpy(text, txt_key_SysRq);
 
1058
                                break;
 
1059
                        case SDLK_BREAK:
 
1060
                                strcpy(text, txt_key_Break);
 
1061
                                break;
 
1062
                        case SDLK_MENU:
 
1063
                                strcpy(text, txt_key_Menu);
 
1064
                                break;
 
1065
                        case SDLK_POWER:
 
1066
                                strcpy(text, txt_key_Power);
 
1067
                                break;
 
1068
                        case SDLK_EURO:
 
1069
                                strcpy(text, txt_key_Euro);
 
1070
                                break;
 
1071
                        case SDLK_UNDO:
 
1072
                                strcpy(text, txt_key_Undo);
 
1073
                                break;
 
1074
                        default:
 
1075
                                sprintf(text, "%i", id);
 
1076
                                /*strcpy(text, "Unknown");*/
 
1077
                                break;
 
1078
                }
 
1079
        } else if (device == DEVICE_JOYSTICK) {
 
1080
                if ((strcmp(joyname, "Microsoft SideWinder Game Pad Pro USB version 1.0")) == 0) {      /* My own joystick :) */
 
1081
                        switch (id) {
 
1082
                                case 0:
 
1083
                                        strcpy(text, "A");
 
1084
                                        break;
 
1085
                                case 1:
 
1086
                                        strcpy(text, "B");
 
1087
                                        break;
 
1088
                                case 2:
 
1089
                                        strcpy(text, "C");
 
1090
                                        break;
 
1091
                                case 3:
 
1092
                                        strcpy(text, "X");
 
1093
                                        break;
 
1094
                                case 4:
 
1095
                                        strcpy(text, "Y");
 
1096
                                        break;
 
1097
                                case 5:
 
1098
                                        strcpy(text, "Z");
 
1099
                                        break;
 
1100
                                case 6:
 
1101
                                        strcpy(text, "LTrig");
 
1102
                                        break;
 
1103
                                case 7:
 
1104
                                        strcpy(text, "RTrig");
 
1105
                                        break;
 
1106
                                case 8:
 
1107
                                        strcpy(text, "Shift");
 
1108
                                        break;
 
1109
                                case 10:
 
1110
                                        strcpy(text, "Left");
 
1111
                                        break;
 
1112
                                case 11:
 
1113
                                        strcpy(text, "Right");
 
1114
                                        break;
 
1115
                                case 12:
 
1116
                                        strcpy(text, "Up");
 
1117
                                        break;
 
1118
                                case 13:
 
1119
                                        strcpy(text, "Down");
 
1120
                                        break;
 
1121
                                default:
 
1122
                                        sprintf(text, "%i", id);
 
1123
                                        /*strcpy(text, "Unknown");*/
 
1124
                                        break;
 
1125
                        }
 
1126
                } else if ((strcmp(joyname, "PEP Joy")) == 0) { /* GP2X F100 joystick */
 
1127
                        switch (id) {
 
1128
                                case GP2X_JOY_N:
 
1129
                                        strcpy(text, "Up");
 
1130
                                        break;
 
1131
                                case GP2X_JOY_NW:
 
1132
                                        strcpy(text, "UpLeft");
 
1133
                                        break;
 
1134
                                case GP2X_JOY_W:
 
1135
                                        strcpy(text, "Left");
 
1136
                                        break;
 
1137
                                case GP2X_JOY_SW:
 
1138
                                        strcpy(text, "DownLeft");
 
1139
                                        break;
 
1140
                                case GP2X_JOY_S:
 
1141
                                        strcpy(text, "Down");
 
1142
                                        break;
 
1143
                                case GP2X_JOY_SE:
 
1144
                                        strcpy(text, "DownRight");
 
1145
                                        break;
 
1146
                                case GP2X_JOY_E:
 
1147
                                        strcpy(text, "Right");
 
1148
                                        break;
 
1149
                                case GP2X_JOY_NE:
 
1150
                                        strcpy(text, "UpRight");
 
1151
                                        break;
 
1152
                                case GP2X_START:
 
1153
                                        strcpy(text, "Start");
 
1154
                                        break;
 
1155
                                case GP2X_SELECT:
 
1156
                                        strcpy(text, "Select");
 
1157
                                        break;
 
1158
                                case GP2X_LTRIG:
 
1159
                                        strcpy(text, "LTrig");
 
1160
                                        break;
 
1161
                                case GP2X_RTRIG:
 
1162
                                        strcpy(text, "RTrig");
 
1163
                                        break;
 
1164
                                case GP2X_BTN_A:
 
1165
                                        strcpy(text, "A");
 
1166
                                        break;
 
1167
                                case GP2X_BTN_B:
 
1168
                                        strcpy(text, "B");
 
1169
                                        break;
 
1170
                                case GP2X_BTN_X:
 
1171
                                        strcpy(text, "X");
 
1172
                                        break;
 
1173
                                case GP2X_BTN_Y:
 
1174
                                        strcpy(text, "Y");
 
1175
                                        break;
 
1176
                                case GP2X_VOL_UP:
 
1177
                                        strcpy(text, "VolUp");
 
1178
                                        break;
 
1179
                                case GP2X_VOL_DN:
 
1180
                                        strcpy(text, "VolDn");
 
1181
                                        break;
 
1182
                                case GP2X_BTN_JOY:
 
1183
                                        strcpy(text, "JoyPush");
 
1184
                                        break;
 
1185
                                default:
 
1186
                                        sprintf(text, "%i", id);
 
1187
                                        /*strcpy(text, "Unknown");*/
 
1188
                                        break;
 
1189
                        }
 
1190
                } else {
 
1191
                        sprintf(text, "%i", id);
 
1192
                }
 
1193
        }
 
1194
}
 
1195
 
 
1196
 
 
1197
 
 
1198
 
 
1199
 
 
1200