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