refactor Via.Port from an abstract class to interface, require inheriting classes to implement SyncState, and of course, don't use SyncObject
This commit is contained in:
parent
4d7afaa70a
commit
2840b69e41
|
@ -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<int> _readPrA;
|
||||
private readonly Func<int> _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<bool> _readClock;
|
||||
private readonly Func<bool> _readData;
|
||||
private readonly Func<bool> _readAtn;
|
||||
private readonly int _driveNumber;
|
||||
|
||||
private int _driveNumber;
|
||||
|
||||
public IecPort(Func<bool> readClock, Func<bool> readData, Func<bool> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue