Mercurial > sdl-ios-xcode
annotate test/testtimer.c @ 892:dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
From: David MacCormack
Subject: [SDL] Linux joystick patch
I recently got myself a PS2 -> USB converter (a super joybox 5). It
accepts 4 PSX/PS2 controllers. It's implemented as a HID, which is nice
because it doesn't require its own driver, but the problem is that it's
implemented as a *single* HID -- that is, it shows up as a single
joystick with 19 axes, 4 hats, and 48 buttons. This poses a problem for a
number of apps which use SDL (stella, fce ultra, zsnes, to name a few) and
see only a single (physical) joystick even though there are really 4
(logical) joysticks. There are a number of these types of devices on the
market, and I've seen others post messages (in the zsnes forum, for
example) with the same problem, so I came up with what I think is a pretty
generic solution.
I patched src/joystick/linux/SDL_sysjoystic.c to include support for
logical joysticks; basically, it's a static array and supporting functions
that map a single physical joystick to multiple logical joysticks. The
attached patch has the new code. It's wrapped inside #ifndef
statements so that you can get the old behavior if you want.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 16 May 2004 18:46:24 +0000 |
parents | ed57c876700d |
children | be9c9c8f6d53 |
rev | line source |
---|---|
0 | 1 |
2 /* Test program to check the resolution of the SDL timer on the current | |
3 platform | |
4 */ | |
5 | |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
8 | |
9 #include "SDL.h" | |
10 | |
11 #define DEFAULT_RESOLUTION 1 | |
12 | |
13 static int ticks = 0; | |
14 | |
15 static Uint32 ticktock(Uint32 interval) | |
16 { | |
17 ++ticks; | |
18 return(interval); | |
19 } | |
20 | |
21 static Uint32 callback(Uint32 interval, void *param) | |
22 { | |
23 printf("Timer %d : param = %d\n", interval, (int) param); | |
24 return interval; | |
25 } | |
26 | |
27 int main(int argc, char *argv[]) | |
28 { | |
29 int desired; | |
30 SDL_TimerID t1, t2, t3; | |
31 | |
32 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) { | |
33 fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError()); | |
34 exit(1); | |
35 } | |
36 atexit(SDL_Quit); | |
37 | |
38 /* Start the timer */ | |
39 desired = 0; | |
40 if ( argv[1] ) { | |
41 desired = atoi(argv[1]); | |
42 } | |
43 if ( desired == 0 ) { | |
44 desired = DEFAULT_RESOLUTION; | |
45 } | |
46 SDL_SetTimer(desired, ticktock); | |
47 | |
48 /* Wait 10 seconds */ | |
49 printf("Waiting 10 seconds\n"); | |
50 SDL_Delay(10*1000); | |
51 | |
52 /* Stop the timer */ | |
53 SDL_SetTimer(0, NULL); | |
54 | |
55 /* Print the results */ | |
56 if ( ticks ) { | |
57 fprintf(stderr, | |
58 "Timer resolution: desired = %d ms, actual = %f ms\n", | |
59 desired, (double)(10*1000)/ticks); | |
60 } | |
61 | |
62 /* Test multiple timers */ | |
63 printf("Testing multiple timers...\n"); | |
64 t1 = SDL_AddTimer(100, callback, (void*)1); | |
65 if(!t1) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
66 fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError()); |
0 | 67 t2 = SDL_AddTimer(50, callback, (void*)2); |
68 if(!t2) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
69 fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError()); |
0 | 70 t3 = SDL_AddTimer(233, callback, (void*)3); |
71 if(!t3) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
72 fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError()); |
0 | 73 |
74 /* Wait 10 seconds */ | |
75 printf("Waiting 10 seconds\n"); | |
76 SDL_Delay(10*1000); | |
77 | |
78 printf("Removing timer 1 and waiting 5 more seconds\n"); | |
79 SDL_RemoveTimer(t1); | |
80 | |
81 SDL_Delay(5*1000); | |
82 | |
83 SDL_RemoveTimer(t2); | |
84 SDL_RemoveTimer(t3); | |
85 | |
86 return(0); | |
87 } |