From 533027002aeb02c52f1069b10e8943ed36a8ce28 Mon Sep 17 00:00:00 2001 From: erysdren Date: Fri, 12 Jul 2024 15:34:26 -0500 Subject: [PATCH] Hard framerate cap of 35 fps using VBLCOUNTER (#61) * Hard framerate cap of 35 fps (VBLCOUNTER) * modexlib.c: Fix no-return error * Fix WaitVBL() not waiting the first time its called --- rott/modexlib.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/rott/modexlib.c b/rott/modexlib.c index 7459f13..15a6bfd 100644 --- a/rott/modexlib.c +++ b/rott/modexlib.c @@ -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 @@ -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; } /*