Avoid switch to supervisor mode in SDL_GetTicks, by updating system counter from vbl interrupt SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Sat, 09 Jun 2007 19:52:05 +0000
branchSDL-1.2
changeset 395540b6b5744e05
parent 3954 649fba69eccd
child 3956 3868bebb9f5b
Avoid switch to supervisor mode in SDL_GetTicks, by updating system counter from vbl interrupt
src/timer/mint/SDL_systimer.c
src/timer/mint/SDL_vbltimer.S
src/timer/mint/SDL_vbltimer_s.h
     1.1 --- a/src/timer/mint/SDL_systimer.c	Fri Jun 08 21:44:40 2007 +0000
     1.2 +++ b/src/timer/mint/SDL_systimer.c	Sat Jun 09 19:52:05 2007 +0000
     1.3 @@ -53,18 +53,18 @@
     1.4  
     1.5  /* The first ticks value of the application */
     1.6  static Uint32 start;
     1.7 -static volatile SDL_bool supervisor;
     1.8 +static SDL_bool read_hz200_from_vbl = SDL_FALSE;
     1.9  static int mint_present; /* can we use Syield() ? */
    1.10  
    1.11  void SDL_StartTicks(void)
    1.12  {
    1.13 -	void *oldpile;
    1.14 +	void *old_stack;
    1.15  	unsigned long dummy;
    1.16  
    1.17  	/* Set first ticks value */
    1.18 -	oldpile=(void *)Super(0);
    1.19 -	start=*((volatile long *)_hz_200);
    1.20 -	Super(oldpile);
    1.21 +	old_stack = (void *)Super(0);
    1.22 +	start = *((volatile long *)_hz_200);
    1.23 +	Super(old_stack);
    1.24  
    1.25  	start *= 5;	/* One _hz_200 tic is 5ms */
    1.26  
    1.27 @@ -73,21 +73,14 @@
    1.28  
    1.29  Uint32 SDL_GetTicks (void)
    1.30  {
    1.31 -	Uint32 now;
    1.32 -	void *oldpile=NULL;
    1.33 +	Uint32 now = start;
    1.34  
    1.35 -	/* Check if we are in supervisor mode 
    1.36 -	   (this is the case when called from SDL_ThreadedTimerCheck,
    1.37 -	   which is called from RunTimer, running in the vbl vector)
    1.38 -	*/
    1.39 -	if (!supervisor) {
    1.40 -		oldpile=(void *)Super(0);
    1.41 -	}
    1.42 -
    1.43 -	now=*((volatile long *)_hz_200);
    1.44 -
    1.45 -	if (!supervisor) {
    1.46 -		Super(oldpile);
    1.47 +	if (read_hz200_from_vbl) {
    1.48 +		now = SDL_Atari_hz200;
    1.49 +	} else {
    1.50 +		void *old_stack = (void *)Super(0);
    1.51 +		now = *((volatile long *)_hz_200);
    1.52 +		Super(old_stack);
    1.53  	}
    1.54  
    1.55  	return((now*5)-start);
    1.56 @@ -108,44 +101,36 @@
    1.57  /* Data to handle a single periodic alarm */
    1.58  static SDL_bool timer_installed=SDL_FALSE;
    1.59  
    1.60 -static void RunTimer(void)
    1.61 -{
    1.62 -	supervisor=SDL_TRUE;
    1.63 -	SDL_ThreadedTimerCheck();
    1.64 -	supervisor=SDL_FALSE;
    1.65 -}
    1.66 -
    1.67  /* This is only called if the event thread is not running */
    1.68  int SDL_SYS_TimerInit(void)
    1.69  {
    1.70 -	void *oldpile;
    1.71 -
    1.72 -	supervisor=SDL_FALSE;
    1.73 +	void *old_stack;
    1.74  
    1.75  	SDL_MintAudio_CheckFpu();
    1.76  
    1.77  	/* Install RunTimer in vbl vector */
    1.78 -	oldpile=(void *)Super(0);
    1.79 -	timer_installed = !SDL_AtariVblInstall(RunTimer);
    1.80 -	Super(oldpile);
    1.81 +	old_stack = (void *)Super(0);
    1.82 +	timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
    1.83 +	Super(old_stack);
    1.84  
    1.85  	if (!timer_installed) {
    1.86  		return(-1);
    1.87  	}
    1.88 +
    1.89 +	read_hz200_from_vbl = SDL_TRUE;
    1.90  	return(SDL_SetTimerThreaded(0));
    1.91  }
    1.92  
    1.93  void SDL_SYS_TimerQuit(void)
    1.94  {
    1.95 -	void *oldpile;
    1.96 -
    1.97 +	/* Uninstall RunTimer vbl vector */
    1.98  	if (timer_installed) {
    1.99 -		/* Uninstall RunTimer vbl vector */
   1.100 -		oldpile=(void *)Super(0);
   1.101 -		SDL_AtariVblUninstall(RunTimer);
   1.102 -		Super(oldpile);
   1.103 +		void *old_stack = (void *)Super(0);
   1.104 +		SDL_AtariVblUninstall(SDL_ThreadedTimerCheck);
   1.105 +		Super(old_stack);
   1.106  		timer_installed = SDL_FALSE;
   1.107  	}
   1.108 +	read_hz200_from_vbl = SDL_FALSE;
   1.109  }
   1.110  
   1.111  int SDL_SYS_StartTimer(void)
     2.1 --- a/src/timer/mint/SDL_vbltimer.S	Fri Jun 08 21:44:40 2007 +0000
     2.2 +++ b/src/timer/mint/SDL_vbltimer.S	Sat Jun 09 19:52:05 2007 +0000
     2.3 @@ -27,6 +27,7 @@
     2.4   */
     2.5  
     2.6  #define _vbl_queue 0x456
     2.7 +#define _hz_200    0x4ba
     2.8  
     2.9  	.text
    2.10  
    2.11 @@ -42,6 +43,7 @@
    2.12  	lea		_my_vbl,a0
    2.13  
    2.14  	clrw	vbl_mutex
    2.15 +	movel	_hz_200.w, _SDL_Atari_hz200
    2.16  
    2.17  	/* Stop interrupts */
    2.18  
    2.19 @@ -108,6 +110,9 @@
    2.20  /*--- Our vbl ---*/
    2.21  
    2.22  _my_vbl:
    2.23 +	/* Update _hz_200 */
    2.24 +	movel	_hz_200.w, _SDL_Atari_hz200
    2.25 +
    2.26  	/* Verify if this is not already running */
    2.27  
    2.28  	tstw	vbl_mutex
    2.29 @@ -147,6 +152,8 @@
    2.30  
    2.31  	.data
    2.32  	.even
    2.33 +	.comm	_SDL_Atari_hz200,4*1
    2.34 +	.even
    2.35  	.comm	vbl_mutex,2*1
    2.36  	.even
    2.37  	.comm	my_vector,4*1
     3.1 --- a/src/timer/mint/SDL_vbltimer_s.h	Fri Jun 08 21:44:40 2007 +0000
     3.2 +++ b/src/timer/mint/SDL_vbltimer_s.h	Sat Jun 09 19:52:05 2007 +0000
     3.3 @@ -28,6 +28,8 @@
     3.4   *	Patrice Mandin
     3.5   */
     3.6  
     3.7 +extern volatile long SDL_Atari_hz200;
     3.8 +
     3.9  /* Functions prototypes */
    3.10  extern int SDL_AtariVblInstall(void *newvector);
    3.11  extern void SDL_AtariVblUninstall(void *newvector);