From bd0393352e6b1247410febe52f59aa96820d8e08 Mon Sep 17 00:00:00 2001 From: stephena Date: Mon, 19 May 2008 21:16:58 +0000 Subject: [PATCH] Changed framerate timing to be based on the number of scanlines found in auto-detect mode. This fixes an issue with the latest JunoFirst beta, which had sound skipping because it has 266 scanlines but ran at 60fps (when it should have been ~59.09 fps or so). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1520 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/common/SoundNull.hxx | 6 ++-- stella/src/common/SoundSDL.cxx | 6 ++-- stella/src/common/SoundSDL.hxx | 8 +++--- stella/src/emucore/Console.cxx | 45 ++++++++++++++++++++---------- stella/src/emucore/Console.hxx | 8 +++--- stella/src/emucore/FrameBuffer.cxx | 4 +-- stella/src/emucore/OSystem.cxx | 6 ++-- stella/src/emucore/OSystem.hxx | 10 +++---- stella/src/emucore/Sound.hxx | 6 ++-- stella/src/emucore/TIA.cxx | 4 +-- 10 files changed, 59 insertions(+), 44 deletions(-) diff --git a/stella/src/common/SoundNull.hxx b/stella/src/common/SoundNull.hxx index 2f0ada4fb..45bfa1977 100644 --- a/stella/src/common/SoundNull.hxx +++ b/stella/src/common/SoundNull.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SoundNull.hxx,v 1.7 2008-02-06 13:45:19 stephena Exp $ +// $Id: SoundNull.hxx,v 1.8 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #ifndef SOUND_NULL_HXX @@ -31,7 +31,7 @@ class Deserializer; is completely disabled. @author Stephen Anthony - @version $Id: SoundNull.hxx,v 1.7 2008-02-06 13:45:19 stephena Exp $ + @version $Id: SoundNull.hxx,v 1.8 2008-05-19 21:16:58 stephena Exp $ */ class SoundNull : public Sound { @@ -77,7 +77,7 @@ class SoundNull : public Sound @param framerate The base framerate depending on NTSC or PAL ROM */ - void setFrameRate(uInt32 framerate) { } + void setFrameRate(float framerate) { } /** Initializes the sound device. This must be called before any diff --git a/stella/src/common/SoundSDL.cxx b/stella/src/common/SoundSDL.cxx index ab91fcb1c..a44875eab 100644 --- a/stella/src/common/SoundSDL.cxx +++ b/stella/src/common/SoundSDL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SoundSDL.cxx,v 1.42 2008-03-31 00:59:30 stephena Exp $ +// $Id: SoundSDL.cxx,v 1.43 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #ifdef SOUND_SUPPORT @@ -45,7 +45,7 @@ SoundSDL::SoundSDL(OSystem* osystem) myIsEnabled(osystem->settings().getBool("sound")), myIsInitializedFlag(false), myLastRegisterSetCycle(0), - myDisplayFrameRate(60), + myDisplayFrameRate(60.0), myNumChannels(1), myFragmentSizeLogBase2(0), myIsMuted(false), @@ -281,7 +281,7 @@ void SoundSDL::setChannels(uInt32 channels) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SoundSDL::setFrameRate(uInt32 framerate) +void SoundSDL::setFrameRate(float framerate) { // FIXME, we should clear out the queue or adjust the values in it myDisplayFrameRate = framerate; diff --git a/stella/src/common/SoundSDL.hxx b/stella/src/common/SoundSDL.hxx index f7251ca89..d6f39cdf4 100644 --- a/stella/src/common/SoundSDL.hxx +++ b/stella/src/common/SoundSDL.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SoundSDL.hxx,v 1.19 2008-02-06 13:45:19 stephena Exp $ +// $Id: SoundSDL.hxx,v 1.20 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #ifndef SOUND_SDL_HXX @@ -34,7 +34,7 @@ class OSystem; This class implements the sound API for SDL. @author Stephen Anthony and Bradford W. Mott - @version $Id: SoundSDL.hxx,v 1.19 2008-02-06 13:45:19 stephena Exp $ + @version $Id: SoundSDL.hxx,v 1.20 2008-05-19 21:16:58 stephena Exp $ */ class SoundSDL : public Sound { @@ -79,7 +79,7 @@ class SoundSDL : public Sound @param framerate The base framerate depending on NTSC or PAL ROM */ - void setFrameRate(uInt32 framerate); + void setFrameRate(float framerate); /** Initializes the sound device. This must be called before any @@ -253,7 +253,7 @@ class SoundSDL : public Sound Int32 myLastRegisterSetCycle; // Indicates the base framerate depending on if the ROM is NTSC or PAL - uInt32 myDisplayFrameRate; + float myDisplayFrameRate; // Indicates the number of channels (mono or stereo) uInt32 myNumChannels; diff --git a/stella/src/emucore/Console.cxx b/stella/src/emucore/Console.cxx index f2d9945a3..0fe2c7066 100644 --- a/stella/src/emucore/Console.cxx +++ b/stella/src/emucore/Console.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Console.cxx,v 1.143 2008-05-19 02:53:57 stephena Exp $ +// $Id: Console.cxx,v 1.144 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #include @@ -66,7 +66,7 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) myProperties(props), myAVox(0), myDisplayFormat("NTSC"), - myFramerate(60), + myFramerate(60.0), myUserPaletteDefined(false) { myControllers[0] = 0; @@ -126,6 +126,7 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) // Auto-detect NTSC/PAL mode if it's requested myDisplayFormat = myProperties.get(Display_Format); + float avgScanlineCount = 0.0; vidinfo << " Display Format: " << myDisplayFormat; if(myDisplayFormat == "AUTO-DETECT" || myOSystem->settings().getBool("rominfo")) @@ -136,14 +137,18 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) // Unfortunately, this means we have to always enable 'fastscbios', // since otherwise the BIOS loading will take over 250 frames! mySystem->reset(); - int palCount = 0; + int palCount = 0, scanlineCount = 0; for(int i = 0; i < 60; ++i) { myMediaSource->update(); - if(i >= 30 && myMediaSource->scanlines() > 285) - ++palCount; + if(i >= 30) + { + if(myMediaSource->scanlines() > 285) + ++palCount; + scanlineCount += myMediaSource->scanlines(); + } } - + avgScanlineCount = scanlineCount / 30.0; myDisplayFormat = (palCount >= 15) ? "PAL" : "NTSC"; if(myProperties.get(Display_Format) == "AUTO-DETECT") vidinfo << " ==> " << myDisplayFormat; @@ -156,13 +161,23 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props) if(myDisplayFormat == "NTSC" || myDisplayFormat == "PAL60" || myDisplayFormat == "SECAM60") { - // Assume we've got ~262 scanlines (NTSC-like format) - myFramerate = 60; + // Try to be as accurate as possible with the framerate + // Use the scanline count if available, otherwise assume we've got + // ~262 scanlines (NTSC-like format) + if(avgScanlineCount > 0.0) + myFramerate = 15720.0 / avgScanlineCount; + else + myFramerate = 60.0; } else { - // Assume we've got ~312 scanlines (PAL-like format) - myFramerate = 50; + // Try to be as accurate as possible with the framerate + // Use the scanline count if available, otherwise assume we've got + // ~312 scanlines (PAL-like format) + if(avgScanlineCount > 0.0) + myFramerate = 15600.0 / avgScanlineCount; + else + myFramerate = 50.0; if(myProperties.get(Display_Height) == "210") myProperties.set(Display_Height, "250"); @@ -262,7 +277,7 @@ void Console::toggleFormat() if(myDisplayFormat.compare(0, 4, "NTSC") == 0) { - if(myFramerate == 60) + if(myFramerate > 55.0) { format = "PAL60"; message = "PAL palette (PAL60)"; @@ -275,7 +290,7 @@ void Console::toggleFormat() } else if(myDisplayFormat.compare(0, 3, "PAL") == 0) { - if(myFramerate == 60) + if(myFramerate > 55.0) { format = "SECAM"; message = "SECAM palette (SECAM60)"; @@ -288,7 +303,7 @@ void Console::toggleFormat() } else if(myDisplayFormat.compare(0, 5, "SECAM") == 0) { - if(myFramerate == 60) + if(myFramerate > 55.0) { format = "NTSC"; message = "NTSC palette (NTSC)"; @@ -795,14 +810,14 @@ void Console::setColorLossPalette(bool loss) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 Console::getFramerate() const +float Console::getFramerate() const { // Set the correct framerate based on the format of the ROM // This can be overridden by changing the framerate in the // VideoDialog box or on the commandline, but it can't be saved // (ie, framerate is now solely determined based on ROM format). int framerate = myOSystem->settings().getInt("framerate"); - return framerate == -1 ? myFramerate : framerate; + return (float) framerate == -1 ? myFramerate : framerate; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/Console.hxx b/stella/src/emucore/Console.hxx index 0cbdf7bf1..9ed00b62a 100644 --- a/stella/src/emucore/Console.hxx +++ b/stella/src/emucore/Console.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Console.hxx,v 1.66 2008-05-08 20:23:31 stephena Exp $ +// $Id: Console.hxx,v 1.67 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #ifndef CONSOLE_HXX @@ -39,7 +39,7 @@ class System; This class represents the entire game console. @author Bradford W. Mott - @version $Id: Console.hxx,v 1.66 2008-05-08 20:23:31 stephena Exp $ + @version $Id: Console.hxx,v 1.67 2008-05-19 21:16:58 stephena Exp $ */ class Console : public Serializable { @@ -229,7 +229,7 @@ class Console : public Serializable Returns the framerate based on a number of factors (whether 'framerate' is set, what display format is in use, etc) */ - uInt32 getFramerate() const; + float getFramerate() const; /** Toggles the TIA bit specified in the method name. @@ -306,7 +306,7 @@ class Console : public Serializable string myDisplayFormat; // The currently defined display framerate - uInt32 myFramerate; + float myFramerate; // Indicates whether an external palette was found and // successfully loaded diff --git a/stella/src/emucore/FrameBuffer.cxx b/stella/src/emucore/FrameBuffer.cxx index 2174c15e5..8741802d6 100644 --- a/stella/src/emucore/FrameBuffer.cxx +++ b/stella/src/emucore/FrameBuffer.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBuffer.cxx,v 1.127 2008-04-02 21:22:16 stephena Exp $ +// $Id: FrameBuffer.cxx,v 1.128 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #include @@ -205,7 +205,7 @@ void FrameBuffer::showMessage(const string& message, MessagePosition position, // Precompute the message coordinates myMessage.text = message; - myMessage.counter = myOSystem->frameRate() << 1; // Show message for 2 seconds + myMessage.counter = uInt32(myOSystem->frameRate()) << 1; // Show message for 2 seconds myMessage.color = color; myMessage.w = myOSystem->font().getStringWidth(myMessage.text) + 10; diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index ef94fc358..96528a962 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: OSystem.cxx,v 1.125 2008-05-16 23:56:30 stephena Exp $ +// $Id: OSystem.cxx,v 1.126 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #include @@ -287,10 +287,10 @@ void OSystem::setBaseDir(const string& basedir) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void OSystem::setFramerate(uInt32 framerate) +void OSystem::setFramerate(float framerate) { myDisplayFrameRate = framerate; - myTimePerFrame = (uInt32)(1000000.0 / (double)myDisplayFrameRate); + myTimePerFrame = (uInt32)(1000000.0 / myDisplayFrameRate); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/OSystem.hxx b/stella/src/emucore/OSystem.hxx index ea7b63066..437920a9b 100644 --- a/stella/src/emucore/OSystem.hxx +++ b/stella/src/emucore/OSystem.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: OSystem.hxx,v 1.65 2008-05-16 23:56:30 stephena Exp $ +// $Id: OSystem.hxx,v 1.66 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #ifndef OSYSTEM_HXX @@ -56,7 +56,7 @@ typedef Common::Array ResolutionList; other objects belong. @author Stephen Anthony - @version $Id: OSystem.hxx,v 1.65 2008-05-16 23:56:30 stephena Exp $ + @version $Id: OSystem.hxx,v 1.66 2008-05-19 21:16:58 stephena Exp $ */ class OSystem { @@ -209,7 +209,7 @@ class OSystem @param framerate The video framerate to use */ - virtual void setFramerate(uInt32 framerate); + virtual void setFramerate(float framerate); /** Set all config file paths for the OSystem. @@ -226,7 +226,7 @@ class OSystem @return The video framerate currently in use */ - inline uInt32 frameRate() const { return myDisplayFrameRate; } + inline float frameRate() const { return myDisplayFrameRate; } /** Get the maximum dimensions of a window for the video hardware. @@ -492,7 +492,7 @@ class OSystem ResolutionList myResolutions; // Number of times per second to iterate through the main loop - uInt32 myDisplayFrameRate; + float myDisplayFrameRate; // Time per frame for a video update, based on the current framerate uInt32 myTimePerFrame; diff --git a/stella/src/emucore/Sound.hxx b/stella/src/emucore/Sound.hxx index 6b2a9a97d..98a2f4b91 100644 --- a/stella/src/emucore/Sound.hxx +++ b/stella/src/emucore/Sound.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Sound.hxx,v 1.24 2008-02-06 13:45:22 stephena Exp $ +// $Id: Sound.hxx,v 1.25 2008-05-19 21:16:58 stephena Exp $ //============================================================================ #ifndef SOUND_HXX @@ -30,7 +30,7 @@ class Deserializer; It has no functionality whatsoever. @author Stephen Anthony - @version $Id: Sound.hxx,v 1.24 2008-02-06 13:45:22 stephena Exp $ + @version $Id: Sound.hxx,v 1.25 2008-05-19 21:16:58 stephena Exp $ */ class Sound { @@ -75,7 +75,7 @@ class Sound @param framerate The base framerate depending on NTSC or PAL ROM */ - virtual void setFrameRate(uInt32 framerate) = 0; + virtual void setFrameRate(float framerate) = 0; /** Initializes the sound device. This must be called before any diff --git a/stella/src/emucore/TIA.cxx b/stella/src/emucore/TIA.cxx index 60c7e63fd..07a214c3f 100644 --- a/stella/src/emucore/TIA.cxx +++ b/stella/src/emucore/TIA.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TIA.cxx,v 1.91 2008-05-18 20:04:30 stephena Exp $ +// $Id: TIA.cxx,v 1.92 2008-05-19 21:16:58 stephena Exp $ //============================================================================ //#define DEBUG_HMOVE @@ -195,7 +195,7 @@ void TIA::reset() myFloatTIAOutputPins = mySettings.getBool("tiafloat"); - if(myConsole.getFramerate() > 55) // NTSC + if(myConsole.getFramerate() > 55.0) // NTSC { myColorLossEnabled = false; myMaximumNumberOfScanlines = 290;