Skip to content

Latest commit

 

History

History
167 lines (131 loc) · 3.27 KB

SDL_systimer.c

File metadata and controls

167 lines (131 loc) · 3.27 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 14, 2006
Apr 14, 2006
24
25
#ifdef SDL_TIMER_MINT
26
27
/*
* TOS/MiNT timer driver
Jul 28, 2014
Jul 28, 2014
28
* based on RISCOS backend
29
30
31
32
33
34
35
36
37
38
39
*
* Patrice Mandin
*/
#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
Apr 1, 2005
Apr 1, 2005
40
#include <mint/cookie.h>
Dec 7, 2002
Dec 7, 2002
41
#include <mint/sysvars.h>
Apr 1, 2005
Apr 1, 2005
42
43
#include <mint/osbind.h>
#include <mint/mintbind.h>
44
45
#include "SDL_timer.h"
Feb 16, 2006
Feb 16, 2006
46
#include "../SDL_timer_c.h"
Jan 10, 2012
Jan 10, 2012
48
49
#include "../../video/ataricommon/SDL_atarisuper.h"
Jul 28, 2014
Jul 28, 2014
50
51
/* from src/video/ataricommon/SDL_atarievents.c */
void SDL_AtariMint_BackgroundTasks(void);
Jul 28, 2014
Jul 28, 2014
53
static Uint32 readHz200Timer(void);
Oct 21, 2006
Oct 21, 2006
54
55
56
/* The first ticks value of the application */
static Uint32 start;
Jul 28, 2014
Jul 28, 2014
57
58
59
60
/* Timer SDL_arraysize(Timer ),start/reset time */
static Uint32 timerStart;
61
62
void SDL_StartTicks(void)
{
Aug 28, 2011
Aug 28, 2011
63
long dummy;
Jul 28, 2014
Jul 28, 2014
65
66
/* Set first ticks value, one _hz_200 tic is 5ms */
start = readHz200Timer() * 5;
67
68
69
70
}
Uint32 SDL_GetTicks (void)
{
Jul 28, 2014
Jul 28, 2014
71
Uint32 now = readHz200Timer() * 5;
Jul 28, 2014
Jul 28, 2014
73
return(now-start);
74
75
76
77
}
void SDL_Delay (Uint32 ms)
{
Aug 28, 2014
Aug 28, 2014
78
79
80
81
82
static Uint32 prev_now = 0;
Uint32 now, cur_tick;
int ran_bg_task = 0;
now = cur_tick = SDL_GetTicks();
Jul 28, 2014
Jul 28, 2014
84
85
/* No need to loop for delay below resolution */
if (ms<5) {
Aug 28, 2014
Aug 28, 2014
86
87
88
if (prev_now != now) {
SDL_AtariMint_BackgroundTasks();
prev_now = now;
Jul 28, 2014
Jul 28, 2014
89
90
91
92
}
return;
}
Aug 28, 2014
Aug 28, 2014
93
94
95
96
97
while (cur_tick-now<ms){
if (prev_now != cur_tick) {
SDL_AtariMint_BackgroundTasks();
prev_now = cur_tick;
ran_bg_task = 1;
Apr 1, 2005
Apr 1, 2005
98
}
Aug 28, 2014
Aug 28, 2014
99
100
101
102
103
cur_tick = SDL_GetTicks();
}
if (!ran_bg_task) {
SDL_AtariMint_BackgroundTasks();
104
105
106
}
}
Jul 28, 2014
Jul 28, 2014
107
static Uint32 readHz200Timer(void)
Jun 9, 2007
Jun 9, 2007
109
void *old_stack;
Jul 28, 2014
Jul 28, 2014
110
Uint32 now;
Jun 9, 2007
Jun 9, 2007
112
old_stack = (void *)Super(0);
Jul 28, 2014
Jul 28, 2014
113
now = *((volatile long *)_hz_200);
Jan 10, 2012
Jan 10, 2012
114
SuperToUser(old_stack);
Jul 28, 2014
Jul 28, 2014
116
117
118
119
return now;
}
/* Non-threaded version of timer */
Jun 9, 2007
Jun 9, 2007
120
Jul 28, 2014
Jul 28, 2014
121
122
123
int SDL_SYS_TimerInit(void)
{
return(0);
124
125
126
127
}
void SDL_SYS_TimerQuit(void)
{
Jul 28, 2014
Jul 28, 2014
128
SDL_SetTimer(0, NULL);
129
130
131
132
}
int SDL_SYS_StartTimer(void)
{
Jul 28, 2014
Jul 28, 2014
133
134
135
timerStart = SDL_GetTicks();
return(0);
136
137
138
139
}
void SDL_SYS_StopTimer(void)
{
Jul 28, 2014
Jul 28, 2014
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Don't need to do anything as we use SDL_timer_running
to detect if we need to check the timer */
}
void SDL_AtariMint_CheckTimer(void)
{
if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval)
{
Uint32 ms;
ms = SDL_alarm_callback(SDL_alarm_interval);
if ( ms != SDL_alarm_interval )
{
if ( ms )
{
SDL_alarm_interval = ROUND_RESOLUTION(ms);
} else
{
SDL_alarm_interval = 0;
SDL_timer_running = 0;
}
}
if (SDL_alarm_interval) timerStart = SDL_GetTicks();
}
Apr 14, 2006
Apr 14, 2006
166
167
#endif /* SDL_TIMER_MINT */