Hex Editor - support archived roms for the Rom File domain

This commit is contained in:
adelikat 2012-09-02 22:45:06 +00:00
parent 4031fd8324
commit 86f3394be0
1 changed files with 74 additions and 3 deletions

View File

@ -174,12 +174,17 @@ namespace BizHawk.MultiClient
for (int j = 0; j < 16; j += DataSize) for (int j = 0; j < 16; j += DataSize)
{ {
if (addr + j < Domain.Size) if (addr + j < Domain.Size)
{
rowStr.AppendFormat(DigitFormatString, MakeValue(addr + j)); rowStr.AppendFormat(DigitFormatString, MakeValue(addr + j));
}
} }
rowStr.Append(" | "); rowStr.Append(" | ");
for (int k = 0; k < 16; k++) for (int k = 0; k < 16; k++)
{ {
rowStr.Append(Remap(Domain.PeekByte(addr + k))); if (addr + k < Domain.Size)
{
rowStr.Append(Remap(Domain.PeekByte(addr + k)));
}
} }
rowStr.AppendLine(); rowStr.AppendLine();
@ -317,14 +322,80 @@ namespace BizHawk.MultiClient
Refresh(); Refresh();
} }
private bool CurrentROMIsArchive()
{
string path = Global.MainForm.CurrentlyOpenRom;
if (path == null)
{
return false;
}
using (var file = new HawkFile())
{
file.Open(path);
if (!file.Exists)
{
return false;
}
if (file.IsArchive)
{
return true;
}
else
{
return false;
}
}
}
private byte[] GetRomBytes()
{
byte[] bytes;
string path = Global.MainForm.CurrentlyOpenRom;
if (path == null)
{
return null;
}
using (var file = new HawkFile())
{
file.Open(path);
if (!file.Exists)
{
return null;
}
if (file.IsArchive)
{
var stream = file.GetStream();
return Util.ReadAllBytes(stream);
}
else
{
return File.ReadAllBytes(path);
}
}
return new byte[0];
}
private void SetMemoryDomain(int pos) private void SetMemoryDomain(int pos)
{ {
if (pos == 999) if (pos == 999)
{ {
ROM = File.ReadAllBytes(Global.MainForm.CurrentlyOpenRom); ROM = GetRomBytes();
ROMDomain = new MemoryDomain("ROM File", ROM.Length, Endian.Little, if (ROM == null)
{
ROM = new byte[1] { 0xFF };
}
ROMDomain = new MemoryDomain("ROM File", ROM.Length, Endian.Little,
addr => ROM[addr], addr => ROM[addr],
(addr, value) => ROM[addr] = value); (addr, value) => ROM[addr] = value);
Domain = ROMDomain; Domain = ROMDomain;
} }
else if (pos < Global.Emulator.MemoryDomains.Count) //Sanity check else if (pos < Global.Emulator.MemoryDomains.Count) //Sanity check