C64 - Refactor Cia.Port to be a base interface instead of abstract class, and remove SyncState since none of the current implementations have any state to sync.

This commit is contained in:
adelikat 2017-05-13 07:55:46 -05:00
parent 1443e39ed0
commit 1c8cc06a02
2 changed files with 15 additions and 26 deletions

View File

@ -1,38 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
public sealed partial class Cia
{
private abstract class Port
private interface IPort
{
public abstract int ReadPra(int pra, int ddra, int prb, int ddrb);
public abstract int ReadPrb(int pra, int ddra, int prb, int ddrb);
int ReadPra(int pra, int ddra, int prb, int ddrb);
int ReadPrb(int pra, int ddra, int prb, int ddrb);
public void SyncState(Serializer ser)
{
SaveState.SyncObject(ser, this);
}
// If an IPort needs to save state we can do it with something like this:
// void SyncState(Serializer ser);
}
private sealed class DisconnectedPort : Port
private sealed class DisconnectedPort : IPort
{
public override int ReadPra(int pra, int ddra, int prb, int ddrb)
public int ReadPra(int pra, int ddra, int prb, int ddrb)
{
return (pra | ~ddra) & 0xFF;
}
public override int ReadPrb(int pra, int ddra, int prb, int ddrb)
public int ReadPrb(int pra, int ddra, int prb, int ddrb)
{
return (prb | ~ddrb) & 0xFF;
}
}
private sealed class JoystickKeyboardPort : Port
private sealed class JoystickKeyboardPort : IPort
{
[SaveState.DoNotSave] private int _ret;
[SaveState.DoNotSave] private int _tst;
@ -112,7 +106,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
return result;
}
public override int ReadPra(int pra, int ddra, int prb, int ddrb)
public int ReadPra(int pra, int ddra, int prb, int ddrb)
{
_ret = (pra | ~ddra) & 0xFF;
_tst = (prb | ~ddrb) & GetJoystick1();
@ -120,7 +114,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
return _ret & GetJoystick2();
}
public override int ReadPrb(int pra, int ddra, int prb, int ddrb)
public int ReadPrb(int pra, int ddra, int prb, int ddrb)
{
_ret = ~ddrb & 0xFF;
_tst = (pra | ~ddra) & GetJoystick2();
@ -129,7 +123,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
}
private sealed class IecPort : Port
private sealed class IecPort : IPort
{
private readonly Func<int> _readIec;
@ -138,12 +132,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_readIec = readIec;
}
public override int ReadPra(int pra, int ddra, int prb, int ddrb)
public int ReadPra(int pra, int ddra, int prb, int ddrb)
{
return (pra & ddra) | (~ddra & _readIec());
}
public override int ReadPrb(int pra, int ddra, int prb, int ddrb)
public int ReadPrb(int pra, int ddra, int prb, int ddrb)
{
return (prb | ~ddrb) & 0xFF;
}

View File

@ -74,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
[SaveState.DoNotSave] private bool _flagInput;
[SaveState.DoNotSave] private bool _taUnderflow;
private readonly Port _port;
private readonly IPort _port;
[SaveState.DoNotSave] private int _todlo;
[SaveState.DoNotSave] private int _todhi;
[SaveState.DoNotSave] private readonly int _todNum;
@ -546,12 +546,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ser.Sync("_newCrb", ref _newCrb);
ser.Sync("_flagLatch", ref _flagLatch);
ser.BeginSection("Port");
_port.SyncState(ser);
ser.EndSection();
ser.Sync("_todCounter", ref _todCounter);
//SaveState.SyncObject(ser, this);
}
}
}