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