make CDL generic, and prep for GB CDL

This commit is contained in:
zeromus 2015-10-26 19:15:21 -05:00
parent 188bf5a6c6
commit bef877365c
8 changed files with 3340 additions and 3270 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3909,6 +3909,5 @@ namespace BizHawk.Client.EmuHawk
}
}
}

View File

@ -54,9 +54,9 @@
this.LoggingActiveCheckbox.AutoSize = true;
this.LoggingActiveCheckbox.Location = new System.Drawing.Point(12, 244);
this.LoggingActiveCheckbox.Name = "LoggingActiveCheckbox";
this.LoggingActiveCheckbox.Size = new System.Drawing.Size(101, 17);
this.LoggingActiveCheckbox.Size = new System.Drawing.Size(107, 17);
this.LoggingActiveCheckbox.TabIndex = 1;
this.LoggingActiveCheckbox.Text = "Loging is Active";
this.LoggingActiveCheckbox.Text = "Logging is Active";
this.LoggingActiveCheckbox.UseVisualStyleBackColor = true;
this.LoggingActiveCheckbox.CheckedChanged += new System.EventHandler(this.LoggingActiveCheckbox_CheckedChanged);
//

View File

@ -25,6 +25,7 @@ namespace BizHawk.Common.IOExtensions
}
// Read bytes from a BinaryReader and translate them into the UTF-8 string they represent.
//WHAT? WHY IS THIS NAMED ASCII BUT USING UTF8
public static string ReadStringFixedAscii(this BinaryReader r, int bytes)
{
var read = new byte[bytes];

View File

@ -346,6 +346,7 @@
</Compile>
<Compile Include="Consoles\Intellivision\PSG.cs" />
<Compile Include="Consoles\Intellivision\STIC.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\CodeDataLog_GB.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\Gambatte.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\Gambatte.IDebuggable.cs">
<DependentUpon>Gambatte.cs</DependentUpon>

View File

@ -5,54 +5,27 @@ using System.Text;
using System.IO;
using BizHawk.Emulation.Common;
//TODO - reorg please
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
namespace BizHawk.Emulation.Cores.Components.H6280
{
public class CodeDataLog : Dictionary<string, byte[]>
public class CodeDataLog_PCE : CodeDataLog
{
private CodeDataLog()
:base()
public static CodeDataLog_PCE Create(IEnumerable<HuC6280.MemMapping> mm)
{
}
public void LogicalOrFrom(CodeDataLog other)
{
if (this.Count != other.Count)
throw new InvalidDataException("Dictionaries must have the same number of keys!");
foreach (var kvp in other)
var t = new CodeDataLog_PCE();
foreach (var kvp in SizesFromHuMap(mm))
{
byte[] fromdata = kvp.Value;
byte[] todata = this[kvp.Key];
if (fromdata.Length != todata.Length)
throw new InvalidDataException("Memory regions must be the same size!");
for (int i = 0; i < todata.Length; i++)
todata[i] |= fromdata[i];
t[kvp.Key] = new byte[kvp.Value];
}
return t;
}
public void ClearData()
{
foreach (byte[] data in Values)
Array.Clear(data, 0, data.Length);
}
public override string SubType { get { return "PCE"; } }
public override int SubVer { get { return 0; } }
public void Save(Stream s)
{
var w = new BinaryWriter(s);
w.Write("BIZHAWK-CDL-1");
w.Write(Count);
foreach (var kvp in this)
{
w.Write(kvp.Key);
w.Write(kvp.Value.Length);
w.Write(kvp.Value);
}
w.Flush();
}
public void Disassemble(Stream s, IMemoryDomains mem)
public override void Disassemble(Stream s, IMemoryDomains mem)
{
var w = new StreamWriter(s);
w.WriteLine("; Bizhawk CDL Disassembly");
@ -90,26 +63,9 @@ namespace BizHawk.Emulation.Cores.Components.H6280
w.Flush();
}
public static CodeDataLog Load(Stream s)
{
var t = new CodeDataLog();
var r = new BinaryReader(s);
string id = r.ReadString();
if (id != "BIZHAWK-CDL-1")
throw new InvalidDataException("File is not a Bizhawk CDL file!");
int count = r.ReadInt32();
for (int i = 0; i < count; i++)
{
string key = r.ReadString();
int len = r.ReadInt32();
byte[] data = r.ReadBytes(len);
t[key] = data;
}
return t;
}
public bool CheckConsistency(IEnumerable<HuC6280.MemMapping> mm)
public bool CheckConsistency(object arg)
{
var mm = (IEnumerable<HuC6280.MemMapping>)arg;
var sizes = SizesFromHuMap(mm);
if (sizes.Count != Count)
return false;
@ -140,15 +96,95 @@ namespace BizHawk.Emulation.Cores.Components.H6280
}
return sizes;
}
}
public static CodeDataLog Create(IEnumerable<HuC6280.MemMapping> mm)
public abstract class CodeDataLog : Dictionary<string, byte[]>
{
public CodeDataLog()
:base()
{
var t = new CodeDataLog();
foreach (var kvp in SizesFromHuMap(mm))
}
/// <summary>
/// You don't have to use this necessarily, it's just provided for convenience
/// </summary>
public bool Active;
public virtual void Disassemble(Stream s, IMemoryDomains mem) { }
public abstract string SubType { get; }
public abstract int SubVer { get; }
public void LogicalOrFrom(CodeDataLog other)
{
if (this.Count != other.Count)
throw new InvalidDataException("Dictionaries must have the same number of keys!");
foreach (var kvp in other)
{
t[kvp.Key] = new byte[kvp.Value];
byte[] fromdata = kvp.Value;
byte[] todata = this[kvp.Key];
if (fromdata.Length != todata.Length)
throw new InvalidDataException("Memory regions must be the same size!");
for (int i = 0; i < todata.Length; i++)
todata[i] |= fromdata[i];
}
return t;
}
public void ClearData()
{
foreach (byte[] data in Values)
Array.Clear(data, 0, data.Length);
}
public void Save(Stream s)
{
var w = new BinaryWriter(s);
w.Write("BIZHAWK-CDL-2");
w.Write(SubType.PadRight(15));
w.Write(Count);
foreach (var kvp in this)
{
w.Write(kvp.Key);
w.Write(kvp.Value.Length);
w.Write(kvp.Value);
}
w.Flush();
}
public static CodeDataLog Load(Stream s)
{
var br = new BinaryReader(s);
string id = br.ReadString();
string FileSubType;
if (id == "BIZHAWK-CDL-1")
FileSubType = "PCE";
else if (id == "BIZHAWK-CDL-2")
FileSubType = br.ReadString().TrimEnd(' ');
else
throw new InvalidDataException("File is not a Bizhawk CDL file!");
if (FileSubType == "PCE")
return new CodeDataLog_PCE().Load(br);
else if(FileSubType == "GB")
return new CodeDataLog_GB().Load(br);
else return null;
}
private CodeDataLog Load(BinaryReader br)
{
int count = br.ReadInt32();
for (int i = 0; i < count; i++)
{
string key = br.ReadString();
int len = br.ReadInt32();
byte[] data = br.ReadBytes(len);
this[key] = data;
}
return this;
}
}

View File

@ -0,0 +1,23 @@
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.H6280;
//TODO - refactor into different files
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{
public class CodeDataLog_GB : CodeDataLog
{
public static CodeDataLog_GB Create(IMemoryDomains memdomains)
{
var t = new CodeDataLog_GB();
t["ROM"] = new byte[memdomains["ROM"].Size];
//t["HRAM"] = new byte[memdomains["HRAM"].Size]; //this is probably useless, but it's here if someone needs it
t["WRAM"] = new byte[memdomains["WRAM"].Size];
t["CartRAM"] = new byte[memdomains["Cart RAM"].Size];
return t;
}
public override string SubType { get { return "GB"; } }
public override int SubVer { get { return 0; } }
}
}

View File

@ -18,9 +18,9 @@ namespace BizHawk.Emulation.Cores.PCEngine
}
}
/// <summary>
/// <summary>
/// informs the CPU of the general memory layout, so it can do CDL
/// </summary>
/// </summary>
public void InitCDLMappings()
{
if (Cpu.Mappings != null)