Skip to content

Latest commit

 

History

History
152 lines (121 loc) · 3.45 KB

SDL_MPWtimer.c

File metadata and controls

152 lines (121 loc) · 3.45 KB
 
Apr 26, 2001
Apr 26, 2001
1
/*
Feb 1, 2006
Feb 1, 2006
2
3
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
Feb 1, 2006
Feb 1, 2006
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
Feb 1, 2006
Feb 1, 2006
10
11
12
13
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
Feb 1, 2006
Feb 1, 2006
19
20
Sam Lantinga
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
Apr 14, 2006
Apr 14, 2006
24
25
#ifdef SDL_TIMER_MACOS
Apr 26, 2001
Apr 26, 2001
26
27
28
29
30
31
32
33
34
#include <Types.h>
#include <Timer.h>
#include <OSUtils.h>
#include <Gestalt.h>
#include <Processes.h>
#include <LowMem.h>
#include "SDL_timer.h"
Feb 16, 2006
Feb 16, 2006
35
#include "../SDL_timer_c.h"
Apr 26, 2001
Apr 26, 2001
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */
/* Note: This is only a step above the original 1/60s implementation.
* For a good implementation, see FastTimes.[ch], by Matt Slot.
*/
#define USE_MICROSECONDS
#define WideTo64bit(w) (*(UInt64 *) &(w))
UInt64 start;
void SDL_StartTicks(void)
{
#ifdef USE_MICROSECONDS
UnsignedWide now;
Microseconds(&now);
start = WideTo64bit(now);
#else
/* FIXME: Should we implement a wrapping algorithm, like Win32? */
#endif
}
Uint32 SDL_GetTicks(void)
{
#ifdef USE_MICROSECONDS
UnsignedWide now;
Microseconds(&now);
return (Uint32)((WideTo64bit(now)-start)/1000);
#else
return(LMGetTicks()*MS_PER_TICK);
#endif
}
void SDL_Delay(Uint32 ms)
{
#ifdef USE_MICROSECONDS
Uint32 end_ms;
end_ms = SDL_GetTicks() + ms;
do {
/* FIXME: Yield CPU? */ ;
} while ( SDL_GetTicks() < end_ms );
#else
UInt32 unused; /* MJS */
Delay(ms/MS_PER_TICK, &unused);
#endif
}
/* Data to handle a single periodic alarm */
typedef struct _ExtendedTimerRec
{
TMTask tmTask;
ProcessSerialNumber taskPSN;
} ExtendedTimerRec, *ExtendedTimerPtr;
static ExtendedTimerRec gExtendedTimerRec;
int SDL_SYS_TimerInit(void)
{
/* We don't need a setup? */
return(0);
}
void SDL_SYS_TimerQuit(void)
{
/* We don't need a cleanup? */
return;
}
/* Our Stub routine to set up and then call the real routine. */
pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr)
{
Uint32 ms;
WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN);
ms = SDL_alarm_callback(SDL_alarm_interval);
if ( ms ) {
SDL_alarm_interval = ROUND_RESOLUTION(ms);
PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask,
SDL_alarm_interval);
} else {
SDL_alarm_interval = 0;
}
}
int SDL_SYS_StartTimer(void)
{
/*
* Configure the global structure that stores the timing information.
*/
gExtendedTimerRec.tmTask.qLink = NULL;
gExtendedTimerRec.tmTask.qType = 0;
gExtendedTimerRec.tmTask.tmAddr = NewTimerUPP(TimerCallbackProc);
gExtendedTimerRec.tmTask.tmCount = 0;
gExtendedTimerRec.tmTask.tmWakeUp = 0;
gExtendedTimerRec.tmTask.tmReserved = 0;
GetCurrentProcess(&gExtendedTimerRec.taskPSN);
/* Install the task record */
InsXTime((QElemPtr)&gExtendedTimerRec.tmTask);
/* Go! */
PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval);
return(0);
}
void SDL_SYS_StopTimer(void)
{
RmvTime((QElemPtr)&gExtendedTimerRec.tmTask);
}
Apr 14, 2006
Apr 14, 2006
151
152
#endif /* SDL_TIMER_MACOS */