2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
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.
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.
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
23 /* YARI's minimal timer implementation is based on that from NDS */
24 #include "SDL_config.h"
26 #include "SDL_thread.h"
27 #include "SDL_timer.h"
28 #include "SDL_error.h"
29 #include "../SDL_timer_c.h"
31 uint64_t yari_rdhwr_TSC(void);
33 static uint32_t scale
, counter_overflow
;
34 static uint64_t start_TSC
, prev_TSC
;
36 uint32_t mips32_rdhwr_counter(void);
37 uint32_t mips32_rdhwr_cycles_pr_count(void);
40 void SDL_StartTicks(void)
42 uint32_t khz_frequency
= 50*1000;
43 uint32_t cycles_pr_count
= mips32_rdhwr_cycles_pr_count();
44 scale
= (1ULL << 32) * cycles_pr_count
/ khz_frequency
;
46 start_TSC
= mips32_rdhwr_counter();
50 * Get the number of milliseconds since the SDL library
51 * initialization. Note that this value wraps if the program runs for
54 Uint32
SDL_GetTicks(void)
56 uint64_t t
= mips32_rdhwr_counter();
58 counter_overflow
+= t
< prev_TSC
; // Happens practically never
60 t
+= ((uint64_t) counter_overflow
<< 32) - start_TSC
;
62 return t
* scale
>> 32;
65 void SDL_Delay(Uint32 delay_ms
)
67 Uint32 t0
= SDL_GetTicks();
69 while (SDL_GetTicks() < t0
+ delay_ms
)
70 SDL_PumpEvents(); // Improve responsiveness at the expense of accuracy
73 /* This is only called if the event thread is not running */
74 int SDL_SYS_TimerInit(void)
79 void SDL_SYS_TimerQuit(void)
83 int SDL_SYS_StartTimer(void)
85 SDL_SetError("Timers not implemented on YARI");
89 void SDL_SYS_StopTimer(void)