src/timer/nds/SDL_systimer.c
branchgsoc2008_nds
changeset 2683 e858ac8868b6
child 2696 0b395a60deff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/timer/nds/SDL_systimer.c	Fri Aug 08 08:22:08 2008 +0000
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2006 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#ifdef SDL_TIMER_NDS
    1.28 +
    1.29 +#include <nds.h>
    1.30 +#include <nds/timers.h>
    1.31 +
    1.32 +#include "SDL_timer.h"
    1.33 +#include "../SDL_timer_c.h"
    1.34 +
    1.35 +static Uint32 timer_ticks;
    1.36 +
    1.37 +void
    1.38 +SDL_StartTicks(void)
    1.39 +{
    1.40 +    if(!timer_alive) {
    1.41 +        SDL_SYS_TimerInit();
    1.42 +        SDL_SYS_StartTimer();
    1.43 +    }
    1.44 +
    1.45 +    timer_ticks = 0;
    1.46 +}
    1.47 +
    1.48 +Uint32
    1.49 +SDL_GetTicks(void)
    1.50 +{
    1.51 +    return timer_ticks;
    1.52 +}
    1.53 +
    1.54 +void
    1.55 +SDL_Delay(Uint32 ms)
    1.56 +{
    1.57 +    Uint32 start = SDL_GetTicks();
    1.58 +    while(timer_alive) {
    1.59 +        if((SDL_GetTicks() - start) >= ms) break;
    1.60 +    }
    1.61 +}
    1.62 +
    1.63 +/* Data to handle a single periodic alarm */
    1.64 +static int timer_alive = 0;
    1.65 +static int timer_ticks = 0;
    1.66 +
    1.67 +static int
    1.68 +RunTimer(void *unused)
    1.69 +{
    1.70 +    while (timer_alive) {
    1.71 +        if (SDL_timer_running) {
    1.72 +        }
    1.73 +        SDL_Delay(1);
    1.74 +    }
    1.75 +    return (0);
    1.76 +}
    1.77 +
    1.78 +void NDS_TimerInterrupt() {
    1.79 +    printf("timer irq\n");
    1.80 +}
    1.81 +
    1.82 +/* This is only called if the event thread is not running */
    1.83 +int
    1.84 +SDL_SYS_TimerInit(void)
    1.85 +{
    1.86 +    timer_alive = 1;
    1.87 +    timer_ticks = 0;
    1.88 +    TIMER_CR(0) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
    1.89 +    TIMER_DATA(0) = TIMER_FREQ_1024(1000);
    1.90 +    irqSet(IRQ_TIMER1, NDS_TimerInterrupt);
    1.91 +    return 0;
    1.92 +}
    1.93 +
    1.94 +void
    1.95 +SDL_SYS_TimerQuit(void)
    1.96 +{
    1.97 +    if (timer_alive) {
    1.98 +        TIMER_CR(0) = 0;
    1.99 +    }
   1.100 +    timer_alive = 0;
   1.101 +}
   1.102 +
   1.103 +int
   1.104 +SDL_SYS_StartTimer(void)
   1.105 +{
   1.106 +    TIMER_CR(0) |= TIMER_ENABLE;
   1.107 +    return 0;
   1.108 +}
   1.109 +
   1.110 +void
   1.111 +SDL_SYS_StopTimer(void)
   1.112 +{
   1.113 +    TIMER_CR(0) &= ~TIMER_ENABLE;
   1.114 +    return;
   1.115 +}
   1.116 +
   1.117 +
   1.118 +#endif /* SDL_TIMER_NDS */
   1.119 +/* vi: set ts=4 sw=4 expandtab: */