Enable manual TV mode selection:

* Make mode autodetection in FrameManager conditional, disable by
      default
    * Add glue for externally setting up TV mode
    * Properly setup TIA TV mode in Console
    * Refactoring
This commit is contained in:
Christian Speckner 2017-01-10 01:19:22 +01:00
parent ef000d2ae5
commit a6725f2436
7 changed files with 70 additions and 26 deletions

View File

@ -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<Cartridge>& 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);

View File

@ -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;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -21,7 +21,7 @@
#include <functional>
#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;

View File

@ -19,7 +19,7 @@
#define TIA_6502TS_CORE_PADDLE_READER
#include "bspf.hxx"
#include "Types.hxx"
#include "TvMode.hxx"
class PaddleReader
{

View File

@ -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);

View File

@ -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.