diff options
author | Franklin Wei <git@fwei.tk> | 2018-02-07 20:04:46 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2018-03-12 20:52:01 -0400 |
commit | 6039eb05ba6d82ef56f2868c96654c552d117bf9 (patch) | |
tree | 9db7016bcbf66cfdf7b9bc998d84c6eaff9c8378 /apps/plugins/sdl/src/timer | |
parent | ef373c03b96b0be08babca581d9f10bccfd4931f (diff) | |
download | rockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.tar.gz rockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.zip |
sdl: remove non-rockbox drivers
We never use any of these other drivers, so having them around just takes
up space.
Change-Id: Iced812162df1fef3fd55522b7e700acb6c3bcd41
Diffstat (limited to 'apps/plugins/sdl/src/timer')
-rw-r--r-- | apps/plugins/sdl/src/timer/beos/SDL_systimer.c | 95 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/dc/SDL_systimer.c | 100 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/macos/FastTimes.c | 352 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/macos/FastTimes.h | 27 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/macos/SDL_MPWtimer.c | 152 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/macos/SDL_systimer.c | 186 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/mint/SDL_systimer.c | 149 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/mint/SDL_vbltimer.S | 228 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/mint/SDL_vbltimer_s.h | 35 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/nds/SDL_systimer.c | 73 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/os2/SDL_systimer.c | 227 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/riscos/SDL_systimer.c | 233 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/symbian/SDL_systimer.cpp | 114 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/unix/SDL_systimer.c | 240 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/win32/SDL_systimer.c | 160 | ||||
-rw-r--r-- | apps/plugins/sdl/src/timer/wince/SDL_systimer.c | 198 |
16 files changed, 0 insertions, 2569 deletions
diff --git a/apps/plugins/sdl/src/timer/beos/SDL_systimer.c b/apps/plugins/sdl/src/timer/beos/SDL_systimer.c deleted file mode 100644 index f4cf6c765e..0000000000 --- a/apps/plugins/sdl/src/timer/beos/SDL_systimer.c +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_BEOS | ||
25 | |||
26 | #include <be/kernel/OS.h> | ||
27 | |||
28 | #include "SDL_thread.h" | ||
29 | #include "SDL_timer.h" | ||
30 | #include "../SDL_timer_c.h" | ||
31 | |||
32 | static bigtime_t start; | ||
33 | |||
34 | void SDL_StartTicks(void) | ||
35 | { | ||
36 | /* Set first ticks value */ | ||
37 | start = system_time(); | ||
38 | } | ||
39 | |||
40 | Uint32 SDL_GetTicks(void) | ||
41 | { | ||
42 | return((system_time()-start)/1000); | ||
43 | } | ||
44 | |||
45 | void SDL_Delay(Uint32 ms) | ||
46 | { | ||
47 | snooze(ms*1000); | ||
48 | } | ||
49 | |||
50 | /* Data to handle a single periodic alarm */ | ||
51 | static int timer_alive = 0; | ||
52 | static SDL_Thread *timer = NULL; | ||
53 | |||
54 | static int RunTimer(void *unused) | ||
55 | { | ||
56 | while ( timer_alive ) { | ||
57 | if ( SDL_timer_running ) { | ||
58 | SDL_ThreadedTimerCheck(); | ||
59 | } | ||
60 | SDL_Delay(10); | ||
61 | } | ||
62 | return(0); | ||
63 | } | ||
64 | |||
65 | /* This is only called if the event thread is not running */ | ||
66 | int SDL_SYS_TimerInit(void) | ||
67 | { | ||
68 | timer_alive = 1; | ||
69 | timer = SDL_CreateThread(RunTimer, NULL); | ||
70 | if ( timer == NULL ) | ||
71 | return(-1); | ||
72 | return(SDL_SetTimerThreaded(1)); | ||
73 | } | ||
74 | |||
75 | void SDL_SYS_TimerQuit(void) | ||
76 | { | ||
77 | timer_alive = 0; | ||
78 | if ( timer ) { | ||
79 | SDL_WaitThread(timer, NULL); | ||
80 | timer = NULL; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | int SDL_SYS_StartTimer(void) | ||
85 | { | ||
86 | SDL_SetError("Internal logic error: BeOS uses threaded timer"); | ||
87 | return(-1); | ||
88 | } | ||
89 | |||
90 | void SDL_SYS_StopTimer(void) | ||
91 | { | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | #endif /* SDL_TIMER_BEOS */ | ||
diff --git a/apps/plugins/sdl/src/timer/dc/SDL_systimer.c b/apps/plugins/sdl/src/timer/dc/SDL_systimer.c deleted file mode 100644 index 386e158607..0000000000 --- a/apps/plugins/sdl/src/timer/dc/SDL_systimer.c +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_DC | ||
25 | |||
26 | #include <kos.h> | ||
27 | |||
28 | #include "SDL_thread.h" | ||
29 | #include "SDL_timer.h" | ||
30 | #include "../SDL_timer_c.h" | ||
31 | |||
32 | static unsigned start; | ||
33 | |||
34 | /* | ||
35 | jif = ms * HZ /1000 | ||
36 | ms = jif * 1000/HZ | ||
37 | */ | ||
38 | |||
39 | void SDL_StartTicks(void) | ||
40 | { | ||
41 | /* Set first ticks value */ | ||
42 | start = jiffies; | ||
43 | } | ||
44 | |||
45 | Uint32 SDL_GetTicks(void) | ||
46 | { | ||
47 | return((jiffies-start)*1000/HZ); | ||
48 | } | ||
49 | |||
50 | void SDL_Delay(Uint32 ms) | ||
51 | { | ||
52 | thd_sleep(ms); | ||
53 | } | ||
54 | |||
55 | /* Data to handle a single periodic alarm */ | ||
56 | static int timer_alive = 0; | ||
57 | static SDL_Thread *timer = NULL; | ||
58 | |||
59 | static int RunTimer(void *unused) | ||
60 | { | ||
61 | while ( timer_alive ) { | ||
62 | if ( SDL_timer_running ) { | ||
63 | SDL_ThreadedTimerCheck(); | ||
64 | } | ||
65 | SDL_Delay(10); | ||
66 | } | ||
67 | return(0); | ||
68 | } | ||
69 | |||
70 | /* This is only called if the event thread is not running */ | ||
71 | int SDL_SYS_TimerInit(void) | ||
72 | { | ||
73 | timer_alive = 1; | ||
74 | timer = SDL_CreateThread(RunTimer, NULL); | ||
75 | if ( timer == NULL ) | ||
76 | return(-1); | ||
77 | return(SDL_SetTimerThreaded(1)); | ||
78 | } | ||
79 | |||
80 | void SDL_SYS_TimerQuit(void) | ||
81 | { | ||
82 | timer_alive = 0; | ||
83 | if ( timer ) { | ||
84 | SDL_WaitThread(timer, NULL); | ||
85 | timer = NULL; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | int SDL_SYS_StartTimer(void) | ||
90 | { | ||
91 | SDL_SetError("Internal logic error: DC uses threaded timer"); | ||
92 | return(-1); | ||
93 | } | ||
94 | |||
95 | void SDL_SYS_StopTimer(void) | ||
96 | { | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | #endif /* SDL_TIMER_DC */ | ||
diff --git a/apps/plugins/sdl/src/timer/macos/FastTimes.c b/apps/plugins/sdl/src/timer/macos/FastTimes.c deleted file mode 100644 index 2da74b7d18..0000000000 --- a/apps/plugins/sdl/src/timer/macos/FastTimes.c +++ /dev/null | |||
@@ -1,352 +0,0 @@ | |||
1 | /* File "FastTimes.c" - Original code by Matt Slot <fprefect@ambrosiasw.com> */ | ||
2 | /* Created 4/24/99 - This file is hereby placed in the public domain */ | ||
3 | /* Updated 5/21/99 - Calibrate to VIA, add TBR support, renamed functions */ | ||
4 | /* Updated 10/4/99 - Use AbsoluteToNanoseconds() in case Absolute = double */ | ||
5 | /* Updated 2/15/00 - Check for native Time Manager, no need to calibrate */ | ||
6 | /* Updated 2/19/00 - Fixed default value for gScale under native Time Mgr */ | ||
7 | /* Updated 3/21/00 - Fixed ns conversion, create 2 different scale factors */ | ||
8 | /* Updated 5/03/00 - Added copyright and placed into PD. No code changes */ | ||
9 | /* Updated 8/01/00 - Made "Carbon-compatible" by replacing LMGetTicks() */ | ||
10 | |||
11 | /* This file is Copyright (C) Matt Slot, 1999-2012. It is hereby placed into | ||
12 | the public domain. The author makes no warranty as to fitness or stability */ | ||
13 | |||
14 | #include <Gestalt.h> | ||
15 | #include <LowMem.h> | ||
16 | #include <CodeFragments.h> | ||
17 | #include <DriverServices.h> | ||
18 | #include <Timer.h> | ||
19 | |||
20 | #include "FastTimes.h" | ||
21 | |||
22 | #ifdef TARGET_CPU_PPC | ||
23 | #undef GENERATINGPOWERPC /* stop whining */ | ||
24 | #define GENERATINGPOWERPC TARGET_CPU_PPC | ||
25 | #endif | ||
26 | |||
27 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
28 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
29 | /* | ||
30 | On 680x0 machines, we just use Microseconds(). | ||
31 | |||
32 | On PowerPC machines, we try several methods: | ||
33 | * DriverServicesLib is available on all PCI PowerMacs, and perhaps | ||
34 | some NuBus PowerMacs. If it is, we use UpTime() : Overhead = 2.1 µsec. | ||
35 | * The PowerPC 601 has a built-in "real time clock" RTC, and we fall | ||
36 | back to that, accessing it directly from asm. Overhead = 1.3 µsec. | ||
37 | * Later PowerPCs have an accurate "time base register" TBR, and we | ||
38 | fall back to that, access it from PowerPC asm. Overhead = 1.3 µsec. | ||
39 | * We can also try Microseconds() which is emulated : Overhead = 36 µsec. | ||
40 | |||
41 | On PowerPC machines, we avoid the following: | ||
42 | * OpenTransport is available on all PCI and some NuBus PowerMacs, but it | ||
43 | uses UpTime() if available and falls back to Microseconds() otherwise. | ||
44 | * InputSprocket is available on many PowerMacs, but again it uses | ||
45 | UpTime() if available and falls back to Microseconds() otherwise. | ||
46 | |||
47 | Another PowerPC note: certain configurations, especially 3rd party upgrade | ||
48 | cards, may return inaccurate timings for the CPU or memory bus -- causing | ||
49 | skew in various system routines (up to 20% drift!). The VIA chip is very | ||
50 | accurate, and it's the basis for the Time Manager and Microseconds(). | ||
51 | Unfortunately, it's also very slow because the MacOS has to (a) switch to | ||
52 | 68K and (b) poll for a VIA event. | ||
53 | |||
54 | We compensate for the drift by calibrating a floating point scale factor | ||
55 | between our fast method and the accurate timer at startup, then convert | ||
56 | each sample quickly on the fly. I'd rather not have the initialization | ||
57 | overhead -- but it's simply necessary for accurate timing. You can drop | ||
58 | it down to 30 ticks if you prefer, but that's as low as I'd recommend. | ||
59 | |||
60 | Under MacOS 9, "new world" Macs (iMacs, B+W G3s and G+W G4s) have a native | ||
61 | Time Manager implementation: UpTime(), Microseconds(), and TickCount() are | ||
62 | all based on the same underlying counter. This makes it silly to calibrate | ||
63 | UpTime() against TickCount(). We now check for this feature using Gestalt(), | ||
64 | and skip the whole calibration step if possible. | ||
65 | |||
66 | */ | ||
67 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
68 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
69 | |||
70 | #define RTCToNano(w) ((double) (w).hi * 1000000000.0 + (double) (w).lo) | ||
71 | #define WideTo64bit(w) (*(UInt64 *) &(w)) | ||
72 | |||
73 | /* LMGetTicks() is not in Carbon and TickCount() has a fair bit of overhead, | ||
74 | so for speed we always read lowmem directly. This is a Mac OS X no-no, but | ||
75 | it always work on those systems that don't have a native Time Manager (ie, | ||
76 | anything before MacOS 9) -- regardless whether we are in Carbon or not! */ | ||
77 | #define MyLMGetTicks() (*(volatile UInt32 *) 0x16A) | ||
78 | |||
79 | #if GENERATINGPOWERPC | ||
80 | |||
81 | static asm UnsignedWide PollRTC(void); | ||
82 | static asm UnsignedWide PollTBR(void); | ||
83 | static Ptr FindFunctionInSharedLib(StringPtr libName, StringPtr funcName); | ||
84 | |||
85 | static Boolean gInited = false; | ||
86 | static Boolean gNative = false; | ||
87 | static Boolean gUseRTC = false; | ||
88 | static Boolean gUseTBR = false; | ||
89 | static double gScaleUSec = 1.0 / 1000.0; /* 1 / ( nsec / usec) */ | ||
90 | static double gScaleMSec = 1.0 / 1000000.0; /* 1 / ( nsec / msec) */ | ||
91 | |||
92 | /* Functions loaded from DriverServicesLib */ | ||
93 | typedef AbsoluteTime (*UpTimeProcPtr)(void); | ||
94 | typedef Nanoseconds (*A2NSProcPtr)(AbsoluteTime); | ||
95 | static UpTimeProcPtr gUpTime = NULL; | ||
96 | static A2NSProcPtr gA2NS = NULL; | ||
97 | |||
98 | #endif /* GENERATINGPOWERPC */ | ||
99 | |||
100 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
101 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
102 | |||
103 | void FastInitialize() { | ||
104 | SInt32 result; | ||
105 | |||
106 | if (!gInited) { | ||
107 | |||
108 | #if GENERATINGPOWERPC | ||
109 | |||
110 | /* Initialize the feature flags */ | ||
111 | gNative = gUseRTC = gUseTBR = false; | ||
112 | |||
113 | /* We use CFM to find and load needed symbols from shared libraries, so | ||
114 | the application doesn't have to weak-link them, for convenience. */ | ||
115 | gUpTime = (UpTimeProcPtr) FindFunctionInSharedLib( | ||
116 | "\pDriverServicesLib", "\pUpTime"); | ||
117 | if (gUpTime) gA2NS = (A2NSProcPtr) FindFunctionInSharedLib( | ||
118 | "\pDriverServicesLib", "\pAbsoluteToNanoseconds"); | ||
119 | if (!gA2NS) gUpTime = nil; /* Pedantic but necessary */ | ||
120 | |||
121 | if (gUpTime) { | ||
122 | /* If we loaded UpTime(), then we need to know if the system has | ||
123 | a native implementation of the Time Manager. If so, then it's | ||
124 | pointless to calculate a scale factor against the missing VIA */ | ||
125 | |||
126 | /* gestaltNativeTimeMgr = 4 in some future version of the headers */ | ||
127 | if (!Gestalt(gestaltTimeMgrVersion, &result) && | ||
128 | (result > gestaltExtendedTimeMgr)) | ||
129 | gNative = true; | ||
130 | } | ||
131 | else { | ||
132 | /* If no DriverServicesLib, use Gestalt() to get the processor type. | ||
133 | Only NuBus PowerMacs with old System Software won't have DSL, so | ||
134 | we know it should either be a 601 or 603. */ | ||
135 | |||
136 | /* Use the processor gestalt to determine which register to use */ | ||
137 | if (!Gestalt(gestaltNativeCPUtype, &result)) { | ||
138 | if (result == gestaltCPU601) gUseRTC = true; | ||
139 | else if (result > gestaltCPU601) gUseTBR = true; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | /* Now calculate a scale factor to keep us accurate. */ | ||
144 | if ((gUpTime && !gNative) || gUseRTC || gUseTBR) { | ||
145 | UInt64 tick, usec1, usec2; | ||
146 | UnsignedWide wide; | ||
147 | |||
148 | /* Wait for the beginning of the very next tick */ | ||
149 | for(tick = MyLMGetTicks() + 1; tick > MyLMGetTicks(); ); | ||
150 | |||
151 | /* Poll the selected timer and prepare it (since we have time) */ | ||
152 | wide = (gUpTime) ? (*gA2NS)((*gUpTime)()) : | ||
153 | ((gUseRTC) ? PollRTC() : PollTBR()); | ||
154 | usec1 = (gUseRTC) ? RTCToNano(wide) : WideTo64bit(wide); | ||
155 | |||
156 | /* Wait for the exact 60th tick to roll over */ | ||
157 | while(tick + 60 > MyLMGetTicks()); | ||
158 | |||
159 | /* Poll the selected timer again and prepare it */ | ||
160 | wide = (gUpTime) ? (*gA2NS)((*gUpTime)()) : | ||
161 | ((gUseRTC) ? PollRTC() : PollTBR()); | ||
162 | usec2 = (gUseRTC) ? RTCToNano(wide) : WideTo64bit(wide); | ||
163 | |||
164 | /* Calculate a scale value that will give microseconds per second. | ||
165 | Remember, there are actually 60.15 ticks in a second, not 60. */ | ||
166 | gScaleUSec = (60.0 * 1000000.0) / ((usec2 - usec1) * 60.15); | ||
167 | gScaleMSec = gScaleUSec / 1000.0; | ||
168 | } | ||
169 | |||
170 | #endif /* GENERATINGPOWERPC */ | ||
171 | |||
172 | /* We've initialized our globals */ | ||
173 | gInited = true; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
178 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
179 | |||
180 | UInt64 FastMicroseconds() { | ||
181 | UnsignedWide wide; | ||
182 | UInt64 usec; | ||
183 | |||
184 | #if GENERATINGPOWERPC | ||
185 | /* Initialize globals the first time we are called */ | ||
186 | if (!gInited) FastInitialize(); | ||
187 | |||
188 | if (gNative) { | ||
189 | /* Use DriverServices if it's available -- it's fast and compatible */ | ||
190 | wide = (*gA2NS)((*gUpTime)()); | ||
191 | usec = (double) WideTo64bit(wide) * gScaleUSec + 0.5; | ||
192 | } | ||
193 | else if (gUpTime) { | ||
194 | /* Use DriverServices if it's available -- it's fast and compatible */ | ||
195 | wide = (*gA2NS)((*gUpTime)()); | ||
196 | usec = (double) WideTo64bit(wide) * gScaleUSec + 0.5; | ||
197 | } | ||
198 | else if (gUseTBR) { | ||
199 | /* On a recent PowerPC, we poll the TBR directly */ | ||
200 | wide = PollTBR(); | ||
201 | usec = (double) WideTo64bit(wide) * gScaleUSec + 0.5; | ||
202 | } | ||
203 | else if (gUseRTC) { | ||
204 | /* On a 601, we can poll the RTC instead */ | ||
205 | wide = PollRTC(); | ||
206 | usec = (double) RTCToNano(wide) * gScaleUSec + 0.5; | ||
207 | } | ||
208 | else | ||
209 | #endif /* GENERATINGPOWERPC */ | ||
210 | { | ||
211 | /* If all else fails, suffer the mixed mode overhead */ | ||
212 | Microseconds(&wide); | ||
213 | usec = WideTo64bit(wide); | ||
214 | } | ||
215 | |||
216 | return(usec); | ||
217 | } | ||
218 | |||
219 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
220 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
221 | |||
222 | UInt64 FastMilliseconds() { | ||
223 | UnsignedWide wide; | ||
224 | UInt64 msec; | ||
225 | |||
226 | #if GENERATINGPOWERPC | ||
227 | /* Initialize globals the first time we are called */ | ||
228 | if (!gInited) FastInitialize(); | ||
229 | |||
230 | if (gNative) { | ||
231 | /* Use DriverServices if it's available -- it's fast and compatible */ | ||
232 | wide = (*gA2NS)((*gUpTime)()); | ||
233 | msec = (double) WideTo64bit(wide) * gScaleMSec + 0.5; | ||
234 | } | ||
235 | else if (gUpTime) { | ||
236 | /* Use DriverServices if it's available -- it's fast and compatible */ | ||
237 | wide = (*gA2NS)((*gUpTime)()); | ||
238 | msec = (double) WideTo64bit(wide) * gScaleMSec + 0.5; | ||
239 | } | ||
240 | else if (gUseTBR) { | ||
241 | /* On a recent PowerPC, we poll the TBR directly */ | ||
242 | wide = PollTBR(); | ||
243 | msec = (double) WideTo64bit(wide) * gScaleMSec + 0.5; | ||
244 | } | ||
245 | else if (gUseRTC) { | ||
246 | /* On a 601, we can poll the RTC instead */ | ||
247 | wide = PollRTC(); | ||
248 | msec = (double) RTCToNano(wide) * gScaleMSec + 0.5; | ||
249 | } | ||
250 | else | ||
251 | #endif /* GENERATINGPOWERPC */ | ||
252 | { | ||
253 | /* If all else fails, suffer the mixed mode overhead */ | ||
254 | Microseconds(&wide); | ||
255 | msec = ((double) WideTo64bit(wide) + 500.0) / 1000.0; | ||
256 | } | ||
257 | |||
258 | return(msec); | ||
259 | } | ||
260 | |||
261 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
262 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
263 | |||
264 | StringPtr FastMethod() { | ||
265 | StringPtr method = "\p<Unknown>"; | ||
266 | |||
267 | #if GENERATINGPOWERPC | ||
268 | /* Initialize globals the first time we are called */ | ||
269 | if (!gInited) FastInitialize(); | ||
270 | |||
271 | if (gNative) { | ||
272 | /* The Time Manager and UpTime() are entirely native on this machine */ | ||
273 | method = "\pNative UpTime()"; | ||
274 | } | ||
275 | else if (gUpTime) { | ||
276 | /* Use DriverServices if it's available -- it's fast and compatible */ | ||
277 | method = "\pUpTime()"; | ||
278 | } | ||
279 | else if (gUseTBR) { | ||
280 | /* On a recent PowerPC, we poll the TBR directly */ | ||
281 | method = "\pPowerPC TBR"; | ||
282 | } | ||
283 | else if (gUseRTC) { | ||
284 | /* On a 601, we can poll the RTC instead */ | ||
285 | method = "\pPowerPC RTC"; | ||
286 | } | ||
287 | else | ||
288 | #endif /* GENERATINGPOWERPC */ | ||
289 | { | ||
290 | /* If all else fails, suffer the mixed mode overhead */ | ||
291 | method = "\pMicroseconds()"; | ||
292 | } | ||
293 | |||
294 | return(method); | ||
295 | } | ||
296 | |||
297 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
298 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
299 | #pragma mark - | ||
300 | |||
301 | #if GENERATINGPOWERPC | ||
302 | asm static UnsignedWide PollRTC_() { | ||
303 | entry PollRTC /* Avoid CodeWarrior glue */ | ||
304 | machine 601 | ||
305 | @AGAIN: | ||
306 | mfrtcu r4 /* RTCU = SPR 4 */ | ||
307 | mfrtcl r5 /* RTCL = SPR 5 */ | ||
308 | mfrtcu r6 | ||
309 | cmpw r4,r6 | ||
310 | bne @AGAIN | ||
311 | stw r4,0(r3) | ||
312 | stw r5,4(r3) | ||
313 | blr | ||
314 | } | ||
315 | |||
316 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
317 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
318 | |||
319 | asm static UnsignedWide PollTBR_() { | ||
320 | entry PollTBR /* Avoid CodeWarrior glue */ | ||
321 | machine 604 | ||
322 | @AGAIN: | ||
323 | mftbu r4 /* TBRU = SPR 268 */ | ||
324 | mftb r5 /* TBRL = SPR 269 */ | ||
325 | mftbu r6 | ||
326 | cmpw r4,r6 | ||
327 | bne @AGAIN | ||
328 | stw r4,0(r3) | ||
329 | stw r5,4(r3) | ||
330 | blr | ||
331 | } | ||
332 | |||
333 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
334 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
335 | |||
336 | static Ptr FindFunctionInSharedLib(StringPtr libName, StringPtr funcName) { | ||
337 | OSErr error = noErr; | ||
338 | Str255 errorStr; | ||
339 | Ptr func = NULL; | ||
340 | Ptr entry = NULL; | ||
341 | CFragSymbolClass symClass; | ||
342 | CFragConnectionID connID; | ||
343 | |||
344 | /* Find CFM containers for the current archecture -- CFM-PPC or CFM-68K */ | ||
345 | if (/* error = */ GetSharedLibrary(libName, kCompiledCFragArch, | ||
346 | kLoadCFrag, &connID, &entry, errorStr)) return(NULL); | ||
347 | if (/* error = */ FindSymbol(connID, funcName, &func, &symClass)) | ||
348 | return(NULL); | ||
349 | |||
350 | return(func); | ||
351 | } | ||
352 | #endif /* GENERATINGPOWERPC */ | ||
diff --git a/apps/plugins/sdl/src/timer/macos/FastTimes.h b/apps/plugins/sdl/src/timer/macos/FastTimes.h deleted file mode 100644 index d25744c330..0000000000 --- a/apps/plugins/sdl/src/timer/macos/FastTimes.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* File "FastTimes.h" - Original code by Matt Slot <fprefect@ambrosiasw.com> */ | ||
2 | #include "SDL_config.h" | ||
3 | /* Created 4/24/99 - This file is hereby placed in the public domain */ | ||
4 | /* Updated 5/21/99 - Calibrate to VIA, add TBR support, renamed functions */ | ||
5 | /* Updated 10/4/99 - Use AbsoluteToNanoseconds() in case Absolute = double */ | ||
6 | /* Updated 2/15/00 - Check for native Time Manager, no need to calibrate */ | ||
7 | /* Updated 3/21/00 - Fixed ns conversion, create 2 different scale factors */ | ||
8 | /* Updated 5/03/00 - Added copyright and placed into PD. No code changes */ | ||
9 | |||
10 | /* This file is Copyright (C) Matt Slot, 1999-2012. It is hereby placed into | ||
11 | the public domain. The author makes no warranty as to fitness or stability */ | ||
12 | |||
13 | #ifndef __FAST_TIMES_HEADER__ | ||
14 | #define __FAST_TIMES_HEADER__ | ||
15 | |||
16 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
17 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
18 | |||
19 | extern void FastInitialize(void); | ||
20 | extern UInt64 FastMicroseconds(void); | ||
21 | extern UInt64 FastMilliseconds(void); | ||
22 | extern StringPtr FastMethod(void); | ||
23 | |||
24 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
25 | /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */ | ||
26 | |||
27 | #endif /* __FAST_TIMES_HEADER__ */ | ||
diff --git a/apps/plugins/sdl/src/timer/macos/SDL_MPWtimer.c b/apps/plugins/sdl/src/timer/macos/SDL_MPWtimer.c deleted file mode 100644 index 114b6c7c0a..0000000000 --- a/apps/plugins/sdl/src/timer/macos/SDL_MPWtimer.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_MACOS | ||
25 | |||
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" | ||
35 | #include "../SDL_timer_c.h" | ||
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 | } | ||
151 | |||
152 | #endif /* SDL_TIMER_MACOS */ | ||
diff --git a/apps/plugins/sdl/src/timer/macos/SDL_systimer.c b/apps/plugins/sdl/src/timer/macos/SDL_systimer.c deleted file mode 100644 index 7a8063e57d..0000000000 --- a/apps/plugins/sdl/src/timer/macos/SDL_systimer.c +++ /dev/null | |||
@@ -1,186 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_MACOS | ||
25 | |||
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" | ||
35 | #include "../SDL_timer_c.h" | ||
36 | |||
37 | #include "FastTimes.h" | ||
38 | |||
39 | #if TARGET_API_MAC_CARBON | ||
40 | #define NewTimerProc NewTimerUPP | ||
41 | #endif | ||
42 | |||
43 | #define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ | ||
44 | |||
45 | |||
46 | #define kTwoPower32 (4294967296.0) /* 2^32 */ | ||
47 | |||
48 | static double start_tick; | ||
49 | static int is_fast_inited = 0; | ||
50 | |||
51 | void SDL_StartTicks(void) | ||
52 | { | ||
53 | if ( ! is_fast_inited ) // important to check or FastTime may hang machine! | ||
54 | SDL_SYS_TimerInit(); | ||
55 | |||
56 | start_tick = FastMicroseconds(); | ||
57 | } | ||
58 | |||
59 | Uint32 SDL_GetTicks(void) | ||
60 | { | ||
61 | |||
62 | if ( ! is_fast_inited ) | ||
63 | SDL_SYS_TimerInit(); | ||
64 | |||
65 | return FastMilliseconds(); | ||
66 | } | ||
67 | |||
68 | void SDL_Delay(Uint32 ms) | ||
69 | { | ||
70 | Uint32 stop, now; | ||
71 | |||
72 | stop = SDL_GetTicks() + ms; | ||
73 | do { | ||
74 | #if TARGET_API_MAC_CARBON | ||
75 | MPYield(); | ||
76 | #else | ||
77 | SystemTask(); | ||
78 | #endif | ||
79 | |||
80 | now = SDL_GetTicks(); | ||
81 | |||
82 | } while ( stop > now ); | ||
83 | } | ||
84 | |||
85 | /* | ||
86 | void SDL_StartTicks(void) | ||
87 | { | ||
88 | // FIXME: Should we implement a wrapping algorithm, like Win32? | ||
89 | } | ||
90 | |||
91 | Uint32 SDL_GetTicks(void) | ||
92 | { | ||
93 | UnsignedWide ms; | ||
94 | |||
95 | Microseconds (&ms); | ||
96 | |||
97 | return ( ms.lo / 1000 ); | ||
98 | } | ||
99 | |||
100 | void SDL_Delay(Uint32 ms) | ||
101 | { | ||
102 | |||
103 | UnsignedWide microsecs; | ||
104 | UInt32 stop; | ||
105 | |||
106 | Microseconds (µsecs); | ||
107 | |||
108 | stop = microsecs.lo + (ms * 1000); | ||
109 | |||
110 | while ( stop > microsecs.lo ) { | ||
111 | |||
112 | SystemTask (); | ||
113 | |||
114 | Microseconds (µsecs); | ||
115 | } | ||
116 | |||
117 | }*/ | ||
118 | |||
119 | /* Data to handle a single periodic alarm */ | ||
120 | typedef struct _ExtendedTimerRec | ||
121 | { | ||
122 | TMTask tmTask; | ||
123 | ProcessSerialNumber taskPSN; | ||
124 | } ExtendedTimerRec, *ExtendedTimerPtr; | ||
125 | |||
126 | static ExtendedTimerRec gExtendedTimerRec; | ||
127 | |||
128 | |||
129 | int SDL_SYS_TimerInit(void) | ||
130 | { | ||
131 | FastInitialize (); | ||
132 | is_fast_inited = 1; | ||
133 | |||
134 | return(0); | ||
135 | } | ||
136 | |||
137 | void SDL_SYS_TimerQuit(void) | ||
138 | { | ||
139 | /* We don't need a cleanup? */ | ||
140 | return; | ||
141 | } | ||
142 | |||
143 | /* Our Stub routine to set up and then call the real routine. */ | ||
144 | pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | ||
145 | { | ||
146 | Uint32 ms; | ||
147 | |||
148 | WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | ||
149 | |||
150 | ms = SDL_alarm_callback(SDL_alarm_interval); | ||
151 | if ( ms ) { | ||
152 | SDL_alarm_interval = ROUND_RESOLUTION(ms); | ||
153 | PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | ||
154 | SDL_alarm_interval); | ||
155 | } else { | ||
156 | SDL_alarm_interval = 0; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | int SDL_SYS_StartTimer(void) | ||
161 | { | ||
162 | /* | ||
163 | * Configure the global structure that stores the timing information. | ||
164 | */ | ||
165 | gExtendedTimerRec.tmTask.qLink = NULL; | ||
166 | gExtendedTimerRec.tmTask.qType = 0; | ||
167 | gExtendedTimerRec.tmTask.tmAddr = NewTimerProc(TimerCallbackProc); | ||
168 | gExtendedTimerRec.tmTask.tmCount = 0; | ||
169 | gExtendedTimerRec.tmTask.tmWakeUp = 0; | ||
170 | gExtendedTimerRec.tmTask.tmReserved = 0; | ||
171 | GetCurrentProcess(&gExtendedTimerRec.taskPSN); | ||
172 | |||
173 | /* Install the task record */ | ||
174 | InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | ||
175 | |||
176 | /* Go! */ | ||
177 | PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | ||
178 | return(0); | ||
179 | } | ||
180 | |||
181 | void SDL_SYS_StopTimer(void) | ||
182 | { | ||
183 | RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | ||
184 | } | ||
185 | |||
186 | #endif /* SDL_TIMER_MACOS */ | ||
diff --git a/apps/plugins/sdl/src/timer/mint/SDL_systimer.c b/apps/plugins/sdl/src/timer/mint/SDL_systimer.c deleted file mode 100644 index 01e7a410c1..0000000000 --- a/apps/plugins/sdl/src/timer/mint/SDL_systimer.c +++ /dev/null | |||
@@ -1,149 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_MINT | ||
25 | |||
26 | /* | ||
27 | * TOS/MiNT timer driver | ||
28 | * based on vbl vector | ||
29 | * | ||
30 | * Patrice Mandin | ||
31 | */ | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <sys/time.h> | ||
35 | #include <signal.h> | ||
36 | #include <unistd.h> | ||
37 | #include <string.h> | ||
38 | #include <errno.h> | ||
39 | |||
40 | #include <mint/cookie.h> | ||
41 | #include <mint/sysvars.h> | ||
42 | #include <mint/osbind.h> | ||
43 | #include <mint/mintbind.h> | ||
44 | |||
45 | #include "SDL_timer.h" | ||
46 | #include "../SDL_timer_c.h" | ||
47 | #include "SDL_thread.h" | ||
48 | |||
49 | #include "../../video/ataricommon/SDL_atarisuper.h" | ||
50 | |||
51 | #include "SDL_vbltimer_s.h" | ||
52 | |||
53 | /* from audio/mint */ | ||
54 | void SDL_MintAudio_CheckFpu(void); | ||
55 | |||
56 | /* The first ticks value of the application */ | ||
57 | static Uint32 start; | ||
58 | static SDL_bool read_hz200_from_vbl = SDL_FALSE; | ||
59 | static int mint_present; /* can we use Syield() ? */ | ||
60 | |||
61 | void SDL_StartTicks(void) | ||
62 | { | ||
63 | void *old_stack; | ||
64 | long dummy; | ||
65 | |||
66 | /* Set first ticks value */ | ||
67 | old_stack = (void *)Super(0); | ||
68 | start = *((volatile long *)_hz_200); | ||
69 | SuperToUser(old_stack); | ||
70 | |||
71 | start *= 5; /* One _hz_200 tic is 5ms */ | ||
72 | |||
73 | mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); | ||
74 | } | ||
75 | |||
76 | Uint32 SDL_GetTicks (void) | ||
77 | { | ||
78 | Uint32 now = start; | ||
79 | |||
80 | if (read_hz200_from_vbl) { | ||
81 | now = SDL_Atari_hz200; | ||
82 | } else { | ||
83 | void *old_stack = (void *)Super(0); | ||
84 | now = *((volatile long *)_hz_200); | ||
85 | SuperToUser(old_stack); | ||
86 | } | ||
87 | |||
88 | return((now*5)-start); | ||
89 | } | ||
90 | |||
91 | void SDL_Delay (Uint32 ms) | ||
92 | { | ||
93 | Uint32 now; | ||
94 | |||
95 | now = SDL_GetTicks(); | ||
96 | while ((SDL_GetTicks()-now)<ms){ | ||
97 | if (mint_present) { | ||
98 | Syield(); | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /* Data to handle a single periodic alarm */ | ||
104 | static SDL_bool timer_installed=SDL_FALSE; | ||
105 | |||
106 | /* This is only called if the event thread is not running */ | ||
107 | int SDL_SYS_TimerInit(void) | ||
108 | { | ||
109 | void *old_stack; | ||
110 | |||
111 | SDL_MintAudio_CheckFpu(); | ||
112 | |||
113 | /* Install RunTimer in vbl vector */ | ||
114 | old_stack = (void *)Super(0); | ||
115 | timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck); | ||
116 | SuperToUser(old_stack); | ||
117 | |||
118 | if (!timer_installed) { | ||
119 | return(-1); | ||
120 | } | ||
121 | |||
122 | read_hz200_from_vbl = SDL_TRUE; | ||
123 | return(SDL_SetTimerThreaded(0)); | ||
124 | } | ||
125 | |||
126 | void SDL_SYS_TimerQuit(void) | ||
127 | { | ||
128 | /* Uninstall RunTimer vbl vector */ | ||
129 | if (timer_installed) { | ||
130 | void *old_stack = (void *)Super(0); | ||
131 | SDL_AtariVblUninstall(SDL_ThreadedTimerCheck); | ||
132 | SuperToUser(old_stack); | ||
133 | timer_installed = SDL_FALSE; | ||
134 | } | ||
135 | read_hz200_from_vbl = SDL_FALSE; | ||
136 | } | ||
137 | |||
138 | int SDL_SYS_StartTimer(void) | ||
139 | { | ||
140 | SDL_SetError("Internal logic error: MiNT uses vbl timer"); | ||
141 | return(-1); | ||
142 | } | ||
143 | |||
144 | void SDL_SYS_StopTimer(void) | ||
145 | { | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | #endif /* SDL_TIMER_MINT */ | ||
diff --git a/apps/plugins/sdl/src/timer/mint/SDL_vbltimer.S b/apps/plugins/sdl/src/timer/mint/SDL_vbltimer.S deleted file mode 100644 index 7837afce08..0000000000 --- a/apps/plugins/sdl/src/timer/mint/SDL_vbltimer.S +++ /dev/null | |||
@@ -1,228 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | * VBL queue routine | ||
25 | * | ||
26 | * Patrice Mandin | ||
27 | */ | ||
28 | |||
29 | #define _vbl_queue 0x456 | ||
30 | #define _hz_200 0x4ba | ||
31 | |||
32 | .text | ||
33 | |||
34 | .globl _SDL_AtariVblInstall | ||
35 | .globl _SDL_AtariVblUninstall | ||
36 | |||
37 | .globl _SDL_MintAudio_hasfpu | ||
38 | |||
39 | /*--- Save/restore FPU context ---*/ | ||
40 | |||
41 | #if defined(__mcoldfire__) | ||
42 | |||
43 | #define SAVE_FPU_CONTEXT \ | ||
44 | lea sp@(-216),sp; \ | ||
45 | fsave sp@; \ | ||
46 | fmovel fpiar,sp@-; \ | ||
47 | lea sp@(-64),sp; \ | ||
48 | fmovemd fp0-fp7,sp@ | ||
49 | |||
50 | #define RESTORE_FPU_CONTEXT \ | ||
51 | fmovemd sp@,fp0-fp7; \ | ||
52 | lea sp@(64),sp; \ | ||
53 | fmovel sp@+,fpiar; \ | ||
54 | frestore sp@; \ | ||
55 | lea sp@(216),sp | ||
56 | |||
57 | #else | ||
58 | |||
59 | #define SAVE_FPU_CONTEXT \ | ||
60 | .chip 68k/68881; \ | ||
61 | fsave sp@-; \ | ||
62 | fmoveml fpcr/fpsr/fpiar,sp@-; \ | ||
63 | fmovemx fp0-fp7,sp@-; \ | ||
64 | .chip 68k | ||
65 | |||
66 | #define RESTORE_FPU_CONTEXT \ | ||
67 | .chip 68k/68881; \ | ||
68 | fmovemx sp@+,fp0-fp7; \ | ||
69 | fmoveml sp@+,fpcr/fpsr/fpiar; \ | ||
70 | frestore sp@+; \ | ||
71 | .chip 68k | ||
72 | |||
73 | #endif | ||
74 | |||
75 | /*--- Vector installer ---*/ | ||
76 | |||
77 | _SDL_AtariVblInstall: | ||
78 | #if defined(__mcoldfire__) | ||
79 | movel sp@(4),d0 | ||
80 | movel d0,my_vector | ||
81 | #else | ||
82 | movel sp@(4),my_vector | ||
83 | #endif | ||
84 | |||
85 | lea _my_vbl,a0 | ||
86 | |||
87 | clrw vbl_mutex | ||
88 | #if defined(__mcoldfire__) | ||
89 | movel _hz_200.w,d0 | ||
90 | movel d0, _SDL_Atari_hz200 | ||
91 | #else | ||
92 | movel _hz_200.w, _SDL_Atari_hz200 | ||
93 | #endif | ||
94 | |||
95 | /* Stop interrupts */ | ||
96 | |||
97 | movew #0x2700,sr | ||
98 | |||
99 | /* Read vbl_queue pointer */ | ||
100 | movel _vbl_queue.w,a1 | ||
101 | |||
102 | /* Search a free place */ | ||
103 | moveq #7,d0 | ||
104 | bcl_search_place: | ||
105 | movel (a1),d1 | ||
106 | beqs place_found | ||
107 | addql #4,a1 | ||
108 | #if defined(__mcoldfire__) | ||
109 | subql #1,d0 | ||
110 | bpls bcl_search_place | ||
111 | #else | ||
112 | dbra d0,bcl_search_place | ||
113 | #endif | ||
114 | |||
115 | /* Not found */ | ||
116 | moveq #1,d0 | ||
117 | bras exit_vbl_queue | ||
118 | |||
119 | /* Then install ourselves */ | ||
120 | place_found: | ||
121 | movel a0,(a1) | ||
122 | moveq #0,d0 | ||
123 | |||
124 | exit_vbl_queue: | ||
125 | /* Restart interrupts */ | ||
126 | movew #0x2300,sr | ||
127 | |||
128 | rts | ||
129 | |||
130 | /*--- Vector uninstaller ---*/ | ||
131 | |||
132 | _SDL_AtariVblUninstall: | ||
133 | movel sp@(4),d0 | ||
134 | cmpl my_vector,d0 | ||
135 | bnes badvector | ||
136 | |||
137 | movel #_my_vbl,d0 | ||
138 | |||
139 | /* Stop interrupts */ | ||
140 | |||
141 | movew #0x2700,sr | ||
142 | |||
143 | /* Read vbl_queue pointer */ | ||
144 | movel _vbl_queue.w,a1 | ||
145 | |||
146 | /* Search where we are */ | ||
147 | moveq #7,d1 | ||
148 | bcl2_search_place: | ||
149 | cmpl (a1),d0 | ||
150 | bnes next_place | ||
151 | clrl (a1) | ||
152 | moveq #0,d1 | ||
153 | next_place: | ||
154 | addql #4,a1 | ||
155 | #if defined(__mcoldfire__) | ||
156 | subql #1,d1 | ||
157 | bpls bcl_search_place | ||
158 | #else | ||
159 | dbra d1,bcl2_search_place | ||
160 | #endif | ||
161 | |||
162 | /* Restart interrupts */ | ||
163 | movew #0x2300,sr | ||
164 | badvector: | ||
165 | rts | ||
166 | |||
167 | /*--- Our vbl ---*/ | ||
168 | |||
169 | _my_vbl: | ||
170 | #if defined(__mcoldfire__) | ||
171 | lea sp@(-60),sp | ||
172 | moveml d0-d7/a0-a6,sp@ | ||
173 | #else | ||
174 | moveml d0-d7/a0-a6,sp@- | ||
175 | #endif | ||
176 | |||
177 | /* Update _hz_200 */ | ||
178 | #if defined(__mcoldfire__) | ||
179 | movel _hz_200.w,d0 | ||
180 | movel d0, _SDL_Atari_hz200 | ||
181 | #else | ||
182 | movel _hz_200.w, _SDL_Atari_hz200 | ||
183 | #endif | ||
184 | |||
185 | /* Verify if this is not already running */ | ||
186 | |||
187 | tstw vbl_mutex | ||
188 | bnes vbl_end | ||
189 | #if defined(__mcoldfire__) | ||
190 | movew vbl_mutex,d0 | ||
191 | notl d0 | ||
192 | movew d0,vbl_mutex | ||
193 | #else | ||
194 | notw vbl_mutex | ||
195 | #endif | ||
196 | |||
197 | /* Save FPU if needed */ | ||
198 | tstw _SDL_MintAudio_hasfpu | ||
199 | beqs SDL_AtariVbl_nofpu1 | ||
200 | SAVE_FPU_CONTEXT | ||
201 | SDL_AtariVbl_nofpu1: | ||
202 | |||
203 | movel my_vector,a0 | ||
204 | jsr a0@ | ||
205 | |||
206 | /* Restore FPU if needed */ | ||
207 | tstw _SDL_MintAudio_hasfpu | ||
208 | beqs SDL_AtariVbl_Xbios_nofpu2 | ||
209 | RESTORE_FPU_CONTEXT | ||
210 | SDL_AtariVbl_Xbios_nofpu2: | ||
211 | |||
212 | clrw vbl_mutex | ||
213 | vbl_end: | ||
214 | #if defined(__mcoldfire__) | ||
215 | moveml sp@,d0-d7/a0-a6 | ||
216 | lea sp@(60),sp | ||
217 | #else | ||
218 | moveml sp@+,d0-d7/a0-a6 | ||
219 | #endif | ||
220 | rts | ||
221 | |||
222 | .data | ||
223 | .even | ||
224 | .comm _SDL_Atari_hz200,4*1 | ||
225 | .even | ||
226 | .comm vbl_mutex,2*1 | ||
227 | .even | ||
228 | .comm my_vector,4*1 | ||
diff --git a/apps/plugins/sdl/src/timer/mint/SDL_vbltimer_s.h b/apps/plugins/sdl/src/timer/mint/SDL_vbltimer_s.h deleted file mode 100644 index 011c138ddb..0000000000 --- a/apps/plugins/sdl/src/timer/mint/SDL_vbltimer_s.h +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* | ||
25 | * TOS/MiNT timer driver | ||
26 | * based on vbl vector | ||
27 | * | ||
28 | * Patrice Mandin | ||
29 | */ | ||
30 | |||
31 | extern volatile long SDL_Atari_hz200; | ||
32 | |||
33 | /* Functions prototypes */ | ||
34 | extern int SDL_AtariVblInstall(void *newvector); | ||
35 | extern void SDL_AtariVblUninstall(void *newvector); | ||
diff --git a/apps/plugins/sdl/src/timer/nds/SDL_systimer.c b/apps/plugins/sdl/src/timer/nds/SDL_systimer.c deleted file mode 100644 index bf54f42b85..0000000000 --- a/apps/plugins/sdl/src/timer/nds/SDL_systimer.c +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #include "SDL_thread.h" | ||
25 | #include "SDL_timer.h" | ||
26 | #include "SDL_error.h" | ||
27 | #include "../SDL_timer_c.h" | ||
28 | |||
29 | #include <nds.h> | ||
30 | |||
31 | #define timers2ms(tlow,thigh)(tlow | (thigh<<16)) >> 5 | ||
32 | |||
33 | |||
34 | void SDL_StartTicks(void) | ||
35 | { | ||
36 | TIMER0_DATA=0; | ||
37 | TIMER1_DATA=0; | ||
38 | TIMER0_CR=TIMER_ENABLE|TIMER_DIV_1024; | ||
39 | TIMER1_CR=TIMER_ENABLE|TIMER_CASCADE; | ||
40 | } | ||
41 | |||
42 | Uint32 SDL_GetTicks(void) | ||
43 | { | ||
44 | return timers2ms(TIMER0_DATA, TIMER1_DATA); | ||
45 | } | ||
46 | |||
47 | void SDL_Delay(Uint32 ms) | ||
48 | { | ||
49 | Uint32 now; | ||
50 | now=timers2ms(TIMER0_DATA, TIMER1_DATA); | ||
51 | while((Uint32)timers2ms(TIMER0_DATA, TIMER1_DATA)<now+ms); | ||
52 | |||
53 | } | ||
54 | |||
55 | /* This is only called if the event thread is not running */ | ||
56 | int SDL_SYS_TimerInit(void) | ||
57 | { | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | void SDL_SYS_TimerQuit(void) | ||
62 | { | ||
63 | } | ||
64 | |||
65 | int SDL_SYS_StartTimer(void) | ||
66 | { | ||
67 | SDL_SetError("Timers not implemented on NDS"); | ||
68 | return -1; | ||
69 | } | ||
70 | |||
71 | void SDL_SYS_StopTimer(void) | ||
72 | { | ||
73 | } | ||
diff --git a/apps/plugins/sdl/src/timer/os2/SDL_systimer.c b/apps/plugins/sdl/src/timer/os2/SDL_systimer.c deleted file mode 100644 index c82d53146d..0000000000 --- a/apps/plugins/sdl/src/timer/os2/SDL_systimer.c +++ /dev/null | |||
@@ -1,227 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_OS2 | ||
25 | |||
26 | #define INCL_DOSMISC | ||
27 | #define INCL_DOSERRORS | ||
28 | #define INCL_DOSSEMAPHORES | ||
29 | #define INCL_DOSDATETIME | ||
30 | #define INCL_DOSPROCESS | ||
31 | #define INCL_DOSPROFILE | ||
32 | #define INCL_DOSEXCEPTIONS | ||
33 | #include <os2.h> | ||
34 | |||
35 | #include "SDL_thread.h" | ||
36 | #include "SDL_timer.h" | ||
37 | #include "../SDL_timer_c.h" | ||
38 | |||
39 | |||
40 | #define TIME_WRAP_VALUE (~(DWORD)0) | ||
41 | |||
42 | /* The first high-resolution ticks value of the application */ | ||
43 | static long long hires_start_ticks; | ||
44 | /* The number of ticks per second of the high-resolution performance counter */ | ||
45 | static ULONG hires_ticks_per_second; | ||
46 | |||
47 | void SDL_StartTicks(void) | ||
48 | { | ||
49 | DosTmrQueryFreq(&hires_ticks_per_second); | ||
50 | DosTmrQueryTime((PQWORD)&hires_start_ticks); | ||
51 | } | ||
52 | |||
53 | DECLSPEC Uint32 SDLCALL SDL_GetTicks(void) | ||
54 | { | ||
55 | long long hires_now; | ||
56 | ULONG ticks = ticks; | ||
57 | |||
58 | DosTmrQueryTime((PQWORD)&hires_now); | ||
59 | /* | ||
60 | hires_now -= hires_start_ticks; | ||
61 | hires_now *= 1000; | ||
62 | hires_now /= hires_ticks_per_second; | ||
63 | */ | ||
64 | /* inline asm to avoid runtime inclusion */ | ||
65 | _asm { | ||
66 | push edx | ||
67 | push eax | ||
68 | mov eax, dword ptr hires_now | ||
69 | mov edx, dword ptr hires_now+4 | ||
70 | sub eax, dword ptr hires_start_ticks | ||
71 | sbb edx, dword ptr hires_start_ticks+4 | ||
72 | mov ebx,1000 | ||
73 | mov ecx,edx | ||
74 | mul ebx | ||
75 | push eax | ||
76 | push edx | ||
77 | mov eax,ecx | ||
78 | mul ebx | ||
79 | pop eax | ||
80 | add edx,eax | ||
81 | pop eax | ||
82 | mov ebx, dword ptr hires_ticks_per_second | ||
83 | div ebx | ||
84 | mov dword ptr ticks, eax | ||
85 | pop edx | ||
86 | pop eax | ||
87 | } | ||
88 | |||
89 | return ticks; | ||
90 | |||
91 | } | ||
92 | |||
93 | /* High resolution sleep, originally made by Ilya Zakharevich */ | ||
94 | DECLSPEC void SDLCALL SDL_Delay(Uint32 ms) | ||
95 | { | ||
96 | /* This is similar to DosSleep(), but has 8ms granularity in time-critical | ||
97 | threads even on Warp3. */ | ||
98 | HEV hevEvent1 = 0; /* Event semaphore handle */ | ||
99 | HTIMER htimerEvent1 = 0; /* Timer handle */ | ||
100 | APIRET rc = NO_ERROR; /* Return code */ | ||
101 | int ret = 1; | ||
102 | ULONG priority = 0, nesting; /* Shut down the warnings */ | ||
103 | PPIB pib; | ||
104 | PTIB tib; | ||
105 | char *e = NULL; | ||
106 | APIRET badrc; | ||
107 | int switch_priority = 50; | ||
108 | |||
109 | DosCreateEventSem(NULL, /* Unnamed */ | ||
110 | &hevEvent1, /* Handle of semaphore returned */ | ||
111 | DC_SEM_SHARED, /* Shared needed for DosAsyncTimer */ | ||
112 | FALSE); /* Semaphore is in RESET state */ | ||
113 | |||
114 | if (ms >= switch_priority) | ||
115 | switch_priority = 0; | ||
116 | if (switch_priority) | ||
117 | { | ||
118 | if (DosGetInfoBlocks(&tib, &pib)!=NO_ERROR) | ||
119 | switch_priority = 0; | ||
120 | else | ||
121 | { | ||
122 | /* In Warp3, to switch scheduling to 8ms step, one needs to do | ||
123 | DosAsyncTimer() in time-critical thread. On laters versions, | ||
124 | more and more cases of wait-for-something are covered. | ||
125 | |||
126 | It turns out that on Warp3fp42 it is the priority at the time | ||
127 | of DosAsyncTimer() which matters. Let's hope that this works | ||
128 | with later versions too... XXXX | ||
129 | */ | ||
130 | priority = (tib->tib_ptib2->tib2_ulpri); | ||
131 | if ((priority & 0xFF00) == 0x0300) /* already time-critical */ | ||
132 | switch_priority = 0; | ||
133 | /* Make us time-critical. Just modifying TIB is not enough... */ | ||
134 | /* tib->tib_ptib2->tib2_ulpri = 0x0300;*/ | ||
135 | /* We do not want to run at high priority if a signal causes us | ||
136 | to longjmp() out of this section... */ | ||
137 | if (DosEnterMustComplete(&nesting)) | ||
138 | switch_priority = 0; | ||
139 | else | ||
140 | DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | if ((badrc = DosAsyncTimer(ms, | ||
145 | (HSEM) hevEvent1, /* Semaphore to post */ | ||
146 | &htimerEvent1))) /* Timer handler (returned) */ | ||
147 | e = "DosAsyncTimer"; | ||
148 | |||
149 | if (switch_priority && tib->tib_ptib2->tib2_ulpri == 0x0300) | ||
150 | { | ||
151 | /* Nobody switched priority while we slept... Ignore errors... */ | ||
152 | /* tib->tib_ptib2->tib2_ulpri = priority; */ /* Get back... */ | ||
153 | if (!(rc = DosSetPriority(PRTYS_THREAD, (priority>>8) & 0xFF, 0, 0))) | ||
154 | rc = DosSetPriority(PRTYS_THREAD, 0, priority & 0xFF, 0); | ||
155 | } | ||
156 | if (switch_priority) | ||
157 | rc = DosExitMustComplete(&nesting); /* Ignore errors */ | ||
158 | |||
159 | /* The actual blocking call is made with "normal" priority. This way we | ||
160 | should not bother with DosSleep(0) etc. to compensate for us interrupting | ||
161 | higher-priority threads. The goal is to prohibit the system spending too | ||
162 | much time halt()ing, not to run us "no matter what". */ | ||
163 | if (!e) /* Wait for AsyncTimer event */ | ||
164 | badrc = DosWaitEventSem(hevEvent1, SEM_INDEFINITE_WAIT); | ||
165 | |||
166 | if (e) ; /* Do nothing */ | ||
167 | else if (badrc == ERROR_INTERRUPT) | ||
168 | ret = 0; | ||
169 | else if (badrc) | ||
170 | e = "DosWaitEventSem"; | ||
171 | if ((rc = DosCloseEventSem(hevEvent1)) && !e) { /* Get rid of semaphore */ | ||
172 | e = "DosCloseEventSem"; | ||
173 | badrc = rc; | ||
174 | } | ||
175 | if (e) | ||
176 | { | ||
177 | SDL_SetError("[SDL_Delay] : Had error in %s(), rc is 0x%x\n", e, badrc); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | /* Data to handle a single periodic alarm */ | ||
182 | static int timer_alive = 0; | ||
183 | static SDL_Thread *timer = NULL; | ||
184 | |||
185 | static int SDLCALL RunTimer(void *unused) | ||
186 | { | ||
187 | DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0); | ||
188 | while ( timer_alive ) { | ||
189 | if ( SDL_timer_running ) { | ||
190 | SDL_ThreadedTimerCheck(); | ||
191 | } | ||
192 | SDL_Delay(10); | ||
193 | } | ||
194 | return(0); | ||
195 | } | ||
196 | |||
197 | /* This is only called if the event thread is not running */ | ||
198 | int SDL_SYS_TimerInit(void) | ||
199 | { | ||
200 | timer_alive = 1; | ||
201 | timer = SDL_CreateThread(RunTimer, NULL); | ||
202 | if ( timer == NULL ) | ||
203 | return(-1); | ||
204 | return(SDL_SetTimerThreaded(1)); | ||
205 | } | ||
206 | |||
207 | void SDL_SYS_TimerQuit(void) | ||
208 | { | ||
209 | timer_alive = 0; | ||
210 | if ( timer ) { | ||
211 | SDL_WaitThread(timer, NULL); | ||
212 | timer = NULL; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | int SDL_SYS_StartTimer(void) | ||
217 | { | ||
218 | SDL_SetError("Internal logic error: OS/2 uses threaded timer"); | ||
219 | return(-1); | ||
220 | } | ||
221 | |||
222 | void SDL_SYS_StopTimer(void) | ||
223 | { | ||
224 | return; | ||
225 | } | ||
226 | |||
227 | #endif /* SDL_TIMER_OS2 */ | ||
diff --git a/apps/plugins/sdl/src/timer/riscos/SDL_systimer.c b/apps/plugins/sdl/src/timer/riscos/SDL_systimer.c deleted file mode 100644 index 25ba65f784..0000000000 --- a/apps/plugins/sdl/src/timer/riscos/SDL_systimer.c +++ /dev/null | |||
@@ -1,233 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_RISCOS | ||
25 | |||
26 | #include <stdio.h> | ||
27 | #include <time.h> | ||
28 | #include <sys/time.h> | ||
29 | #include <unistd.h> | ||
30 | #include <string.h> | ||
31 | #include <errno.h> | ||
32 | |||
33 | #include "SDL_timer.h" | ||
34 | #include "../SDL_timer_c.h" | ||
35 | |||
36 | #if SDL_THREADS_DISABLED | ||
37 | /* Timer SDL_arraysize(Timer ),start/reset time */ | ||
38 | static Uint32 timerStart; | ||
39 | /* Timer running function */ | ||
40 | void RISCOS_CheckTimer(); | ||
41 | #else | ||
42 | #include <pthread.h> | ||
43 | extern Uint32 riscos_main_thread; | ||
44 | extern int riscos_using_threads; | ||
45 | extern Uint32 SDL_ThreadID(); | ||
46 | extern Uint32 SDL_EventThreadID(void); | ||
47 | #endif | ||
48 | |||
49 | |||
50 | extern void RISCOS_BackgroundTasks(void); | ||
51 | |||
52 | /* The first ticks value of the application */ | ||
53 | clock_t start; | ||
54 | |||
55 | void SDL_StartTicks(void) | ||
56 | { | ||
57 | /* Set first ticks value */ | ||
58 | start = clock(); | ||
59 | } | ||
60 | |||
61 | Uint32 SDL_GetTicks (void) | ||
62 | { | ||
63 | clock_t ticks; | ||
64 | |||
65 | ticks=clock()-start; | ||
66 | |||
67 | |||
68 | #if CLOCKS_PER_SEC == 1000 | ||
69 | |||
70 | return(ticks); | ||
71 | |||
72 | #elif CLOCKS_PER_SEC == 100 | ||
73 | |||
74 | return (ticks * 10); | ||
75 | |||
76 | #else | ||
77 | |||
78 | return ticks*(1000/CLOCKS_PER_SEC); | ||
79 | |||
80 | #endif | ||
81 | |||
82 | } | ||
83 | |||
84 | void SDL_Delay (Uint32 ms) | ||
85 | { | ||
86 | Uint32 now,then,elapsed; | ||
87 | #if !SDL_THREADS_DISABLED | ||
88 | int is_event_thread; | ||
89 | if (riscos_using_threads) | ||
90 | { | ||
91 | is_event_thread = 0; | ||
92 | if (SDL_EventThreadID()) | ||
93 | { | ||
94 | if (SDL_EventThreadID() == SDL_ThreadID()) is_event_thread = 1; | ||
95 | } else if (SDL_ThreadID() == riscos_main_thread) is_event_thread = 1; | ||
96 | } else is_event_thread = 1; | ||
97 | #endif | ||
98 | |||
99 | /*TODO: Next version of Unixlib may allow us to use usleep here */ | ||
100 | /* for non event threads */ | ||
101 | |||
102 | /* Set the timeout interval - Linux only needs to do this once */ | ||
103 | then = SDL_GetTicks(); | ||
104 | |||
105 | do { | ||
106 | /* Do background tasks required while sleeping as we are not multithreaded */ | ||
107 | #if SDL_THREADS_DISABLED | ||
108 | RISCOS_BackgroundTasks(); | ||
109 | #else | ||
110 | /* For threaded build only run background tasks in event thread */ | ||
111 | if (is_event_thread) RISCOS_BackgroundTasks(); | ||
112 | #endif | ||
113 | |||
114 | /* Calculate the time interval left (in case of interrupt) */ | ||
115 | now = SDL_GetTicks(); | ||
116 | elapsed = (now-then); | ||
117 | then = now; | ||
118 | if ( elapsed >= ms ) { | ||
119 | break; | ||
120 | } | ||
121 | ms -= elapsed; | ||
122 | #if !SDL_THREADS_DISABLED | ||
123 | /* Need to yield to let other threads have a go */ | ||
124 | if (riscos_using_threads) pthread_yield(); | ||
125 | #endif | ||
126 | |||
127 | } while ( 1 ); | ||
128 | } | ||
129 | |||
130 | #if SDL_THREADS_DISABLED | ||
131 | |||
132 | /* Non-threaded version of timer */ | ||
133 | |||
134 | int SDL_SYS_TimerInit(void) | ||
135 | { | ||
136 | return(0); | ||
137 | } | ||
138 | |||
139 | void SDL_SYS_TimerQuit(void) | ||
140 | { | ||
141 | SDL_SetTimer(0, NULL); | ||
142 | } | ||
143 | |||
144 | int SDL_SYS_StartTimer(void) | ||
145 | { | ||
146 | timerStart = SDL_GetTicks(); | ||
147 | |||
148 | return(0); | ||
149 | } | ||
150 | |||
151 | void SDL_SYS_StopTimer(void) | ||
152 | { | ||
153 | /* Don't need to do anything as we use SDL_timer_running | ||
154 | to detect if we need to check the timer */ | ||
155 | } | ||
156 | |||
157 | |||
158 | void RISCOS_CheckTimer() | ||
159 | { | ||
160 | if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval) | ||
161 | { | ||
162 | Uint32 ms; | ||
163 | |||
164 | ms = SDL_alarm_callback(SDL_alarm_interval); | ||
165 | if ( ms != SDL_alarm_interval ) | ||
166 | { | ||
167 | if ( ms ) | ||
168 | { | ||
169 | SDL_alarm_interval = ROUND_RESOLUTION(ms); | ||
170 | } else | ||
171 | { | ||
172 | SDL_alarm_interval = 0; | ||
173 | SDL_timer_running = 0; | ||
174 | } | ||
175 | } | ||
176 | if (SDL_alarm_interval) timerStart = SDL_GetTicks(); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | #else | ||
181 | |||
182 | /* Threaded version of timer - based on code for linux */ | ||
183 | |||
184 | #include "SDL_thread.h" | ||
185 | |||
186 | /* Data to handle a single periodic alarm */ | ||
187 | static int timer_alive = 0; | ||
188 | static SDL_Thread *timer = NULL; | ||
189 | |||
190 | static int RunTimer(void *unused) | ||
191 | { | ||
192 | while ( timer_alive ) { | ||
193 | if ( SDL_timer_running ) { | ||
194 | SDL_ThreadedTimerCheck(); | ||
195 | } | ||
196 | SDL_Delay(1); | ||
197 | } | ||
198 | return(0); | ||
199 | } | ||
200 | |||
201 | /* This is only called if the event thread is not running */ | ||
202 | int SDL_SYS_TimerInit(void) | ||
203 | { | ||
204 | timer_alive = 1; | ||
205 | timer = SDL_CreateThread(RunTimer, NULL); | ||
206 | if ( timer == NULL ) | ||
207 | return(-1); | ||
208 | return(SDL_SetTimerThreaded(1)); | ||
209 | } | ||
210 | |||
211 | void SDL_SYS_TimerQuit(void) | ||
212 | { | ||
213 | timer_alive = 0; | ||
214 | if ( timer ) { | ||
215 | SDL_WaitThread(timer, NULL); | ||
216 | timer = NULL; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | int SDL_SYS_StartTimer(void) | ||
221 | { | ||
222 | SDL_SetError("Internal logic error: RISC OS uses threaded timer"); | ||
223 | return(-1); | ||
224 | } | ||
225 | |||
226 | void SDL_SYS_StopTimer(void) | ||
227 | { | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | #endif /* SDL_THREADS_DISABLED */ | ||
232 | |||
233 | #endif /* SDL_TIMER_RISCOS */ | ||
diff --git a/apps/plugins/sdl/src/timer/symbian/SDL_systimer.cpp b/apps/plugins/sdl/src/timer/symbian/SDL_systimer.cpp deleted file mode 100644 index a5bb749cac..0000000000 --- a/apps/plugins/sdl/src/timer/symbian/SDL_systimer.cpp +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public | ||
16 | License along with this library; if not, write to the Free | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@devolution.com | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | SDL_systimer.cpp | ||
25 | |||
26 | Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) | ||
27 | Markus Mertama | ||
28 | */ | ||
29 | |||
30 | #include <e32std.h> | ||
31 | #include <e32hal.h> | ||
32 | |||
33 | extern "C" { | ||
34 | #include "SDL_error.h" | ||
35 | #include "SDL_thread.h" | ||
36 | #include "SDL_timer.h" | ||
37 | #include "SDL_timer_c.h" | ||
38 | |||
39 | static TUint start = 0; | ||
40 | static TInt tickPeriodMilliSeconds; | ||
41 | |||
42 | |||
43 | void SDL_StartTicks(void) | ||
44 | { | ||
45 | /* Set first ticks value */ | ||
46 | start = User::TickCount(); | ||
47 | |||
48 | TTimeIntervalMicroSeconds32 period; | ||
49 | TInt tmp = UserHal::TickPeriod(period); | ||
50 | tickPeriodMilliSeconds = period.Int() / 1000; | ||
51 | } | ||
52 | |||
53 | Uint32 SDL_GetTicks(void) | ||
54 | { | ||
55 | TUint deltaTics = User::TickCount() - start; | ||
56 | return(deltaTics * tickPeriodMilliSeconds); | ||
57 | } | ||
58 | |||
59 | void SDL_Delay(Uint32 ms) | ||
60 | { | ||
61 | User::After(TTimeIntervalMicroSeconds32(ms*1000)); | ||
62 | } | ||
63 | |||
64 | /* Data to handle a single periodic alarm */ | ||
65 | static int timer_alive = 0; | ||
66 | static SDL_Thread *timer = NULL; | ||
67 | |||
68 | static int RunTimer(void *unused) | ||
69 | { | ||
70 | while ( timer_alive ) | ||
71 | { | ||
72 | if (SDL_timer_running) | ||
73 | { | ||
74 | SDL_ThreadedTimerCheck(); | ||
75 | } | ||
76 | SDL_Delay(10); | ||
77 | } | ||
78 | return(0); | ||
79 | } | ||
80 | |||
81 | /* This is only called if the event thread is not running */ | ||
82 | int SDL_SYS_TimerInit(void) | ||
83 | { | ||
84 | if(timer != NULL) | ||
85 | return (-1); | ||
86 | timer_alive = 1; | ||
87 | timer = SDL_CreateThread(RunTimer, NULL); | ||
88 | if ( timer == NULL ) | ||
89 | return(-1); | ||
90 | return(SDL_SetTimerThreaded(1)); | ||
91 | } | ||
92 | |||
93 | void SDL_SYS_TimerQuit(void) | ||
94 | { | ||
95 | timer_alive = 0; | ||
96 | if ( timer ) | ||
97 | { | ||
98 | SDL_WaitThread(timer, NULL); | ||
99 | timer = NULL; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | int SDL_SYS_StartTimer(void) | ||
104 | { | ||
105 | SDL_SetError("Internal logic error: Epoc uses threaded timer"); | ||
106 | return(-1); | ||
107 | } | ||
108 | |||
109 | void SDL_SYS_StopTimer(void) | ||
110 | { | ||
111 | return; | ||
112 | } | ||
113 | |||
114 | } // extern "C" | ||
diff --git a/apps/plugins/sdl/src/timer/unix/SDL_systimer.c b/apps/plugins/sdl/src/timer/unix/SDL_systimer.c deleted file mode 100644 index 80b22283b6..0000000000 --- a/apps/plugins/sdl/src/timer/unix/SDL_systimer.c +++ /dev/null | |||
@@ -1,240 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_UNIX | ||
25 | |||
26 | #include <stdio.h> | ||
27 | #include <sys/time.h> | ||
28 | #include <signal.h> | ||
29 | #include <unistd.h> | ||
30 | #include <string.h> | ||
31 | #include <errno.h> | ||
32 | |||
33 | #include "SDL_timer.h" | ||
34 | #include "../SDL_timer_c.h" | ||
35 | |||
36 | /* The clock_gettime provides monotonous time, so we should use it if | ||
37 | it's available. The clock_gettime function is behind ifdef | ||
38 | for __USE_POSIX199309 | ||
39 | Tommi Kyntola (tommi.kyntola@ray.fi) 27/09/2005 | ||
40 | */ | ||
41 | #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME | ||
42 | #include <time.h> | ||
43 | #endif | ||
44 | |||
45 | #if SDL_THREAD_PTH | ||
46 | #include <pth.h> | ||
47 | #endif | ||
48 | |||
49 | #if SDL_THREADS_DISABLED | ||
50 | #define USE_ITIMER | ||
51 | #endif | ||
52 | |||
53 | /* The first ticks value of the application */ | ||
54 | #ifdef HAVE_CLOCK_GETTIME | ||
55 | static struct timespec start; | ||
56 | #else | ||
57 | static struct timeval start; | ||
58 | #endif /* HAVE_CLOCK_GETTIME */ | ||
59 | |||
60 | |||
61 | void SDL_StartTicks(void) | ||
62 | { | ||
63 | /* Set first ticks value */ | ||
64 | #if HAVE_CLOCK_GETTIME | ||
65 | clock_gettime(CLOCK_MONOTONIC,&start); | ||
66 | #else | ||
67 | gettimeofday(&start, NULL); | ||
68 | #endif | ||
69 | } | ||
70 | |||
71 | Uint32 SDL_GetTicks (void) | ||
72 | { | ||
73 | #if HAVE_CLOCK_GETTIME | ||
74 | Uint32 ticks; | ||
75 | struct timespec now; | ||
76 | clock_gettime(CLOCK_MONOTONIC,&now); | ||
77 | ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_nsec-start.tv_nsec)/1000000; | ||
78 | return(ticks); | ||
79 | #else | ||
80 | Uint32 ticks; | ||
81 | struct timeval now; | ||
82 | gettimeofday(&now, NULL); | ||
83 | ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; | ||
84 | return(ticks); | ||
85 | #endif | ||
86 | } | ||
87 | |||
88 | void SDL_Delay (Uint32 ms) | ||
89 | { | ||
90 | #if SDL_THREAD_PTH | ||
91 | pth_time_t tv; | ||
92 | tv.tv_sec = ms/1000; | ||
93 | tv.tv_usec = (ms%1000)*1000; | ||
94 | pth_nap(tv); | ||
95 | #else | ||
96 | int was_error; | ||
97 | |||
98 | #if HAVE_NANOSLEEP | ||
99 | struct timespec elapsed, tv; | ||
100 | #else | ||
101 | struct timeval tv; | ||
102 | Uint32 then, now, elapsed; | ||
103 | #endif | ||
104 | |||
105 | /* Set the timeout interval */ | ||
106 | #if HAVE_NANOSLEEP | ||
107 | elapsed.tv_sec = ms/1000; | ||
108 | elapsed.tv_nsec = (ms%1000)*1000000; | ||
109 | #else | ||
110 | then = SDL_GetTicks(); | ||
111 | #endif | ||
112 | do { | ||
113 | errno = 0; | ||
114 | |||
115 | #if HAVE_NANOSLEEP | ||
116 | tv.tv_sec = elapsed.tv_sec; | ||
117 | tv.tv_nsec = elapsed.tv_nsec; | ||
118 | was_error = nanosleep(&tv, &elapsed); | ||
119 | #else | ||
120 | /* Calculate the time interval left (in case of interrupt) */ | ||
121 | now = SDL_GetTicks(); | ||
122 | elapsed = (now-then); | ||
123 | then = now; | ||
124 | if ( elapsed >= ms ) { | ||
125 | break; | ||
126 | } | ||
127 | ms -= elapsed; | ||
128 | tv.tv_sec = ms/1000; | ||
129 | tv.tv_usec = (ms%1000)*1000; | ||
130 | |||
131 | was_error = select(0, NULL, NULL, NULL, &tv); | ||
132 | #endif /* HAVE_NANOSLEEP */ | ||
133 | } while ( was_error && (errno == EINTR) ); | ||
134 | #endif /* SDL_THREAD_PTH */ | ||
135 | } | ||
136 | |||
137 | #ifdef USE_ITIMER | ||
138 | |||
139 | static void HandleAlarm(int sig) | ||
140 | { | ||
141 | Uint32 ms; | ||
142 | |||
143 | if ( SDL_alarm_callback ) { | ||
144 | ms = (*SDL_alarm_callback)(SDL_alarm_interval); | ||
145 | if ( ms != SDL_alarm_interval ) { | ||
146 | SDL_SetTimer(ms, SDL_alarm_callback); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | int SDL_SYS_TimerInit(void) | ||
152 | { | ||
153 | struct sigaction action; | ||
154 | |||
155 | /* Set the alarm handler (Linux specific) */ | ||
156 | SDL_memset(&action, 0, sizeof(action)); | ||
157 | action.sa_handler = HandleAlarm; | ||
158 | action.sa_flags = SA_RESTART; | ||
159 | sigemptyset(&action.sa_mask); | ||
160 | sigaction(SIGALRM, &action, NULL); | ||
161 | return(0); | ||
162 | } | ||
163 | |||
164 | void SDL_SYS_TimerQuit(void) | ||
165 | { | ||
166 | SDL_SetTimer(0, NULL); | ||
167 | } | ||
168 | |||
169 | int SDL_SYS_StartTimer(void) | ||
170 | { | ||
171 | struct itimerval timer; | ||
172 | |||
173 | timer.it_value.tv_sec = (SDL_alarm_interval/1000); | ||
174 | timer.it_value.tv_usec = (SDL_alarm_interval%1000)*1000; | ||
175 | timer.it_interval.tv_sec = (SDL_alarm_interval/1000); | ||
176 | timer.it_interval.tv_usec = (SDL_alarm_interval%1000)*1000; | ||
177 | setitimer(ITIMER_REAL, &timer, NULL); | ||
178 | return(0); | ||
179 | } | ||
180 | |||
181 | void SDL_SYS_StopTimer(void) | ||
182 | { | ||
183 | struct itimerval timer; | ||
184 | |||
185 | SDL_memset(&timer, 0, (sizeof timer)); | ||
186 | setitimer(ITIMER_REAL, &timer, NULL); | ||
187 | } | ||
188 | |||
189 | #else /* USE_ITIMER */ | ||
190 | |||
191 | #include "SDL_thread.h" | ||
192 | |||
193 | /* Data to handle a single periodic alarm */ | ||
194 | static int timer_alive = 0; | ||
195 | static SDL_Thread *timer = NULL; | ||
196 | |||
197 | static int RunTimer(void *unused) | ||
198 | { | ||
199 | while ( timer_alive ) { | ||
200 | if ( SDL_timer_running ) { | ||
201 | SDL_ThreadedTimerCheck(); | ||
202 | } | ||
203 | SDL_Delay(1); | ||
204 | } | ||
205 | return(0); | ||
206 | } | ||
207 | |||
208 | /* This is only called if the event thread is not running */ | ||
209 | int SDL_SYS_TimerInit(void) | ||
210 | { | ||
211 | timer_alive = 1; | ||
212 | timer = SDL_CreateThread(RunTimer, NULL); | ||
213 | if ( timer == NULL ) | ||
214 | return(-1); | ||
215 | return(SDL_SetTimerThreaded(1)); | ||
216 | } | ||
217 | |||
218 | void SDL_SYS_TimerQuit(void) | ||
219 | { | ||
220 | timer_alive = 0; | ||
221 | if ( timer ) { | ||
222 | SDL_WaitThread(timer, NULL); | ||
223 | timer = NULL; | ||
224 | } | ||
225 | } | ||
226 | |||
227 | int SDL_SYS_StartTimer(void) | ||
228 | { | ||
229 | SDL_SetError("Internal logic error: Linux uses threaded timer"); | ||
230 | return(-1); | ||
231 | } | ||
232 | |||
233 | void SDL_SYS_StopTimer(void) | ||
234 | { | ||
235 | return; | ||
236 | } | ||
237 | |||
238 | #endif /* USE_ITIMER */ | ||
239 | |||
240 | #endif /* SDL_TIMER_UNIX */ | ||
diff --git a/apps/plugins/sdl/src/timer/win32/SDL_systimer.c b/apps/plugins/sdl/src/timer/win32/SDL_systimer.c deleted file mode 100644 index b025e2e7c5..0000000000 --- a/apps/plugins/sdl/src/timer/win32/SDL_systimer.c +++ /dev/null | |||
@@ -1,160 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_WIN32 | ||
25 | |||
26 | #define WIN32_LEAN_AND_MEAN | ||
27 | #include <windows.h> | ||
28 | #include <mmsystem.h> | ||
29 | |||
30 | #include "SDL_timer.h" | ||
31 | #include "../SDL_timer_c.h" | ||
32 | |||
33 | #ifdef _WIN32_WCE | ||
34 | #error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead. | ||
35 | #endif | ||
36 | |||
37 | #define TIME_WRAP_VALUE (~(DWORD)0) | ||
38 | |||
39 | /* The first (low-resolution) ticks value of the application */ | ||
40 | static DWORD start; | ||
41 | |||
42 | #ifndef USE_GETTICKCOUNT | ||
43 | /* Store if a high-resolution performance counter exists on the system */ | ||
44 | static BOOL hires_timer_available; | ||
45 | /* The first high-resolution ticks value of the application */ | ||
46 | static LARGE_INTEGER hires_start_ticks; | ||
47 | /* The number of ticks per second of the high-resolution performance counter */ | ||
48 | static LARGE_INTEGER hires_ticks_per_second; | ||
49 | #endif | ||
50 | |||
51 | void SDL_StartTicks(void) | ||
52 | { | ||
53 | /* Set first ticks value */ | ||
54 | #ifdef USE_GETTICKCOUNT | ||
55 | start = GetTickCount(); | ||
56 | #else | ||
57 | #if 0 /* Apparently there are problems with QPC on Win2K */ | ||
58 | if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) | ||
59 | { | ||
60 | hires_timer_available = TRUE; | ||
61 | QueryPerformanceCounter(&hires_start_ticks); | ||
62 | } | ||
63 | else | ||
64 | #endif | ||
65 | { | ||
66 | hires_timer_available = FALSE; | ||
67 | timeBeginPeriod(1); /* use 1 ms timer precision */ | ||
68 | start = timeGetTime(); | ||
69 | } | ||
70 | #endif | ||
71 | } | ||
72 | |||
73 | Uint32 SDL_GetTicks(void) | ||
74 | { | ||
75 | DWORD now, ticks; | ||
76 | #ifndef USE_GETTICKCOUNT | ||
77 | LARGE_INTEGER hires_now; | ||
78 | #endif | ||
79 | |||
80 | #ifdef USE_GETTICKCOUNT | ||
81 | now = GetTickCount(); | ||
82 | #else | ||
83 | if (hires_timer_available) | ||
84 | { | ||
85 | QueryPerformanceCounter(&hires_now); | ||
86 | |||
87 | hires_now.QuadPart -= hires_start_ticks.QuadPart; | ||
88 | hires_now.QuadPart *= 1000; | ||
89 | hires_now.QuadPart /= hires_ticks_per_second.QuadPart; | ||
90 | |||
91 | return (DWORD)hires_now.QuadPart; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | now = timeGetTime(); | ||
96 | } | ||
97 | #endif | ||
98 | |||
99 | if ( now < start ) { | ||
100 | ticks = (TIME_WRAP_VALUE-start) + now; | ||
101 | } else { | ||
102 | ticks = (now - start); | ||
103 | } | ||
104 | return(ticks); | ||
105 | } | ||
106 | |||
107 | void SDL_Delay(Uint32 ms) | ||
108 | { | ||
109 | Sleep(ms); | ||
110 | } | ||
111 | |||
112 | /* Data to handle a single periodic alarm */ | ||
113 | static UINT timerID = 0; | ||
114 | |||
115 | static void CALLBACK HandleAlarm(UINT uID, UINT uMsg, DWORD_PTR dwUser, | ||
116 | DWORD_PTR dw1, DWORD_PTR dw2) | ||
117 | { | ||
118 | SDL_ThreadedTimerCheck(); | ||
119 | } | ||
120 | |||
121 | |||
122 | int SDL_SYS_TimerInit(void) | ||
123 | { | ||
124 | MMRESULT result; | ||
125 | |||
126 | /* Set timer resolution */ | ||
127 | result = timeBeginPeriod(TIMER_RESOLUTION); | ||
128 | if ( result != TIMERR_NOERROR ) { | ||
129 | SDL_SetError("Warning: Can't set %d ms timer resolution", | ||
130 | TIMER_RESOLUTION); | ||
131 | } | ||
132 | /* Allow 10 ms of drift so we don't chew on CPU */ | ||
133 | timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC); | ||
134 | if ( ! timerID ) { | ||
135 | SDL_SetError("timeSetEvent() failed"); | ||
136 | return(-1); | ||
137 | } | ||
138 | return(SDL_SetTimerThreaded(1)); | ||
139 | } | ||
140 | |||
141 | void SDL_SYS_TimerQuit(void) | ||
142 | { | ||
143 | if ( timerID ) { | ||
144 | timeKillEvent(timerID); | ||
145 | } | ||
146 | timeEndPeriod(TIMER_RESOLUTION); | ||
147 | } | ||
148 | |||
149 | int SDL_SYS_StartTimer(void) | ||
150 | { | ||
151 | SDL_SetError("Internal logic error: Win32 uses threaded timer"); | ||
152 | return(-1); | ||
153 | } | ||
154 | |||
155 | void SDL_SYS_StopTimer(void) | ||
156 | { | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | #endif /* SDL_TIMER_WIN32 */ | ||
diff --git a/apps/plugins/sdl/src/timer/wince/SDL_systimer.c b/apps/plugins/sdl/src/timer/wince/SDL_systimer.c deleted file mode 100644 index 2b018b0ed5..0000000000 --- a/apps/plugins/sdl/src/timer/wince/SDL_systimer.c +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifdef SDL_TIMER_WINCE | ||
25 | |||
26 | #define WIN32_LEAN_AND_MEAN | ||
27 | #include <windows.h> | ||
28 | #include <mmsystem.h> | ||
29 | |||
30 | #include "SDL_thread.h" | ||
31 | #include "SDL_timer.h" | ||
32 | #include "../SDL_timer_c.h" | ||
33 | |||
34 | static Uint64 start_date; | ||
35 | static Uint64 start_ticks; | ||
36 | |||
37 | static Uint64 wce_ticks(void) | ||
38 | { | ||
39 | return((Uint64)GetTickCount()); | ||
40 | } | ||
41 | |||
42 | static Uint64 wce_date(void) | ||
43 | { | ||
44 | union | ||
45 | { | ||
46 | FILETIME ftime; | ||
47 | Uint64 itime; | ||
48 | } ftime; | ||
49 | SYSTEMTIME stime; | ||
50 | |||
51 | GetSystemTime(&stime); | ||
52 | SystemTimeToFileTime(&stime,&ftime.ftime); | ||
53 | ftime.itime/=10000; // Convert 100ns intervals to 1ms intervals | ||
54 | // Remove ms portion, which can't be relied on | ||
55 | ftime.itime -= (ftime.itime % 1000); | ||
56 | return(ftime.itime); | ||
57 | } | ||
58 | |||
59 | static Sint32 wce_rel_ticks(void) | ||
60 | { | ||
61 | return((Sint32)(wce_ticks()-start_ticks)); | ||
62 | } | ||
63 | |||
64 | static Sint32 wce_rel_date(void) | ||
65 | { | ||
66 | return((Sint32)(wce_date()-start_date)); | ||
67 | } | ||
68 | |||
69 | /* Return time in ms relative to when SDL was started */ | ||
70 | Uint32 SDL_GetTicks() | ||
71 | { | ||
72 | Sint32 offset=wce_rel_date()-wce_rel_ticks(); | ||
73 | if((offset < -1000) || (offset > 1000)) | ||
74 | { | ||
75 | // fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000); | ||
76 | start_ticks-=offset; | ||
77 | } | ||
78 | |||
79 | return((Uint32)wce_rel_ticks()); | ||
80 | } | ||
81 | |||
82 | /* Give up approx. givem milliseconds to the OS. */ | ||
83 | void SDL_Delay(Uint32 ms) | ||
84 | { | ||
85 | Sleep(ms); | ||
86 | } | ||
87 | |||
88 | /* Recard start-time of application for reference */ | ||
89 | void SDL_StartTicks(void) | ||
90 | { | ||
91 | start_date=wce_date(); | ||
92 | start_ticks=wce_ticks(); | ||
93 | } | ||
94 | |||
95 | static UINT WIN_timer; | ||
96 | |||
97 | #if ( _WIN32_WCE <= 420 ) | ||
98 | |||
99 | static HANDLE timersThread = 0; | ||
100 | static HANDLE timersQuitEvent = 0; | ||
101 | |||
102 | DWORD TimersThreadProc(void *data) | ||
103 | { | ||
104 | while(WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT) | ||
105 | { | ||
106 | SDL_ThreadedTimerCheck(); | ||
107 | } | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | int SDL_SYS_TimerInit(void) | ||
112 | { | ||
113 | // create a thread to process a threaded timers | ||
114 | // SetTimer does not suit the needs because | ||
115 | // TimerCallbackProc will be called only when WM_TIMER occured | ||
116 | |||
117 | timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0); | ||
118 | if( !timersQuitEvent ) | ||
119 | { | ||
120 | SDL_SetError("Cannot create event for timers thread"); | ||
121 | return -1; | ||
122 | } | ||
123 | timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0); | ||
124 | if( !timersThread ) | ||
125 | { | ||
126 | SDL_SetError("Cannot create timers thread, check amount of RAM available"); | ||
127 | return -1; | ||
128 | } | ||
129 | SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST); | ||
130 | |||
131 | return(SDL_SetTimerThreaded(1)); | ||
132 | } | ||
133 | |||
134 | void SDL_SYS_TimerQuit(void) | ||
135 | { | ||
136 | SetEvent(timersQuitEvent); | ||
137 | if( WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT ) | ||
138 | TerminateThread(timersThread, 0); | ||
139 | CloseHandle(timersThread); | ||
140 | CloseHandle(timersQuitEvent); | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | #else | ||
145 | |||
146 | #pragma comment(lib, "mmtimer.lib") | ||
147 | |||
148 | /* Data to handle a single periodic alarm */ | ||
149 | static UINT timerID = 0; | ||
150 | |||
151 | static void CALLBACK HandleAlarm(UINT uID, UINT uMsg, DWORD dwUser, | ||
152 | DWORD dw1, DWORD dw2) | ||
153 | { | ||
154 | SDL_ThreadedTimerCheck(); | ||
155 | } | ||
156 | |||
157 | |||
158 | int SDL_SYS_TimerInit(void) | ||
159 | { | ||
160 | MMRESULT result; | ||
161 | |||
162 | /* Set timer resolution */ | ||
163 | result = timeBeginPeriod(TIMER_RESOLUTION); | ||
164 | if ( result != TIMERR_NOERROR ) { | ||
165 | SDL_SetError("Warning: Can't set %d ms timer resolution", | ||
166 | TIMER_RESOLUTION); | ||
167 | } | ||
168 | /* Allow 10 ms of drift so we don't chew on CPU */ | ||
169 | timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC); | ||
170 | if ( ! timerID ) { | ||
171 | SDL_SetError("timeSetEvent() failed"); | ||
172 | return(-1); | ||
173 | } | ||
174 | return(SDL_SetTimerThreaded(1)); | ||
175 | } | ||
176 | |||
177 | void SDL_SYS_TimerQuit(void) | ||
178 | { | ||
179 | if ( timerID ) { | ||
180 | timeKillEvent(timerID); | ||
181 | } | ||
182 | timeEndPeriod(TIMER_RESOLUTION); | ||
183 | } | ||
184 | |||
185 | #endif | ||
186 | |||
187 | int SDL_SYS_StartTimer(void) | ||
188 | { | ||
189 | SDL_SetError("Internal logic error: WinCE uses threaded timer"); | ||
190 | return(-1); | ||
191 | } | ||
192 | |||
193 | void SDL_SYS_StopTimer(void) | ||
194 | { | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | #endif /* SDL_TIMER_WINCE */ | ||