Mercurial > sdl-ios-xcode
annotate src/timer/macos/SDL_systimer.c @ 1502:d403a39389da
UTF-32 by definition can't handle characters higher than 0x10FFFF
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 13 Mar 2006 01:16:16 +0000 |
parents | d910939febfa |
children | 92947e3a18db |
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 |
24 #include <Types.h> | |
25 #include <Timer.h> | |
26 #include <OSUtils.h> | |
27 #include <Gestalt.h> | |
28 #include <Processes.h> | |
29 | |
30 #include <LowMem.h> | |
31 | |
32 #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
|
33 #include "../SDL_timer_c.h" |
0 | 34 |
35 #include "FastTimes.h" | |
36 | |
37 #define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ | |
38 | |
39 | |
40 #define kTwoPower32 (4294967296.0) /* 2^32 */ | |
41 | |
42 static double start_tick; | |
43 static int is_fast_inited = 0; | |
44 | |
45 void SDL_StartTicks(void) | |
46 { | |
47 if ( ! is_fast_inited ) // important to check or FastTime may hang machine! | |
48 SDL_SYS_TimerInit(); | |
49 | |
50 start_tick = FastMicroseconds(); | |
51 } | |
52 | |
53 Uint32 SDL_GetTicks(void) | |
54 { | |
55 | |
56 if ( ! is_fast_inited ) | |
57 SDL_SYS_TimerInit(); | |
58 | |
59 return FastMilliseconds(); | |
60 } | |
61 | |
62 void SDL_Delay(Uint32 ms) | |
63 { | |
64 Uint32 stop, now; | |
65 | |
66 stop = SDL_GetTicks() + ms; | |
67 do { | |
68 SystemTask(); | |
69 | |
70 now = SDL_GetTicks(); | |
71 | |
72 } while ( stop > now ); | |
73 } | |
74 | |
75 /* | |
76 void SDL_StartTicks(void) | |
77 { | |
78 // FIXME: Should we implement a wrapping algorithm, like Win32? | |
79 } | |
80 | |
81 Uint32 SDL_GetTicks(void) | |
82 { | |
83 UnsignedWide ms; | |
84 | |
85 Microseconds (&ms); | |
86 | |
87 return ( ms.lo / 1000 ); | |
88 } | |
89 | |
90 void SDL_Delay(Uint32 ms) | |
91 { | |
92 | |
93 UnsignedWide microsecs; | |
94 UInt32 stop; | |
95 | |
96 Microseconds (µsecs); | |
97 | |
98 stop = microsecs.lo + (ms * 1000); | |
99 | |
100 while ( stop > microsecs.lo ) { | |
101 | |
102 SystemTask (); | |
103 | |
104 Microseconds (µsecs); | |
105 } | |
106 | |
107 }*/ | |
108 | |
109 /* Data to handle a single periodic alarm */ | |
110 typedef struct _ExtendedTimerRec | |
111 { | |
112 TMTask tmTask; | |
113 ProcessSerialNumber taskPSN; | |
114 } ExtendedTimerRec, *ExtendedTimerPtr; | |
115 | |
116 static ExtendedTimerRec gExtendedTimerRec; | |
117 | |
118 | |
119 int SDL_SYS_TimerInit(void) | |
120 { | |
121 FastInitialize (); | |
122 is_fast_inited = 1; | |
123 | |
124 return(0); | |
125 } | |
126 | |
127 void SDL_SYS_TimerQuit(void) | |
128 { | |
129 /* We don't need a cleanup? */ | |
130 return; | |
131 } | |
132 | |
133 /* Our Stub routine to set up and then call the real routine. */ | |
134 pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | |
135 { | |
136 Uint32 ms; | |
137 | |
138 WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | |
139 | |
140 ms = SDL_alarm_callback(SDL_alarm_interval); | |
141 if ( ms ) { | |
142 SDL_alarm_interval = ROUND_RESOLUTION(ms); | |
143 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | |
144 SDL_alarm_interval); | |
145 } else { | |
146 SDL_alarm_interval = 0; | |
147 } | |
148 } | |
149 | |
150 int SDL_SYS_StartTimer(void) | |
151 { | |
152 /* | |
153 * Configure the global structure that stores the timing information. | |
154 */ | |
155 gExtendedTimerRec.tmTask.qLink = NULL; | |
156 gExtendedTimerRec.tmTask.qType = 0; | |
157 gExtendedTimerRec.tmTask.tmAddr = NewTimerProc(TimerCallbackProc); | |
158 gExtendedTimerRec.tmTask.tmCount = 0; | |
159 gExtendedTimerRec.tmTask.tmWakeUp = 0; | |
160 gExtendedTimerRec.tmTask.tmReserved = 0; | |
161 GetCurrentProcess(&gExtendedTimerRec.taskPSN); | |
162 | |
163 /* Install the task record */ | |
164 InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
165 | |
166 /* Go! */ | |
167 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | |
168 return(0); | |
169 } | |
170 | |
171 void SDL_SYS_StopTimer(void) | |
172 { | |
173 RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
174 } |