comparison src/timer/mint/SDL_systimer.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children eb5e61b72da3
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
49 #include "SDL_vbltimer_s.h" 49 #include "SDL_vbltimer_s.h"
50 50
51 /* The first ticks value of the application */ 51 /* The first ticks value of the application */
52 static Uint32 start; 52 static Uint32 start;
53 static SDL_bool supervisor; 53 static SDL_bool supervisor;
54 static int mint_present; /* can we use Syield() ? */ 54 static int mint_present; /* can we use Syield() ? */
55 55
56 void SDL_StartTicks(void) 56 void
57 SDL_StartTicks(void)
57 { 58 {
58 void *oldpile; 59 void *oldpile;
59 unsigned long dummy; 60 unsigned long dummy;
60 61
61 /* Set first ticks value */ 62 /* Set first ticks value */
62 oldpile=(void *)Super(0); 63 oldpile = (void *) Super(0);
63 start=*((volatile long *)_hz_200); 64 start = *((volatile long *) _hz_200);
64 Super(oldpile); 65 Super(oldpile);
65 66
66 start *= 5; /* One _hz_200 tic is 5ms */ 67 start *= 5; /* One _hz_200 tic is 5ms */
67 68
68 mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); 69 mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
69 } 70 }
70 71
71 Uint32 SDL_GetTicks (void) 72 Uint32
73 SDL_GetTicks(void)
72 { 74 {
73 Uint32 now; 75 Uint32 now;
74 void *oldpile=NULL; 76 void *oldpile = NULL;
75 77
76 /* Check if we are in supervisor mode 78 /* Check if we are in supervisor mode
77 (this is the case when called from SDL_ThreadedTimerCheck, 79 (this is the case when called from SDL_ThreadedTimerCheck,
78 which is called from RunTimer, running in the vbl vector) 80 which is called from RunTimer, running in the vbl vector)
79 */ 81 */
80 if (!supervisor) { 82 if (!supervisor) {
81 oldpile=(void *)Super(0); 83 oldpile = (void *) Super(0);
82 } 84 }
83 85
84 now=*((volatile long *)_hz_200); 86 now = *((volatile long *) _hz_200);
85 87
86 if (!supervisor) { 88 if (!supervisor) {
87 Super(oldpile); 89 Super(oldpile);
88 } 90 }
89 91
90 return((now*5)-start); 92 return ((now * 5) - start);
91 } 93 }
92 94
93 void SDL_Delay (Uint32 ms) 95 void
96 SDL_Delay(Uint32 ms)
94 { 97 {
95 Uint32 now; 98 Uint32 now;
96 99
97 now = SDL_GetTicks(); 100 now = SDL_GetTicks();
98 while ((SDL_GetTicks()-now)<ms){ 101 while ((SDL_GetTicks() - now) < ms) {
99 if (mint_present) { 102 if (mint_present) {
100 Syield(); 103 Syield();
101 } 104 }
102 } 105 }
103 } 106 }
104 107
105 /* Data to handle a single periodic alarm */ 108 /* Data to handle a single periodic alarm */
106 static SDL_bool timer_installed=SDL_FALSE; 109 static SDL_bool timer_installed = SDL_FALSE;
107 110
108 static void RunTimer(void) 111 static void
112 RunTimer(void)
109 { 113 {
110 supervisor=SDL_TRUE; 114 supervisor = SDL_TRUE;
111 SDL_ThreadedTimerCheck(); 115 SDL_ThreadedTimerCheck();
112 supervisor=SDL_FALSE; 116 supervisor = SDL_FALSE;
113 } 117 }
114 118
115 /* This is only called if the event thread is not running */ 119 /* This is only called if the event thread is not running */
116 int SDL_SYS_TimerInit(void) 120 int
121 SDL_SYS_TimerInit(void)
117 { 122 {
118 void *oldpile; 123 void *oldpile;
119 124
120 supervisor=SDL_FALSE; 125 supervisor = SDL_FALSE;
121 126
122 /* Install RunTimer in vbl vector */ 127 /* Install RunTimer in vbl vector */
123 oldpile=(void *)Super(0); 128 oldpile = (void *) Super(0);
124 timer_installed = !SDL_AtariVblInstall(RunTimer); 129 timer_installed = !SDL_AtariVblInstall(RunTimer);
125 Super(oldpile); 130 Super(oldpile);
126 131
127 if (!timer_installed) { 132 if (!timer_installed) {
128 return(-1); 133 return (-1);
129 } 134 }
130 return(SDL_SetTimerThreaded(0)); 135 return (SDL_SetTimerThreaded(0));
131 } 136 }
132 137
133 void SDL_SYS_TimerQuit(void) 138 void
139 SDL_SYS_TimerQuit(void)
134 { 140 {
135 void *oldpile; 141 void *oldpile;
136 142
137 if (timer_installed) { 143 if (timer_installed) {
138 /* Uninstall RunTimer vbl vector */ 144 /* Uninstall RunTimer vbl vector */
139 oldpile=(void *)Super(0); 145 oldpile = (void *) Super(0);
140 SDL_AtariVblUninstall(RunTimer); 146 SDL_AtariVblUninstall(RunTimer);
141 Super(oldpile); 147 Super(oldpile);
142 timer_installed = SDL_FALSE; 148 timer_installed = SDL_FALSE;
143 } 149 }
144 } 150 }
145 151
146 int SDL_SYS_StartTimer(void) 152 int
153 SDL_SYS_StartTimer(void)
147 { 154 {
148 SDL_SetError("Internal logic error: MiNT uses vbl timer"); 155 SDL_SetError("Internal logic error: MiNT uses vbl timer");
149 return(-1); 156 return (-1);
150 } 157 }
151 158
152 void SDL_SYS_StopTimer(void) 159 void
160 SDL_SYS_StopTimer(void)
153 { 161 {
154 return; 162 return;
155 } 163 }
156 164
157 #endif /* SDL_TIMER_MINT */ 165 #endif /* SDL_TIMER_MINT */
166 /* vi: set ts=4 sw=4 expandtab: */