From e129391dbdac8b89e8c4608c90f187c50ce75c5c Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 9 Sep 2018 23:30:20 +0200 Subject: [PATCH] Fixes, properly handle TV format any ystart changes from GUI. --- src/emucore/Console.cxx | 28 +++++++++++++++---- src/emucore/Console.hxx | 9 ++++-- .../frame-manager/AbstractFrameManager.cxx | 1 - .../tia/frame-manager/FrameLayoutDetector.cxx | 6 ++++ .../tia/frame-manager/FrameLayoutDetector.hxx | 2 +- .../tia/frame-manager/FrameManager.cxx | 1 + .../tia/frame-manager/YStartDetector.cxx | 6 ++++ .../tia/frame-manager/YStartDetector.hxx | 2 +- src/gui/GameInfoDialog.cxx | 8 ++---- 9 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index c3dd0082e..c79f76780 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -216,7 +216,7 @@ Console::~Console() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::autodetectFrameLayout() +void Console::autodetectFrameLayout(bool reset) { // Run the TIA, looking for PAL scanline patterns // We turn off the SuperCharger progress bars, otherwise the SC BIOS @@ -227,7 +227,8 @@ void Console::autodetectFrameLayout() FrameLayoutDetector frameLayoutDetector; myTIA->setFrameManager(&frameLayoutDetector); - mySystem->reset(true); + + if (reset) mySystem->reset(true); for(int i = 0; i < 60; ++i) myTIA->update(); @@ -247,7 +248,7 @@ void Console::redetectFrameLayout() myOSystem.sound().close(); save(s); - autodetectFrameLayout(); + autodetectFrameLayout(false); if (myYStartAutodetected) autodetectYStart(); load(s); @@ -255,7 +256,7 @@ void Console::redetectFrameLayout() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::autodetectYStart() +void Console::autodetectYStart(bool reset) { // We turn off the SuperCharger progress bars, otherwise the SC BIOS // will take over 250 frames! @@ -266,7 +267,8 @@ void Console::autodetectYStart() YStartDetector ystartDetector; ystartDetector.setLayout(myDisplayFormat == "PAL" ? FrameLayout::pal : FrameLayout::ntsc); myTIA->setFrameManager(&ystartDetector); - mySystem->reset(true); + + if (reset) mySystem->reset(true); for (int i = 0; i < 80; i++) myTIA->update(); @@ -288,7 +290,7 @@ void Console::redetectYStart() myOSystem.sound().close(); save(s); - autodetectYStart(); + autodetectYStart(false); load(s); initializeAudio(); @@ -718,6 +720,20 @@ void Console::changeYStart(int direction) myTIA->frameReset(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Console::updateYStart(uInt32 ystart) +{ + if (ystart == TIAConstants::minYStart-1 && !myYStartAutodetected) { + redetectYStart(); + ystart = myAutodetectedYstart; + } else if (ystart <= TIAConstants::maxYStart) myYStartAutodetected = false; + + if (ystart <= TIAConstants::maxYStart) { + myTIA->setYStart(ystart); + myTIA->frameReset(); + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::changeHeight(int direction) { diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index 11166b3ca..fdf37de64 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -304,16 +304,21 @@ class Console : public Serializable */ void toggleJitter() const; + /** + * Update yatart and run autodetection if necessary. + */ + void updateYStart(uInt32 ystart); + private: /** * Dry-run the emulation and detect the frame layout (PAL / NTSC). */ - void autodetectFrameLayout(); + void autodetectFrameLayout(bool reset = true); /** * Dryrun the emulation and detect ystart (the first visible scanline). */ - void autodetectYStart(); + void autodetectYStart(bool reset = true); /** * Rerun frame layout autodetection diff --git a/src/emucore/tia/frame-manager/AbstractFrameManager.cxx b/src/emucore/tia/frame-manager/AbstractFrameManager.cxx index 85a269057..b82042ae3 100644 --- a/src/emucore/tia/frame-manager/AbstractFrameManager.cxx +++ b/src/emucore/tia/frame-manager/AbstractFrameManager.cxx @@ -24,7 +24,6 @@ AbstractFrameManager::AbstractFrameManager() : myOnFrameComplete(nullptr) { layout(FrameLayout::ntsc); - reset(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx index 301759843..1168a51cb 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx @@ -42,6 +42,12 @@ FrameLayout FrameLayoutDetector::detectedLayout() const{ return myPalFrames > myNtscFrames ? FrameLayout::pal : FrameLayout::ntsc; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +FrameLayoutDetector::FrameLayoutDetector() +{ + reset(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameLayoutDetector::onReset() { diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx index 42c0ca030..39fbc51b5 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.hxx @@ -28,7 +28,7 @@ class FrameLayoutDetector: public AbstractFrameManager { public: - FrameLayoutDetector() = default; + FrameLayoutDetector(); public: diff --git a/src/emucore/tia/frame-manager/FrameManager.cxx b/src/emucore/tia/frame-manager/FrameManager.cxx index bcbc5685c..da6f1b040 100644 --- a/src/emucore/tia/frame-manager/FrameManager.cxx +++ b/src/emucore/tia/frame-manager/FrameManager.cxx @@ -49,6 +49,7 @@ FrameManager::FrameManager() myYStart(0), myJitterEnabled(false) { + reset(); onLayoutChange(); } diff --git a/src/emucore/tia/frame-manager/YStartDetector.cxx b/src/emucore/tia/frame-manager/YStartDetector.cxx index 8673e01b1..5d7fe50b0 100644 --- a/src/emucore/tia/frame-manager/YStartDetector.cxx +++ b/src/emucore/tia/frame-manager/YStartDetector.cxx @@ -46,6 +46,12 @@ enum Metrics: uInt32 { initialGarbageFrames = TIAConstants::initialGarbageFrames }; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +YStartDetector::YStartDetector() +{ + reset(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 YStartDetector::detectedYStart() const { diff --git a/src/emucore/tia/frame-manager/YStartDetector.hxx b/src/emucore/tia/frame-manager/YStartDetector.hxx index 3d6003814..f5f4bc164 100644 --- a/src/emucore/tia/frame-manager/YStartDetector.hxx +++ b/src/emucore/tia/frame-manager/YStartDetector.hxx @@ -28,7 +28,7 @@ class YStartDetector: public AbstractFrameManager { public: - YStartDetector() = default; + YStartDetector(); public: diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index 5b3a24324..798ffa941 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -560,12 +560,8 @@ void GameInfoDialog::saveConfig() // update 'Display' tab settings immediately bool reset = false; instance().console().setFormat(myFormat->getSelected()); - if(uInt32(myYStart->getValue()) != TIAConstants::minYStart - 1 && - uInt32(myYStart->getValue()) != instance().console().tia().ystart()) - { - instance().console().tia().setYStart(myYStart->getValue()); - reset = true; - } + instance().console().updateYStart(myYStart->getValue()); + if(uInt32(myHeight->getValue()) != TIAConstants::minViewableHeight - 1 && uInt32(myHeight->getValue()) != instance().console().tia().height()) {