From c78b4b8a3ab9aefcce052219e2ef5a5087505ad8 Mon Sep 17 00:00:00 2001 From: dborth Date: Sat, 11 Oct 2008 06:15:20 +0000 Subject: [PATCH] new frameskip algorithm, update makefiles --- Makefile.gc | 3 ++- Makefile.wii | 3 ++- source/ngc/vbasupport.cpp | 39 +++++++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Makefile.gc b/Makefile.gc index 0ffb6a7..38352fe 100644 --- a/Makefile.gc +++ b/Makefile.gc @@ -26,7 +26,8 @@ INCLUDES := source/vba source/ngc #--------------------------------------------------------------------------------- CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) \ - -DNGC -DUSE_VM -DWORDS_BIGENDIAN -DC_CORE -DFINAL_VERSION \ + -DNGC -DUSE_VM -DWORDS_BIGENDIAN \ + -DC_CORE -D__ppc__ -D__POWERPC__ -DFINAL_VERSION \ -DSDL -DNO_PNG -DHAVE_ZUTIL_H CXXFLAGS = $(CFLAGS) LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map diff --git a/Makefile.wii b/Makefile.wii index c4557d2..90ad224 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -26,7 +26,8 @@ INCLUDES := source/vba source/ngc #--------------------------------------------------------------------------------- CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) \ - -DNGC -DWII_DVD -DWORDS_BIGENDIAN -DC_CORE -D__ppc__ -DFINAL_VERSION \ + -DNGC -DWII_DVD -DWORDS_BIGENDIAN -DVIDEO_THREADING \ + -DC_CORE -D__ppc__ -D__POWERPC__ -DFINAL_VERSION \ -DSDL -DNO_PNG -DHAVE_ZUTIL_H CXXFLAGS = $(CFLAGS) LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index 3bc6b4f..2610115 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -47,9 +47,6 @@ static tb_t start, now; u32 loadtimeradjust; -static u32 autoFrameSkipLastTime = 0; -static int frameskipadjust = 0; - int vAspect = 0; int hAspect = 0; @@ -132,20 +129,38 @@ void GC_Sleep(u32 dwMiliseconds) } } */ + +static u32 autoFrameSkipLastTime = 0; + void system10Frames(int rate) { - if ( cartridgeType == 1 ) + if (cartridgeType == 1) return; u32 time = systemGetClock(); u32 diff = time - autoFrameSkipLastTime; + + // difference should be 1/6 second or (1/6)*1000 ms or 167 ms + int timeOff = (167 - diff); + + if(timeOff > 3 && timeOff < 60) // we're running ahead! + usleep(timeOff*1000); // let's take a nap + else + timeOff = 0; // timeoff was not valid + + if(diff > 175 && systemFrameSkip < 9) + systemFrameSkip++; + else if(diff < 150 && systemFrameSkip > 0) + systemFrameSkip--; + + autoFrameSkipLastTime = time + timeOff; // total time = processing time + sleep time + + /* + // Original VBA SDL frameskip algorithm int speed = 100; if(diff) speed = (1000000/rate)/diff; - /* char temp[512]; - sprintf(temp,"Speed: %i",speed); - MENU_DrawString( -1, 450,temp , 1 ); */ if(speed >= 98) { @@ -174,6 +189,7 @@ void system10Frames(int rate) } autoFrameSkipLastTime = time; + */ } /**************************************************************************** @@ -518,15 +534,6 @@ void systemDrawScreen() { // GB / GBC Have oodles of time - so sync on VSync GX_Render( srcWidth, srcHeight, pix, srcPitch ); - - /*#ifdef HW_RVL - VIDEO_WaitVSync (); - #else - if ( cartridgeType == 1 ) - { - VIDEO_WaitVSync(); - } - #endif*/ } extern bool gbUpdateSizes();