Mercurial > sdl-ios-xcode
annotate src/timer/macos/SDL_systimer.c @ 1636:3d0dec74ad01
A script to build a fat version of the SDL library... completely untested!
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 14 Apr 2006 05:43:04 +0000 |
parents | 92947e3a18db |
children | 14717b52abc0 4c270c3a88ed |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
24 #ifdef SDL_TIMER_MACOS |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
25 |
0 | 26 #include <Types.h> |
27 #include <Timer.h> | |
28 #include <OSUtils.h> | |
29 #include <Gestalt.h> | |
30 #include <Processes.h> | |
31 | |
32 #include <LowMem.h> | |
33 | |
34 #include "SDL_timer.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
35 #include "../SDL_timer_c.h" |
0 | 36 |
37 #include "FastTimes.h" | |
38 | |
39 #define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ | |
40 | |
41 | |
42 #define kTwoPower32 (4294967296.0) /* 2^32 */ | |
43 | |
44 static double start_tick; | |
45 static int is_fast_inited = 0; | |
46 | |
47 void SDL_StartTicks(void) | |
48 { | |
49 if ( ! is_fast_inited ) // important to check or FastTime may hang machine! | |
50 SDL_SYS_TimerInit(); | |
51 | |
52 start_tick = FastMicroseconds(); | |
53 } | |
54 | |
55 Uint32 SDL_GetTicks(void) | |
56 { | |
57 | |
58 if ( ! is_fast_inited ) | |
59 SDL_SYS_TimerInit(); | |
60 | |
61 return FastMilliseconds(); | |
62 } | |
63 | |
64 void SDL_Delay(Uint32 ms) | |
65 { | |
66 Uint32 stop, now; | |
67 | |
68 stop = SDL_GetTicks() + ms; | |
69 do { | |
70 SystemTask(); | |
71 | |
72 now = SDL_GetTicks(); | |
73 | |
74 } while ( stop > now ); | |
75 } | |
76 | |
77 /* | |
78 void SDL_StartTicks(void) | |
79 { | |
80 // FIXME: Should we implement a wrapping algorithm, like Win32? | |
81 } | |
82 | |
83 Uint32 SDL_GetTicks(void) | |
84 { | |
85 UnsignedWide ms; | |
86 | |
87 Microseconds (&ms); | |
88 | |
89 return ( ms.lo / 1000 ); | |
90 } | |
91 | |
92 void SDL_Delay(Uint32 ms) | |
93 { | |
94 | |
95 UnsignedWide microsecs; | |
96 UInt32 stop; | |
97 | |
98 Microseconds (µsecs); | |
99 | |
100 stop = microsecs.lo + (ms * 1000); | |
101 | |
102 while ( stop > microsecs.lo ) { | |
103 | |
104 SystemTask (); | |
105 | |
106 Microseconds (µsecs); | |
107 } | |
108 | |
109 }*/ | |
110 | |
111 /* Data to handle a single periodic alarm */ | |
112 typedef struct _ExtendedTimerRec | |
113 { | |
114 TMTask tmTask; | |
115 ProcessSerialNumber taskPSN; | |
116 } ExtendedTimerRec, *ExtendedTimerPtr; | |
117 | |
118 static ExtendedTimerRec gExtendedTimerRec; | |
119 | |
120 | |
121 int SDL_SYS_TimerInit(void) | |
122 { | |
123 FastInitialize (); | |
124 is_fast_inited = 1; | |
125 | |
126 return(0); | |
127 } | |
128 | |
129 void SDL_SYS_TimerQuit(void) | |
130 { | |
131 /* We don't need a cleanup? */ | |
132 return; | |
133 } | |
134 | |
135 /* Our Stub routine to set up and then call the real routine. */ | |
136 pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | |
137 { | |
138 Uint32 ms; | |
139 | |
140 WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | |
141 | |
142 ms = SDL_alarm_callback(SDL_alarm_interval); | |
143 if ( ms ) { | |
144 SDL_alarm_interval = ROUND_RESOLUTION(ms); | |
145 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | |
146 SDL_alarm_interval); | |
147 } else { | |
148 SDL_alarm_interval = 0; | |
149 } | |
150 } | |
151 | |
152 int SDL_SYS_StartTimer(void) | |
153 { | |
154 /* | |
155 * Configure the global structure that stores the timing information. | |
156 */ | |
157 gExtendedTimerRec.tmTask.qLink = NULL; | |
158 gExtendedTimerRec.tmTask.qType = 0; | |
159 gExtendedTimerRec.tmTask.tmAddr = NewTimerProc(TimerCallbackProc); | |
160 gExtendedTimerRec.tmTask.tmCount = 0; | |
161 gExtendedTimerRec.tmTask.tmWakeUp = 0; | |
162 gExtendedTimerRec.tmTask.tmReserved = 0; | |
163 GetCurrentProcess(&gExtendedTimerRec.taskPSN); | |
164 | |
165 /* Install the task record */ | |
166 InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
167 | |
168 /* Go! */ | |
169 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | |
170 return(0); | |
171 } | |
172 | |
173 void SDL_SYS_StopTimer(void) | |
174 { | |
175 RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
176 } | |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
177 |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
178 #endif /* SDL_TIMER_MACOS */ |