src/timer/riscos/SDL_systimer.c
changeset 630 550bccdf04bd
child 769 b8d311d90021
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/timer/riscos/SDL_systimer.c	Thu May 29 04:44:13 2003 +0000
     1.3 @@ -0,0 +1,146 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 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 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +#include <stdio.h>
    1.32 +#include <time.h>
    1.33 +#include <sys/time.h>
    1.34 +#include <unistd.h>
    1.35 +#include <string.h>
    1.36 +#include <errno.h>
    1.37 +
    1.38 +#include "SDL_error.h"
    1.39 +#include "SDL_timer.h"
    1.40 +#include "SDL_timer_c.h"
    1.41 +
    1.42 +/* Timer start/reset time */
    1.43 +static Uint32 timerStart;
    1.44 +/* Timer running function */
    1.45 +void RISCOS_CheckTimer();
    1.46 +
    1.47 +extern void RISCOS_BackgroundTasks(void);
    1.48 +
    1.49 +/* The first ticks value of the application */
    1.50 +clock_t start;
    1.51 +
    1.52 +void SDL_StartTicks(void)
    1.53 +{
    1.54 +	/* Set first ticks value */
    1.55 +	start = clock();
    1.56 +}
    1.57 +
    1.58 +Uint32 SDL_GetTicks (void)
    1.59 +{
    1.60 +	clock_t ticks;
    1.61 +
    1.62 +	ticks=clock()-start;
    1.63 +
    1.64 +
    1.65 +#if CLOCKS_PER_SEC == 1000
    1.66 +
    1.67 +	return(ticks);
    1.68 +
    1.69 +#elif CLOCKS_PER_SEC == 100
    1.70 +
    1.71 +	return (ticks * 10);
    1.72 +
    1.73 +#else
    1.74 +
    1.75 +	return ticks*(1000/CLOCKS_PER_SEC);
    1.76 +
    1.77 +#endif
    1.78 +
    1.79 +}
    1.80 +
    1.81 +extern void DRenderer_FillBuffers();
    1.82 +
    1.83 +void SDL_Delay (Uint32 ms)
    1.84 +{
    1.85 +    Uint32 now,then,elapsed;
    1.86 +
    1.87 +	/* Set the timeout interval - Linux only needs to do this once */
    1.88 +	then = SDL_GetTicks();
    1.89 +
    1.90 +	do {
    1.91 +		/* Do background tasks required while sleeping as we are not multithreaded */
    1.92 +		RISCOS_BackgroundTasks();
    1.93 +		/* Calculate the time interval left (in case of interrupt) */
    1.94 +		now = SDL_GetTicks();
    1.95 +		elapsed = (now-then);
    1.96 +		then = now;
    1.97 +		if ( elapsed >= ms ) {
    1.98 +			break;
    1.99 +		}
   1.100 +		ms -= elapsed;
   1.101 +
   1.102 +	} while ( 1 );
   1.103 +}
   1.104 +
   1.105 +int SDL_SYS_TimerInit(void)
   1.106 +{
   1.107 +	return(0);
   1.108 +}
   1.109 +
   1.110 +void SDL_SYS_TimerQuit(void)
   1.111 +{
   1.112 +	SDL_SetTimer(0, NULL);
   1.113 +}
   1.114 +
   1.115 +int SDL_SYS_StartTimer(void)
   1.116 +{
   1.117 +	timerStart = SDL_GetTicks();
   1.118 +
   1.119 +	return(0);
   1.120 +}
   1.121 +
   1.122 +void SDL_SYS_StopTimer(void)
   1.123 +{
   1.124 +	/* Don't need to do anything as we use SDL_timer_running
   1.125 +	   to detect if we need to check the timer */
   1.126 +}
   1.127 +
   1.128 +
   1.129 +void RISCOS_CheckTimer()
   1.130 +{
   1.131 +	if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval)
   1.132 +	{
   1.133 +		Uint32 ms;
   1.134 +
   1.135 +		ms = SDL_alarm_callback(SDL_alarm_interval);
   1.136 +		if ( ms != SDL_alarm_interval )
   1.137 +		{
   1.138 +			if ( ms )
   1.139 +			{
   1.140 +				SDL_alarm_interval = ROUND_RESOLUTION(ms);
   1.141 +			} else
   1.142 +			{
   1.143 +				SDL_alarm_interval = 0;
   1.144 +				SDL_timer_running = 0;
   1.145 +			}
   1.146 +		}
   1.147 +		if (SDL_alarm_interval) timerStart = SDL_GetTicks();
   1.148 +	}
   1.149 +}