diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs index 51d3d0be4f..8afeed35bf 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Motherboard.cs @@ -323,7 +323,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 Cassette.SyncState(ser); ser.EndSection(); - ser.BeginSection("Serial"); SaveState.SyncObject(ser, Serial); ser.EndSection(); + ser.BeginSection("Serial"); + Serial.SyncState(ser); + ser.EndSection(); + ser.BeginSection("TapeDrive"); SaveState.SyncObject(ser, TapeDrive); ser.EndSection(); // TODO: only if tape ser.BeginSection("User"); SaveState.SyncObject(ser, User); ser.EndSection(); ser.BeginSection("DiskDrive"); SaveState.SyncObject(ser, DiskDrive); ser.EndSection(); // TODO: only if disk diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs index 26bd641184..dbd863c1a8 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs @@ -406,7 +406,55 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS public void SyncState(Serializer ser) { - SaveState.SyncObject(ser, this); + ser.Sync("PortOutputA", ref _pra); + ser.Sync("PortDirectionA", ref _ddra); + ser.Sync("PortOutputB", ref _prb); + ser.Sync("PortDirectionB", ref _ddrb); + ser.Sync("Timer1Counter", ref _t1C); + ser.Sync("Timer1Latch", ref _t1L); + ser.Sync("Timer2Counter", ref _t2C); + ser.Sync("Timer2Latch", ref _t2L); + ser.Sync("ShiftRegister", ref _sr); + ser.Sync("AuxiliaryControlRegister", ref _acr); + ser.Sync("PeripheralControlRegister", ref _pcr); + ser.Sync("InterruptFlagRegister", ref _ifr); + ser.Sync("InterruptEnableRegister", ref _ier); + + ser.BeginSection("Port"); + _port.SyncState(ser); // TODO + ser.EndSection(); + + + ser.Sync("PortLatchA", ref _paLatch); + ser.Sync("PortLatchB", ref _pbLatch); + ser.Sync("CA1InterruptControl", ref _pcrCa1IntControl); + ser.Sync("CA2Control", ref _pcrCa2Control); + ser.Sync("CB1InterruptControl", ref _pcrCb1IntControl); + ser.Sync("CB2Control", ref _pcrCb2Control); + ser.Sync("PortLatchEnableA", ref _acrPaLatchEnable); + ser.Sync("PortLatchEnableB", ref _acrPbLatchEnable); + ser.Sync("ShiftRegisterControl", ref _acrSrControl); + ser.Sync("Timer1Control", ref _acrT1Control); + ser.Sync("Timer2Control", ref _acrT2Control); + ser.Sync("PreviousCA1", ref _ca1L); + ser.Sync("PreviousCA2", ref _ca2L); + ser.Sync("PreviousCB1", ref _cb1L); + ser.Sync("PreviousCB2", ref _cb2L); + ser.Sync("PreviousPB6", ref _pb6L); + ser.Sync("ResetCa2NextClock", ref _resetCa2NextClock); + ser.Sync("ResetCb2NextClock", ref _resetCb2NextClock); + ser.Sync("HandshakeCa2NextClock", ref _handshakeCa2NextClock); + ser.Sync("HandshakeCb2NextClock", ref _handshakeCb2NextClock); + ser.Sync("CA1", ref Ca1); + ser.Sync("CA2", ref Ca2); + ser.Sync("CB1", ref Cb1); + ser.Sync("CB2", ref Cb2); + ser.Sync("PB6", ref _pb6); + ser.Sync("InterruptNextClock", ref _interruptNextClock); + ser.Sync("T1Loaded", ref _t1CLoaded); + ser.Sync("T2Loaded", ref _t2CLoaded); + ser.Sync("T1Delayed", ref _t1Delayed); + ser.Sync("T2Delayed", ref _t2Delayed); } } } diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.cs index 1d4d6b5947..0bbda93ceb 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/Drive1541.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Text; +using BizHawk.Common; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Components.M6502; using BizHawk.Emulation.Cores.Computers.Commodore64.Media; @@ -24,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial [SaveState.SaveWithName("ByteReady")] private bool _byteReady; [SaveState.SaveWithName("DriveCpuClockNumerator")] - private readonly int _driveCpuClockNum; + private int _driveCpuClockNum; [SaveState.SaveWithName("TrackNumber")] private int _trackNumber; [SaveState.SaveWithName("MotorEnabled")] @@ -36,13 +37,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial [SaveState.SaveWithName("CPU")] private readonly MOS6502X _cpu; [SaveState.SaveWithName("RAM")] - private readonly int[] _ram; + private int[] _ram; [SaveState.SaveWithName("VIA0")] public readonly Via Via0; [SaveState.SaveWithName("VIA1")] public readonly Via Via1; [SaveState.SaveWithName("SystemCpuClockNumerator")] - private readonly int _cpuClockNum; + private int _cpuClockNum; [SaveState.SaveWithName("SystemDriveCpuRatioDifference")] private int _ratioDifference; [SaveState.SaveWithName("DriveLightOffTime")] @@ -76,6 +77,52 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial _driveCpuClockNum = clockDen * 16000000; // 16mhz } + public override void SyncState(Serializer ser) + { + ser.BeginSection("Disk"); + _disk.SyncState(ser); // TODO + ser.EndSection(); + + ser.Sync("BitHistory", ref _bitHistory); + ser.Sync("BitsRemainingInLatchedByte", ref _bitsRemainingInLatchedByte); + ser.Sync("Sync", ref _sync); + ser.Sync("DriveCpuClockNumerator", ref _driveCpuClockNum); + ser.Sync("TrackNumber", ref _trackNumber); + ser.Sync("MotorEnabled", ref _motorEnabled); + ser.Sync("LedEnabled", ref _ledEnabled); + ser.Sync("MotorStep", ref _motorStep); + + _cpu.SyncState(ser); + + ser.Sync("RAM", ref _ram, useNull: false); + + ser.BeginSection("VIA0"); + Via0.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("VIA1"); + Via1.SyncState(ser); + ser.EndSection(); + + ser.Sync("SystemCpuClockNumerator", ref _cpuClockNum); + ser.Sync("SystemDriveCpuRatioDifference", ref _ratioDifference); + ser.Sync("DriveLightOffTime", ref _driveLightOffTime); + ser.Sync("DiskDensityCounter", ref _diskDensityCounter); + ser.Sync("DiskSupplementaryCounter", ref _diskSupplementaryCounter); + ser.Sync("DiskFluxReversalDetected", ref _diskFluxReversalDetected); + ser.Sync("DiskBitsRemainingInDataEntry", ref _diskBitsLeft); + ser.Sync("DiskDataEntryIndex", ref _diskByteOffset); + ser.Sync("DiskDataEntry", ref _diskBits); + ser.Sync("DiskCurrentCycle", ref _diskCycle); + ser.Sync("DiskDensityConfig", ref _diskDensity); + ser.Sync("PreviousCA1", ref _previousCa1); + ser.Sync("CountsBeforeRandomTransition", ref _countsBeforeRandomTransition); + ser.Sync("CurrentRNG", ref _rngCurrent); + ser.Sync("Clocks", ref _clocks); + ser.Sync("CpuClocks", ref _cpuClocks); + ser.Sync("OverflowFlagDelayShiftRegister", ref _overflowFlagDelaySr); + } + public override void ExecutePhase() { _ratioDifference += _driveCpuClockNum; diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPort.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPort.cs index a462dd55e1..cecd7b2330 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPort.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPort.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; + using BizHawk.Common; using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Computers.Commodore64.Cassette; namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial { @@ -19,6 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial [SaveState.SaveWithName("Device")] private SerialPortDevice _device; + [SaveState.SaveWithName("Connected")] private bool _connected; @@ -63,7 +61,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial public void SyncState(Serializer ser) { - SaveState.SyncObject(ser, this); + _device?.SyncState(ser); + ser.Sync("Connected", ref _connected); } public void Connect(SerialPortDevice device) diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPortDevice.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPortDevice.cs index 088467f67b..b164ef47f4 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPortDevice.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Serial/SerialPortDevice.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using BizHawk.Common; namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial @@ -10,8 +7,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial { [SaveState.DoNotSave] public Func ReadMasterAtn = () => true; + [SaveState.DoNotSave] public Func ReadMasterClk = () => true; + [SaveState.DoNotSave] public Func ReadMasterData = () => true; @@ -42,9 +41,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial return false; } - public virtual void SyncState(Serializer ser) - { - SaveState.SyncObject(ser, this); - } + public abstract void SyncState(Serializer ser); } }