Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Jan 27, 2024
1 parent 9fd7de7 commit 5b8fd9d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 56 deletions.
43 changes: 4 additions & 39 deletions Emulator/Base/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Thread::execute()
{
if (missing) {

trace(TIM_DEBUG, "%s SYNC POINT: %lld us\n", ThreadModeEnum::key(M),
trace(TIM_DEBUG, "execute<%s>: %lld us\n", ThreadModeEnum::key(M),
execClock.restart().asMicroseconds());

loadClock.go();
Expand All @@ -46,41 +46,6 @@ Thread::execute()
}
}

/*
template <> void
Thread::execute<THREAD_PERIODIC>()
{
loadClock.go();
sliceCounter++;
execute();
loadClock.stop();
}
template <> void
Thread::execute<THREAD_PULSED>()
{
loadClock.go();
sliceCounter++;
execute();
loadClock.stop();
}
template <> void
Thread::execute<THREAD_ADAPTIVE>()
{
if (missing) {
trace(TIM_DEBUG, "THREAD_ADAPTIVE: %lld us\n", execClock.restart().asMicroseconds());
loadClock.go();
execute();
sliceCounter++;
missing--;
loadClock.stop();
}
}
*/

template <> void
Thread::sleep<THREAD_PERIODIC>()
{
Expand Down Expand Up @@ -127,7 +92,7 @@ Thread::sleep<THREAD_PULSED>()
// Wait for the next pulse
waitForWakeUp(timeout);

// Determine the number of overdue slices
// Determine the number of slices that are overdue
missing = missingSlices();

if (missing) {
Expand All @@ -136,10 +101,10 @@ Thread::sleep<THREAD_PULSED>()
deltaTime = wakeupPeriod() / missing;
targetTime = util::Time::now() + deltaTime;

// Start over when we are out of sync
// Start over if the emulator got out of sync
if (std::abs(missing) > 5 * slicesPerFrame()) {

debug(true, "Adaptive sync: Off by %ld slices\n", missing);
warn("Emulation is off by %ld SYNC points\n", missing);
resync();
}
}
Expand Down
39 changes: 22 additions & 17 deletions Emulator/Components/C64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ C64::setInspectionTarget(InspectionTarget target, Cycle trigger)
ThreadMode
C64::getThreadMode() const
{
// return THREAD_PULSED;
return config.syncMode == SYNC_VSYNC ? THREAD_PULSED : THREAD_ADAPTIVE;
}

Expand All @@ -1030,7 +1029,8 @@ template <bool enable8, bool enable9> void
C64::execute()
{
bool exit = false;
isize lastCycle = vic.getCyclesPerLine();
auto lastCycle = vic.getCyclesPerLine();
auto syncLine = nextSyncLine(scanline);

do {

Expand Down Expand Up @@ -1088,24 +1088,29 @@ C64::execute()
if (flags && processFlags()) { rasterCycle++; exit = true; break; }
}

if (rasterCycle > lastCycle) {
// Finish the current scanline if we are at the end
if (rasterCycle > lastCycle) endScanline();

// Finish the current scanline
endScanline();
// Check if we have reached the next sync point
if (scanline == syncLine) exit = true;

// Terminate the loop if an entire frame has been emulated
if (scanline == 0) exit = true;
}
} while (!exit);

trace(TIM_DEBUG, "Syncing at scanline %d\n", scanline);
}

isize
C64::nextSyncLine(isize line)
{
switch (slicesPerFrame()) {

// Experimental
if (slicesPerFrame() == 2 && scanline == 156) exit = true;
if (slicesPerFrame() == 3 && scanline == 104) exit = true;
if (slicesPerFrame() == 3 && scanline == 208) exit = true;
if (slicesPerFrame() == 4 && scanline == 78) exit = true;
if (slicesPerFrame() == 4 && scanline == 156) exit = true;
if (slicesPerFrame() == 4 && scanline == 234) exit = true;
case 2: return line < 156 ? 156 : 0;
case 3: return line < 104 ? 104 : line < 208 ? 208 : 0;
case 4: return line < 78 ? 78 : line < 156 ? 156 : line < 234 ? 234 : 0;

} while (!exit);
default:
return 0;
}
}

bool
Expand Down Expand Up @@ -1200,7 +1205,7 @@ C64::refreshRate() const
isize
C64::slicesPerFrame() const
{
return 4;
return 1;
}

util::Time
Expand Down
1 change: 1 addition & 0 deletions Emulator/Components/C64.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ class C64 : public Thread {
ThreadMode getThreadMode() const override;
void execute() override;
template <bool enable8, bool enable9> void execute();
isize nextSyncLine(isize scanline);
bool processFlags();

public:
Expand Down

0 comments on commit 5b8fd9d

Please sign in to comment.