src/timer/nds/SDL_systimer.c
author Darren Alton <dalton@stevens.edu>
Fri, 08 Aug 2008 08:22:08 +0000
branchgsoc2008_nds
changeset 2683 e858ac8868b6
child 2696 0b395a60deff
permissions -rw-r--r--
Ongoing video render work; initial work on NDS Timers.
dalton@2683
     1
/*
dalton@2683
     2
    SDL - Simple DirectMedia Layer
dalton@2683
     3
    Copyright (C) 1997-2006 Sam Lantinga
dalton@2683
     4
dalton@2683
     5
    This library is free software; you can redistribute it and/or
dalton@2683
     6
    modify it under the terms of the GNU Lesser General Public
dalton@2683
     7
    License as published by the Free Software Foundation; either
dalton@2683
     8
    version 2.1 of the License, or (at your option) any later version.
dalton@2683
     9
dalton@2683
    10
    This library is distributed in the hope that it will be useful,
dalton@2683
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
dalton@2683
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dalton@2683
    13
    Lesser General Public License for more details.
dalton@2683
    14
dalton@2683
    15
    You should have received a copy of the GNU Lesser General Public
dalton@2683
    16
    License along with this library; if not, write to the Free Software
dalton@2683
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
dalton@2683
    18
dalton@2683
    19
    Sam Lantinga
dalton@2683
    20
    slouken@libsdl.org
dalton@2683
    21
*/
dalton@2683
    22
#include "SDL_config.h"
dalton@2683
    23
dalton@2683
    24
#ifdef SDL_TIMER_NDS
dalton@2683
    25
dalton@2683
    26
#include <nds.h>
dalton@2683
    27
#include <nds/timers.h>
dalton@2683
    28
dalton@2683
    29
#include "SDL_timer.h"
dalton@2683
    30
#include "../SDL_timer_c.h"
dalton@2683
    31
dalton@2683
    32
static Uint32 timer_ticks;
dalton@2683
    33
dalton@2683
    34
void
dalton@2683
    35
SDL_StartTicks(void)
dalton@2683
    36
{
dalton@2683
    37
    if(!timer_alive) {
dalton@2683
    38
        SDL_SYS_TimerInit();
dalton@2683
    39
        SDL_SYS_StartTimer();
dalton@2683
    40
    }
dalton@2683
    41
dalton@2683
    42
    timer_ticks = 0;
dalton@2683
    43
}
dalton@2683
    44
dalton@2683
    45
Uint32
dalton@2683
    46
SDL_GetTicks(void)
dalton@2683
    47
{
dalton@2683
    48
    return timer_ticks;
dalton@2683
    49
}
dalton@2683
    50
dalton@2683
    51
void
dalton@2683
    52
SDL_Delay(Uint32 ms)
dalton@2683
    53
{
dalton@2683
    54
    Uint32 start = SDL_GetTicks();
dalton@2683
    55
    while(timer_alive) {
dalton@2683
    56
        if((SDL_GetTicks() - start) >= ms) break;
dalton@2683
    57
    }
dalton@2683
    58
}
dalton@2683
    59
dalton@2683
    60
/* Data to handle a single periodic alarm */
dalton@2683
    61
static int timer_alive = 0;
dalton@2683
    62
static int timer_ticks = 0;
dalton@2683
    63
dalton@2683
    64
static int
dalton@2683
    65
RunTimer(void *unused)
dalton@2683
    66
{
dalton@2683
    67
    while (timer_alive) {
dalton@2683
    68
        if (SDL_timer_running) {
dalton@2683
    69
        }
dalton@2683
    70
        SDL_Delay(1);
dalton@2683
    71
    }
dalton@2683
    72
    return (0);
dalton@2683
    73
}
dalton@2683
    74
dalton@2683
    75
void NDS_TimerInterrupt() {
dalton@2683
    76
    printf("timer irq\n");
dalton@2683
    77
}
dalton@2683
    78
dalton@2683
    79
/* This is only called if the event thread is not running */
dalton@2683
    80
int
dalton@2683
    81
SDL_SYS_TimerInit(void)
dalton@2683
    82
{
dalton@2683
    83
    timer_alive = 1;
dalton@2683
    84
    timer_ticks = 0;
dalton@2683
    85
    TIMER_CR(0) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
dalton@2683
    86
    TIMER_DATA(0) = TIMER_FREQ_1024(1000);
dalton@2683
    87
    irqSet(IRQ_TIMER1, NDS_TimerInterrupt);
dalton@2683
    88
    return 0;
dalton@2683
    89
}
dalton@2683
    90
dalton@2683
    91
void
dalton@2683
    92
SDL_SYS_TimerQuit(void)
dalton@2683
    93
{
dalton@2683
    94
    if (timer_alive) {
dalton@2683
    95
        TIMER_CR(0) = 0;
dalton@2683
    96
    }
dalton@2683
    97
    timer_alive = 0;
dalton@2683
    98
}
dalton@2683
    99
dalton@2683
   100
int
dalton@2683
   101
SDL_SYS_StartTimer(void)
dalton@2683
   102
{
dalton@2683
   103
    TIMER_CR(0) |= TIMER_ENABLE;
dalton@2683
   104
    return 0;
dalton@2683
   105
}
dalton@2683
   106
dalton@2683
   107
void
dalton@2683
   108
SDL_SYS_StopTimer(void)
dalton@2683
   109
{
dalton@2683
   110
    TIMER_CR(0) &= ~TIMER_ENABLE;
dalton@2683
   111
    return;
dalton@2683
   112
}
dalton@2683
   113
dalton@2683
   114
dalton@2683
   115
#endif /* SDL_TIMER_NDS */
dalton@2683
   116
/* vi: set ts=4 sw=4 expandtab: */