diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.core.cs b/BizHawk.Emulation/Computers/Commodore64/C64.core.cs index e97ac2bbd8..f1fa692303 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.core.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.core.cs @@ -35,6 +35,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 public VicIINew vic; public ChipSignals signal; + // cpu + private bool haltCPU; + public bool DriveLED { get @@ -65,7 +68,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 { // initalize cpu cpu = new MOS6502X(); - cpu.ReadMemory = ReadMemory; + cpu.ReadMemory = ReadMemoryCPU; cpu.WriteMemory = WriteMemory; cpu.DummyReadMemory = PeekMemory; @@ -150,6 +153,13 @@ namespace BizHawk.Emulation.Computers.Commodore64 return mem.Read(addr); } + private byte ReadMemoryCPU(ushort addr) + { + if (!signal.CpuAEC) + haltCPU = true; + return mem.Read(addr); + } + public void WriteMemory(ushort addr, byte value) { mem.Write(addr, value); diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index ba3f219d2b..57eeb66852 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -102,10 +102,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 // perform the cycle for (int i = 0; i < cyclesPerFrame; i++) { - if (signal.CpuAEC) - { + if (!haltCPU) cpu.ExecuteOne(); - } + vic.PerformCycle(); cpu.IRQ = signal.CpuIRQ; cpu.NMI = signal.CpuNMI; @@ -114,8 +113,13 @@ namespace BizHawk.Emulation.Computers.Commodore64 cia1.PerformCycle(); signal.CiaIRQ1 = cia1.IRQ; sid.PerformCycle(); + if (diskDriveAttached) diskDrive.PerformCycle(); + + if (signal.CpuAEC) + haltCPU = false; + } _islag = !mem.inputWasRead; diff --git a/BizHawk.Emulation/Computers/Commodore64/Cia.cs b/BizHawk.Emulation/Computers/Commodore64/Cia.cs index 5a84ef3385..2f2b69f7a0 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cia.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cia.cs @@ -475,7 +475,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 { int timer = regs.T[index]; timer--; - if (timer == 0) + if (timer < 0) { underflow[index] = true; if (regs.RUNMODE[index]) diff --git a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs index 0bddda535b..37a2ad0be7 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs @@ -101,6 +101,8 @@ namespace BizHawk.Emulation.Computers.Commodore64 cia1 = newCia1; cpuPort = cpuPortBus.Connect(); + cpuPort.Latch = 0x00; + cpuPort.Direction = 0x1F; cpuPortBus.AttachWriteHook(UpdateLayout); cpuIO = cpuPortBus.Connect();