Mercurial > sdl-ios-xcode
annotate test/testtimer.c @ 937:1e6366bde299
Date: Tue, 27 Jul 2004 17:14:00 +0200
From: "Eckhard Stolberg"
Subject: Controller names in SDL for Windows
I'm working on an Atari 2600 emulator for different systems that uses
the SDL. Some time ago someone created an adaptor that lets you use
your old Atari controllers with your computer through the USB port.
Some of the Atari controllers require special handling by the emulator,
so it would be nice, if it would be possible to detect if any of the
controllers connected to the computer is this adaptor.
SDL would allow that with the SDL_JoystickName function, but unfortunately
it doesn't work properly on Windows. On Linux and MacOSX this function
returns the name of the controller, but on Windows you'll only get the
name of the joystick driver. Most joysticks nowadays use the generic
Microsoft driver, so they all return the same name.
In an old MSDN article
(http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarinput/html/msdn_extdirect.asp)
Microsoft describes how to read out the OEM controller names from the registry.
I have implemented this for the SDL controller handler on Windows,
and now reading the joystick name works properly there too.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 21 Aug 2004 03:45:58 +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 } |