src/timer/dc/SDL_systimer.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
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@1402
    22
#include "SDL_config.h"
slouken@509
    23
slouken@1635
    24
#ifdef SDL_TIMER_DC
slouken@1635
    25
slouken@509
    26
#include <kos.h>
slouken@509
    27
slouken@509
    28
#include "SDL_thread.h"
slouken@509
    29
#include "SDL_timer.h"
slouken@1361
    30
#include "../SDL_timer_c.h"
slouken@509
    31
slouken@509
    32
static unsigned start;
slouken@509
    33
slouken@509
    34
/* 
slouken@509
    35
	jif =  ms * HZ /1000
slouken@509
    36
	ms  = jif * 1000/HZ
slouken@509
    37
*/
slouken@509
    38
slouken@1662
    39
void
slouken@1668
    40
SDL_StartTicks(void)
slouken@509
    41
{
slouken@1662
    42
    /* Set first ticks value */
slouken@1662
    43
    start = jiffies;
slouken@509
    44
}
slouken@509
    45
slouken@1662
    46
Uint32
slouken@1668
    47
SDL_GetTicks(void)
slouken@509
    48
{
slouken@1662
    49
    return ((jiffies - start) * 1000 / HZ);
slouken@509
    50
}
slouken@509
    51
slouken@1662
    52
void
slouken@1668
    53
SDL_Delay(Uint32 ms)
slouken@509
    54
{
slouken@1668
    55
    thd_sleep(ms);
slouken@509
    56
}
slouken@509
    57
slouken@509
    58
/* Data to handle a single periodic alarm */
slouken@509
    59
static int timer_alive = 0;
slouken@509
    60
static SDL_Thread *timer = NULL;
slouken@509
    61
slouken@1662
    62
static int
slouken@1668
    63
RunTimer(void *unused)
slouken@509
    64
{
slouken@1662
    65
    while (timer_alive) {
slouken@1662
    66
        if (SDL_timer_running) {
slouken@1668
    67
            SDL_ThreadedTimerCheck();
slouken@1662
    68
        }
slouken@1668
    69
        SDL_Delay(10);
slouken@1662
    70
    }
slouken@1662
    71
    return (0);
slouken@509
    72
}
slouken@509
    73
slouken@509
    74
/* This is only called if the event thread is not running */
slouken@1662
    75
int
slouken@1668
    76
SDL_SYS_TimerInit(void)
slouken@509
    77
{
slouken@1662
    78
    timer_alive = 1;
slouken@1668
    79
    timer = SDL_CreateThread(RunTimer, NULL);
slouken@1662
    80
    if (timer == NULL)
slouken@1662
    81
        return (-1);
slouken@1668
    82
    return (SDL_SetTimerThreaded(1));
slouken@509
    83
}
slouken@509
    84
slouken@1662
    85
void
slouken@1668
    86
SDL_SYS_TimerQuit(void)
slouken@509
    87
{
slouken@1662
    88
    timer_alive = 0;
slouken@1662
    89
    if (timer) {
slouken@1668
    90
        SDL_WaitThread(timer, NULL);
slouken@1662
    91
        timer = NULL;
slouken@1662
    92
    }
slouken@509
    93
}
slouken@509
    94
slouken@1662
    95
int
slouken@1668
    96
SDL_SYS_StartTimer(void)
slouken@509
    97
{
slouken@1668
    98
    SDL_SetError("Internal logic error: DC uses threaded timer");
slouken@1662
    99
    return (-1);
slouken@509
   100
}
slouken@509
   101
slouken@1662
   102
void
slouken@1668
   103
SDL_SYS_StopTimer(void)
slouken@509
   104
{
slouken@1662
   105
    return;
slouken@509
   106
}
slouken@1635
   107
slouken@1635
   108
#endif /* SDL_TIMER_DC */
slouken@1662
   109
/* vi: set ts=4 sw=4 expandtab: */