/
SDL_systimer.c
167 lines (131 loc) · 3.27 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
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
13
Lesser General Public License for more details.
14
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
*/
22
#include "SDL_config.h"
23
24
25
#ifdef SDL_TIMER_MINT
26
27
/*
* TOS/MiNT timer driver
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>
40
#include <mint/cookie.h>
41
#include <mint/sysvars.h>
42
43
#include <mint/osbind.h>
#include <mint/mintbind.h>
44
45
#include "SDL_timer.h"
46
#include "../SDL_timer_c.h"
47
48
49
#include "../../video/ataricommon/SDL_atarisuper.h"
50
51
/* from src/video/ataricommon/SDL_atarievents.c */
void SDL_AtariMint_BackgroundTasks(void);
52
53
static Uint32 readHz200Timer(void);
54
55
56
/* The first ticks value of the application */
static Uint32 start;
57
58
59
60
/* Timer SDL_arraysize(Timer ),start/reset time */
static Uint32 timerStart;
61
62
void SDL_StartTicks(void)
{
63
long dummy;
64
65
66
/* Set first ticks value, one _hz_200 tic is 5ms */
start = readHz200Timer() * 5;
67
68
69
70
}
Uint32 SDL_GetTicks (void)
{
71
Uint32 now = readHz200Timer() * 5;
72
73
return(now-start);
74
75
76
77
}
void SDL_Delay (Uint32 ms)
{
78
79
80
81
82
static Uint32 prev_now = 0;
Uint32 now, cur_tick;
int ran_bg_task = 0;
now = cur_tick = SDL_GetTicks();
83
84
85
/* No need to loop for delay below resolution */
if (ms<5) {
86
87
88
if (prev_now != now) {
SDL_AtariMint_BackgroundTasks();
prev_now = now;
89
90
91
92
}
return;
}
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;
98
}
99
100
101
102
103
cur_tick = SDL_GetTicks();
}
if (!ran_bg_task) {
SDL_AtariMint_BackgroundTasks();
104
105
106
}
}
107
static Uint32 readHz200Timer(void)
108
{
109
void *old_stack;
110
Uint32 now;
111
112
old_stack = (void *)Super(0);
113
now = *((volatile long *)_hz_200);
114
SuperToUser(old_stack);
115
116
117
118
119
return now;
}
/* Non-threaded version of timer */
120
121
122
123
int SDL_SYS_TimerInit(void)
{
return(0);
124
125
126
127
}
void SDL_SYS_TimerQuit(void)
{
128
SDL_SetTimer(0, NULL);
129
130
131
132
}
int SDL_SYS_StartTimer(void)
{
133
134
135
timerStart = SDL_GetTicks();
return(0);
136
137
138
139
}
void SDL_SYS_StopTimer(void)
{
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();
}
165
}
166
167
#endif /* SDL_TIMER_MINT */