CDL - add .cdl file map to dialogbox display

This commit is contained in:
zeromus 2015-11-01 11:23:33 -06:00
parent 8497c25414
commit 1ce0437c3d
2 changed files with 56 additions and 22 deletions

View File

@ -74,38 +74,45 @@ namespace BizHawk.Client.EmuHawk
private void UpdateDisplay() private void UpdateDisplay()
{ {
var lines = new List<string>();
if (_cdl == null) if (_cdl == null)
{ {
lines.Add("No CDL loaded."); CdlTextbox.Text = "No CDL loaded.";
return;
} }
else
StringWriter sw = new StringWriter();
sw.WriteLine("CDL contains the following domains:");
foreach (var kvp in _cdl)
{ {
lines.Add("CDL contains the following domains:"); int total = 0;
foreach (var kvp in _cdl) unsafe
{ {
int total = 0; fixed (byte* data = kvp.Value)
unsafe
{ {
fixed (byte* data = kvp.Value) byte* src = data;
byte* end = data + kvp.Value.Length;
while (src < end)
{ {
byte* src = data; if (*src++ != 0)
byte* end = data + kvp.Value.Length;
while (src < end)
{ {
if (*src++ != 0) total++;
{
total++;
}
} }
} }
} }
lines.Add(string.Format("Domain {0} Size {1} Mapped {2}% ({3}/{4} bytes)", kvp.Key, kvp.Value.Length, total / (float) kvp.Value.Length * 100f, total, kvp.Value.Length));
} }
sw.WriteLine("Domain {0} Size {1} Mapped {2}% ({3}/{4} bytes)", kvp.Key, kvp.Value.Length, total / (float)kvp.Value.Length * 100f, total, kvp.Value.Length);
}
sw.WriteLine();
var bm = _cdl.GetBlockMap();
foreach (var kvp in bm)
{
sw.WriteLine("{0:X8}: {1}", kvp.Value, kvp.Key);
} }
CdlTextbox.Lines = lines.ToArray(); CdlTextbox.Text = sw.ToString();
} }
public bool AskSaveChanges() public bool AskSaveChanges()

View File

@ -71,17 +71,44 @@ namespace BizHawk.Emulation.Common
public void Save(Stream s) public void Save(Stream s)
{ {
_Save(s, true);
}
Dictionary<string, long> _Save(Stream s, bool forReal)
{
var ret = new Dictionary<string, long>();
var w = new BinaryWriter(s); var w = new BinaryWriter(s);
w.Write("BIZHAWK-CDL-2"); w.Write("BIZHAWK-CDL-2");
w.Write(SubType.PadRight(15)); w.Write(SubType.PadRight(15));
w.Write(Count); w.Write(Count);
foreach (var kvp in this) w.Flush();
long addr = s.Position;
if (forReal)
{ {
w.Write(kvp.Key); foreach (var kvp in this)
w.Write(kvp.Value.Length); {
w.Write(kvp.Value); w.Write(kvp.Key);
w.Write(kvp.Value.Length);
w.Write(kvp.Value);
}
}
else
{
foreach (var kvp in this)
{
addr += kvp.Key.Length + 1; //assumes shortly-encoded key names
addr += 4;
ret[kvp.Key] = addr;
addr += kvp.Value.Length;
}
} }
w.Flush(); w.Flush();
return ret;
}
public Dictionary<string, long> GetBlockMap()
{
return _Save(new MemoryStream(), false);
} }
public void Load(Stream s) public void Load(Stream s)