src/timer/nds/SDL_systimer.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 15 Feb 2013 08:47:44 -0800
changeset 6885 700f1b25f77f
parent 6138 4c64952a58fb
permissions -rw-r--r--
Happy New Year!
slouken@2735
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@2735
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@2735
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@2735
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2735
    20
*/
slouken@2735
    21
#include "SDL_config.h"
slouken@2735
    22
slouken@2735
    23
#ifdef SDL_TIMER_NDS
slouken@2735
    24
slouken@2735
    25
#include <nds.h>
slouken@2735
    26
#include <nds/timers.h>
slouken@2735
    27
slouken@2735
    28
#include "SDL_timer.h"
slouken@2735
    29
slouken@5515
    30
/* Will wrap after 49 days. Shouldn't be an issue. */
slouken@5111
    31
static volatile Uint32 timer_ticks;
slouken@5111
    32
slouken@5111
    33
static void
slouken@5111
    34
NDS_TimerInterrupt(void)
slouken@5111
    35
{
slouken@5111
    36
    timer_ticks++;
slouken@5111
    37
}
slouken@2735
    38
slouken@2735
    39
void
slouken@2735
    40
SDL_StartTicks(void)
slouken@2735
    41
{
slouken@5111
    42
    timer_ticks = 0;
slouken@2735
    43
slouken@5270
    44
	/* Set timer 2 to fire every ms. */
slouken@5270
    45
	timerStart(2, ClockDivider_1024, TIMER_FREQ_1024(1000), NDS_TimerInterrupt);
slouken@2735
    46
}
slouken@2735
    47
slouken@2735
    48
Uint32
slouken@2735
    49
SDL_GetTicks(void)
slouken@2735
    50
{
slouken@2735
    51
    return timer_ticks;
slouken@2735
    52
}
slouken@2735
    53
slouken@5514
    54
Uint64
slouken@5514
    55
SDL_GetPerformanceCounter(void)
slouken@5514
    56
{
slouken@5514
    57
    return SDL_GetTicks();
slouken@5514
    58
}
slouken@5514
    59
slouken@5514
    60
Uint64
slouken@5514
    61
SDL_GetPerformanceFrequency(void)
slouken@5514
    62
{
slouken@5514
    63
    return 1000;
slouken@5514
    64
}
slouken@5514
    65
slouken@2735
    66
void
slouken@2735
    67
SDL_Delay(Uint32 ms)
slouken@2735
    68
{
slouken@2735
    69
    Uint32 start = SDL_GetTicks();
slouken@5270
    70
    while (1) {
slouken@2735
    71
        if ((SDL_GetTicks() - start) >= ms)
slouken@2735
    72
            break;
slouken@2735
    73
    }
slouken@2735
    74
}
slouken@2735
    75
slouken@5111
    76
#endif /* SDL_TIMER_NDS */
slouken@2735
    77
slouken@2735
    78
/* vi: set ts=4 sw=4 expandtab: */