From bca1afc555271849cdc7d76ef406226584a873c1 Mon Sep 17 00:00:00 2001 From: dborth Date: Sat, 18 Oct 2008 08:54:23 +0000 Subject: [PATCH] frameskipping changes, fix GB crash --- source/ngc/vbasupport.cpp | 32 +++++++++++++++++++++++++------- source/vba/dmg/GB.cpp | 3 ++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index 8c33f28..74196f9 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -140,15 +140,32 @@ void system10Frames(int rate) // 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! + if(timeOff > 0 && timeOff < 100) // we're running ahead! usleep(timeOff*1000); // let's take a nap else timeOff = 0; // timeoff was not valid - if(diff > 170 && systemFrameSkip < 9) - systemFrameSkip++; - else if(diff < 150 && systemFrameSkip > 0) - systemFrameSkip--; + // consider increasing skip + if(diff >= 230) + systemFrameSkip += 3; + else if(diff >= 200) + systemFrameSkip += 2; + else if(diff >= 170) + systemFrameSkip += 1; + + // consider decreasing skip + else if(diff <= 90) + systemFrameSkip -= 3; + else if(diff <= 120) + systemFrameSkip -= 2; + else if(diff <= 150) + systemFrameSkip -= 1; + + // correct invalid frame skip values + if(systemFrameSkip > 20) + systemFrameSkip = 20; + else if(systemFrameSkip < 0) + systemFrameSkip = 0; autoFrameSkipLastTime = time + timeOff; // total time = processing time + sleep time @@ -623,7 +640,7 @@ bool LoadVBAROM(int method) //WaitPrompt("GameBoy Image"); cartridgeType = 1; emulator = GBSystem; - + gbBorderOn = 0; if(gbBorderOn) @@ -675,9 +692,10 @@ bool LoadVBAROM(int method) // used for the handling of the gb Boot Rom //if (gbHardware & 5) //gbCPUInit(gbBiosFileName, useBios); - + gbSoundReset(); gbSoundSetQuality(soundQuality); + gbSoundSetDeclicking(true); gbReset(); } else diff --git a/source/vba/dmg/GB.cpp b/source/vba/dmg/GB.cpp index ccbbcf8..e5429db 100644 --- a/source/vba/dmg/GB.cpp +++ b/source/vba/dmg/GB.cpp @@ -4026,7 +4026,8 @@ void gbCleanUp() } if(pix != NULL) { - free(pix); + // this causes system to CRASH when switching from GB to GBA and then back to GB + //free(pix); pix = NULL; }