Avoid switch to supervisor mode in SDL_GetTicks, by updating system counter from vbl interrupt
authorPatrice Mandin <patmandin@gmail.com>
Sat, 09 Jun 2007 19:58:41 +0000
changeset 2116b42abf0a50bc
parent 2115 502ae1f2a577
child 2117 40888832d785
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:55 2007 +0000
     1.2 +++ b/src/timer/mint/SDL_systimer.c	Sat Jun 09 19:58:41 2007 +0000
     1.3 @@ -53,7 +53,7 @@
     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
    1.12 @@ -75,21 +75,14 @@
    1.13  Uint32
    1.14  SDL_GetTicks(void)
    1.15  {
    1.16 -    Uint32 now;
    1.17 -    void *oldpile = NULL;
    1.18 +    Uint32 now = start;
    1.19  
    1.20 -    /* Check if we are in supervisor mode 
    1.21 -       (this is the case when called from SDL_ThreadedTimerCheck,
    1.22 -       which is called from RunTimer, running in the vbl vector)
    1.23 -     */
    1.24 -    if (!supervisor) {
    1.25 -        oldpile = (void *) Super(0);
    1.26 -    }
    1.27 -
    1.28 -    now = *((volatile long *) _hz_200);
    1.29 -
    1.30 -    if (!supervisor) {
    1.31 -        Super(oldpile);
    1.32 +    if (read_hz200_from_vbl) {
    1.33 +        now = SDL_Atari_hz200;
    1.34 +    } else {
    1.35 +        void *old_stack = (void *)Super(0);
    1.36 +        now = *((volatile long *)_hz_200);
    1.37 +        Super(old_stack);
    1.38      }
    1.39  
    1.40      return ((now * 5) - start);
    1.41 @@ -111,47 +104,38 @@
    1.42  /* Data to handle a single periodic alarm */
    1.43  static SDL_bool timer_installed = SDL_FALSE;
    1.44  
    1.45 -static void
    1.46 -RunTimer(void)
    1.47 -{
    1.48 -    supervisor = SDL_TRUE;
    1.49 -    SDL_ThreadedTimerCheck();
    1.50 -    supervisor = SDL_FALSE;
    1.51 -}
    1.52 -
    1.53  /* This is only called if the event thread is not running */
    1.54  int
    1.55  SDL_SYS_TimerInit(void)
    1.56  {
    1.57 -    void *oldpile;
    1.58 -
    1.59 -    supervisor = SDL_FALSE;
    1.60 +    void *old_stack;
    1.61  
    1.62      SDL_MintAudio_CheckFpu();
    1.63  
    1.64      /* Install RunTimer in vbl vector */
    1.65 -    oldpile = (void *) Super(0);
    1.66 -    timer_installed = !SDL_AtariVblInstall(RunTimer);
    1.67 -    Super(oldpile);
    1.68 +    old_stack = (void *) Super(0);
    1.69 +    timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
    1.70 +    Super(old_stack);
    1.71  
    1.72      if (!timer_installed) {
    1.73          return (-1);
    1.74      }
    1.75 +
    1.76 +    read_hz200_from_vbl = SDL_TRUE;
    1.77      return (SDL_SetTimerThreaded(0));
    1.78  }
    1.79  
    1.80  void
    1.81  SDL_SYS_TimerQuit(void)
    1.82  {
    1.83 -    void *oldpile;
    1.84 -
    1.85      if (timer_installed) {
    1.86          /* Uninstall RunTimer vbl vector */
    1.87 -        oldpile = (void *) Super(0);
    1.88 +        void *old_stack = (void *) Super(0);
    1.89          SDL_AtariVblUninstall(RunTimer);
    1.90 -        Super(oldpile);
    1.91 +        Super(old_stack);
    1.92          timer_installed = SDL_FALSE;
    1.93      }
    1.94 +    read_hz200_from_vbl = SDL_FALSE;
    1.95  }
    1.96  
    1.97  int
     2.1 --- a/src/timer/mint/SDL_vbltimer.S	Fri Jun 08 21:44:55 2007 +0000
     2.2 +++ b/src/timer/mint/SDL_vbltimer.S	Sat Jun 09 19:58:41 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:55 2007 +0000
     3.2 +++ b/src/timer/mint/SDL_vbltimer_s.h	Sat Jun 09 19:58:41 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);