Use ystart / layout autodetection and real FrameManager in profiling run.

This commit is contained in:
Christian Speckner 2019-02-28 23:56:02 +01:00
parent ac398ac31b
commit 2b19f4ab5e
2 changed files with 52 additions and 31 deletions

View File

@ -16,6 +16,7 @@
//============================================================================ //============================================================================
#include <chrono> #include <chrono>
#include <cmath>
#include "ProfilingRunner.hxx" #include "ProfilingRunner.hxx"
#include "FSNode.hxx" #include "FSNode.hxx"
@ -27,7 +28,11 @@
#include "M6532.hxx" #include "M6532.hxx"
#include "TIA.hxx" #include "TIA.hxx"
#include "ConsoleTiming.hxx" #include "ConsoleTiming.hxx"
#include "DummyFrameManager.hxx" #include "FrameManager.hxx"
#include "YStartDetector.hxx"
#include "FrameLayoutDetector.hxx"
#include "EmulationTiming.hxx"
#include "ConsoleTiming.hxx"
#include "System.hxx" #include "System.hxx"
#include "Joystick.hxx" #include "Joystick.hxx"
#include "Random.hxx" #include "Random.hxx"
@ -37,7 +42,6 @@ using namespace std::chrono;
namespace { namespace {
static constexpr uInt32 RUNTIME_DEFAULT = 60; static constexpr uInt32 RUNTIME_DEFAULT = 60;
static constexpr uInt32 cyclesPerSecond = 262 * 76 * 60;
void updateProgress(uInt32 from, uInt32 to) { void updateProgress(uInt32 from, uInt32 to) {
while (from < to) { while (from < to) {
@ -70,6 +74,8 @@ ProfilingRunner::ProfilingRunner(int argc, char* argv[])
run.runtime = runtime > 0 ? runtime : RUNTIME_DEFAULT; run.runtime = runtime > 0 ? runtime : RUNTIME_DEFAULT;
} }
} }
mySettings.setValue("fastscbios", true);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -115,7 +121,6 @@ bool ProfilingRunner::runOne(const ProfilingRun run)
IO consoleIO; IO consoleIO;
Random rng(0); Random rng(0);
Event event; Event event;
DummyFrameManager frameManager;
M6502 cpu(mySettings); M6502 cpu(mySettings);
M6532 riot(consoleIO, mySettings); M6532 riot(consoleIO, mySettings);
@ -126,15 +131,54 @@ bool ProfilingRunner::runOne(const ProfilingRun run)
consoleIO.myRightControl = make_unique<Joystick>(Controller::Right, event, system); consoleIO.myRightControl = make_unique<Joystick>(Controller::Right, event, system);
consoleIO.mySwitches = make_unique<Switches>(event, myProps, mySettings); consoleIO.mySwitches = make_unique<Switches>(event, myProps, mySettings);
tia.setFrameManager(&frameManager);
tia.bindToControllers(); tia.bindToControllers();
cartridge->setStartBankFromPropsFunc([]() { return -1; }); cartridge->setStartBankFromPropsFunc([]() { return -1; });
system.initialize(); system.initialize();
FrameLayoutDetector frameLayoutDetector;
tia.setFrameManager(&frameLayoutDetector);
system.reset(); system.reset();
(cout << "detecting frame layout... ").flush();
for(int i = 0; i < 60; ++i) tia.update();
FrameLayout frameLayout = frameLayoutDetector.detectedLayout();
ConsoleTiming consoleTiming;
switch (frameLayout) {
case FrameLayout::ntsc:
cout << "NTSC";
consoleTiming = ConsoleTiming::ntsc;
break;
case FrameLayout::pal:
cout << "PAL";
consoleTiming = ConsoleTiming::pal;
break;
}
(cout << endl).flush();
YStartDetector ystartDetector;
tia.setFrameManager(&ystartDetector);
system.reset();
(cout << "detecting ystart... ").flush();
for (int i = 0; i < 80; i++) tia.update();
uInt32 yStart = ystartDetector.detectedYStart();
(cout << yStart << endl).flush();
FrameManager frameManager;
tia.setFrameManager(&frameManager);
tia.setLayout(frameLayout);
tia.setYStart(yStart);
system.reset();
EmulationTiming emulationTiming(frameLayout, consoleTiming);
uInt64 cycles = 0; uInt64 cycles = 0;
uInt64 cyclesTarget = run.runtime * cyclesPerSecond; uInt64 cyclesTarget = run.runtime * emulationTiming.cyclesPerSecond();
DispatchResult dispatchResult; DispatchResult dispatchResult;
dispatchResult.setOk(0); dispatchResult.setOk(0);
@ -148,6 +192,8 @@ bool ProfilingRunner::runOne(const ProfilingRun run)
tia.update(dispatchResult); tia.update(dispatchResult);
cycles += dispatchResult.getCycles(); cycles += dispatchResult.getCycles();
if (tia.newFramePending()) tia.renderToFrameBuffer();
uInt32 percentNow = std::min((100 * cycles) / cyclesTarget, static_cast<uInt64>(100)); uInt32 percentNow = std::min((100 * cycles) / cyclesTarget, static_cast<uInt64>(100));
updateProgress(percent, percentNow); updateProgress(percent, percentNow);

View File

@ -1,25 +0,0 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef TIA_DUMMY_FRAME_MANAGER
#define TIA_DUMMY_FRAME_MANAGER
#include "AbstractFrameManager.hxx"
class DummyFrameManager: public AbstractFrameManager {};
#endif // TIA_DUMMY_FRAME_MANAGER