Skip to content

Commit

Permalink
Hard framerate cap of 35 fps using VBLCOUNTER (#61)
Browse files Browse the repository at this point in the history
* Hard framerate cap of 35 fps (VBLCOUNTER)

* modexlib.c: Fix no-return error

* Fix WaitVBL() not waiting the first time its called
  • Loading branch information
erysdren committed Jul 12, 2024
1 parent 94abaa1 commit 5330270
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion rott/modexlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "rt_net.h" // for GamePaused
#include "myprint.h"

#include "isr.h" // for VBLCOUNTER

static void StretchMemPicture ();
// GLOBAL VARIABLES

Expand Down Expand Up @@ -214,9 +216,29 @@ void TurnOffTextCursor ( void )
=
====================
*/

static Uint64 next_time = 0;

static Uint64 time_left(void)
{
Uint64 now = SDL_GetTicks();

if (next_time <= now)
return 0;
else
return next_time - now;
}

void WaitVBL( void )
{
SDL_Delay (16667/1000);
// was:
// SDL_Delay (16667/1000);

if (next_time == 0)
next_time = SDL_GetTicks() + VBLCOUNTER;

SDL_Delay(time_left());
next_time += VBLCOUNTER;
}

/*
Expand Down

0 comments on commit 5330270

Please sign in to comment.