Break up ColecoVision.cs into separate files

This commit is contained in:
adelikat 2014-12-05 03:16:08 +00:00
parent 923b5e2543
commit 3ded6116a6
9 changed files with 359 additions and 238 deletions

View File

@ -7,6 +7,11 @@ namespace BizHawk.Emulation.Common
/// </summary>
public interface IStatable : IEmulatorService, IEmulator
{
/// <summary>
/// true if the core would rather give a binary savestate than a text one. both must function regardless
/// </summary>
bool BinarySaveStatesPreferred { get; }
void SaveStateText(TextWriter writer);
void LoadStateText(TextReader reader);
@ -18,10 +23,5 @@ namespace BizHawk.Emulation.Common
/// </summary>
/// <returns>you may NOT modify this. if you call SaveStateBinary() again with the same core, the old data MAY be overwritten.</returns>
byte[] SaveStateBinary();
/// <summary>
/// true if the core would rather give a binary savestate than a text one. both must function regardless
/// </summary>
bool BinarySaveStatesPreferred { get; }
}
}

View File

@ -242,6 +242,21 @@
<Compile Include="Consoles\Atari\lynx\LibLynx.cs" />
<Compile Include="Consoles\Atari\lynx\Lynx.cs" />
<Compile Include="Consoles\Coleco\ColecoVision.cs" />
<Compile Include="Consoles\Coleco\ColecoVision.IDebuggable.cs">
<DependentUpon>ColecoVision.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Coleco\ColecoVision.IInputPollable.cs">
<DependentUpon>ColecoVision.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Coleco\ColecoVision.IMemoryDomains.cs">
<DependentUpon>ColecoVision.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Coleco\ColecoVision.ISettable.cs">
<DependentUpon>ColecoVision.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Coleco\ColecoVision.IStatable.cs">
<DependentUpon>ColecoVision.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Coleco\Input.cs" />
<Compile Include="Consoles\Coleco\MemoryMap.cs" />
<Compile Include="Consoles\Coleco\TMS9918A.cs" />
@ -278,7 +293,7 @@
<DependentUpon>N64.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Nintendo\N64\N64.IStatable.cs">
<DependentUpon>N64.cs</DependentUpon>
<DependentUpon>N64.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Nintendo\N64\N64Input.cs" />
<Compile Include="Consoles\Nintendo\N64\N64Settings.cs" />

View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public partial class ColecoVision : IDebuggable
{
public IDictionary<string, int> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, int>
{
{ "A", Cpu.RegisterA },
{ "AF", Cpu.RegisterAF },
{ "B", Cpu.RegisterB },
{ "BC", Cpu.RegisterBC },
{ "C", Cpu.RegisterC },
{ "D", Cpu.RegisterD },
{ "DE", Cpu.RegisterDE },
{ "E", Cpu.RegisterE },
{ "F", Cpu.RegisterF },
{ "H", Cpu.RegisterH },
{ "HL", Cpu.RegisterHL },
{ "I", Cpu.RegisterI },
{ "IX", Cpu.RegisterIX },
{ "IY", Cpu.RegisterIY },
{ "L", Cpu.RegisterL },
{ "PC", Cpu.RegisterPC },
{ "R", Cpu.RegisterR },
{ "Shadow AF", Cpu.RegisterShadowAF },
{ "Shadow BC", Cpu.RegisterShadowBC },
{ "Shadow DE", Cpu.RegisterShadowDE },
{ "Shadow HL", Cpu.RegisterShadowHL },
{ "SP", Cpu.RegisterSP },
{ "Flag C", Cpu.RegisterF.Bit(0) ? 1 : 0 },
{ "Flag N", Cpu.RegisterF.Bit(1) ? 1 : 0 },
{ "Flag P/V", Cpu.RegisterF.Bit(2) ? 1 : 0 },
{ "Flag 3rd", Cpu.RegisterF.Bit(3) ? 1 : 0 },
{ "Flag H", Cpu.RegisterF.Bit(4) ? 1 : 0 },
{ "Flag 5th", Cpu.RegisterF.Bit(5) ? 1 : 0 },
{ "Flag Z", Cpu.RegisterF.Bit(6) ? 1 : 0 },
{ "Flag S", Cpu.RegisterF.Bit(7) ? 1 : 0 }
};
}
public void SetCpuRegister(string register, int value)
{
switch (register)
{
default:
throw new InvalidOperationException();
case "A":
Cpu.RegisterA = (byte)value;
break;
case "AF":
Cpu.RegisterAF = (byte)value;
break;
case "B":
Cpu.RegisterB = (byte)value;
break;
case "BC":
Cpu.RegisterBC = (byte)value;
break;
case "C":
Cpu.RegisterC = (byte)value;
break;
case "D":
Cpu.RegisterD = (byte)value;
break;
case "DE":
Cpu.RegisterDE = (byte)value;
break;
case "E":
Cpu.RegisterE = (byte)value;
break;
case "F":
Cpu.RegisterF = (byte)value;
break;
case "H":
Cpu.RegisterH = (byte)value;
break;
case "HL":
Cpu.RegisterHL = (byte)value;
break;
case "I":
Cpu.RegisterI = (byte)value;
break;
case "IX":
Cpu.RegisterIX = (byte)value;
break;
case "IY":
Cpu.RegisterIY = (byte)value;
break;
case "L":
Cpu.RegisterL = (byte)value;
break;
case "PC":
Cpu.RegisterPC = (ushort)value;
break;
case "R":
Cpu.RegisterR = (byte)value;
break;
case "Shadow AF":
Cpu.RegisterShadowAF = (byte)value;
break;
case "Shadow BC":
Cpu.RegisterShadowBC = (byte)value;
break;
case "Shadow DE":
Cpu.RegisterShadowDE = (byte)value;
break;
case "Shadow HL":
Cpu.RegisterShadowHL = (byte)value;
break;
case "SP":
Cpu.RegisterSP = (byte)value;
break;
}
}
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
public IMemoryCallbackSystem MemoryCallbacks
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public partial class ColecoVision : IInputPollable
{
public int LagCount
{
get { return _lagCount; }
set { _lagCount = value; }
}
public bool IsLagFrame
{
get { return _isLag; }
}
public IInputCallbackSystem InputCallbacks
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
private int _lagCount = 0;
private bool _isLag = true;
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public partial class ColecoVision : IMemoryDomains
{
public MemoryDomainList MemoryDomains
{
get { return memoryDomains; }
}
private MemoryDomainList memoryDomains;
private void SetupMemoryDomains()
{
var domains = new List<MemoryDomain>(3);
var MainMemoryDomain = new MemoryDomain("Main RAM", Ram.Length, MemoryDomain.Endian.Little,
addr => Ram[addr],
(addr, value) => Ram[addr] = value);
var VRamDomain = new MemoryDomain("Video RAM", VDP.VRAM.Length, MemoryDomain.Endian.Little,
addr => VDP.VRAM[addr],
(addr, value) => VDP.VRAM[addr] = value);
var SystemBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
return Cpu.ReadMemory((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
Cpu.WriteMemory((ushort)addr, value);
});
domains.Add(MainMemoryDomain);
domains.Add(VRamDomain);
domains.Add(SystemBusDomain);
memoryDomains = new MemoryDomainList(domains);
}
}
}

View File

@ -0,0 +1,41 @@
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public partial class ColecoVision : ISettable<object, ColecoVision.ColecoSyncSettings>
{
public object GetSettings()
{
return null;
}
public ColecoSyncSettings GetSyncSettings()
{
return _syncSettings.Clone();
}
public bool PutSettings(object o)
{
return false;
}
public bool PutSyncSettings(ColecoSyncSettings o)
{
bool ret = o.SkipBiosIntro != _syncSettings.SkipBiosIntro;
_syncSettings = o;
return ret;
}
private ColecoSyncSettings _syncSettings;
public class ColecoSyncSettings
{
public bool SkipBiosIntro { get; set; }
public ColecoSyncSettings Clone()
{
return (ColecoSyncSettings)MemberwiseClone();
}
}
}
}

View File

@ -0,0 +1,71 @@
using System.IO;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public partial class ColecoVision : IStatable
{
public bool BinarySaveStatesPreferred
{
get { return false; }
}
public void SaveStateBinary(BinaryWriter bw)
{
SyncState(Serializer.CreateBinaryWriter(bw));
}
public void LoadStateBinary(BinaryReader br)
{
SyncState(Serializer.CreateBinaryReader(br));
}
public void SaveStateText(TextWriter tw)
{
SyncState(Serializer.CreateTextWriter(tw));
}
public void LoadStateText(TextReader tr)
{
SyncState(Serializer.CreateTextReader(tr));
}
public byte[] SaveStateBinary()
{
if (_stateBuffer == null)
{
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
SaveStateBinary(writer);
_stateBuffer = stream.ToArray();
writer.Close();
return _stateBuffer;
}
else
{
var stream = new MemoryStream(_stateBuffer);
var writer = new BinaryWriter(stream);
SaveStateBinary(writer);
writer.Close();
return _stateBuffer;
}
}
private void SyncState(Serializer ser)
{
ser.BeginSection("Coleco");
Cpu.SyncState(ser);
VDP.SyncState(ser);
PSG.SyncState(ser);
ser.Sync("RAM", ref Ram, false);
ser.Sync("Frame", ref frame);
ser.Sync("LagCount", ref _lagCount);
ser.Sync("IsLag", ref _isLag);
ser.EndSection();
}
private byte[] _stateBuffer;
}
}

View File

@ -37,8 +37,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{
ServiceProvider = new BasicServiceProvider(this);
CoreComm = comm;
this.SyncSettings = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings();
bool skipbios = this.SyncSettings.SkipBiosIntro;
_syncSettings = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings();
bool skipbios = this._syncSettings.SkipBiosIntro;
Cpu = new Z80A();
Cpu.ReadMemory = ReadMemory;
@ -63,63 +63,20 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public IEmulatorServiceProvider ServiceProvider { get; private set; }
private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem();
public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } }
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
public IMemoryCallbackSystem MemoryCallbacks
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
public MemoryDomainList MemoryDomains { get { return memoryDomains; } }
MemoryDomainList memoryDomains;
const ushort RamSizeMask = 0x03FF;
void SetupMemoryDomains()
{
var domains = new List<MemoryDomain>(3);
var MainMemoryDomain = new MemoryDomain("Main RAM", Ram.Length, MemoryDomain.Endian.Little,
addr => Ram[addr],
(addr, value) => Ram[addr] = value);
var VRamDomain = new MemoryDomain("Video RAM", VDP.VRAM.Length, MemoryDomain.Endian.Little,
addr => VDP.VRAM[addr],
(addr, value) => VDP.VRAM[addr] = value);
var SystemBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
return Cpu.ReadMemory((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
Cpu.WriteMemory((ushort)addr, value);
});
domains.Add(MainMemoryDomain);
domains.Add(VRamDomain);
domains.Add(SystemBusDomain);
memoryDomains = new MemoryDomainList(domains);
}
public void FrameAdvance(bool render, bool renderSound)
{
Frame++;
isLag = true;
_isLag = true;
PSG.BeginFrame(Cpu.TotalExecutedCycles);
VDP.ExecuteFrame();
PSG.EndFrame(Cpu.TotalExecutedCycles);
if (isLag)
if (_isLag)
{
LagCount++;
}
}
void LoadRom(byte[] rom, bool skipbios)
@ -191,53 +148,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public bool DeterministicEmulation { get { return true; } }
public bool BinarySaveStatesPreferred { get { return false; } }
public void SaveStateBinary(BinaryWriter bw) { SyncState(Serializer.CreateBinaryWriter(bw)); }
public void LoadStateBinary(BinaryReader br) { SyncState(Serializer.CreateBinaryReader(br)); }
public void SaveStateText(TextWriter tw) { SyncState(Serializer.CreateTextWriter(tw)); }
public void LoadStateText(TextReader tr) { SyncState(Serializer.CreateTextReader(tr)); }
void SyncState(Serializer ser)
{
ser.BeginSection("Coleco");
Cpu.SyncState(ser);
VDP.SyncState(ser);
PSG.SyncState(ser);
ser.Sync("RAM", ref Ram, false);
ser.Sync("Frame", ref frame);
ser.Sync("LagCount", ref lagCount);
ser.Sync("IsLag", ref isLag);
ser.EndSection();
}
byte[] stateBuffer;
public byte[] SaveStateBinary()
{
if (stateBuffer == null)
{
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
SaveStateBinary(writer);
stateBuffer = stream.ToArray();
writer.Close();
return stateBuffer;
}
else
{
var stream = new MemoryStream(stateBuffer);
var writer = new BinaryWriter(stream);
SaveStateBinary(writer);
writer.Close();
return stateBuffer;
}
}
public void Dispose() { }
public void ResetCounters()
{
Frame = 0;
lagCount = 0;
isLag = false;
_lagCount = 0;
_isLag = false;
}
public string SystemId { get { return "Coleco"; } }
@ -251,138 +167,5 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public ISyncSoundProvider SyncSoundProvider { get { return null; } }
public bool StartAsyncSound() { return true; }
public void EndAsyncSound() { }
public object GetSettings() { return null; }
public ColecoSyncSettings GetSyncSettings() { return SyncSettings.Clone(); }
public bool PutSettings(object o) { return false; }
public bool PutSyncSettings(ColecoSyncSettings o)
{
bool ret = o.SkipBiosIntro != SyncSettings.SkipBiosIntro;
SyncSettings = o;
return ret;
}
ColecoSyncSettings SyncSettings;
public class ColecoSyncSettings
{
public bool SkipBiosIntro = false;
public ColecoSyncSettings Clone()
{
return (ColecoSyncSettings)MemberwiseClone();
}
}
public IDictionary<string, int> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, int>
{
{ "A", Cpu.RegisterA },
{ "AF", Cpu.RegisterAF },
{ "B", Cpu.RegisterB },
{ "BC", Cpu.RegisterBC },
{ "C", Cpu.RegisterC },
{ "D", Cpu.RegisterD },
{ "DE", Cpu.RegisterDE },
{ "E", Cpu.RegisterE },
{ "F", Cpu.RegisterF },
{ "H", Cpu.RegisterH },
{ "HL", Cpu.RegisterHL },
{ "I", Cpu.RegisterI },
{ "IX", Cpu.RegisterIX },
{ "IY", Cpu.RegisterIY },
{ "L", Cpu.RegisterL },
{ "PC", Cpu.RegisterPC },
{ "R", Cpu.RegisterR },
{ "Shadow AF", Cpu.RegisterShadowAF },
{ "Shadow BC", Cpu.RegisterShadowBC },
{ "Shadow DE", Cpu.RegisterShadowDE },
{ "Shadow HL", Cpu.RegisterShadowHL },
{ "SP", Cpu.RegisterSP },
{ "Flag C", Cpu.RegisterF.Bit(0) ? 1 : 0 },
{ "Flag N", Cpu.RegisterF.Bit(1) ? 1 : 0 },
{ "Flag P/V", Cpu.RegisterF.Bit(2) ? 1 : 0 },
{ "Flag 3rd", Cpu.RegisterF.Bit(3) ? 1 : 0 },
{ "Flag H", Cpu.RegisterF.Bit(4) ? 1 : 0 },
{ "Flag 5th", Cpu.RegisterF.Bit(5) ? 1 : 0 },
{ "Flag Z", Cpu.RegisterF.Bit(6) ? 1 : 0 },
{ "Flag S", Cpu.RegisterF.Bit(7) ? 1 : 0 }
};
}
public void SetCpuRegister(string register, int value)
{
switch (register)
{
default:
throw new InvalidOperationException();
case "A":
Cpu.RegisterA = (byte)value;
break;
case "AF":
Cpu.RegisterAF = (byte)value;
break;
case "B":
Cpu.RegisterB = (byte)value;
break;
case "BC":
Cpu.RegisterBC = (byte)value;
break;
case "C":
Cpu.RegisterC = (byte)value;
break;
case "D":
Cpu.RegisterD = (byte)value;
break;
case "DE":
Cpu.RegisterDE = (byte)value;
break;
case "E":
Cpu.RegisterE = (byte)value;
break;
case "F":
Cpu.RegisterF = (byte)value;
break;
case "H":
Cpu.RegisterH = (byte)value;
break;
case "HL":
Cpu.RegisterHL = (byte)value;
break;
case "I":
Cpu.RegisterI = (byte)value;
break;
case "IX":
Cpu.RegisterIX = (byte)value;
break;
case "IY":
Cpu.RegisterIY = (byte)value;
break;
case "L":
Cpu.RegisterL = (byte)value;
break;
case "PC":
Cpu.RegisterPC = (ushort)value;
break;
case "R":
Cpu.RegisterR = (byte)value;
break;
case "Shadow AF":
Cpu.RegisterShadowAF = (byte)value;
break;
case "Shadow BC":
Cpu.RegisterShadowBC = (byte)value;
break;
case "Shadow DE":
Cpu.RegisterShadowDE = (byte)value;
break;
case "Shadow HL":
Cpu.RegisterShadowHL = (byte)value;
break;
case "SP":
Cpu.RegisterSP = (byte)value;
break;
}
}
}
}

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
byte ReadController1()
{
isLag = false;
_isLag = false;
if (InputPortSelection == InputPortMode.Left)
{
@ -73,7 +73,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
byte ReadController2()
{
isLag = false;
_isLag = false;
if (InputPortSelection == InputPortMode.Left)
{
@ -115,11 +115,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
}
public int Frame { get { return frame; } set { frame = value; } }
public int LagCount { get { return lagCount; } set { lagCount = value; } }
public bool IsLagFrame { get { return isLag; } }
int frame;
int lagCount = 0;
bool isLag = true;
}
}