Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Avoid switch to supervisor mode in SDL_GetTicks, by updating system c…
Browse files Browse the repository at this point in the history
…ounter from vbl interrupt
  • Loading branch information
pmandin committed Jun 9, 2007
1 parent a9a5be5 commit 87f0a38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
52 changes: 18 additions & 34 deletions src/timer/mint/SDL_systimer.c
Expand Up @@ -53,7 +53,7 @@ void SDL_MintAudio_CheckFpu(void);

/* The first ticks value of the application */
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() ? */

void
Expand All @@ -75,21 +75,14 @@ SDL_StartTicks(void)
Uint32
SDL_GetTicks(void)
{
Uint32 now;
void *oldpile = NULL;

/* Check if we are in supervisor mode
(this is the case when called from SDL_ThreadedTimerCheck,
which is called from RunTimer, running in the vbl vector)
*/
if (!supervisor) {
oldpile = (void *) Super(0);
}

now = *((volatile long *) _hz_200);

if (!supervisor) {
Super(oldpile);
Uint32 now = start;

if (read_hz200_from_vbl) {
now = SDL_Atari_hz200;
} else {
void *old_stack = (void *)Super(0);
now = *((volatile long *)_hz_200);
Super(old_stack);
}

return ((now * 5) - start);
Expand All @@ -111,47 +104,38 @@ SDL_Delay(Uint32 ms)
/* Data to handle a single periodic alarm */
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 */
int
SDL_SYS_TimerInit(void)
{
void *oldpile;

supervisor = SDL_FALSE;
void *old_stack;

SDL_MintAudio_CheckFpu();

/* Install RunTimer in vbl vector */
oldpile = (void *) Super(0);
timer_installed = !SDL_AtariVblInstall(RunTimer);
Super(oldpile);
old_stack = (void *) Super(0);
timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
Super(old_stack);

if (!timer_installed) {
return (-1);
}

read_hz200_from_vbl = SDL_TRUE;
return (SDL_SetTimerThreaded(0));
}

void
SDL_SYS_TimerQuit(void)
{
void *oldpile;

if (timer_installed) {
/* Uninstall RunTimer vbl vector */
oldpile = (void *) Super(0);
void *old_stack = (void *) Super(0);
SDL_AtariVblUninstall(RunTimer);
Super(oldpile);
Super(old_stack);
timer_installed = SDL_FALSE;
}
read_hz200_from_vbl = SDL_FALSE;
}

int
Expand Down
7 changes: 7 additions & 0 deletions src/timer/mint/SDL_vbltimer.S
Expand Up @@ -27,6 +27,7 @@
*/

#define _vbl_queue 0x456
#define _hz_200 0x4ba

.text

Expand All @@ -42,6 +43,7 @@ _SDL_AtariVblInstall:
lea _my_vbl,a0

clrw vbl_mutex
movel _hz_200.w, _SDL_Atari_hz200

/* Stop interrupts */

Expand Down Expand Up @@ -108,6 +110,9 @@ badvector:
/*--- Our vbl ---*/

_my_vbl:
/* Update _hz_200 */
movel _hz_200.w, _SDL_Atari_hz200

/* Verify if this is not already running */

tstw vbl_mutex
Expand Down Expand Up @@ -147,6 +152,8 @@ vbl_end:

.data
.even
.comm _SDL_Atari_hz200,4*1
.even
.comm vbl_mutex,2*1
.even
.comm my_vector,4*1
2 changes: 2 additions & 0 deletions src/timer/mint/SDL_vbltimer_s.h
Expand Up @@ -28,6 +28,8 @@
* Patrice Mandin
*/

extern volatile long SDL_Atari_hz200;

/* Functions prototypes */
extern int SDL_AtariVblInstall(void *newvector);
extern void SDL_AtariVblUninstall(void *newvector);
Expand Down

0 comments on commit 87f0a38

Please sign in to comment.