comparison src/timer/mint/SDL_systimer.c @ 2116:b42abf0a50bc

Avoid switch to supervisor mode in SDL_GetTicks, by updating system counter from vbl interrupt
author Patrice Mandin <patmandin@gmail.com>
date Sat, 09 Jun 2007 19:58:41 +0000
parents 502ae1f2a577
children 2c835d58faad
comparison
equal deleted inserted replaced
2115:502ae1f2a577 2116:b42abf0a50bc
51 /* from audio/mint */ 51 /* from audio/mint */
52 void SDL_MintAudio_CheckFpu(void); 52 void SDL_MintAudio_CheckFpu(void);
53 53
54 /* The first ticks value of the application */ 54 /* The first ticks value of the application */
55 static Uint32 start; 55 static Uint32 start;
56 static volatile SDL_bool supervisor; 56 static SDL_bool read_hz200_from_vbl = SDL_FALSE;
57 static int mint_present; /* can we use Syield() ? */ 57 static int mint_present; /* can we use Syield() ? */
58 58
59 void 59 void
60 SDL_StartTicks(void) 60 SDL_StartTicks(void)
61 { 61 {
73 } 73 }
74 74
75 Uint32 75 Uint32
76 SDL_GetTicks(void) 76 SDL_GetTicks(void)
77 { 77 {
78 Uint32 now; 78 Uint32 now = start;
79 void *oldpile = NULL;
80 79
81 /* Check if we are in supervisor mode 80 if (read_hz200_from_vbl) {
82 (this is the case when called from SDL_ThreadedTimerCheck, 81 now = SDL_Atari_hz200;
83 which is called from RunTimer, running in the vbl vector) 82 } else {
84 */ 83 void *old_stack = (void *)Super(0);
85 if (!supervisor) { 84 now = *((volatile long *)_hz_200);
86 oldpile = (void *) Super(0); 85 Super(old_stack);
87 }
88
89 now = *((volatile long *) _hz_200);
90
91 if (!supervisor) {
92 Super(oldpile);
93 } 86 }
94 87
95 return ((now * 5) - start); 88 return ((now * 5) - start);
96 } 89 }
97 90
109 } 102 }
110 103
111 /* Data to handle a single periodic alarm */ 104 /* Data to handle a single periodic alarm */
112 static SDL_bool timer_installed = SDL_FALSE; 105 static SDL_bool timer_installed = SDL_FALSE;
113 106
114 static void
115 RunTimer(void)
116 {
117 supervisor = SDL_TRUE;
118 SDL_ThreadedTimerCheck();
119 supervisor = SDL_FALSE;
120 }
121
122 /* This is only called if the event thread is not running */ 107 /* This is only called if the event thread is not running */
123 int 108 int
124 SDL_SYS_TimerInit(void) 109 SDL_SYS_TimerInit(void)
125 { 110 {
126 void *oldpile; 111 void *old_stack;
127
128 supervisor = SDL_FALSE;
129 112
130 SDL_MintAudio_CheckFpu(); 113 SDL_MintAudio_CheckFpu();
131 114
132 /* Install RunTimer in vbl vector */ 115 /* Install RunTimer in vbl vector */
133 oldpile = (void *) Super(0); 116 old_stack = (void *) Super(0);
134 timer_installed = !SDL_AtariVblInstall(RunTimer); 117 timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
135 Super(oldpile); 118 Super(old_stack);
136 119
137 if (!timer_installed) { 120 if (!timer_installed) {
138 return (-1); 121 return (-1);
139 } 122 }
123
124 read_hz200_from_vbl = SDL_TRUE;
140 return (SDL_SetTimerThreaded(0)); 125 return (SDL_SetTimerThreaded(0));
141 } 126 }
142 127
143 void 128 void
144 SDL_SYS_TimerQuit(void) 129 SDL_SYS_TimerQuit(void)
145 { 130 {
146 void *oldpile;
147
148 if (timer_installed) { 131 if (timer_installed) {
149 /* Uninstall RunTimer vbl vector */ 132 /* Uninstall RunTimer vbl vector */
150 oldpile = (void *) Super(0); 133 void *old_stack = (void *) Super(0);
151 SDL_AtariVblUninstall(RunTimer); 134 SDL_AtariVblUninstall(RunTimer);
152 Super(oldpile); 135 Super(old_stack);
153 timer_installed = SDL_FALSE; 136 timer_installed = SDL_FALSE;
154 } 137 }
138 read_hz200_from_vbl = SDL_FALSE;
155 } 139 }
156 140
157 int 141 int
158 SDL_SYS_StartTimer(void) 142 SDL_SYS_StartTimer(void)
159 { 143 {