Mercurial > sdl-ios-xcode
annotate src/timer/macos/SDL_systimer.c @ 914:bbf8dcc8aed6
Date: Wed, 23 Jun 2004 17:05:33 -0400
From: Chris Nelson
Subject: [SDL] [Patch] WiseGroup MP-8800 / MP-8866 (PS2 Joystick)
In the current cvs version, SDL doesn't handle these Playstation2
controller => USB adapters correctly, in linux.
It will always assume that the maximum number of joysticks (2 in the
case of the MP-8866, 4 in the case of the 8800) are plugged in. This is
bad not only because it allows SDL to exaggerate the number of logical
joysticks, but primarily because the joystick axes are mapped
incorrectly, all over the place, such that the devices are effectively
unusable unless you have the maximum number of joysticks plugged in.
My changes to src/joystick/linux/SDL_sysjoystick.c build on another's
previous work (which was a special case for this very joystick,
actually), and fix both of these problems, as well as making the current
code a little more general, to allow for others to more easily drop in
code for quirky joysticks such as these.
I've tested this code under 2.6.7 as well as 2.4.24... Both work as
advertised (provided you load the JOYDEV linux code as a module,
otherwise they won't work at all, new code or old, but that's another
issue entirely).
Though this sounds horribly formal, you have my permission to distribute
all of my work on this issue under the LGPL. So there.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 25 Jul 2004 18:31:50 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <Types.h> | |
29 #include <Timer.h> | |
30 #include <OSUtils.h> | |
31 #include <Gestalt.h> | |
32 #include <Processes.h> | |
33 | |
34 #include <LowMem.h> | |
35 | |
36 #include "SDL_timer.h" | |
37 #include "SDL_timer_c.h" | |
38 | |
39 #include "FastTimes.h" | |
40 | |
41 #define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ | |
42 | |
43 | |
44 #define kTwoPower32 (4294967296.0) /* 2^32 */ | |
45 | |
46 static double start_tick; | |
47 static int is_fast_inited = 0; | |
48 | |
49 void SDL_StartTicks(void) | |
50 { | |
51 if ( ! is_fast_inited ) // important to check or FastTime may hang machine! | |
52 SDL_SYS_TimerInit(); | |
53 | |
54 start_tick = FastMicroseconds(); | |
55 } | |
56 | |
57 Uint32 SDL_GetTicks(void) | |
58 { | |
59 | |
60 if ( ! is_fast_inited ) | |
61 SDL_SYS_TimerInit(); | |
62 | |
63 return FastMilliseconds(); | |
64 } | |
65 | |
66 void SDL_Delay(Uint32 ms) | |
67 { | |
68 Uint32 stop, now; | |
69 | |
70 stop = SDL_GetTicks() + ms; | |
71 do { | |
72 SystemTask(); | |
73 | |
74 now = SDL_GetTicks(); | |
75 | |
76 } while ( stop > now ); | |
77 } | |
78 | |
79 /* | |
80 void SDL_StartTicks(void) | |
81 { | |
82 // FIXME: Should we implement a wrapping algorithm, like Win32? | |
83 } | |
84 | |
85 Uint32 SDL_GetTicks(void) | |
86 { | |
87 UnsignedWide ms; | |
88 | |
89 Microseconds (&ms); | |
90 | |
91 return ( ms.lo / 1000 ); | |
92 } | |
93 | |
94 void SDL_Delay(Uint32 ms) | |
95 { | |
96 | |
97 UnsignedWide microsecs; | |
98 UInt32 stop; | |
99 | |
100 Microseconds (µsecs); | |
101 | |
102 stop = microsecs.lo + (ms * 1000); | |
103 | |
104 while ( stop > microsecs.lo ) { | |
105 | |
106 SystemTask (); | |
107 | |
108 Microseconds (µsecs); | |
109 } | |
110 | |
111 }*/ | |
112 | |
113 /* Data to handle a single periodic alarm */ | |
114 typedef struct _ExtendedTimerRec | |
115 { | |
116 TMTask tmTask; | |
117 ProcessSerialNumber taskPSN; | |
118 } ExtendedTimerRec, *ExtendedTimerPtr; | |
119 | |
120 static ExtendedTimerRec gExtendedTimerRec; | |
121 | |
122 | |
123 int SDL_SYS_TimerInit(void) | |
124 { | |
125 FastInitialize (); | |
126 is_fast_inited = 1; | |
127 | |
128 return(0); | |
129 } | |
130 | |
131 void SDL_SYS_TimerQuit(void) | |
132 { | |
133 /* We don't need a cleanup? */ | |
134 return; | |
135 } | |
136 | |
137 /* Our Stub routine to set up and then call the real routine. */ | |
138 pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | |
139 { | |
140 Uint32 ms; | |
141 | |
142 WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | |
143 | |
144 ms = SDL_alarm_callback(SDL_alarm_interval); | |
145 if ( ms ) { | |
146 SDL_alarm_interval = ROUND_RESOLUTION(ms); | |
147 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | |
148 SDL_alarm_interval); | |
149 } else { | |
150 SDL_alarm_interval = 0; | |
151 } | |
152 } | |
153 | |
154 int SDL_SYS_StartTimer(void) | |
155 { | |
156 /* | |
157 * Configure the global structure that stores the timing information. | |
158 */ | |
159 gExtendedTimerRec.tmTask.qLink = NULL; | |
160 gExtendedTimerRec.tmTask.qType = 0; | |
161 gExtendedTimerRec.tmTask.tmAddr = NewTimerProc(TimerCallbackProc); | |
162 gExtendedTimerRec.tmTask.tmCount = 0; | |
163 gExtendedTimerRec.tmTask.tmWakeUp = 0; | |
164 gExtendedTimerRec.tmTask.tmReserved = 0; | |
165 GetCurrentProcess(&gExtendedTimerRec.taskPSN); | |
166 | |
167 /* Install the task record */ | |
168 InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
169 | |
170 /* Go! */ | |
171 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | |
172 return(0); | |
173 } | |
174 | |
175 void SDL_SYS_StopTimer(void) | |
176 { | |
177 RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
178 } |