diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.Port.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.Port.cs index b248e0c625..7af89bcb2a 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.Port.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.Port.cs @@ -1,51 +1,49 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using BizHawk.Common; -using BizHawk.Emulation.Cores.Computers.Commodore64.Media; namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS { public sealed partial class Via { - private abstract class Port + private interface IPort { - public abstract int ReadPra(int pra, int ddra); - public abstract int ReadPrb(int prb, int ddrb); - public abstract int ReadExternalPra(); - public abstract int ReadExternalPrb(); + int ReadPra(int pra, int ddra); + int ReadPrb(int prb, int ddrb); + int ReadExternalPra(); + int ReadExternalPrb(); - public void SyncState(Serializer ser) - { - SaveState.SyncObject(ser, this); - } + void SyncState(Serializer ser); } - private sealed class DisconnectedPort : Port + private sealed class DisconnectedPort : IPort { - public override int ReadPra(int pra, int ddra) + public int ReadPra(int pra, int ddra) { return (pra | ~ddra) & 0xFF; } - public override int ReadPrb(int prb, int ddrb) + public int ReadPrb(int prb, int ddrb) { return (prb | ~ddrb) & 0xFF; } - public override int ReadExternalPra() + public int ReadExternalPra() { return 0xFF; } - public override int ReadExternalPrb() + public int ReadExternalPrb() { return 0xFF; } + + public void SyncState(Serializer ser) + { + // Do nothing + } } - private sealed class DriverPort : Port + private sealed class DriverPort : IPort { private readonly Func _readPrA; private readonly Func _readPrB; @@ -56,33 +54,39 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS _readPrB = readPrB; } - public override int ReadPra(int pra, int ddra) + public int ReadPra(int pra, int ddra) { return _readPrA(); } - public override int ReadPrb(int prb, int ddrb) + public int ReadPrb(int prb, int ddrb) { return (prb & ddrb) | (_readPrB() & ~ddrb); } - public override int ReadExternalPra() + public int ReadExternalPra() { return _readPrA(); } - public override int ReadExternalPrb() + public int ReadExternalPrb() { return _readPrB(); } + + public void SyncState(Serializer ser) + { + // Do nothing + } } - private sealed class IecPort : Port + private sealed class IecPort : IPort { private readonly Func _readClock; private readonly Func _readData; private readonly Func _readAtn; - private readonly int _driveNumber; + + private int _driveNumber; public IecPort(Func readClock, Func readData, Func readAtn, int driveNumber) { @@ -92,12 +96,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS _driveNumber = (driveNumber & 0x3) << 5; } - public override int ReadPra(int pra, int ddra) + public int ReadPra(int pra, int ddra) { return (pra | ~ddra) & 0xFF; } - public override int ReadPrb(int prb, int ddrb) + public int ReadPrb(int prb, int ddrb) { return (prb & ddrb) | (~ddrb & 0xE5 & ( @@ -108,12 +112,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS ); } - public override int ReadExternalPra() + public int ReadExternalPra() { return 0xFF; } - public override int ReadExternalPrb() + public int ReadExternalPrb() { return (_readClock() ? 0x04 : 0x00) | @@ -121,6 +125,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS (_readAtn() ? 0x80 : 0x00) | _driveNumber; } + + public void SyncState(Serializer ser) + { + ser.Sync("_driveNumber", ref _driveNumber); + } } } } diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs index dbd863c1a8..511a5f867e 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Via.cs @@ -61,7 +61,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS [SaveState.SaveWithName("InterruptEnableRegister")] private int _ier; [SaveState.SaveWithName("Port")] - private readonly Port _port; + private readonly IPort _port; [SaveState.SaveWithName("PortLatchA")] private int _paLatch; @@ -421,7 +421,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS ser.Sync("InterruptEnableRegister", ref _ier); ser.BeginSection("Port"); - _port.SyncState(ser); // TODO + _port.SyncState(ser); ser.EndSection();