Mercurial > sdl-ios-xcode
annotate src/timer/macos/SDL_MPWtimer.c @ 3867:4dae257a9cbf SDL-1.2
Forgot cpu boundaries
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Sat, 16 Sep 2006 12:00:03 +0000 |
parents | 92947e3a18db |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
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 #define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */ | |
38 | |
39 /* Note: This is only a step above the original 1/60s implementation. | |
40 * For a good implementation, see FastTimes.[ch], by Matt Slot. | |
41 */ | |
42 #define USE_MICROSECONDS | |
43 #define WideTo64bit(w) (*(UInt64 *) &(w)) | |
44 | |
45 UInt64 start; | |
46 | |
47 void SDL_StartTicks(void) | |
48 { | |
49 #ifdef USE_MICROSECONDS | |
50 UnsignedWide now; | |
51 | |
52 Microseconds(&now); | |
53 start = WideTo64bit(now); | |
54 #else | |
55 /* FIXME: Should we implement a wrapping algorithm, like Win32? */ | |
56 #endif | |
57 } | |
58 | |
59 Uint32 SDL_GetTicks(void) | |
60 { | |
61 #ifdef USE_MICROSECONDS | |
62 UnsignedWide now; | |
63 | |
64 Microseconds(&now); | |
65 return (Uint32)((WideTo64bit(now)-start)/1000); | |
66 #else | |
67 return(LMGetTicks()*MS_PER_TICK); | |
68 #endif | |
69 } | |
70 | |
71 void SDL_Delay(Uint32 ms) | |
72 { | |
73 #ifdef USE_MICROSECONDS | |
74 Uint32 end_ms; | |
75 | |
76 end_ms = SDL_GetTicks() + ms; | |
77 do { | |
78 /* FIXME: Yield CPU? */ ; | |
79 } while ( SDL_GetTicks() < end_ms ); | |
80 #else | |
81 UInt32 unused; /* MJS */ | |
82 Delay(ms/MS_PER_TICK, &unused); | |
83 #endif | |
84 } | |
85 | |
86 | |
87 /* Data to handle a single periodic alarm */ | |
88 typedef struct _ExtendedTimerRec | |
89 { | |
90 TMTask tmTask; | |
91 ProcessSerialNumber taskPSN; | |
92 } ExtendedTimerRec, *ExtendedTimerPtr; | |
93 | |
94 static ExtendedTimerRec gExtendedTimerRec; | |
95 | |
96 | |
97 int SDL_SYS_TimerInit(void) | |
98 { | |
99 /* We don't need a setup? */ | |
100 return(0); | |
101 } | |
102 | |
103 void SDL_SYS_TimerQuit(void) | |
104 { | |
105 /* We don't need a cleanup? */ | |
106 return; | |
107 } | |
108 | |
109 /* Our Stub routine to set up and then call the real routine. */ | |
110 pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | |
111 { | |
112 Uint32 ms; | |
113 | |
114 WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | |
115 | |
116 ms = SDL_alarm_callback(SDL_alarm_interval); | |
117 if ( ms ) { | |
118 SDL_alarm_interval = ROUND_RESOLUTION(ms); | |
119 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | |
120 SDL_alarm_interval); | |
121 } else { | |
122 SDL_alarm_interval = 0; | |
123 } | |
124 } | |
125 | |
126 int SDL_SYS_StartTimer(void) | |
127 { | |
128 /* | |
129 * Configure the global structure that stores the timing information. | |
130 */ | |
131 gExtendedTimerRec.tmTask.qLink = NULL; | |
132 gExtendedTimerRec.tmTask.qType = 0; | |
133 gExtendedTimerRec.tmTask.tmAddr = NewTimerUPP(TimerCallbackProc); | |
134 gExtendedTimerRec.tmTask.tmCount = 0; | |
135 gExtendedTimerRec.tmTask.tmWakeUp = 0; | |
136 gExtendedTimerRec.tmTask.tmReserved = 0; | |
137 GetCurrentProcess(&gExtendedTimerRec.taskPSN); | |
138 | |
139 /* Install the task record */ | |
140 InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
141 | |
142 /* Go! */ | |
143 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | |
144 return(0); | |
145 } | |
146 | |
147 void SDL_SYS_StopTimer(void) | |
148 { | |
149 RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | |
150 } | |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
151 |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
152 #endif /* SDL_TIMER_MACOS */ |