comparison src/timer/dc/SDL_systimer.c @ 509:dad72daf44b3

Added initial support for Dreamcast (thanks HERO!)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Oct 2002 16:50:56 +0000
parents
children b8d311d90021
comparison
equal deleted inserted replaced
508:9ff7e90aaa94 509:dad72daf44b3
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 BERO
20 bero@geocities.co.jp
21
22 based on win32/SDL_systimer.c
23
24 Sam Lantinga
25 slouken@libsdl.org
26 */
27
28 #ifdef SAVE_RCSID
29 static char rcsid =
30 "@(#) $Id$";
31 #endif
32
33 #include <kos.h>
34
35 #include "SDL_thread.h"
36 #include "SDL_timer.h"
37 #include "SDL_error.h"
38 #include "SDL_timer_c.h"
39
40 static unsigned start;
41
42 /*
43 jif = ms * HZ /1000
44 ms = jif * 1000/HZ
45 */
46
47 void SDL_StartTicks(void)
48 {
49 /* Set first ticks value */
50 start = jiffies;
51 }
52
53 Uint32 SDL_GetTicks(void)
54 {
55 return((jiffies-start)*1000/HZ);
56 }
57
58 void SDL_Delay(Uint32 ms)
59 {
60 thd_sleep(ms);
61 }
62
63 /* Data to handle a single periodic alarm */
64 static int timer_alive = 0;
65 static SDL_Thread *timer = NULL;
66
67 static int RunTimer(void *unused)
68 {
69 while ( timer_alive ) {
70 if ( SDL_timer_running ) {
71 SDL_ThreadedTimerCheck();
72 }
73 SDL_Delay(10);
74 }
75 return(0);
76 }
77
78 /* This is only called if the event thread is not running */
79 int SDL_SYS_TimerInit(void)
80 {
81 timer_alive = 1;
82 timer = SDL_CreateThread(RunTimer, NULL);
83 if ( timer == NULL )
84 return(-1);
85 return(SDL_SetTimerThreaded(1));
86 }
87
88 void SDL_SYS_TimerQuit(void)
89 {
90 timer_alive = 0;
91 if ( timer ) {
92 SDL_WaitThread(timer, NULL);
93 timer = NULL;
94 }
95 }
96
97 int SDL_SYS_StartTimer(void)
98 {
99 SDL_SetError("Internal logic error: DC uses threaded timer");
100 return(-1);
101 }
102
103 void SDL_SYS_StopTimer(void)
104 {
105 return;
106 }