src/timer/dc/SDL_systimer.c
author Sam Lantinga
Mon, 06 Feb 2006 08:28:51 +0000
changeset 1330 450721ad5436
parent 1312 c9b51268668f
child 1358 c71e05b4dc2e
permissions -rw-r--r--
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
slouken@509
     1
/*
slouken@509
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@509
     4
slouken@509
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@509
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@509
     9
slouken@509
    10
    This library is distributed in the hope that it will be useful,
slouken@509
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@509
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@509
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@509
    18
slouken@509
    19
    Sam Lantinga
slouken@509
    20
    slouken@libsdl.org
slouken@509
    21
*/
slouken@509
    22
slouken@509
    23
#include <kos.h>
slouken@509
    24
slouken@509
    25
#include "SDL_thread.h"
slouken@509
    26
#include "SDL_timer.h"
slouken@509
    27
#include "SDL_error.h"
slouken@509
    28
#include "SDL_timer_c.h"
slouken@509
    29
slouken@509
    30
static unsigned start;
slouken@509
    31
slouken@509
    32
/* 
slouken@509
    33
	jif =  ms * HZ /1000
slouken@509
    34
	ms  = jif * 1000/HZ
slouken@509
    35
*/
slouken@509
    36
slouken@509
    37
void SDL_StartTicks(void)
slouken@509
    38
{
slouken@509
    39
	/* Set first ticks value */
slouken@509
    40
	start = jiffies;
slouken@509
    41
}
slouken@509
    42
slouken@509
    43
Uint32 SDL_GetTicks(void)
slouken@509
    44
{
slouken@509
    45
	return((jiffies-start)*1000/HZ);
slouken@509
    46
}
slouken@509
    47
slouken@509
    48
void SDL_Delay(Uint32 ms)
slouken@509
    49
{
slouken@509
    50
	thd_sleep(ms);
slouken@509
    51
}
slouken@509
    52
slouken@509
    53
/* Data to handle a single periodic alarm */
slouken@509
    54
static int timer_alive = 0;
slouken@509
    55
static SDL_Thread *timer = NULL;
slouken@509
    56
slouken@509
    57
static int RunTimer(void *unused)
slouken@509
    58
{
slouken@509
    59
	while ( timer_alive ) {
slouken@509
    60
		if ( SDL_timer_running ) {
slouken@509
    61
			SDL_ThreadedTimerCheck();
slouken@509
    62
		}
slouken@509
    63
		SDL_Delay(10);
slouken@509
    64
	}
slouken@509
    65
	return(0);
slouken@509
    66
}
slouken@509
    67
slouken@509
    68
/* This is only called if the event thread is not running */
slouken@509
    69
int SDL_SYS_TimerInit(void)
slouken@509
    70
{
slouken@509
    71
	timer_alive = 1;
slouken@509
    72
	timer = SDL_CreateThread(RunTimer, NULL);
slouken@509
    73
	if ( timer == NULL )
slouken@509
    74
		return(-1);
slouken@509
    75
	return(SDL_SetTimerThreaded(1));
slouken@509
    76
}
slouken@509
    77
slouken@509
    78
void SDL_SYS_TimerQuit(void)
slouken@509
    79
{
slouken@509
    80
	timer_alive = 0;
slouken@509
    81
	if ( timer ) {
slouken@509
    82
		SDL_WaitThread(timer, NULL);
slouken@509
    83
		timer = NULL;
slouken@509
    84
	}
slouken@509
    85
}
slouken@509
    86
slouken@509
    87
int SDL_SYS_StartTimer(void)
slouken@509
    88
{
slouken@509
    89
	SDL_SetError("Internal logic error: DC uses threaded timer");
slouken@509
    90
	return(-1);
slouken@509
    91
}
slouken@509
    92
slouken@509
    93
void SDL_SYS_StopTimer(void)
slouken@509
    94
{
slouken@509
    95
	return;
slouken@509
    96
}