From 6ed11de85b1acc7dfcd3ca51934b6abfc2e625df Mon Sep 17 00:00:00 2001 From: SaxxonPike Date: Sat, 6 Jul 2019 01:19:58 -0500 Subject: [PATCH] C64: Soft/Hard reset: it's about time --- .../Computers/Commodore64/C64.IEmulator.cs | 26 +++++++++++++++++++ .../Computers/Commodore64/C64.Motherboard.cs | 18 +++++++++++++ .../Computers/Commodore64/C64.cs | 14 ++++++++-- .../Computers/Commodore64/MOS/Chip6510.cs | 7 +++++ .../Computers/Commodore64/MOS/Vic.State.cs | 1 + 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IEmulator.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IEmulator.cs index 29aea5b261..b0f5b1a55c 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IEmulator.cs @@ -21,6 +21,32 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 _board.Cpu.TraceCallback = null; } + if (controller.IsPressed("Power")) + { + if (!_powerPressed) + { + _powerPressed = true; + HardReset(); + } + } + else + { + _powerPressed = false; + } + + if (controller.IsPressed("Reset")) + { + if (!_resetPressed) + { + _resetPressed = true; + SoftReset(); + } + } + else + { + _resetPressed = false; + } + if (controller.IsPressed("Next Disk") && !_nextPressed) { _nextPressed = true; diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs index 605277c2ad..a2b72bb9a3 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs @@ -191,6 +191,24 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 CartPort.HardReset(); } + public void SoftReset() + { + // equivalent to a hard reset EXCEPT cpu, color ram, memory + Bus = 0xFF; + InputRead = false; + + Cia0.HardReset(); + Cia1.HardReset(); + Serial.HardReset(); + Sid.HardReset(); + Vic.HardReset(); + User.HardReset(); + Cassette.HardReset(); + Serial.HardReset(); + Cpu.SoftReset(); + CartPort.HardReset(); + } + public void Init() { CartPort.ReadOpenBus = ReadOpenBus; diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs index 0e17385256..926942bbe4 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs @@ -34,6 +34,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 _cyclesPerFrame = _board.Vic.CyclesPerFrame; _memoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus" }); + InitMedia(_roms[_currentDisk]); HardReset(); switch (SyncSettings.VicType) @@ -137,7 +138,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 "Key Commodore", "Key Left Shift", "Key Z", "Key X", "Key C", "Key V", "Key B", "Key N", "Key M", "Key Comma", "Key Period", "Key Slash", "Key Right Shift", "Key Cursor Up/Down", "Key Cursor Left/Right", "Key Space", "Key F1", "Key F3", "Key F5", "Key F7", - "Previous Disk", "Next Disk" + "Previous Disk", "Next Disk", + "Power", "Reset" } }; @@ -147,6 +149,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 private int _frame; private readonly ITraceable _tracer; + + // Power stuff + private bool _powerPressed; + private bool _resetPressed; // Disk stuff private bool _nextPressed; @@ -358,8 +364,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 private void HardReset() { - InitMedia(_roms[_currentDisk]); _board.HardReset(); } + + private void SoftReset() + { + _board.SoftReset(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.cs index dc99da4183..ba2ba3bf53 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.cs @@ -97,6 +97,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS _pinNmiLast = true; } + public void SoftReset() + { + _cpu.NESSoftReset(); + _port.Direction = 0x00; + _port.Latch = 0xFF; + } + // ------------------------------------ public void ExecutePhase() { diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.State.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.State.cs index aae4938e95..aa6976c443 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.State.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.State.cs @@ -137,6 +137,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS _xScroll = 0; _yScroll = 0; _cycle = 0; + _cycleIndex = 0; // reset sprites for (var i = 0; i < 8; i++)