Hook up new ystart autodetection.

This commit is contained in:
Christian Speckner 2017-10-12 00:02:31 +02:00
parent dc5c68bb80
commit 23c2901d14
6 changed files with 77 additions and 73 deletions

View File

@ -80,7 +80,8 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
myCart(std::move(cart)),
myDisplayFormat(""), // Unknown TV format @ start
myFramerate(0.0), // Unknown framerate @ start
myCurrentFormat(0), // Unknown format @ start
myCurrentFormat(0), // Unknown format @ start,
myAutodetectedYstart(0),
myUserPaletteDefined(false),
myConsoleTiming(ConsoleTiming::ntsc)
{
@ -120,43 +121,17 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
if(myDisplayFormat == "AUTO" || myOSystem.settings().getBool("rominfo"))
{
// Run the TIA, looking for PAL scanline patterns
// We turn off the SuperCharger progress bars, otherwise the SC BIOS
// will take over 250 frames!
// The 'fastscbios' option must be changed before the system is reset
bool fastscbios = myOSystem.settings().getBool("fastscbios");
myOSystem.settings().setValue("fastscbios", true);
FrameLayoutDetector frameLayoutDetector;
myTIA->setFrameManager(&frameLayoutDetector);
mySystem->reset(true);
for(int i = 0; i < 60; ++i) myTIA->update();
myTIA->setFrameManager(myFrameManager.get());
myDisplayFormat = frameLayoutDetector.detectedLayout() == FrameLayout::pal ? "PAL" : "NTSC";
autodetectFrameLayout();
if(myProperties.get(Display_Format) == "AUTO")
{
autodetected = "*";
myCurrentFormat = 0;
}
}
// Don't forget to reset the SC progress bars again
myOSystem.settings().setValue("fastscbios", fastscbios);
// TODO: move! move! move! (temporary for testing)
YStartDetector ystartDetector;
ystartDetector.setLayout(frameLayoutDetector.detectedLayout());
myTIA->setFrameManager(&ystartDetector);
mySystem->reset();
for (int i = 0; i < 80; i++) myTIA->update();
myTIA->setFrameManager(myFrameManager.get());
(cout << "detected ystart value: " << ystartDetector.detectedYStart() << std::endl).flush();
if (atoi(myProperties.get(Display_YStart).c_str()) == 0) {
autodetectYStart();
}
myConsoleInfo.DisplayFormat = myDisplayFormat + autodetected;
@ -232,6 +207,54 @@ Console::~Console()
myRightControl->close();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Console::autodetectFrameLayout()
{
// Run the TIA, looking for PAL scanline patterns
// We turn off the SuperCharger progress bars, otherwise the SC BIOS
// will take over 250 frames!
// The 'fastscbios' option must be changed before the system is reset
bool fastscbios = myOSystem.settings().getBool("fastscbios");
myOSystem.settings().setValue("fastscbios", true);
FrameLayoutDetector frameLayoutDetector;
myTIA->setFrameManager(&frameLayoutDetector);
mySystem->reset(true);
for(int i = 0; i < 60; ++i) myTIA->update();
myTIA->setFrameManager(myFrameManager.get());
myDisplayFormat = frameLayoutDetector.detectedLayout() == FrameLayout::pal ? "PAL" : "NTSC";
// Don't forget to reset the SC progress bars again
myOSystem.settings().setValue("fastscbios", fastscbios);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Console::autodetectYStart()
{
// We turn off the SuperCharger progress bars, otherwise the SC BIOS
// will take over 250 frames!
// The 'fastscbios' option must be changed before the system is reset
bool fastscbios = myOSystem.settings().getBool("fastscbios");
myOSystem.settings().setValue("fastscbios", true);
YStartDetector ystartDetector;
ystartDetector.setLayout(myDisplayFormat == "PAL" ? FrameLayout::pal : FrameLayout::ntsc);
myTIA->setFrameManager(&ystartDetector);
mySystem->reset();
for (int i = 0; i < 80; i++) myTIA->update();
myTIA->setFrameManager(myFrameManager.get());
myAutodetectedYstart = ystartDetector.detectedYStart();
// Don't forget to reset the SC progress bars again
myOSystem.settings().setValue("fastscbios", fastscbios);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Console::save(Serializer& out) const
{
@ -593,11 +616,17 @@ void Console::changeYStart(int direction)
}
else if(direction == -1) // decrease YStart
{
if(ystart == TIAConstants::minYStart-1)
if (ystart == TIAConstants::minYStart && myAutodetectedYstart == 0) {
myOSystem.frameBuffer().showMessage("Autodetected YStart not available");
return;
}
if(ystart == TIAConstants::minYStart-1 && myAutodetectedYstart > 0)
{
myOSystem.frameBuffer().showMessage("YStart at minimum");
return;
}
ystart--;
}
else
@ -609,7 +638,7 @@ void Console::changeYStart(int direction)
myOSystem.frameBuffer().showMessage("YStart autodetected");
else
{
if(myTIA->ystartIsAuto(ystart))
if(myAutodetectedYstart > 0 && myAutodetectedYstart == ystart)
{
// We've reached the auto-detect value, so reset
myOSystem.frameBuffer().showMessage("YStart " + val.str() + " (Auto)");
@ -688,7 +717,7 @@ void Console::setTIAProperties()
myTIA->setLayout(FrameLayout::pal);
}
myTIA->setYStart(ystart);
myTIA->setYStart(ystart != 0 ? ystart : myAutodetectedYstart);
myTIA->setHeight(height);
}

View File

@ -305,6 +305,16 @@ class Console : public Serializable
void toggleJitter() const;
private:
/**
* Dry-run the emulation and detect the frame layout (PAL / NTSC).
*/
void autodetectFrameLayout();
/**
* Dryrun the emulation and detect ystart (the first visible scanline).
*/
void autodetectYStart();
/**
Sets various properties of the TIA (YStart, Height, etc) based on
the current display format.
@ -385,6 +395,9 @@ class Console : public Serializable
// Display format currently in use
uInt32 myCurrentFormat;
// Autodetected ystart.
uInt32 myAutodetectedYstart;
// Indicates whether an external palette was found and
// successfully loaded
bool myUserPaletteDefined;

View File

@ -206,7 +206,6 @@ class TIA : public Device
uInt32 width() const { return 160; }
uInt32 height() const { return myFrameManager->height(); }
uInt32 ystart() const { return myFrameManager->ystart(); }
bool ystartIsAuto(uInt32 line) const { return myFrameManager->ystartIsAuto(line); }
/**
Changes the current Height/YStart properties.

View File

@ -185,11 +185,6 @@ class AbstractFrameManager : public Serializable
*/
virtual uInt32 ystart() const { return 0; }
/**
* TODO: this looks pretty weird --- does this actually work?
*/
virtual bool ystartIsAuto(uInt32 line) const { return false; }
/**
* Set the frame layout. This may be a noop (on the autodetection manager).
*/

View File

@ -57,9 +57,6 @@ void FrameManager::onReset()
myVsyncLines = 0;
myY = 0;
myFramePending = false;
myStabilizationFrames = 0;
myStableFrames = 0;
myHasStabilized = false;
myStableFrameLines = -1;
myStableFrameHeightCountdown = 0;
@ -158,21 +155,6 @@ void FrameManager::setState(FrameManager::State state)
switch (myState) {
case State::waitForFrameStart:
if (!myHasStabilized) {
myHasStabilized =
myStableFrames >= Metrics::minStableFrames ||
myStabilizationFrames >= Metrics::maxStabilizationFrames;
updateIsRendering();
myStabilizationFrames++;
if (myVblankManager.isStable())
myStableFrames++;
else
myStableFrames = 0;
}
if (myFramePending) finalizeFrame();
notifyFrameStart();
@ -297,7 +279,7 @@ void FrameManager::enableJitter(bool enabled)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameManager::updateIsRendering() {
myIsRendering = myState == State::frame && myHasStabilized;
myIsRendering = myState == State::frame;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -312,10 +294,6 @@ bool FrameManager::onSave(Serializer& out) const
out.putInt(myLastY);
out.putBool(myFramePending);
out.putInt(myStableFrames);
out.putInt(myStabilizationFrames);
out.putBool(myHasStabilized);
out.putInt(myVblankLines);
out.putInt(myKernelLines);
out.putInt(myOverscanLines);
@ -343,10 +321,6 @@ bool FrameManager::onLoad(Serializer& in)
myLastY = in.getInt();
myFramePending = in.getBool();
myStableFrames = in.getInt();
myStabilizationFrames = in.getInt();
myHasStabilized = in.getBool();
myVblankLines = in.getInt();
myKernelLines = in.getInt();
myOverscanLines = in.getInt();

View File

@ -50,8 +50,6 @@ class FrameManager: public AbstractFrameManager {
uInt32 ystart() const override { return myVblankManager.ystart(); }
bool ystartIsAuto(uInt32 line) const override { return myVblankManager.ystartIsAuto(line); };
void setLayout(FrameLayout mode) override { layout(mode); }
void onSetVblank() override;
@ -103,10 +101,6 @@ class FrameManager: public AbstractFrameManager {
uInt32 myY, myLastY;
bool myFramePending;
uInt32 myStableFrames;
uInt32 myStabilizationFrames;
bool myHasStabilized;
uInt32 myVblankLines;
uInt32 myKernelLines;
uInt32 myOverscanLines;