diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 093e5650f..d0021c2c9 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -53,6 +53,7 @@ #include "CommandMenu.hxx" #include "Serializable.hxx" #include "Version.hxx" +#include "TvMode.hxx" #ifdef DEBUGGER_SUPPORT #include "Debugger.hxx" @@ -116,9 +117,10 @@ Console::Console(OSystem& osystem, unique_ptr& cart, bool fastscbios = myOSystem.settings().getBool("fastscbios"); myOSystem.settings().setValue("fastscbios", true); mySystem->reset(true); // autodetect in reset enabled + myTIA->autodetectTvMode(true); for(int i = 0; i < 60; ++i) myTIA->update(); - myDisplayFormat = myTIA->isPAL() ? "PAL" : "NTSC"; + myDisplayFormat = myTIA->tvMode() == TvMode::pal ? "PAL" : "NTSC"; if(myProperties.get(Display_Format) == "AUTO") { autodetected = "*"; @@ -231,7 +233,7 @@ void Console::toggleFormat(int direction) { case 0: // auto-detect myTIA->update(); - myDisplayFormat = myTIA->isPAL() ? "PAL" : "NTSC"; + myDisplayFormat = myTIA->tvMode() == TvMode::pal ? "PAL" : "NTSC"; message = "Auto-detect mode: " + myDisplayFormat; saveformat = "AUTO"; break; @@ -546,12 +548,15 @@ void Console::setTIAProperties() if(height < 210 && height != 0) height = 210; else if(height > 256) height = 256; + myTIA->autodetectTvMode(false); + if(myDisplayFormat == "NTSC" || myDisplayFormat == "PAL60" || myDisplayFormat == "SECAM60") { // Assume we've got ~262 scanlines (NTSC-like format) myFramerate = 60.0; myConsoleInfo.InitialFrameRate = "60"; + myTIA->setTvMode(TvMode::ntsc); } else { @@ -561,6 +566,8 @@ void Console::setTIAProperties() // PAL ROMs normally need at least 250 lines if (height != 0) height = std::max(height, 250u); + + myTIA->setTvMode(TvMode::pal); } myTIA->setYStart(ystart); diff --git a/src/emucore/tia/FrameManager.cxx b/src/emucore/tia/FrameManager.cxx index dc8304702..a4b66bb14 100644 --- a/src/emucore/tia/FrameManager.cxx +++ b/src/emucore/tia/FrameManager.cxx @@ -45,11 +45,12 @@ static constexpr uInt32 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameManager::FrameManager() : myMode(TvMode::pal), + myAutodetectTvMode(true), myFixedHeight(0), myVblankMode(VblankMode::floating), myYstart(0) { - setTvMode(TvMode::ntsc); + updateTvMode(TvMode::ntsc); reset(); } @@ -265,6 +266,18 @@ uInt32 FrameManager::maxVisibleFrameLines() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameManager::setTvMode(TvMode mode) +{ + if (!myAutodetectTvMode) updateTvMode(mode); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameManager::autodetectTvMode(bool toggle) +{ + myAutodetectTvMode = toggle; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameManager::updateTvMode(TvMode mode) { if (mode == myMode) return; @@ -336,6 +349,16 @@ void FrameManager::finalizeFrame(FrameManager::State state) #endif // TIA_FRAMEMANAGER_DEBUG_LOG setState(state); + + if (myAutodetectTvMode) updateAutodetectedTvMode(); + + myFrameRate = (myMode == TvMode::pal ? 15600.0 : 15720.0) / + myCurrentFrameFinalLines; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameManager::updateAutodetectedTvMode() +{ if (myTotalFrames <= Metrics::initialGarbageFrames) { return; } @@ -347,16 +370,16 @@ void FrameManager::finalizeFrame(FrameManager::State state) deltaPAL = abs(Int32(myCurrentFrameFinalLines) - Int32(frameLinesPAL)); if (std::min(deltaNTSC, deltaPAL) <= Metrics::tvModeDetectionTolerance) - setTvMode(deltaNTSC <= deltaPAL ? TvMode::ntsc : TvMode::pal); + updateTvMode(deltaNTSC <= deltaPAL ? TvMode::ntsc : TvMode::pal); else if (!myModeConfirmed) { if ( (myCurrentFrameFinalLines < frameLinesPAL) && (myCurrentFrameFinalLines > frameLinesNTSC) && (myCurrentFrameFinalLines % 2) ) - setTvMode(TvMode::ntsc); + updateTvMode(TvMode::ntsc); else - setTvMode(deltaNTSC <= deltaPAL ? TvMode::ntsc : TvMode::pal); + updateTvMode(deltaNTSC <= deltaPAL ? TvMode::ntsc : TvMode::pal); } if (oldMode == myMode) @@ -366,9 +389,6 @@ void FrameManager::finalizeFrame(FrameManager::State state) if (myFramesInMode > Metrics::framesForModeConfirmation) myModeConfirmed = true; - - myFrameRate = (myMode == TvMode::pal ? 15600.0 : 15720.0) / - myCurrentFrameFinalLines; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/FrameManager.hxx b/src/emucore/tia/FrameManager.hxx index b78a191df..bef4a3fea 100644 --- a/src/emucore/tia/FrameManager.hxx +++ b/src/emucore/tia/FrameManager.hxx @@ -21,7 +21,7 @@ #include #include "Serializable.hxx" -#include "Types.hxx" +#include "TvMode.hxx" #include "bspf.hxx" class FrameManager : public Serializable @@ -71,6 +71,10 @@ class FrameManager : public Serializable uInt32 ystart() const; + void autodetectTvMode(bool toggle); + + void setTvMode(TvMode mode); + /** Serializable methods (see that class for more information). */ @@ -99,7 +103,9 @@ class FrameManager : public Serializable private: - void setTvMode(TvMode mode); + void updateTvMode(TvMode mode); + + void updateAutodetectedTvMode(); void setState(State state); @@ -113,6 +119,7 @@ class FrameManager : public Serializable callback myOnFrameComplete; TvMode myMode; + bool myAutodetectTvMode; State myState; uInt32 myLineInState; uInt32 myCurrentFrameTotalLines; diff --git a/src/emucore/tia/PaddleReader.hxx b/src/emucore/tia/PaddleReader.hxx index 4c9f0a78e..5c697497d 100644 --- a/src/emucore/tia/PaddleReader.hxx +++ b/src/emucore/tia/PaddleReader.hxx @@ -19,7 +19,7 @@ #define TIA_6502TS_CORE_PADDLE_READER #include "bspf.hxx" -#include "Types.hxx" +#include "TvMode.hxx" class PaddleReader { diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 93223c86d..bef657500 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -16,10 +16,8 @@ //============================================================================ #include "TIA.hxx" -#include "TIATypes.hxx" #include "M6502.hxx" #include "Console.hxx" -#include "Types.hxx" #ifdef DEBUGGER_SUPPORT #include "CartDebug.hxx" @@ -637,6 +635,24 @@ void TIA::setYStart(uInt32 ystart) myFrameManager.setYstart(ystart); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TIA::autodetectTvMode(bool toggle) +{ + myFrameManager.autodetectTvMode(toggle); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TIA::setTvMode(TvMode mode) +{ + myFrameManager.setTvMode(mode); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TvMode TIA::tvMode() const +{ + return myFrameManager.tvMode(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::enableAutoFrame(bool enabled) { @@ -649,12 +665,6 @@ void TIA::enableColorLoss(bool enabled) { } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool TIA::isPAL() const -{ - return myFrameManager.tvMode() == TvMode::pal; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // TODO: stub uInt32 TIA::clocksThisLine() const @@ -766,7 +776,7 @@ bool TIA::toggleFixedColors(uInt8 mode) // Otherwise, flip the state bool on = (mode == 0 || mode == 1) ? bool(mode) : myColorHBlank == 0; - bool pal = isPAL(); + bool pal = myFrameManager.tvMode() == TvMode::pal; myMissile0.setDebugColor(pal ? M0ColorPAL : M0ColorNTSC); myMissile1.setDebugColor(pal ? M1ColorPAL : M1ColorNTSC); myPlayer0.setDebugColor(pal ? P0ColorPAL : P0ColorNTSC); diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 45c924e8f..73d9d7b69 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -33,6 +33,7 @@ #include "Ball.hxx" #include "LatchedInput.hxx" #include "PaddleReader.hxx" +#include "TvMode.hxx" class Console; @@ -172,6 +173,10 @@ class TIA : public Device void setHeight(uInt32 height); void setYStart(uInt32 ystart); + void autodetectTvMode(bool toggle); + void setTvMode(TvMode mode); + TvMode tvMode() const; + /** Enables/disables auto-frame calculation. If enabled, the TIA re-adjusts the framerate at regular intervals. @@ -187,11 +192,6 @@ class TIA : public Device */ void enableColorLoss(bool enabled); - /** - Answers whether this TIA runs at NTSC or PAL scanrates. - */ - bool isPAL() const; - /** Answers the current color clock we've gotten to on this scanline. diff --git a/src/emucore/tia/Types.hxx b/src/emucore/tia/TvMode.hxx similarity index 100% rename from src/emucore/tia/Types.hxx rename to src/emucore/tia/TvMode.hxx