Avoid switch to supervisor mode in SDL_GetTicks, by updating system counter from vbl interrupt
--HG-- branch : SDL-1.2 extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402337
This commit is contained in:
parent
ebf84b70dd
commit
32a4452933
3 changed files with 32 additions and 38 deletions
|
@ -53,18 +53,18 @@ void SDL_MintAudio_CheckFpu(void);
|
||||||
|
|
||||||
/* The first ticks value of the application */
|
/* The first ticks value of the application */
|
||||||
static Uint32 start;
|
static Uint32 start;
|
||||||
static volatile SDL_bool supervisor;
|
static SDL_bool read_hz200_from_vbl = SDL_FALSE;
|
||||||
static int mint_present; /* can we use Syield() ? */
|
static int mint_present; /* can we use Syield() ? */
|
||||||
|
|
||||||
void SDL_StartTicks(void)
|
void SDL_StartTicks(void)
|
||||||
{
|
{
|
||||||
void *oldpile;
|
void *old_stack;
|
||||||
unsigned long dummy;
|
unsigned long dummy;
|
||||||
|
|
||||||
/* Set first ticks value */
|
/* Set first ticks value */
|
||||||
oldpile=(void *)Super(0);
|
old_stack = (void *)Super(0);
|
||||||
start=*((volatile long *)_hz_200);
|
start = *((volatile long *)_hz_200);
|
||||||
Super(oldpile);
|
Super(old_stack);
|
||||||
|
|
||||||
start *= 5; /* One _hz_200 tic is 5ms */
|
start *= 5; /* One _hz_200 tic is 5ms */
|
||||||
|
|
||||||
|
@ -73,21 +73,14 @@ void SDL_StartTicks(void)
|
||||||
|
|
||||||
Uint32 SDL_GetTicks (void)
|
Uint32 SDL_GetTicks (void)
|
||||||
{
|
{
|
||||||
Uint32 now;
|
Uint32 now = start;
|
||||||
void *oldpile=NULL;
|
|
||||||
|
|
||||||
/* Check if we are in supervisor mode
|
if (read_hz200_from_vbl) {
|
||||||
(this is the case when called from SDL_ThreadedTimerCheck,
|
now = SDL_Atari_hz200;
|
||||||
which is called from RunTimer, running in the vbl vector)
|
} else {
|
||||||
*/
|
void *old_stack = (void *)Super(0);
|
||||||
if (!supervisor) {
|
now = *((volatile long *)_hz_200);
|
||||||
oldpile=(void *)Super(0);
|
Super(old_stack);
|
||||||
}
|
|
||||||
|
|
||||||
now=*((volatile long *)_hz_200);
|
|
||||||
|
|
||||||
if (!supervisor) {
|
|
||||||
Super(oldpile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return((now*5)-start);
|
return((now*5)-start);
|
||||||
|
@ -108,44 +101,36 @@ void SDL_Delay (Uint32 ms)
|
||||||
/* Data to handle a single periodic alarm */
|
/* Data to handle a single periodic alarm */
|
||||||
static SDL_bool timer_installed=SDL_FALSE;
|
static SDL_bool timer_installed=SDL_FALSE;
|
||||||
|
|
||||||
static void RunTimer(void)
|
|
||||||
{
|
|
||||||
supervisor=SDL_TRUE;
|
|
||||||
SDL_ThreadedTimerCheck();
|
|
||||||
supervisor=SDL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is only called if the event thread is not running */
|
/* This is only called if the event thread is not running */
|
||||||
int SDL_SYS_TimerInit(void)
|
int SDL_SYS_TimerInit(void)
|
||||||
{
|
{
|
||||||
void *oldpile;
|
void *old_stack;
|
||||||
|
|
||||||
supervisor=SDL_FALSE;
|
|
||||||
|
|
||||||
SDL_MintAudio_CheckFpu();
|
SDL_MintAudio_CheckFpu();
|
||||||
|
|
||||||
/* Install RunTimer in vbl vector */
|
/* Install RunTimer in vbl vector */
|
||||||
oldpile=(void *)Super(0);
|
old_stack = (void *)Super(0);
|
||||||
timer_installed = !SDL_AtariVblInstall(RunTimer);
|
timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
|
||||||
Super(oldpile);
|
Super(old_stack);
|
||||||
|
|
||||||
if (!timer_installed) {
|
if (!timer_installed) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read_hz200_from_vbl = SDL_TRUE;
|
||||||
return(SDL_SetTimerThreaded(0));
|
return(SDL_SetTimerThreaded(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_SYS_TimerQuit(void)
|
void SDL_SYS_TimerQuit(void)
|
||||||
{
|
{
|
||||||
void *oldpile;
|
/* Uninstall RunTimer vbl vector */
|
||||||
|
|
||||||
if (timer_installed) {
|
if (timer_installed) {
|
||||||
/* Uninstall RunTimer vbl vector */
|
void *old_stack = (void *)Super(0);
|
||||||
oldpile=(void *)Super(0);
|
SDL_AtariVblUninstall(SDL_ThreadedTimerCheck);
|
||||||
SDL_AtariVblUninstall(RunTimer);
|
Super(old_stack);
|
||||||
Super(oldpile);
|
|
||||||
timer_installed = SDL_FALSE;
|
timer_installed = SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
read_hz200_from_vbl = SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDL_SYS_StartTimer(void)
|
int SDL_SYS_StartTimer(void)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _vbl_queue 0x456
|
#define _vbl_queue 0x456
|
||||||
|
#define _hz_200 0x4ba
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ _SDL_AtariVblInstall:
|
||||||
lea _my_vbl,a0
|
lea _my_vbl,a0
|
||||||
|
|
||||||
clrw vbl_mutex
|
clrw vbl_mutex
|
||||||
|
movel _hz_200.w, _SDL_Atari_hz200
|
||||||
|
|
||||||
/* Stop interrupts */
|
/* Stop interrupts */
|
||||||
|
|
||||||
|
@ -108,6 +110,9 @@ badvector:
|
||||||
/*--- Our vbl ---*/
|
/*--- Our vbl ---*/
|
||||||
|
|
||||||
_my_vbl:
|
_my_vbl:
|
||||||
|
/* Update _hz_200 */
|
||||||
|
movel _hz_200.w, _SDL_Atari_hz200
|
||||||
|
|
||||||
/* Verify if this is not already running */
|
/* Verify if this is not already running */
|
||||||
|
|
||||||
tstw vbl_mutex
|
tstw vbl_mutex
|
||||||
|
@ -147,6 +152,8 @@ vbl_end:
|
||||||
|
|
||||||
.data
|
.data
|
||||||
.even
|
.even
|
||||||
|
.comm _SDL_Atari_hz200,4*1
|
||||||
|
.even
|
||||||
.comm vbl_mutex,2*1
|
.comm vbl_mutex,2*1
|
||||||
.even
|
.even
|
||||||
.comm my_vector,4*1
|
.comm my_vector,4*1
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
* Patrice Mandin
|
* Patrice Mandin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern volatile long SDL_Atari_hz200;
|
||||||
|
|
||||||
/* Functions prototypes */
|
/* Functions prototypes */
|
||||||
extern int SDL_AtariVblInstall(void *newvector);
|
extern int SDL_AtariVblInstall(void *newvector);
|
||||||
extern void SDL_AtariVblUninstall(void *newvector);
|
extern void SDL_AtariVblUninstall(void *newvector);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue