comparison src/timer/amigaos/SDL_systimer.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 92947e3a18db
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
57 /* The first ticks value of the application */ 57 /* The first ticks value of the application */
58 58
59 #if !defined(__PPC__) || defined(STORMC4_WOS) || defined(MORPHOS) 59 #if !defined(__PPC__) || defined(STORMC4_WOS) || defined(MORPHOS)
60 static clock_t start; 60 static clock_t start;
61 61
62 void SDL_StartTicks(void) 62 void
63 { 63 SDL_StartTicks (void)
64 /* Set first ticks value */ 64 {
65 start=clock(); 65 /* Set first ticks value */
66 } 66 start = clock ();
67 67 }
68 Uint32 SDL_GetTicks (void) 68
69 { 69 Uint32
70 clock_t ticks; 70 SDL_GetTicks (void)
71 71 {
72 ticks=clock()-start; 72 clock_t ticks;
73
74 ticks = clock () - start;
73 75
74 #ifdef __SASC 76 #ifdef __SASC
75 // CLOCKS_PER_SEC == 1000 ! 77 // CLOCKS_PER_SEC == 1000 !
76 78
77 return(ticks); 79 return (ticks);
78 #else 80 #else
79 // CLOCKS_PER_SEC != 1000 ! 81 // CLOCKS_PER_SEC != 1000 !
80 82
81 return ticks*(1000/CLOCKS_PER_SEC); 83 return ticks * (1000 / CLOCKS_PER_SEC);
82 #endif 84 #endif
83 } 85 }
84 86
85 void SDL_Delay (Uint32 ms) 87 void
88 SDL_Delay (Uint32 ms)
86 { 89 {
87 // Do a busy wait if time is less than 50ms 90 // Do a busy wait if time is less than 50ms
88 91
89 if(ms<50) 92 if (ms < 50) {
90 { 93 clock_t to_wait = clock ();
91 clock_t to_wait=clock();
92 94
93 #ifndef __SASC 95 #ifndef __SASC
94 ms*=(CLOCKS_PER_SEC/1000); 96 ms *= (CLOCKS_PER_SEC / 1000);
95 #endif 97 #endif
96 to_wait+=ms; 98 to_wait += ms;
97 99
98 while(clock()<to_wait); 100 while (clock () < to_wait);
99 } 101 } else {
100 else 102 Delay (ms / 20);
101 { 103 }
102 Delay(ms/20);
103 }
104 } 104 }
105 105
106 #else 106 #else
107 107
108 ULONG MY_CLOCKS_PER_SEC; 108 ULONG MY_CLOCKS_PER_SEC;
109 109
110 void PPC_TimerInit(void); 110 void PPC_TimerInit (void);
111 APTR MyTimer; 111 APTR MyTimer;
112 112
113 ULONG start[2]; 113 ULONG start[2];
114 114
115 void SDL_StartTicks(void) 115 void
116 { 116 SDL_StartTicks (void)
117 /* Set first ticks value */ 117 {
118 if(!MyTimer) 118 /* Set first ticks value */
119 PPC_TimerInit(); 119 if (!MyTimer)
120 120 PPC_TimerInit ();
121 PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,start); 121
122 start[1]>>=10; 122 PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, start);
123 start[1]|=((result[0]&0x3ff)<<22); 123 start[1] >>= 10;
124 start[0]>>=10; 124 start[1] |= ((result[0] & 0x3ff) << 22);
125 } 125 start[0] >>= 10;
126 126 }
127 Uint32 SDL_GetTicks (void) 127
128 { 128 Uint32
129 ULONG result[2]; 129 SDL_GetTicks (void)
130 PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,result); 130 {
131 131 ULONG result[2];
132 // PPCAsr64p(result,10); 132 PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, result);
133
134 // PPCAsr64p(result,10);
133 // Non va, la emulo: 135 // Non va, la emulo:
134 136
135 result[1]>>=10; 137 result[1] >>= 10;
136 result[1]|=((result[0]&0x3ff)<<22); 138 result[1] |= ((result[0] & 0x3ff) << 22);
137 139
138 // Non mi interessa piu' result[0] 140 // Non mi interessa piu' result[0]
139 141
140 return result[1]*1000/MY_CLOCKS_PER_SEC; 142 return result[1] * 1000 / MY_CLOCKS_PER_SEC;
141 } 143 }
142 144
143 void SDL_Delay (Uint32 ms) 145 void
146 SDL_Delay (Uint32 ms)
144 { 147 {
145 // Do a busy wait if time is less than 50ms 148 // Do a busy wait if time is less than 50ms
146 149
147 if(ms<50) 150 if (ms < 50) {
148 { 151 ULONG to_wait[2], actual[2];
149 ULONG to_wait[2],actual[2]; 152 PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, result);
150 PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,result); 153 actual[1] = 0;
151 actual[1]=0; 154 to_wait[1] += ms * 1000 / MY_CLOCKS_PER_SEC;
152 to_wait[1]+=ms*1000/MY_CLOCKS_PER_SEC; 155
153 156 while (actual[1] < to_wait[1]) {
154 while(actual[1]<to_wait[1]) 157 PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, actual);
155 { 158 }
156 PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,actual); 159 } else {
157 } 160 Delay (ms / 50);
158 } 161 }
159 else 162 }
160 { 163
161 Delay(ms/50); 164 void
162 } 165 PPC_TimerInit (void)
163 } 166 {
164 167 struct TagItem tags[] = {
165 void PPC_TimerInit(void) 168 PPCTIMERTAG_CPU, TRUE,
166 { 169 TAG_DONE, 0
167 struct TagItem tags[]= 170 };
168 { 171
169 PPCTIMERTAG_CPU,TRUE, 172
170 TAG_DONE,0 173 if (MyTimer = PPCCreateTimerObject (tags)) {
171 }; 174 ULONG result[2];
172 175
173 176 PPCGetTimerObject (MyTimer, PPCTIMERTAG_TICKSPERSEC, result);
174 if(MyTimer=PPCCreateTimerObject(tags)) 177 D (bug
175 { 178 ("Timer inizializzato, TPS: %lu - %lu\n", result[0], result[1]));
176 ULONG result[2]; 179 // PPCAsr64p(result,10);
177 180 result[1] >>= 10;
178 PPCGetTimerObject(MyTimer,PPCTIMERTAG_TICKSPERSEC,result); 181 result[1] |= ((result[0] & 0x3ff) << 22);
179 D(bug("Timer inizializzato, TPS: %lu - %lu\n",result[0],result[1])); 182 result[0] >>= 10;
180 // PPCAsr64p(result,10); 183
181 result[1]>>=10; 184 D (bug ("Shiftato TPS: %lu - %lu\n", result[0], result[1]));
182 result[1]|=((result[0]&0x3ff)<<22); 185 MY_CLOCKS_PER_SEC = result[1];
183 result[0]>>=10; 186
184 187 PPCGetTimerObject (MyTimer, PPCTIMERTAG_CURRENTTICKS, result);
185 D(bug("Shiftato TPS: %lu - %lu\n",result[0],result[1])); 188
186 MY_CLOCKS_PER_SEC=result[1]; 189 D (bug ("Current ticks: %lu - %lu\n", result[0], result[1]));
187 190 result[1] >>= 10;
188 PPCGetTimerObject(MyTimer,PPCTIMERTAG_CURRENTTICKS,result); 191 result[1] |= ((result[0] & 0x3ff) << 22);
189 192 result[0] >>= 10;
190 D(bug("Current ticks: %lu - %lu\n",result[0],result[1])); 193 // PPCAsr64p(result,10);
191 result[1]>>=10; 194 D (bug ("Shiftato: %lu - %lu\n", result[0], result[1]));
192 result[1]|=((result[0]&0x3ff)<<22); 195 } else {
193 result[0]>>=10; 196 D (bug ("Errore nell'inizializzazione del timer!\n"));
194 // PPCAsr64p(result,10); 197 }
195 D(bug("Shiftato: %lu - %lu\n",result[0],result[1]));
196 }
197 else
198 {
199 D(bug("Errore nell'inizializzazione del timer!\n"));
200 }
201 } 198 }
202 199
203 #endif 200 #endif
204 201
205 #include "SDL_thread.h" 202 #include "SDL_thread.h"
206 203
207 /* Data to handle a single periodic alarm */ 204 /* Data to handle a single periodic alarm */
208 static int timer_alive = 0; 205 static int timer_alive = 0;
209 static SDL_Thread *timer_thread = NULL; 206 static SDL_Thread *timer_thread = NULL;
210 207
211 static int RunTimer(void *unused) 208 static int
212 { 209 RunTimer (void *unused)
213 D(bug("SYSTimer: Entering RunTimer loop...")); 210 {
214 211 D (bug ("SYSTimer: Entering RunTimer loop..."));
215 if(GfxBase==NULL) 212
216 GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37); 213 if (GfxBase == NULL)
217 214 GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 37);
218 while ( timer_alive ) { 215
219 if ( SDL_timer_running ) { 216 while (timer_alive) {
220 SDL_ThreadedTimerCheck(); 217 if (SDL_timer_running) {
221 } 218 SDL_ThreadedTimerCheck ();
222 if(GfxBase) 219 }
223 WaitTOF(); // Check the timer every fifth of seconds. Was SDL_Delay(1)->BusyWait! 220 if (GfxBase)
224 else 221 WaitTOF (); // Check the timer every fifth of seconds. Was SDL_Delay(1)->BusyWait!
225 Delay(1); 222 else
226 } 223 Delay (1);
227 D(bug("SYSTimer: EXITING RunTimer loop...")); 224 }
228 return(0); 225 D (bug ("SYSTimer: EXITING RunTimer loop..."));
226 return (0);
229 } 227 }
230 228
231 /* This is only called if the event thread is not running */ 229 /* This is only called if the event thread is not running */
232 int SDL_SYS_TimerInit(void) 230 int
233 { 231 SDL_SYS_TimerInit (void)
234 D(bug("Creating thread for the timer (NOITIMER)...\n")); 232 {
235 233 D (bug ("Creating thread for the timer (NOITIMER)...\n"));
236 timer_alive = 1; 234
237 timer_thread = SDL_CreateThread(RunTimer, NULL); 235 timer_alive = 1;
238 if ( timer_thread == NULL ) 236 timer_thread = SDL_CreateThread (RunTimer, NULL);
239 { 237 if (timer_thread == NULL) {
240 D(bug("Creazione del thread fallita...\n")); 238 D (bug ("Creazione del thread fallita...\n"));
241 239
242 return(-1); 240 return (-1);
243 } 241 }
244 return(SDL_SetTimerThreaded(1)); 242 return (SDL_SetTimerThreaded (1));
245 } 243 }
246 244
247 void SDL_SYS_TimerQuit(void) 245 void
248 { 246 SDL_SYS_TimerQuit (void)
249 timer_alive = 0; 247 {
250 if ( timer_thread ) { 248 timer_alive = 0;
251 SDL_WaitThread(timer_thread, NULL); 249 if (timer_thread) {
252 timer_thread = NULL; 250 SDL_WaitThread (timer_thread, NULL);
253 } 251 timer_thread = NULL;
254 } 252 }
255 253 }
256 int SDL_SYS_StartTimer(void) 254
257 { 255 int
258 SDL_SetError("Internal logic error: AmigaOS uses threaded timer"); 256 SDL_SYS_StartTimer (void)
259 return(-1); 257 {
260 } 258 SDL_SetError ("Internal logic error: AmigaOS uses threaded timer");
261 259 return (-1);
262 void SDL_SYS_StopTimer(void) 260 }
263 { 261
264 return; 262 void
263 SDL_SYS_StopTimer (void)
264 {
265 return;
265 } 266 }
266 267
267 #endif /* SDL_TIMER_AMIGA */ 268 #endif /* SDL_TIMER_AMIGA */
269 /* vi: set ts=4 sw=4 expandtab: */