Mercurial > sdl-ios-xcode
comparison src/timer/mint/SDL_systimer.c @ 281:c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 17 Feb 2002 19:54:28 +0000 |
parents | |
children | f6ffac90895c |
comparison
equal
deleted
inserted
replaced
280:0ddcea45d829 | 281:c5010ab8ba35 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* | |
29 * TOS/MiNT timer driver | |
30 * based on vbl vector | |
31 * | |
32 * Patrice Mandin | |
33 */ | |
34 | |
35 #include <stdio.h> | |
36 #include <sys/time.h> | |
37 #include <signal.h> | |
38 #include <unistd.h> | |
39 #include <string.h> | |
40 #include <errno.h> | |
41 | |
42 #include <mint/osbind.h> | |
43 #include <sysvars.h> | |
44 | |
45 #include "SDL_error.h" | |
46 #include "SDL_timer.h" | |
47 #include "SDL_timer_c.h" | |
48 #include "SDL_thread.h" | |
49 | |
50 #include "SDL_vbltimer_s.h" | |
51 | |
52 /* The first ticks value of the application */ | |
53 static Uint32 start; | |
54 static SDL_bool supervisor; | |
55 | |
56 void SDL_StartTicks(void) | |
57 { | |
58 void *oldpile; | |
59 | |
60 /* Set first ticks value */ | |
61 oldpile=(void *)Super(0); | |
62 start=*((volatile long *)_hz_200); | |
63 Super(oldpile); | |
64 | |
65 start *= 5; /* One _hz_200 tic is 5ms */ | |
66 } | |
67 | |
68 Uint32 SDL_GetTicks (void) | |
69 { | |
70 Uint32 now; | |
71 void *oldpile; | |
72 | |
73 /* Check if we are in supervisor mode | |
74 (this is the case when called from SDL_ThreadedTimerCheck, | |
75 which is called from RunTimer, running in the vbl vector) | |
76 */ | |
77 if (!supervisor) { | |
78 oldpile=(void *)Super(0); | |
79 } | |
80 | |
81 now=*((volatile long *)_hz_200); | |
82 | |
83 if (!supervisor) { | |
84 Super(oldpile); | |
85 } | |
86 | |
87 return((now*5)-start); | |
88 } | |
89 | |
90 void SDL_Delay (Uint32 ms) | |
91 { | |
92 Uint32 now; | |
93 | |
94 now = SDL_GetTicks(); | |
95 while ((SDL_GetTicks()-now)<ms){ | |
96 } | |
97 } | |
98 | |
99 /* Data to handle a single periodic alarm */ | |
100 static SDL_bool timer_installed=SDL_FALSE; | |
101 | |
102 static void RunTimer(void) | |
103 { | |
104 supervisor=SDL_TRUE; | |
105 SDL_ThreadedTimerCheck(); | |
106 supervisor=SDL_FALSE; | |
107 } | |
108 | |
109 /* This is only called if the event thread is not running */ | |
110 int SDL_SYS_TimerInit(void) | |
111 { | |
112 void *oldpile; | |
113 | |
114 supervisor=SDL_FALSE; | |
115 | |
116 /* Install RunTimer in vbl vector */ | |
117 oldpile=(void *)Super(0); | |
118 timer_installed = !SDL_AtariVblInstall(RunTimer); | |
119 Super(oldpile); | |
120 | |
121 if (!timer_installed) { | |
122 return(-1); | |
123 } | |
124 return(SDL_SetTimerThreaded(0)); | |
125 } | |
126 | |
127 void SDL_SYS_TimerQuit(void) | |
128 { | |
129 void *oldpile; | |
130 | |
131 if (timer_installed) { | |
132 /* Uninstall RunTimer vbl vector */ | |
133 oldpile=(void *)Super(0); | |
134 SDL_AtariVblUninstall(RunTimer); | |
135 Super(oldpile); | |
136 timer_installed = SDL_FALSE; | |
137 } | |
138 } | |
139 | |
140 int SDL_SYS_StartTimer(void) | |
141 { | |
142 SDL_SetError("Internal logic error: MiNT uses vbl timer"); | |
143 return(-1); | |
144 } | |
145 | |
146 void SDL_SYS_StopTimer(void) | |
147 { | |
148 return; | |
149 } |