Mercurial > sdl-ios-xcode
annotate src/timer/macos/SDL_systimer.c @ 1143:71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
requested this effort on the mailing list, apparently because of binary
compatibility issues between 10.4 and earlier systems (or gcc4 and earlier
compilers?).
Works fine with SDL12/test/testcdrom.c, with this command line:
./testcdrom -status -list -play -sleep 5000 -pause -sleep 3000 -resume \
-sleep 5000 -stop -sleep 3000 -play -sleep 3000 -stop \
-sleep 3000 -eject
Unix Makefiles work, XCode project still need updating for new filenames.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 22 Sep 2005 08:48:16 +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 } |