Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
161 lines (130 loc) · 3.67 KB

SDL_MPWtimer.c

File metadata and controls

161 lines (130 loc) · 3.67 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
May 28, 2006
May 28, 2006
37
#define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */
Apr 26, 2001
Apr 26, 2001
38
39
40
41
42
43
44
45
46
/* 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;
May 28, 2006
May 28, 2006
47
48
void
SDL_StartTicks (void)
Apr 26, 2001
Apr 26, 2001
49
50
{
#ifdef USE_MICROSECONDS
May 28, 2006
May 28, 2006
51
52
53
54
UnsignedWide now;
Microseconds (&now);
start = WideTo64bit (now);
Apr 26, 2001
Apr 26, 2001
55
#else
May 28, 2006
May 28, 2006
56
/* FIXME: Should we implement a wrapping algorithm, like Win32? */
Apr 26, 2001
Apr 26, 2001
57
58
59
#endif
}
May 28, 2006
May 28, 2006
60
61
Uint32
SDL_GetTicks (void)
Apr 26, 2001
Apr 26, 2001
62
63
{
#ifdef USE_MICROSECONDS
May 28, 2006
May 28, 2006
64
65
66
67
UnsignedWide now;
Microseconds (&now);
return (Uint32) ((WideTo64bit (now) - start) / 1000);
Apr 26, 2001
Apr 26, 2001
68
#else
May 28, 2006
May 28, 2006
69
return (LMGetTicks () * MS_PER_TICK);
Apr 26, 2001
Apr 26, 2001
70
71
72
#endif
}
May 28, 2006
May 28, 2006
73
74
void
SDL_Delay (Uint32 ms)
Apr 26, 2001
Apr 26, 2001
75
76
{
#ifdef USE_MICROSECONDS
May 28, 2006
May 28, 2006
77
78
79
80
81
82
83
Uint32 end_ms;
end_ms = SDL_GetTicks () + ms;
do {
/* FIXME: Yield CPU? */ ;
}
while (SDL_GetTicks () < end_ms);
Apr 26, 2001
Apr 26, 2001
84
#else
May 28, 2006
May 28, 2006
85
86
UInt32 unused; /* MJS */
Delay (ms / MS_PER_TICK, &unused);
Apr 26, 2001
Apr 26, 2001
87
88
89
90
91
92
93
#endif
}
/* Data to handle a single periodic alarm */
typedef struct _ExtendedTimerRec
{
May 28, 2006
May 28, 2006
94
95
TMTask tmTask;
ProcessSerialNumber taskPSN;
Apr 26, 2001
Apr 26, 2001
96
97
98
99
100
} ExtendedTimerRec, *ExtendedTimerPtr;
static ExtendedTimerRec gExtendedTimerRec;
May 28, 2006
May 28, 2006
101
102
int
SDL_SYS_TimerInit (void)
Apr 26, 2001
Apr 26, 2001
103
{
May 28, 2006
May 28, 2006
104
105
/* We don't need a setup? */
return (0);
Apr 26, 2001
Apr 26, 2001
106
107
}
May 28, 2006
May 28, 2006
108
109
void
SDL_SYS_TimerQuit (void)
Apr 26, 2001
Apr 26, 2001
110
{
May 28, 2006
May 28, 2006
111
112
/* We don't need a cleanup? */
return;
Apr 26, 2001
Apr 26, 2001
113
114
115
}
/* Our Stub routine to set up and then call the real routine. */
May 28, 2006
May 28, 2006
116
117
pascal void
TimerCallbackProc (TMTaskPtr tmTaskPtr)
Apr 26, 2001
Apr 26, 2001
118
{
May 28, 2006
May 28, 2006
119
120
121
122
123
124
125
126
127
128
129
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;
}
Apr 26, 2001
Apr 26, 2001
130
131
}
May 28, 2006
May 28, 2006
132
133
int
SDL_SYS_StartTimer (void)
Apr 26, 2001
Apr 26, 2001
134
{
May 28, 2006
May 28, 2006
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* 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);
Apr 26, 2001
Apr 26, 2001
152
153
}
May 28, 2006
May 28, 2006
154
155
void
SDL_SYS_StopTimer (void)
Apr 26, 2001
Apr 26, 2001
156
{
May 28, 2006
May 28, 2006
157
RmvTime ((QElemPtr) & gExtendedTimerRec.tmTask);
Apr 26, 2001
Apr 26, 2001
158
}
Apr 14, 2006
Apr 14, 2006
159
160
#endif /* SDL_TIMER_MACOS */
May 28, 2006
May 28, 2006
161
/* vi: set ts=4 sw=4 expandtab: */