a bit of memory domain cleanup
This commit is contained in:
parent
4b2d116738
commit
af451143bf
|
@ -135,8 +135,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
_rom = GetRomBytes();
|
_rom = GetRomBytes();
|
||||||
_romDomain = new MemoryDomain(
|
_romDomain = MemoryDomain.FromByteArray("File on Disk", MemoryDomain.Endian.Little, _rom);
|
||||||
"File on Disk", _rom.Length, MemoryDomain.Endian.Little, i => _rom[i], (i, value) => _rom[i] = value);
|
|
||||||
|
|
||||||
if (_domain.Name == _romDomain.Name)
|
if (_domain.Name == _romDomain.Name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,19 +28,49 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public Action<long, byte> PokeByte { get; private set; }
|
public Action<long, byte> PokeByte { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// creates a memorydomain that references a managed byte array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="endian"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <param name="writable">if false, writes will be ignored</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static MemoryDomain FromByteArray(string name, Endian endian, byte[] data, bool writable = true)
|
||||||
|
{
|
||||||
|
if (data == null)
|
||||||
|
throw new ArgumentNullException("data");
|
||||||
|
return new MemoryDomain
|
||||||
|
(
|
||||||
|
name,
|
||||||
|
data.Length,
|
||||||
|
endian,
|
||||||
|
delegate(long addr)
|
||||||
|
{
|
||||||
|
return data[addr];
|
||||||
|
},
|
||||||
|
delegate(long addr, byte val)
|
||||||
|
{
|
||||||
|
if (writable)
|
||||||
|
data[addr] = val;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// create a memorydomain that references an unmanaged memory block
|
/// create a memorydomain that references an unmanaged memory block
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">must remain valid as long as the MemoryDomain exists!</param>
|
/// <param name="data">must remain valid as long as the MemoryDomain exists!</param>
|
||||||
/// <param name="writable">if false, writes will be ignored</param>
|
/// <param name="writable">if false, writes will be ignored</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public unsafe static MemoryDomain FromIntPtr(string name, int size, Endian endian, IntPtr data, bool writable = true)
|
public unsafe static MemoryDomain FromIntPtr(string name, long size, Endian endian, IntPtr data, bool writable = true)
|
||||||
{
|
{
|
||||||
if (data == IntPtr.Zero)
|
if (data == IntPtr.Zero)
|
||||||
throw new ArgumentNullException("data");
|
throw new ArgumentNullException("data");
|
||||||
if (size <= 0)
|
if ((ulong)size >= 0x80000000)
|
||||||
throw new ArgumentOutOfRangeException("size");
|
throw new ArgumentOutOfRangeException("size");
|
||||||
byte* p = (byte*)data;
|
byte* p = (byte*)data;
|
||||||
|
uint l = (uint)size;
|
||||||
return new MemoryDomain
|
return new MemoryDomain
|
||||||
(
|
(
|
||||||
name,
|
name,
|
||||||
|
@ -48,7 +78,7 @@ namespace BizHawk.Emulation.Common
|
||||||
endian,
|
endian,
|
||||||
delegate(long addr)
|
delegate(long addr)
|
||||||
{
|
{
|
||||||
if ((uint)addr >= size)
|
if ((uint)addr >= l)
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
return p[addr];
|
return p[addr];
|
||||||
},
|
},
|
||||||
|
@ -56,7 +86,7 @@ namespace BizHawk.Emulation.Common
|
||||||
{
|
{
|
||||||
if (writable)
|
if (writable)
|
||||||
{
|
{
|
||||||
if ((uint)addr >= size)
|
if ((uint)addr >= l)
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
p[addr] = val;
|
p[addr] = val;
|
||||||
}
|
}
|
||||||
|
@ -70,13 +100,14 @@ namespace BizHawk.Emulation.Common
|
||||||
/// <param name="data">must remain valid as long as the MemoryDomain exists!</param>
|
/// <param name="data">must remain valid as long as the MemoryDomain exists!</param>
|
||||||
/// <param name="writable">if false, writes will be ignored</param>
|
/// <param name="writable">if false, writes will be ignored</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public unsafe static MemoryDomain FromIntPtrSwap16(string name, int size, Endian endian, IntPtr data, bool writable = true)
|
public unsafe static MemoryDomain FromIntPtrSwap16(string name, long size, Endian endian, IntPtr data, bool writable = true)
|
||||||
{
|
{
|
||||||
if (data == IntPtr.Zero)
|
if (data == IntPtr.Zero)
|
||||||
throw new ArgumentNullException("data");
|
throw new ArgumentNullException("data");
|
||||||
if (size <= 0)
|
if ((ulong)size >= 0x80000000)
|
||||||
throw new ArgumentOutOfRangeException("size");
|
throw new ArgumentOutOfRangeException("size");
|
||||||
byte* p = (byte*)data;
|
byte* p = (byte*)data;
|
||||||
|
uint l = (uint)size;
|
||||||
return new MemoryDomain
|
return new MemoryDomain
|
||||||
(
|
(
|
||||||
name,
|
name,
|
||||||
|
@ -84,7 +115,7 @@ namespace BizHawk.Emulation.Common
|
||||||
endian,
|
endian,
|
||||||
delegate(long addr)
|
delegate(long addr)
|
||||||
{
|
{
|
||||||
if (addr < 0 || addr >= size)
|
if ((uint)addr >= l)
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
return p[addr ^ 1];
|
return p[addr ^ 1];
|
||||||
},
|
},
|
||||||
|
@ -92,7 +123,7 @@ namespace BizHawk.Emulation.Common
|
||||||
{
|
{
|
||||||
if (writable)
|
if (writable)
|
||||||
{
|
{
|
||||||
if (addr < 0 || addr >= size)
|
if ((uint)addr >= l)
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
p[addr ^ 1] = val;
|
p[addr ^ 1] = val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,7 @@ namespace BizHawk.Emulation.Cores.Calculators
|
||||||
{
|
{
|
||||||
var domains = new List<MemoryDomain>
|
var domains = new List<MemoryDomain>
|
||||||
{
|
{
|
||||||
new MemoryDomain(
|
MemoryDomain.FromByteArray("Main RAM", MemoryDomain.Endian.Little, ram)
|
||||||
"Main RAM",
|
|
||||||
ram.Length,
|
|
||||||
MemoryDomain.Endian.Little,
|
|
||||||
addr => ram[addr],
|
|
||||||
(addr, value) => ram[addr] = value
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_memoryDomains = new MemoryDomainList(domains);
|
_memoryDomains = new MemoryDomainList(domains);
|
||||||
|
|
|
@ -598,6 +598,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
||||||
string name = Marshal.PtrToStringAnsi(pname);
|
string name = Marshal.PtrToStringAnsi(pname);
|
||||||
if (name == "VRAM")
|
if (name == "VRAM")
|
||||||
{
|
{
|
||||||
|
// vram pokes need to go through hook which invalidates cached tiles
|
||||||
byte* p = (byte*)area;
|
byte* p = (byte*)area;
|
||||||
mm.Add(new MemoryDomain(name, size, MemoryDomain.Endian.Unknown,
|
mm.Add(new MemoryDomain(name, size, MemoryDomain.Endian.Unknown,
|
||||||
delegate(long addr)
|
delegate(long addr)
|
||||||
|
|
Loading…
Reference in New Issue