From 0e8462c8a535b13693d47edb78d0e895879303b9 Mon Sep 17 00:00:00 2001 From: Marc Parsons Date: Fri, 24 Apr 2026 13:27:42 +0100 Subject: [PATCH] Bug fix: Emulator now resets properly --- Desktop/Form1.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Desktop/Form1.cs b/Desktop/Form1.cs index 8d79c28..3f0f4c7 100644 --- a/Desktop/Form1.cs +++ b/Desktop/Form1.cs @@ -28,6 +28,7 @@ namespace Desktop public double FrameTime = 0; public bool highSpeed = false; public bool tapeLoaded = false; + private volatile bool _pendingReset = false; public Form1() @@ -78,7 +79,21 @@ namespace Desktop long audioSampleCount = 0; while (_isRunning) - { + { + if (_pendingReset) + { + _cpu.Reset(); + _memoryBus.CrapRAMData(); // Important! If RAM has garbage, the ROM boots instantly. If it has old data, it fails the RAM check! + + // Reset all local loop timing variables + TotalFrameCount = 0; + scanlineCount = 0; + audioSampleCount = 0; + nextScanlineTarget = TStatesPerFrame; + stopwatch.Restart(); + + _pendingReset = false; + } if (_isPaused) { @@ -277,6 +292,7 @@ namespace Desktop private void btnReset_Click(object sender, EventArgs e) { + _pendingReset = true; _isPaused = true; _cpu.Reset(); _memoryBus.CleanRAMData();