Break a bunch of memory domain stuff with pointless refactoring

This commit is contained in:
nattthebear 2016-04-13 19:50:06 -04:00
parent 71e32bc3d9
commit 111648cf98
34 changed files with 468 additions and 438 deletions

View File

@ -229,7 +229,7 @@ namespace BizHawk.Client.Common
var d = (string.IsNullOrEmpty(domain)) ? Domain : DomainList[VerifyMemoryDomain(domain)]; var d = (string.IsNullOrEmpty(domain)) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (addr < d.Size) if (addr < d.Size)
{ {
var val = d.PeekDWord(addr, bigendian); var val = d.PeekUint(addr, bigendian);
var bytes = BitConverter.GetBytes(val); var bytes = BitConverter.GetBytes(val);
return BitConverter.ToSingle(bytes, 0); return BitConverter.ToSingle(bytes, 0);
} }
@ -252,7 +252,7 @@ namespace BizHawk.Client.Common
var dv = (float)value; var dv = (float)value;
var bytes = BitConverter.GetBytes(dv); var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0); var v = BitConverter.ToUInt32(bytes, 0);
d.PokeDWord(addr, v, bigendian); d.PokeUint(addr, v, bigendian);
} }
else else
{ {

View File

@ -888,11 +888,11 @@ namespace BizHawk.Client.Common
return theByte; return theByte;
case WatchSize.Word: case WatchSize.Word:
var theWord = _settings.Domain.PeekWord(addr % Domain.Size, _settings.BigEndian); var theWord = _settings.Domain.PeekUshort(addr % Domain.Size, _settings.BigEndian);
return theWord; return theWord;
case WatchSize.DWord: case WatchSize.DWord:
var theDWord = _settings.Domain.PeekDWord(addr % Domain.Size, _settings.BigEndian); var theDWord = _settings.Domain.PeekUint(addr % Domain.Size, _settings.BigEndian);
return theDWord; return theDWord;
} }
} }
@ -958,7 +958,7 @@ namespace BizHawk.Client.Common
public MiniWordWatch(MemoryDomain domain, long addr, bool bigEndian) public MiniWordWatch(MemoryDomain domain, long addr, bool bigEndian)
{ {
Address = addr; Address = addr;
_previous = domain.PeekWord(Address % domain.Size, bigEndian); _previous = domain.PeekUshort(Address % domain.Size, bigEndian);
} }
public long Previous public long Previous
@ -968,7 +968,7 @@ namespace BizHawk.Client.Common
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian) public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
{ {
_previous = domain.PeekWord(Address, bigendian); _previous = domain.PeekUshort(Address, bigendian);
} }
} }
@ -980,7 +980,7 @@ namespace BizHawk.Client.Common
public MiniDWordWatch(MemoryDomain domain, long addr, bool bigEndian) public MiniDWordWatch(MemoryDomain domain, long addr, bool bigEndian)
{ {
Address = addr; Address = addr;
_previous = domain.PeekDWord(Address % domain.Size, bigEndian); _previous = domain.PeekUint(Address % domain.Size, bigEndian);
} }
public long Previous public long Previous
@ -990,7 +990,7 @@ namespace BizHawk.Client.Common
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian) public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
{ {
_previous = domain.PeekDWord(Address, bigendian); _previous = domain.PeekUint(Address, bigendian);
} }
} }
@ -1071,7 +1071,7 @@ namespace BizHawk.Client.Common
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian) public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
{ {
_previous = _prevFrame = domain.PeekWord(Address % domain.Size, bigendian); _previous = _prevFrame = domain.PeekUshort(Address % domain.Size, bigendian);
} }
public long Previous public long Previous
@ -1086,7 +1086,7 @@ namespace BizHawk.Client.Common
public void Update(PreviousType type, MemoryDomain domain, bool bigendian) public void Update(PreviousType type, MemoryDomain domain, bool bigendian)
{ {
var value = domain.PeekWord(Address % domain.Size, bigendian); var value = domain.PeekUshort(Address % domain.Size, bigendian);
if (value != Previous) if (value != Previous)
{ {
_changecount++; _changecount++;
@ -1131,7 +1131,7 @@ namespace BizHawk.Client.Common
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian) public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
{ {
_previous = _prevFrame = domain.PeekDWord(Address % domain.Size, bigendian); _previous = _prevFrame = domain.PeekUint(Address % domain.Size, bigendian);
} }
public long Previous public long Previous
@ -1146,7 +1146,7 @@ namespace BizHawk.Client.Common
public void Update(PreviousType type, MemoryDomain domain, bool bigendian) public void Update(PreviousType type, MemoryDomain domain, bool bigendian)
{ {
var value = domain.PeekDWord(Address % domain.Size, bigendian); var value = domain.PeekUint(Address % domain.Size, bigendian);
if (value != Previous) if (value != Previous)
{ {
_changecount++; _changecount++;
@ -1180,7 +1180,7 @@ namespace BizHawk.Client.Common
public Settings(IMemoryDomains memoryDomains) public Settings(IMemoryDomains memoryDomains)
{ {
BigEndian = memoryDomains.MainMemory.EndianType == MemoryDomain.Endian.Big; BigEndian = memoryDomains.MainMemory.EndianType == MemoryDomain.Endian.Big;
Size = (WatchSize)memoryDomains.MainMemory.ByteSize; Size = (WatchSize)memoryDomains.MainMemory.WordSize;
Type = DisplayType.Unsigned; Type = DisplayType.Unsigned;
Mode = memoryDomains.MainMemory.Size > (1024 * 1024) ? Mode = memoryDomains.MainMemory.Size > (1024 * 1024) ?
SearchMode.Fast : SearchMode.Fast :

View File

@ -373,11 +373,11 @@ namespace BizHawk.Client.Common
{ {
if (_domain.Size == 0) if (_domain.Size == 0)
{ {
return _domain.PeekWord(_address, _bigEndian); return _domain.PeekUshort(_address, _bigEndian);
} }
else else
{ {
return _domain.PeekWord(_address % _domain.Size, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain return _domain.PeekUshort(_address % _domain.Size, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
} }
} }
} }
@ -393,11 +393,11 @@ namespace BizHawk.Client.Common
{ {
if (_domain.Size == 0) if (_domain.Size == 0)
{ {
return _domain.PeekDWord(_address, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain return _domain.PeekUint(_address, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
} }
else else
{ {
return _domain.PeekDWord(_address % _domain.Size, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain return _domain.PeekUint(_address % _domain.Size, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
} }
} }
} }
@ -412,15 +412,15 @@ namespace BizHawk.Client.Common
protected void PokeWord(ushort val) protected void PokeWord(ushort val)
{ {
if (_domain.Size == 0) if (_domain.Size == 0)
_domain.PokeWord(_address, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain _domain.PokeUshort(_address, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
else _domain.PokeWord(_address % _domain.Size, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain else _domain.PokeUshort(_address % _domain.Size, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
} }
protected void PokeDWord(uint val) protected void PokeDWord(uint val)
{ {
if (_domain.Size == 0) if (_domain.Size == 0)
_domain.PokeDWord(_address, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain _domain.PokeUint(_address, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
else _domain.PokeDWord(_address % _domain.Size, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain else _domain.PokeUint(_address % _domain.Size, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
} }
#endregion Protected #endregion Protected

View File

@ -873,10 +873,10 @@ namespace BizHawk.Client.EmuHawk
val = _currentDomain.PeekByte(addr); val = _currentDomain.PeekByte(addr);
break; break;
case 2: case 2:
val = _currentDomain.PeekWord(addr, _bigEndian); val = _currentDomain.PeekUshort(addr, _bigEndian);
break; break;
case 4: case 4:
val = (int)_currentDomain.PeekDWord(addr, _bigEndian); val = (int)_currentDomain.PeekUint(addr, _bigEndian);
break; break;
} }

View File

@ -23,6 +23,28 @@ namespace BizHawk.Client.EmuHawk
// int to long TODO: 32 bit domains have more digits than the hex editor can account for and the address covers up the 0 column // int to long TODO: 32 bit domains have more digits than the hex editor can account for and the address covers up the 0 column
public partial class HexEditor : ToolFormBase, IToolFormAutoConfig public partial class HexEditor : ToolFormBase, IToolFormAutoConfig
{ {
private class NullMemoryDomain : MemoryDomain
{
public override byte PeekByte(long addr)
{
return 0;
}
public override void PokeByte(long addr, byte val)
{
}
public NullMemoryDomain()
{
EndianType = Endian.Unknown;
Name = "Null";
Size = 1024;
Writable = true;
WordSize = 1;
}
}
[RequiredService] [RequiredService]
private IMemoryDomains MemoryDomains { get; set; } private IMemoryDomains MemoryDomains { get; set; }
@ -47,8 +69,7 @@ namespace BizHawk.Client.EmuHawk
private long _maxRow; private long _maxRow;
private MemoryDomain _domain = new MemoryDomain( private MemoryDomain _domain = new NullMemoryDomain();
"NULL", 1024, MemoryDomain.Endian.Little, addr => 0, delegate(long a, byte v) { v = 0; });
private long _row; private long _row;
private long _addr; private long _addr;
@ -429,7 +450,7 @@ namespace BizHawk.Client.EmuHawk
private void HexEditor_Load(object sender, EventArgs e) private void HexEditor_Load(object sender, EventArgs e)
{ {
DataSize = _domain.ByteSize; DataSize = _domain.WordSize;
SetDataSize(DataSize); SetDataSize(DataSize);
if (RecentTables.AutoLoad) if (RecentTables.AutoLoad)
@ -555,9 +576,9 @@ namespace BizHawk.Client.EmuHawk
case 1: case 1:
return _domain.PeekByte(address); return _domain.PeekByte(address);
case 2: case 2:
return _domain.PeekWord(address, BigEndian); return _domain.PeekUshort(address, BigEndian);
case 4: case 4:
return (int)_domain.PeekDWord(address, BigEndian); return (int)_domain.PeekUint(address, BigEndian);
} }
} }
@ -1096,15 +1117,15 @@ namespace BizHawk.Client.EmuHawk
(byte)(_domain.PeekByte(address) + 1)); (byte)(_domain.PeekByte(address) + 1));
break; break;
case 2: case 2:
_domain.PokeWord( _domain.PokeUshort(
address, address,
(ushort)(_domain.PeekWord(address, BigEndian) + 1), (ushort)(_domain.PeekUshort(address, BigEndian) + 1),
BigEndian); BigEndian);
break; break;
case 4: case 4:
_domain.PokeDWord( _domain.PokeUint(
address, address,
_domain.PeekDWord(address, BigEndian) + 1, _domain.PeekUint(address, BigEndian) + 1,
BigEndian); BigEndian);
break; break;
} }
@ -1129,15 +1150,15 @@ namespace BizHawk.Client.EmuHawk
(byte)(_domain.PeekByte(address) - 1)); (byte)(_domain.PeekByte(address) - 1));
break; break;
case 2: case 2:
_domain.PokeWord( _domain.PokeUshort(
address, address,
(ushort)(_domain.PeekWord(address, BigEndian) - 1), (ushort)(_domain.PeekUshort(address, BigEndian) - 1),
BigEndian); BigEndian);
break; break;
case 4: case 4:
_domain.PokeDWord( _domain.PokeUint(
address, address,
_domain.PeekDWord(address, BigEndian) - 1, _domain.PeekUint(address, BigEndian) - 1,
BigEndian); BigEndian);
break; break;
} }
@ -2293,8 +2314,8 @@ namespace BizHawk.Client.EmuHawk
{ {
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
ushort hi = _domain.PeekWord(((addr+(i<<3)+(j<<1) )^0x0),bigend); ushort hi = _domain.PeekUshort(((addr+(i<<3)+(j<<1) )^0x0),bigend);
ushort lo = _domain.PeekWord(((addr+(i<<3)+(j<<1) + 32)^0x0),bigend); ushort lo = _domain.PeekUshort(((addr+(i<<3)+(j<<1) + 32)^0x0),bigend);
matVals[i,j] = (int)(((hi << 16) | lo)) / 65536.0f; matVals[i,j] = (int)(((hi << 16) | lo)) / 65536.0f;
} }
} }

View File

@ -46,7 +46,7 @@ namespace BizHawk.Client.EmuHawk
{ {
default: default:
case Mode.New: case Mode.New:
switch (MemoryDomains.First().ByteSize) switch (MemoryDomains.First().WordSize)
{ {
default: default:
case 1: case 1:

View File

@ -5,37 +5,23 @@ using System.Collections.ObjectModel;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
public class MemoryDomain public abstract class MemoryDomain
{ {
public enum Endian { Big, Little, Unknown } public enum Endian { Big, Little, Unknown }
public MemoryDomain(string name, long size, Endian endian, Func<long, byte> peekByte, Action<long, byte> pokeByte, int byteSize = 1) public string Name { get; protected set; }
{
Name = name;
Size = size;
ByteSize = byteSize;
EndianType = endian;
PeekByte = peekByte;
PokeByte = pokeByte;
}
public string Name { get; private set; } public long Size { get; protected set; }
public long Size { get; private set; } public int WordSize { get; protected set; }
public int ByteSize { get; private set; } public Endian EndianType { get; protected set; }
public Endian EndianType { get; private set; } public bool Writable { get; protected set; }
public Func<long, byte> PeekByte { get; private set; } public abstract byte PeekByte(long addr);
public Action<long, byte> PokeByte { get; private set; } public abstract void PokeByte(long addr, byte val);
public void SetPeekPokeDelegates(Func<long, byte> peeker, Action<long, byte> poker)
{
PeekByte = peeker;
PokeByte = poker;
}
/// <summary> /// <summary>
/// creates a memorydomain that references a managed byte array /// creates a memorydomain that references a managed byte array
@ -45,59 +31,10 @@ namespace BizHawk.Emulation.Common
/// <param name="data"></param> /// <param name="data"></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 static MemoryDomain FromByteArray(string name, Endian endian, byte[] data, bool writable = true, int byteSize = 1) [Obsolete]
public static MemoryDomain FromByteArray(string name, Endian endian, byte[] data, bool writable = true, int wordSize = 1)
{ {
if (data == null) return new MemoryDomainByteArray(name, endian, data, writable, wordSize);
throw new ArgumentNullException("data");
return new MemoryDomain
(
name,
data.Length,
endian,
delegate(long addr)
{
return data[addr];
},
writable ?
delegate(long addr, byte val)
{
data[addr] = val;
}
: (Action<long, byte>)null,
byteSize
);
}
public void SetDelegatesForIntPtr(long size, Endian endian, IntPtr data, bool writable = true, int byteSize = 1)
{
Func<long, byte> peeker;
Action<long, byte> poker;
CreateDelegatesForIntPtr(size, endian, data, out peeker, out poker, writable, byteSize);
PeekByte = peeker;
PokeByte = poker;
}
public unsafe static void CreateDelegatesForIntPtr(long size, Endian endian, IntPtr data, out Func<long, byte> peeker, out Action<long, byte> poker, bool writable = true, int byteSize = 1)
{
byte* p = (byte*)data;
uint l = (uint)size;
peeker = delegate(long addr)
{
if ((uint)addr >= l)
throw new ArgumentOutOfRangeException();
return p[addr];
};
poker =
writable ?
delegate(long addr, byte val)
{
if ((uint)addr >= l)
throw new ArgumentOutOfRangeException();
p[addr] = val;
}
: (Action<long, byte>)null;
} }
/// <summary> /// <summary>
@ -106,16 +43,10 @@ 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 FromIntPtr(string name, long size, Endian endian, IntPtr data, bool writable = true, int byteSize = 1) [Obsolete]
public unsafe static MemoryDomain FromIntPtr(string name, long size, Endian endian, IntPtr data, bool writable = true, int wordSize = 1)
{ {
if (data == IntPtr.Zero) return new MemoryDomainIntPtr(name, endian, data, size, writable, wordSize);
throw new ArgumentNullException("data");
if ((ulong)size >= 0x80000000)
throw new ArgumentOutOfRangeException("size");
var md = new MemoryDomain(name,size,endian, null, null, byteSize);
md.SetDelegatesForIntPtr(size, endian, data, writable, byteSize);
return md;
} }
/// <summary> /// <summary>
@ -124,35 +55,10 @@ 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, long size, Endian endian, IntPtr data, bool writable = true, int byteSize = 1) [Obsolete]
public unsafe static MemoryDomain FromIntPtrSwap16(string name, long size, Endian endian, IntPtr data, bool writable = true)
{ {
if (data == IntPtr.Zero) return new MemoryDomainIntPtrSwap16(name, endian, data, size, writable);
throw new ArgumentNullException("data");
if ((ulong)size >= 0x80000000)
throw new ArgumentOutOfRangeException("size");
byte* p = (byte*)data;
uint l = (uint)size;
return new MemoryDomain
(
name,
size,
endian,
delegate(long addr)
{
if ((uint)addr >= l)
throw new ArgumentOutOfRangeException();
return p[addr ^ 1];
},
writable ?
delegate(long addr, byte val)
{
if ((uint)addr >= l)
throw new ArgumentOutOfRangeException();
p[addr ^ 1] = val;
}
: (Action<long, byte>)null,
byteSize
);
} }
public override string ToString() public override string ToString()
@ -160,7 +66,7 @@ namespace BizHawk.Emulation.Common
return Name; return Name;
} }
public ushort PeekWord(long addr, bool bigEndian) public virtual ushort PeekUshort(long addr, bool bigEndian)
{ {
Endian endian = bigEndian ? Endian.Big : Endian.Little; Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian) switch (endian)
@ -173,7 +79,7 @@ namespace BizHawk.Emulation.Common
} }
} }
public uint PeekDWord(long addr, bool bigEndian) public virtual uint PeekUint(long addr, bool bigEndian)
{ {
Endian endian = bigEndian ? Endian.Big : Endian.Little; Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian) switch (endian)
@ -192,7 +98,7 @@ namespace BizHawk.Emulation.Common
} }
} }
public void PokeWord(long addr, ushort val, bool bigEndian) public virtual void PokeUshort(long addr, ushort val, bool bigEndian)
{ {
Endian endian = bigEndian ? Endian.Big : Endian.Little; Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian) switch (endian)
@ -209,7 +115,7 @@ namespace BizHawk.Emulation.Common
} }
} }
public void PokeDWord(long addr, uint val, bool bigEndian) public virtual void PokeUint(long addr, uint val, bool bigEndian)
{ {
Endian endian = bigEndian ? Endian.Big : Endian.Little; Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian) switch (endian)
@ -230,84 +136,4 @@ namespace BizHawk.Emulation.Common
} }
} }
} }
public class MemoryDomainList : ReadOnlyCollection<MemoryDomain>, IMemoryDomains
{
private MemoryDomain _mainMemory;
private MemoryDomain _systemBus;
public bool Has(string name)
{
return this.FirstOrDefault((md) => md.Name == name) != null;
}
public MemoryDomainList(IList<MemoryDomain> domains)
: base(domains)
{
}
public MemoryDomain this[string name]
{
get
{
return this.FirstOrDefault(x => x.Name == name);
}
}
public MemoryDomain MainMemory
{
get
{
if (_mainMemory != null)
{
return _mainMemory;
}
return this.First();
}
set
{
_mainMemory = value;
}
}
public bool HasSystemBus
{
get
{
if (_systemBus != null)
{
return true;
}
return this.Any(x => x.Name == "System Bus");
}
}
public MemoryDomain SystemBus
{
get
{
if (_systemBus != null)
{
return _systemBus;
}
var bus = this.FirstOrDefault(x => x.Name == "System Bus");
if (bus != null)
{
return bus;
}
return MainMemory;
}
set
{
_systemBus = value;
}
}
}
} }

View File

@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Common
{
public class MemoryDomainDelegate : MemoryDomain
{
private Func<long, byte> _peek;
private Action<long, byte> _poke;
public Func<long, byte> Peek { get { return _peek; } set { _peek = value; } }
public Action<long, byte> Poke { get { return _poke; } set { _poke = value; Writable = value != null; } }
public override byte PeekByte(long addr)
{
return _peek(addr);
}
public override void PokeByte(long addr, byte val)
{
if (_poke != null)
_poke(addr, val);
}
public MemoryDomainDelegate(string name, long size, Endian endian, Func<long, byte> peek, Action<long, byte> poke, int wordSize)
{
Name = name;
EndianType = endian;
Size = size;
_peek = peek;
_poke = poke;
Writable = poke != null;
}
}
public class MemoryDomainByteArray : MemoryDomain
{
private byte[] _data;
public byte[] Data { get { return _data; } set { _data = value; Size = _data.LongLength; } }
public override byte PeekByte(long addr)
{
return Data[addr];
}
public override void PokeByte(long addr, byte val)
{
if (Writable)
Data[addr] = val;
}
public MemoryDomainByteArray(string name, Endian endian, byte[] data, bool writable, int wordSize)
{
Name = name;
EndianType = endian;
Data = data;
Writable = writable;
WordSize = wordSize;
}
}
public unsafe class MemoryDomainIntPtr : MemoryDomain
{
public IntPtr Data { get; set; }
public override byte PeekByte(long addr)
{
if ((ulong)addr >= (ulong)Size)
return ((byte*)Data)[addr];
else
throw new ArgumentOutOfRangeException("addr");
}
public override void PokeByte(long addr, byte val)
{
if (Writable)
{
if ((ulong)addr >= (ulong)Size)
((byte*)Data)[addr] = val;
else
throw new ArgumentOutOfRangeException("addr");
}
}
public MemoryDomainIntPtr(string name, Endian endian, IntPtr data, long size, bool writable, int wordSize)
{
Name = name;
EndianType = endian;
Data = data;
Size = size;
Writable = writable;
WordSize = wordSize;
}
}
public unsafe class MemoryDomainIntPtrSwap16 : MemoryDomain
{
public IntPtr Data { get; set; }
public override byte PeekByte(long addr)
{
if ((ulong)addr >= (ulong)Size)
return ((byte*)Data)[addr ^ 1];
else
throw new ArgumentOutOfRangeException("addr");
}
public override void PokeByte(long addr, byte val)
{
if (Writable)
{
if ((ulong)addr >= (ulong)Size)
((byte*)Data)[addr ^ 1] = val;
else
throw new ArgumentOutOfRangeException("addr");
}
}
public MemoryDomainIntPtrSwap16(string name, Endian endian, IntPtr data, long size, bool writable)
{
Name = name;
EndianType = endian;
Data = data;
Size = size;
Writable = writable;
WordSize = 2;
}
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
namespace BizHawk.Emulation.Common
{
public class MemoryDomainList : ReadOnlyCollection<MemoryDomain>, IMemoryDomains
{
private MemoryDomain _mainMemory;
private MemoryDomain _systemBus;
public bool Has(string name)
{
return this.FirstOrDefault((md) => md.Name == name) != null;
}
public MemoryDomainList(IList<MemoryDomain> domains)
: base(domains)
{
}
public MemoryDomain this[string name]
{
get
{
return this.FirstOrDefault(x => x.Name == name);
}
}
public MemoryDomain MainMemory
{
get
{
if (_mainMemory != null)
{
return _mainMemory;
}
return this.First();
}
set
{
_mainMemory = value;
}
}
public bool HasSystemBus
{
get
{
if (_systemBus != null)
{
return true;
}
return this.Any(x => x.Name == "System Bus");
}
}
public MemoryDomain SystemBus
{
get
{
if (_systemBus != null)
{
return _systemBus;
}
var bus = this.FirstOrDefault(x => x.Name == "System Bus");
if (bus != null)
{
return bus;
}
return MainMemory;
}
set
{
_systemBus = value;
}
}
}
}

View File

@ -96,6 +96,8 @@
<Compile Include="Base Implementations\InputCallbackSystem.cs" /> <Compile Include="Base Implementations\InputCallbackSystem.cs" />
<Compile Include="Base Implementations\MemoryCallbackSystem.cs" /> <Compile Include="Base Implementations\MemoryCallbackSystem.cs" />
<Compile Include="Base Implementations\MemoryDomain.cs" /> <Compile Include="Base Implementations\MemoryDomain.cs" />
<Compile Include="Base Implementations\MemoryDomainImpls.cs" />
<Compile Include="Base Implementations\MemoryDomainList.cs" />
<Compile Include="Base Implementations\NullController.cs" /> <Compile Include="Base Implementations\NullController.cs" />
<Compile Include="Base Implementations\NullEmulator.cs" /> <Compile Include="Base Implementations\NullEmulator.cs" />
<Compile Include="Base Implementations\NullSound.cs" /> <Compile Include="Base Implementations\NullSound.cs" />

View File

@ -208,7 +208,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
public static bool CanPoke(this MemoryDomain d) public static bool CanPoke(this MemoryDomain d)
{ {
if (d.PokeByte == null) if (!d.Writable)
{ {
return false; return false;
} }

View File

@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
}, },
delegate(ushort addr) delegate(ushort addr)
{ {
return md.PeekWord(addr + i, false); return md.PeekUshort(addr + i, false);
} }
); );
w.WriteLine("0x{0:x8}: {1}", i, dis); w.WriteLine("0x{0:x8}: {1}", i, dis);

View File

@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Calculators
MemoryDomain.FromByteArray("Main RAM", MemoryDomain.Endian.Little, _ram) MemoryDomain.FromByteArray("Main RAM", MemoryDomain.Endian.Little, _ram)
}; };
var systemBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little, var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Calculators
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
Cpu.WriteMemory((ushort)addr, value); Cpu.WriteMemory((ushort)addr, value);
}); }, 1);
domains.Add(systemBusDomain); domains.Add(systemBusDomain);

View File

@ -11,7 +11,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
{ {
var domains = new List<MemoryDomain>(); var domains = new List<MemoryDomain>();
var mainRamDomain = new MemoryDomain("Main Ram", 0xC000, MemoryDomain.Endian.Little, var mainRamDomain = new MemoryDomainDelegate("Main Ram", 0xC000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 0xC000) if (addr < 0 || addr >= 0xC000)
@ -23,11 +23,11 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
if (addr < 0 || addr >= 0xC000) if (addr < 0 || addr >= 0xC000)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
_machine.Memory.Write((int)addr, value); _machine.Memory.Write((int)addr, value);
}); }, 1);
domains.Add(mainRamDomain); domains.Add(mainRamDomain);
var systemBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little, var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
_machine.Memory.Write((int)addr, value); _machine.Memory.Write((int)addr, value);
}); }, 1);
domains.Add(systemBusDomain); domains.Add(systemBusDomain);

View File

@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public static MemoryDomain Create(string name, int size, Func<int, int> peekByte, Action<int, int> pokeByte) public static MemoryDomain Create(string name, int size, Func<int, int> peekByte, Action<int, int> pokeByte)
{ {
return new MemoryDomain(name, size, MemoryDomain.Endian.Little, addr => unchecked((byte)peekByte((int)addr)), (addr, val) => pokeByte(unchecked((int)addr), val)); return new MemoryDomainDelegate(name, size, MemoryDomain.Endian.Little, addr => unchecked((byte)peekByte((int)addr)), (addr, val) => pokeByte(unchecked((int)addr), val), 1);
} }
} }
} }

View File

@ -11,50 +11,45 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
{ {
var domains = new List<MemoryDomain> var domains = new List<MemoryDomain>
{ {
new MemoryDomain( new MemoryDomainByteArray(
"Main RAM", "Main RAM",
128,
MemoryDomain.Endian.Little, MemoryDomain.Endian.Little,
addr => Ram[addr], Ram, true, 1),
(addr, value) => Ram[addr] = value), new MemoryDomainDelegate(
new MemoryDomain(
"TIA", "TIA",
16, 16,
MemoryDomain.Endian.Little, MemoryDomain.Endian.Little,
addr => _tia.ReadMemory((ushort)addr, true), addr => _tia.ReadMemory((ushort)addr, true),
(addr, value) => this._tia.WriteMemory((ushort)addr, value)), (addr, value) => this._tia.WriteMemory((ushort)addr, value), 1),
new MemoryDomain( new MemoryDomainDelegate(
"PIA", "PIA",
1024, 1024,
MemoryDomain.Endian.Little, MemoryDomain.Endian.Little,
addr => M6532.ReadMemory((ushort)addr, true), addr => M6532.ReadMemory((ushort)addr, true),
(addr, value) => M6532.WriteMemory((ushort)addr, value)), (addr, value) => M6532.WriteMemory((ushort)addr, value), 1),
new MemoryDomain( new MemoryDomainDelegate(
"System Bus", "System Bus",
65536, 65536,
MemoryDomain.Endian.Little, MemoryDomain.Endian.Little,
addr => _mapper.PeekMemory((ushort) addr), addr => _mapper.PeekMemory((ushort) addr),
(addr, value) => _mapper.PokeMemory((ushort) addr, value)) (addr, value) => _mapper.PokeMemory((ushort) addr, value), 1)
}; };
if (_mapper is mDPC) // TODO: also mDPCPlus if (_mapper is mDPC) // TODO: also mDPCPlus
{ {
domains.Add(new MemoryDomain( domains.Add(new MemoryDomainByteArray(
"DPC", "DPC",
2048, MemoryDomain.Endian.Little,(_mapper as mDPC).DspData, true, 1));
MemoryDomain.Endian.Little,
addr => (_mapper as mDPC).DspData[addr],
(addr, value) => (_mapper as mDPC).DspData[addr] = value));
} }
if (_mapper.HasCartRam) if (_mapper.HasCartRam)
{ {
domains.Add(new MemoryDomain( domains.Add(new MemoryDomainDelegate(
"Cart Ram", "Cart Ram",
_mapper.CartRam.Len, _mapper.CartRam.Len,
MemoryDomain.Endian.Little, MemoryDomain.Endian.Little,
addr => _mapper.CartRam[(int)addr], addr => _mapper.CartRam[(int)addr],
(addr, value) => _mapper.CartRam[(int)addr] = value)); (addr, value) => _mapper.CartRam[(int)addr] = value, 1));
} }
MemoryDomains = new MemoryDomainList(domains); MemoryDomains = new MemoryDomainList(domains);

View File

@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
_MemoryDomains = new List<MemoryDomain>(); _MemoryDomains = new List<MemoryDomain>();
if (theMachine is Machine7800) if (theMachine is Machine7800)
{ {
_MemoryDomains.Add(new MemoryDomain( _MemoryDomains.Add(new MemoryDomainDelegate(
"RAM", 0x1000, MemoryDomain.Endian.Unknown, "RAM", 0x1000, MemoryDomain.Endian.Unknown,
delegate(long addr) delegate(long addr)
{ {
@ -51,40 +51,22 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
{ {
((Machine7800)theMachine).RAM2[(ushort)addr] = val; ((Machine7800)theMachine).RAM2[(ushort)addr] = val;
} }
})); }, 1));
_MemoryDomains.Add(new MemoryDomain( _MemoryDomains.Add(new MemoryDomainByteArray(
"BIOS ROM", bios.Length, MemoryDomain.Endian.Unknown, "BIOS ROM", MemoryDomain.Endian.Unknown,
delegate(long addr) bios, false, 1));
{
return bios[addr];
},
null
));
if (hsc7800 != null) if (hsc7800 != null)
{ {
_MemoryDomains.Add(new MemoryDomain( _MemoryDomains.Add(new MemoryDomainByteArray(
"HSC ROM", hsbios.Length, MemoryDomain.Endian.Unknown, "HSC ROM", MemoryDomain.Endian.Unknown, hsbios, false, 1));
delegate(long addr)
{
return hsbios[addr];
},
null));
_MemoryDomains.Add(new MemoryDomain( _MemoryDomains.Add(new MemoryDomainByteArray(
"HSC RAM", hsram.Length, MemoryDomain.Endian.Unknown, "HSC RAM", MemoryDomain.Endian.Unknown, hsram, true, 1));
delegate(long addr)
{
return hsram[addr];
},
delegate(long addr, byte val)
{
hsram[addr] = val;
}));
} }
_MemoryDomains.Add(new MemoryDomain( _MemoryDomains.Add(new MemoryDomainDelegate(
"System Bus", 65536, MemoryDomain.Endian.Unknown, "System Bus", 65536, MemoryDomain.Endian.Unknown,
delegate(long addr) delegate(long addr)
{ {
@ -97,7 +79,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
if (addr < 0 || addr >= 0x10000) if (addr < 0 || addr >= 0x10000)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
theMachine.Mem[(ushort)addr] = val; theMachine.Mem[(ushort)addr] = val;
})); }, 1));
} }
else // todo 2600? else // todo 2600?
{ {

View File

@ -12,13 +12,9 @@ namespace BizHawk.Emulation.Cores.ColecoVision
private void SetupMemoryDomains() private void SetupMemoryDomains()
{ {
var domains = new List<MemoryDomain>(3); var domains = new List<MemoryDomain>(3);
var MainMemoryDomain = new MemoryDomain("Main RAM", Ram.Length, MemoryDomain.Endian.Little, var MainMemoryDomain = new MemoryDomainByteArray("Main RAM", MemoryDomain.Endian.Little, Ram, true, 1);
addr => Ram[addr], var VRamDomain = new MemoryDomainByteArray("Video RAM", MemoryDomain.Endian.Little, VDP.VRAM, true, 1);
(addr, value) => Ram[addr] = value); var SystemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
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) => (addr) =>
{ {
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
@ -36,7 +32,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
} }
Cpu.WriteMemory((ushort)addr, value); Cpu.WriteMemory((ushort)addr, value);
}); }, 1);
domains.Add(MainMemoryDomain); domains.Add(MainMemoryDomain);
domains.Add(VRamDomain); domains.Add(VRamDomain);

View File

@ -181,17 +181,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
var s = new LibmGBA.MemoryAreas(); var s = new LibmGBA.MemoryAreas();
LibmGBA.BizGetMemoryAreas(core, s); LibmGBA.BizGetMemoryAreas(core, s);
var LE = MemoryDomain.Endian.Little; _iwram.Data = s.iwram;
MemoryDomains["IWRAM"].SetDelegatesForIntPtr(MemoryDomains["IWRAM"].Size, LE, s.wram, true, 4); _ewram.Data = s.wram;
MemoryDomains["EWRAM"].SetDelegatesForIntPtr(MemoryDomains["EWRAM"].Size, LE, s.wram, true, 4); _bios.Data = s.bios;
MemoryDomains["BIOS"].SetDelegatesForIntPtr(MemoryDomains["BIOS"].Size, LE, s.bios, false, 4); _palram.Data = s.palram;
MemoryDomains["PALRAM"].SetDelegatesForIntPtr(MemoryDomains["PALRAM"].Size, LE, s.palram, false, 4); _vram.Data = s.vram;
MemoryDomains["VRAM"].SetDelegatesForIntPtr(MemoryDomains["VRAM"].Size, LE, s.vram, true, 4); _oam.Data = s.oam;
MemoryDomains["OAM"].SetDelegatesForIntPtr(MemoryDomains["OAM"].Size, LE, s.oam, false, 4); _rom.Data = s.rom;
MemoryDomains["ROM"].SetDelegatesForIntPtr(MemoryDomains["ROM"].Size, LE, s.rom, false, 4);
// special combined ram memory domain // special combined ram memory domain
MemoryDomains["Combined WRAM"].SetPeekPokeDelegates(
_cwram.Peek =
delegate(long addr) delegate(long addr)
{ {
LibmGBA.BizGetMemoryAreas(core, s); LibmGBA.BizGetMemoryAreas(core, s);
@ -201,7 +201,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
return PeekWRAM(s.iwram, addr & 32767); return PeekWRAM(s.iwram, addr & 32767);
else else
return PeekWRAM(s.wram, addr); return PeekWRAM(s.wram, addr);
}, };
_cwram.Poke =
delegate(long addr, byte val) delegate(long addr, byte val)
{ {
if (addr < 0 || addr >= (256 + 32) * 1024) if (addr < 0 || addr >= (256 + 32) * 1024)
@ -210,8 +211,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
PokeWRAM(s.iwram, addr & 32767, val); PokeWRAM(s.iwram, addr & 32767, val);
else else
PokeWRAM(s.wram, addr, val); PokeWRAM(s.wram, addr, val);
} };
);
_gpumem = new GBAGPUMemoryAreas _gpumem = new GBAGPUMemoryAreas
{ {
@ -220,22 +220,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
palram = s.palram, palram = s.palram,
vram = s.vram vram = s.vram
}; };
} }
private MemoryDomainIntPtr _iwram;
private MemoryDomainIntPtr _ewram;
private MemoryDomainIntPtr _bios;
private MemoryDomainIntPtr _palram;
private MemoryDomainIntPtr _vram;
private MemoryDomainIntPtr _oam;
private MemoryDomainIntPtr _rom;
private MemoryDomainDelegate _cwram;
private void CreateMemoryDomains(int romsize) private void CreateMemoryDomains(int romsize)
{ {
var LE = MemoryDomain.Endian.Little; var LE = MemoryDomain.Endian.Little;
var mm = new List<MemoryDomain>(); var mm = new List<MemoryDomain>();
mm.Add(new MemoryDomain("IWRAM", 32 * 1024, LE, null, null, 4)); mm.Add(_iwram = new MemoryDomainIntPtr("IWRAM", LE, IntPtr.Zero, 32 * 1024, true, 4));
mm.Add(new MemoryDomain("EWRAM", 256 * 1024, LE, null, null, 4)); mm.Add(_ewram = new MemoryDomainIntPtr("EWRAM", LE, IntPtr.Zero, 256 * 1024, true, 4));
mm.Add(new MemoryDomain("BIOS", 16 * 1024, LE, null, null, 4)); mm.Add(_bios = new MemoryDomainIntPtr("BIOS", LE, IntPtr.Zero, 16 * 1024, false, 4));
mm.Add(new MemoryDomain("PALRAM", 1024, LE, null, null, 4)); mm.Add(_palram = new MemoryDomainIntPtr("PALRAM", LE, IntPtr.Zero, 1024, true, 4));
mm.Add(new MemoryDomain("VRAM", 96 * 1024, LE, null, null, 4)); mm.Add(_vram = new MemoryDomainIntPtr("VRAM", LE, IntPtr.Zero, 96 * 1024, true, 4));
mm.Add(new MemoryDomain("OAM", 1024, LE, null, null, 4)); mm.Add(_oam = new MemoryDomainIntPtr("OAM", LE, IntPtr.Zero, 1024, true, 4));
mm.Add(new MemoryDomain("ROM", romsize, LE, null, null, 4)); mm.Add(_rom = new MemoryDomainIntPtr("ROM", LE, IntPtr.Zero, romsize, false, 4));
mm.Add(new MemoryDomain("Combined WRAM", (256 + 32) * 1024, LE, null, null, 4)); mm.Add(_cwram = new MemoryDomainDelegate("Combined WRAM", (256 + 32) * 1024, LE, null, null, 4));
MemoryDomains = new MemoryDomainList(mm); MemoryDomains = new MemoryDomainList(mm);
WireMemoryDomainPointers(); WireMemoryDomainPointers();

View File

@ -36,7 +36,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
AddMemoryDomain(LibMeteor.MemoryArea.rom, 32 * 1024 * 1024, "ROM"); AddMemoryDomain(LibMeteor.MemoryArea.rom, 32 * 1024 * 1024, "ROM");
// special domain for system bus // special domain for system bus
{ {
MemoryDomain sb = new MemoryDomain("System Bus", 1 << 28, MemoryDomain.Endian.Little, MemoryDomain sb = new MemoryDomainDelegate("System Bus", 1 << 28, MemoryDomain.Endian.Little,
delegate(long addr) delegate(long addr)
{ {
if (addr < 0 || addr >= 0x10000000) if (addr < 0 || addr >= 0x10000000)
@ -48,14 +48,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
if (addr < 0 || addr >= 0x10000000) if (addr < 0 || addr >= 0x10000000)
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
LibMeteor.libmeteor_writebus((uint)addr, val); LibMeteor.libmeteor_writebus((uint)addr, val);
}); }, 4);
_domainList.Add(sb); _domainList.Add(sb);
} }
// special combined ram memory domain // special combined ram memory domain
{ {
var ew = _domainList[1]; var ew = _domainList[1];
var iw = _domainList[0]; var iw = _domainList[0];
MemoryDomain cr = new MemoryDomain("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little, MemoryDomain cr = new MemoryDomainDelegate("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
delegate(long addr) delegate(long addr)
{ {
if (addr < 0 || addr >= (256 + 32) * 1024) if (addr < 0 || addr >= (256 + 32) * 1024)
@ -73,7 +73,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
iw.PokeByte(addr & 32767, val); iw.PokeByte(addr & 32767, val);
else else
ew.PokeByte(addr, val); ew.PokeByte(addr, val);
}); }, 4);
_domainList.Add(cr); _domainList.Add(cr);
} }

View File

@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
mm.Add(MemoryDomain.FromIntPtr("OAM", 1024, l, s.oam, true, 4)); mm.Add(MemoryDomain.FromIntPtr("OAM", 1024, l, s.oam, true, 4));
mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom, true, 4)); mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom, true, 4));
mm.Add(new MemoryDomain("System Bus", 0x10000000, l, mm.Add(new MemoryDomainDelegate("System Bus", 0x10000000, l,
delegate(long addr) delegate(long addr)
{ {
if (addr < 0 || addr >= 0x10000000) if (addr < 0 || addr >= 0x10000000)
@ -41,7 +41,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
{ {
var ew = mm[1]; var ew = mm[1];
var iw = mm[0]; var iw = mm[0];
MemoryDomain cr = new MemoryDomain("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little, MemoryDomain cr = new MemoryDomainDelegate("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
delegate(long addr) delegate(long addr)
{ {
if (addr < 0 || addr >= (256 + 32) * 1024) if (addr < 0 || addr >= (256 + 32) * 1024)

View File

@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// also add a special memory domain for the system bus, where calls get sent directly to the core each time // also add a special memory domain for the system bus, where calls get sent directly to the core each time
_memoryDomains.Add(new MemoryDomain("System Bus", 65536, MemoryDomain.Endian.Little, _memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little,
delegate(long addr) delegate(long addr)
{ {
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
@ -47,7 +47,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
LibGambatte.gambatte_cpuwrite(GambatteState, (ushort)addr, val); LibGambatte.gambatte_cpuwrite(GambatteState, (ushort)addr, val);
})); }, 1));
MemoryDomains = new MemoryDomainList(_memoryDomains); MemoryDomains = new MemoryDomainList(_memoryDomains);
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(MemoryDomains); (ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(MemoryDomains);

View File

@ -16,16 +16,43 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
foreach (var md in L.MemoryDomains) foreach (var md in L.MemoryDomains)
{ {
mm.Add(new MemoryDomain("L " + md.Name, md.Size, md.EndianType, md.PeekByte, md.PokeByte)); mm.Add(new WrappedMemoryDomain("L " + md.Name, md));
} }
foreach (var md in R.MemoryDomains) foreach (var md in R.MemoryDomains)
{ {
mm.Add(new MemoryDomain("R " + md.Name, md.Size, md.EndianType, md.PeekByte, md.PokeByte)); mm.Add(new WrappedMemoryDomain("R " + md.Name, md));
} }
_memoryDomains = new MemoryDomainList(mm); _memoryDomains = new MemoryDomainList(mm);
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains); (ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains);
} }
// todo: clean this up
private class WrappedMemoryDomain : MemoryDomain
{
private readonly MemoryDomain _m;
public WrappedMemoryDomain(string name, MemoryDomain m)
{
_m = m;
Name = name;
Size = m.Size;
WordSize = m.WordSize;
EndianType = m.EndianType;
Writable = m.Writable;
}
public override byte PeekByte(long addr)
{
return _m.PeekByte(addr);
}
public override void PokeByte(long addr, byte val)
{
_m.PokeByte(addr, val);
}
}
} }
} }

View File

@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
public string Disassemble(MemoryDomain m, uint addr, out int length) public string Disassemble(MemoryDomain m, uint addr, out int length)
{ {
length = 4; // TODO: is this right? length = 4; // TODO: is this right?
var instruction = m.PeekDWord(addr, true); var instruction = m.PeekUint(addr, true);
//TODO - reserve buffer here for disassembling into. allocating repeatedly will be slower //TODO - reserve buffer here for disassembling into. allocating repeatedly will be slower
var result = api.m64p_decode_op(instruction, addr); var result = api.m64p_decode_op(instruction, addr);

View File

@ -71,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
}; };
} }
var md = new MemoryDomain(name, size, endian, peekByte, pokeByte, 4); var md = new MemoryDomainDelegate(name, size, endian, peekByte, pokeByte, 4);
_memoryDomains.Add(md); _memoryDomains.Add(md);
} }
@ -129,13 +129,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
api.m64p_write_memory_8((uint)addr, val); api.m64p_write_memory_8((uint)addr, val);
}; };
_memoryDomains.Add(new MemoryDomain _memoryDomains.Add(new MemoryDomainDelegate
( (
name: "System Bus", "System Bus",
size: uint.MaxValue, uint.MaxValue,
endian: MemoryDomain.Endian.Big, MemoryDomain.Endian.Big,
peekByte: peekByte, peekByte,
pokeByte: pokeByte pokeByte, 4
)); ));
MemoryDomains = new MemoryDomainList(_memoryDomains); MemoryDomains = new MemoryDomainList(_memoryDomains);

View File

@ -228,7 +228,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public MemoryDomain GetDiskPeeker() public MemoryDomain GetDiskPeeker()
{ {
return new MemoryDomain("FDS Side", diskdrive.NumBytes, MemoryDomain.Endian.Little, diskdrive.PeekData, null); return new MemoryDomainDelegate("FDS Side", diskdrive.NumBytes, MemoryDomain.Endian.Little, diskdrive.PeekData, null, 1);
} }
void SetIRQ() void SetIRQ()

View File

@ -13,16 +13,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
private void SetupMemoryDomains() private void SetupMemoryDomains()
{ {
var domains = new List<MemoryDomain>(); var domains = new List<MemoryDomain>();
var RAM = new MemoryDomain("RAM", 0x800, MemoryDomain.Endian.Little, var RAM = new MemoryDomainByteArray("RAM", MemoryDomain.Endian.Little, ram, true, 1);
addr => ram[addr], (addr, value) => ram[addr] = value); var SystemBus = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
var SystemBus = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little, addr => PeekMemory((ushort)addr), (addr, value) => ApplySystemBusPoke((int)addr, value), 1);
addr => PeekMemory((ushort)addr), (addr, value) => ApplySystemBusPoke((int)addr, value)); var PPUBus = new MemoryDomainDelegate("PPU Bus", 0x4000, MemoryDomain.Endian.Little,
var PPUBus = new MemoryDomain("PPU Bus", 0x4000, MemoryDomain.Endian.Little, addr => ppu.ppubus_peek((int)addr), (addr, value) => ppu.ppubus_write((int)addr, value), 1);
addr => ppu.ppubus_peek((int)addr), (addr, value) => ppu.ppubus_write((int)addr, value)); var CIRAMdomain = new MemoryDomainByteArray("CIRAM (nametables)", MemoryDomain.Endian.Little, CIRAM, true, 1);
var CIRAMdomain = new MemoryDomain("CIRAM (nametables)", 0x800, MemoryDomain.Endian.Little, var OAMdoman = new MemoryDomainByteArray("OAM", MemoryDomain.Endian.Unknown, ppu.OAM, true, 1);
addr => CIRAM[addr], (addr, value) => CIRAM[addr] = value);
var OAMdoman = new MemoryDomain("OAM", 64 * 4, MemoryDomain.Endian.Unknown,
addr => ppu.OAM[addr], (addr, value) => ppu.OAM[addr] = value);
domains.Add(RAM); domains.Add(RAM);
domains.Add(SystemBus); domains.Add(SystemBus);
@ -32,36 +29,31 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (!(Board is FDS) && Board.SaveRam != null) if (!(Board is FDS) && Board.SaveRam != null)
{ {
var BatteryRam = new MemoryDomain("Battery RAM", Board.SaveRam.Length, MemoryDomain.Endian.Little, var BatteryRam = new MemoryDomainByteArray("Battery RAM", MemoryDomain.Endian.Little, Board.SaveRam, true, 1);
addr => Board.SaveRam[addr], (addr, value) => Board.SaveRam[addr] = value);
domains.Add(BatteryRam); domains.Add(BatteryRam);
} }
if (Board.ROM != null) if (Board.ROM != null)
{ {
var PRGROM = new MemoryDomain("PRG ROM", cart.prg_size * 1024, MemoryDomain.Endian.Little, var PRGROM = new MemoryDomainByteArray("PRG ROM", MemoryDomain.Endian.Little, Board.ROM, true, 1);
addr => Board.ROM[addr], (addr, value) => Board.ROM[addr] = value);
domains.Add(PRGROM); domains.Add(PRGROM);
} }
if (Board.VROM != null) if (Board.VROM != null)
{ {
var CHRROM = new MemoryDomain("CHR VROM", cart.chr_size * 1024, MemoryDomain.Endian.Little, var CHRROM = new MemoryDomainByteArray("CHR VROM", MemoryDomain.Endian.Little, Board.VROM, true, 1);
addr => Board.VROM[addr], (addr, value) => Board.VROM[addr] = value);
domains.Add(CHRROM); domains.Add(CHRROM);
} }
if (Board.VRAM != null) if (Board.VRAM != null)
{ {
var VRAM = new MemoryDomain("VRAM", Board.VRAM.Length, MemoryDomain.Endian.Little, var VRAM = new MemoryDomainByteArray("VRAM", MemoryDomain.Endian.Little, Board.VRAM, true, 1);
addr => Board.VRAM[addr], (addr, value) => Board.VRAM[addr] = value);
domains.Add(VRAM); domains.Add(VRAM);
} }
if (Board.WRAM != null) if (Board.WRAM != null)
{ {
var WRAM = new MemoryDomain("WRAM", Board.WRAM.Length, MemoryDomain.Endian.Little, var WRAM = new MemoryDomainByteArray("WRAM", MemoryDomain.Endian.Little, Board.WRAM, true, 1);
addr => Board.WRAM[addr], (addr, value) => Board.WRAM[addr] = value);
domains.Add(WRAM); domains.Add(WRAM);
} }

View File

@ -27,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
} }
} }
// add system bus // add system bus
mm.Add(new MemoryDomain mm.Add(new MemoryDomainDelegate
( (
"System Bus", "System Bus",
0x10000, 0x10000,
@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
} }
QN.qn_poke_prgbus(Context, (int)addr, val); QN.qn_poke_prgbus(Context, (int)addr, val);
} }, 1
)); ));
_memoryDomains = new MemoryDomainList(mm); _memoryDomains = new MemoryDomainList(mm);

View File

@ -1076,7 +1076,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
byte* blockptr = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.WRAM); byte* blockptr = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.WRAM);
var md = new MemoryDomain("System Bus", 0x1000000, MemoryDomain.Endian.Little, var md = new MemoryDomainDelegate("System Bus", 0x1000000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
var a = FakeBusMap((int)addr); var a = FakeBusMap((int)addr);
@ -1090,7 +1090,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
var a = FakeBusMap((int)addr); var a = FakeBusMap((int)addr);
if (a.HasValue) if (a.HasValue)
blockptr[a.Value] = val; blockptr[a.Value] = val;
}, byteSize: 2); }, wordSize: 2);
_memoryDomains.Add(md); _memoryDomains.Add(md);
} }
@ -1116,17 +1116,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
//maybe a better way to visualize it is with an empty bus and adjacent banks //maybe a better way to visualize it is with an empty bus and adjacent banks
//so, we just throw away everything above its size of 544 bytes //so, we just throw away everything above its size of 544 bytes
if (size != 544) throw new InvalidOperationException("oam size isnt 544 bytes.. wtf?"); if (size != 544) throw new InvalidOperationException("oam size isnt 544 bytes.. wtf?");
md = new MemoryDomain(name, size, endian, md = new MemoryDomainDelegate(name, size, endian,
(addr) => (addr < 544) ? blockptr[addr] : (byte)0x00, (addr) => (addr < 544) ? blockptr[addr] : (byte)0x00,
(addr, value) => { if (addr < 544) blockptr[addr] = value; }, (addr, value) => { if (addr < 544) blockptr[addr] = value; },
byteSize); byteSize);
} }
else if(pow2) else if(pow2)
md = new MemoryDomain(name, size, endian, md = new MemoryDomainDelegate(name, size, endian,
(addr) => blockptr[addr & mask], (addr) => blockptr[addr & mask],
(addr, value) => blockptr[addr & mask] = value, byteSize); (addr, value) => blockptr[addr & mask] = value, byteSize);
else else
md = new MemoryDomain(name, size, endian, md = new MemoryDomainDelegate(name, size, endian,
(addr) => blockptr[addr % size], (addr) => blockptr[addr % size],
(addr, value) => blockptr[addr % size] = value, byteSize); (addr, value) => blockptr[addr % size] = value, byteSize);
@ -1137,9 +1137,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
void SetupMemoryDomains(byte[] romData, byte[] sgbRomData) void SetupMemoryDomains(byte[] romData, byte[] sgbRomData)
{ {
// remember, MainMemory must always be the same as MemoryDomains[0], else GIANT DRAGONS
//<zeromus> - this is stupid.
//lets just do this entirely differently for SGB //lets just do this entirely differently for SGB
if (IsSGB) if (IsSGB)
{ {
@ -1147,13 +1144,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
//You wouldnt expect a DMG game to access excess wram, but what if it tried to? maybe an oversight in bsnes? //You wouldnt expect a DMG game to access excess wram, but what if it tried to? maybe an oversight in bsnes?
MakeMemoryDomain("SGB WRAM", LibsnesApi.SNES_MEMORY.SGB_WRAM, MemoryDomain.Endian.Little); MakeMemoryDomain("SGB WRAM", LibsnesApi.SNES_MEMORY.SGB_WRAM, MemoryDomain.Endian.Little);
var romDomain = new MemoryDomainByteArray("SGB CARTROM", MemoryDomain.Endian.Little, romData, true, 1);
var romDomain = new MemoryDomain("SGB CARTROM", romData.Length, MemoryDomain.Endian.Little,
(addr) => romData[addr],
(addr, value) => romData[addr] = value);
_memoryDomains.Add(romDomain); _memoryDomains.Add(romDomain);
//the last 1 byte of this is special.. its an interrupt enable register, instead of ram. weird. maybe its actually ram and just getting specially used? //the last 1 byte of this is special.. its an interrupt enable register, instead of ram. weird. maybe its actually ram and just getting specially used?
MakeMemoryDomain("SGB HRAM", LibsnesApi.SNES_MEMORY.SGB_HRAM, MemoryDomain.Endian.Little); MakeMemoryDomain("SGB HRAM", LibsnesApi.SNES_MEMORY.SGB_HRAM, MemoryDomain.Endian.Little);
@ -1161,9 +1154,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
MainMemory = MakeMemoryDomain("WRAM", LibsnesApi.SNES_MEMORY.WRAM, MemoryDomain.Endian.Little); MainMemory = MakeMemoryDomain("WRAM", LibsnesApi.SNES_MEMORY.WRAM, MemoryDomain.Endian.Little);
var sgbromDomain = new MemoryDomain("SGB.SFC ROM", sgbRomData.Length, MemoryDomain.Endian.Little, var sgbromDomain = new MemoryDomainByteArray("SGB.SFC ROM", MemoryDomain.Endian.Little, sgbRomData, true, 1);
(addr) => sgbRomData[addr],
(addr, value) => sgbRomData[addr] = value);
_memoryDomains.Add(sgbromDomain); _memoryDomains.Add(sgbromDomain);
} }
else else
@ -1180,9 +1171,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
if (!DeterministicEmulation) if (!DeterministicEmulation)
{ {
_memoryDomains.Add(new MemoryDomain("System Bus", 0x1000000, MemoryDomain.Endian.Little, _memoryDomains.Add(new MemoryDomainDelegate("System Bus", 0x1000000, MemoryDomain.Endian.Little,
(addr) => api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr), (addr) => api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr),
(addr, val) => api.QUERY_poke(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr, val), byteSize: 2)); (addr, val) => api.QUERY_poke(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr, val), wordSize: 2));
} }
else else
{ {

View File

@ -513,13 +513,10 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
var domains = new List<MemoryDomain>(10); var domains = new List<MemoryDomain>(10);
int mainmemorymask = Ram.Length - 1; int mainmemorymask = Ram.Length - 1;
var MainMemoryDomain = new MemoryDomain("Main Memory", Ram.Length, MemoryDomain.Endian.Little, var MainMemoryDomain = new MemoryDomainByteArray("Main Memory", MemoryDomain.Endian.Little, Ram, true, 1);
addr => Ram[addr],
(addr, value) => Ram[addr] = value,
byteSize: 2);
domains.Add(MainMemoryDomain); domains.Add(MainMemoryDomain);
var SystemBusDomain = new MemoryDomain("System Bus (21 bit)", 0x200000, MemoryDomain.Endian.Little, var SystemBusDomain = new MemoryDomainDelegate("System Bus (21 bit)", 0x200000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 0x200000) if (addr < 0 || addr >= 0x200000)
@ -532,10 +529,10 @@ namespace BizHawk.Emulation.Cores.PCEngine
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
Cpu.WriteMemory21((int)addr, value); Cpu.WriteMemory21((int)addr, value);
}, },
byteSize: 2); wordSize: 2);
domains.Add(SystemBusDomain); domains.Add(SystemBusDomain);
var CpuBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little, var CpuBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 0x10000) if (addr < 0 || addr >= 0x10000)
@ -548,63 +545,41 @@ namespace BizHawk.Emulation.Cores.PCEngine
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
Cpu.WriteMemory((ushort)addr, value); Cpu.WriteMemory((ushort)addr, value);
}, },
byteSize: 2); wordSize: 2);
domains.Add(CpuBusDomain); domains.Add(CpuBusDomain);
var RomDomain = new MemoryDomain("ROM", RomLength, MemoryDomain.Endian.Little, var RomDomain = new MemoryDomainByteArray("ROM", MemoryDomain.Endian.Little, RomData, true, 1);
addr => RomData[addr],
(addr, value) => RomData[addr] = value,
byteSize: 2);
domains.Add(RomDomain); domains.Add(RomDomain);
if (BRAM != null) if (BRAM != null)
{ {
var BRAMMemoryDomain = new MemoryDomain("Battery RAM", Ram.Length, MemoryDomain.Endian.Little, var BRAMMemoryDomain = new MemoryDomainByteArray("Battery RAM", MemoryDomain.Endian.Little, BRAM, true, 1);
addr => BRAM[addr],
(addr, value) => BRAM[addr] = value,
byteSize: 2);
domains.Add(BRAMMemoryDomain); domains.Add(BRAMMemoryDomain);
} }
if (TurboCD) if (TurboCD)
{ {
var CDRamMemoryDomain = new MemoryDomain("TurboCD RAM", CDRam.Length, MemoryDomain.Endian.Little, var CDRamMemoryDomain = new MemoryDomainByteArray("TurboCD RAM", MemoryDomain.Endian.Little, CDRam, true, 1);
addr => CDRam[addr],
(addr, value) => CDRam[addr] = value,
byteSize: 2);
domains.Add(CDRamMemoryDomain); domains.Add(CDRamMemoryDomain);
var AdpcmMemoryDomain = new MemoryDomain("ADPCM RAM", ADPCM.RAM.Length, MemoryDomain.Endian.Little, var AdpcmMemoryDomain = new MemoryDomainByteArray("ADPCM RAM", MemoryDomain.Endian.Little, ADPCM.RAM, true, 1);
addr => ADPCM.RAM[addr],
(addr, value) => ADPCM.RAM[addr] = value,
byteSize: 2);
domains.Add(AdpcmMemoryDomain); domains.Add(AdpcmMemoryDomain);
if (SuperRam != null) if (SuperRam != null)
{ {
var SuperRamMemoryDomain = new MemoryDomain("Super System Card RAM", SuperRam.Length, MemoryDomain.Endian.Little, var SuperRamMemoryDomain = new MemoryDomainByteArray("Super System Card RAM", MemoryDomain.Endian.Little, SuperRam, true, 1);
addr => SuperRam[addr],
(addr, value) => SuperRam[addr] = value,
byteSize: 2);
domains.Add(SuperRamMemoryDomain); domains.Add(SuperRamMemoryDomain);
} }
} }
if (ArcadeCard) if (ArcadeCard)
{ {
var ArcadeRamMemoryDomain = new MemoryDomain("Arcade Card RAM", ArcadeRam.Length, MemoryDomain.Endian.Little, var ArcadeRamMemoryDomain = new MemoryDomainByteArray("Arcade Card RAM", MemoryDomain.Endian.Little, ArcadeRam, true, 1);
addr => ArcadeRam[addr],
(addr, value) => ArcadeRam[addr] = value,
byteSize: 2);
domains.Add(ArcadeRamMemoryDomain);
} }
if (PopulousRAM != null) if (PopulousRAM != null)
{ {
var PopulusRAMDomain = new MemoryDomain("Cart Battery RAM", PopulousRAM.Length, MemoryDomain.Endian.Little, var PopulusRAMDomain = new MemoryDomainByteArray("Cart Battery RAM", MemoryDomain.Endian.Little, PopulousRAM, true, 1);
addr => PopulousRAM[addr],
(addr, value) => PopulousRAM[addr] = value,
byteSize: 2);
domains.Add(PopulusRAMDomain); domains.Add(PopulusRAMDomain);
} }

View File

@ -458,6 +458,7 @@ namespace BizHawk.Emulation.Cores.Sega.Genesis
void SetupMemoryDomains() void SetupMemoryDomains()
{ {
/*
var domains = new List<MemoryDomain>(3); var domains = new List<MemoryDomain>(3);
var MainMemoryDomain = new MemoryDomain("Main RAM", Ram.Length, MemoryDomain.Endian.Big, var MainMemoryDomain = new MemoryDomain("Main RAM", Ram.Length, MemoryDomain.Endian.Big,
addr => Ram[addr & 0xFFFF], addr => Ram[addr & 0xFFFF],
@ -485,6 +486,8 @@ namespace BizHawk.Emulation.Cores.Sega.Genesis
domains.Add(SystemBusDomain); domains.Add(SystemBusDomain);
memoryDomains = new MemoryDomainList(domains); memoryDomains = new MemoryDomainList(domains);
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(memoryDomains); (ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(memoryDomains);
*/
throw new NotImplementedException();
} }
public void Dispose() { } public void Dispose() { }

View File

@ -12,18 +12,12 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
void SetupMemoryDomains() void SetupMemoryDomains()
{ {
var domains = new List<MemoryDomain>(3); var domains = new List<MemoryDomain>(3);
var MainMemoryDomain = new MemoryDomain("Main RAM", SystemRam.Length, MemoryDomain.Endian.Little, var MainMemoryDomain = new MemoryDomainByteArray("Main RAM", MemoryDomain.Endian.Little, SystemRam, true, 1);
addr => SystemRam[addr], var VRamDomain = new MemoryDomainByteArray("Video RAM", MemoryDomain.Endian.Little, Vdp.VRAM, true, 1);
(addr, value) => SystemRam[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 ROMDomain = new MemoryDomain("ROM", RomData.Length, MemoryDomain.Endian.Little, var ROMDomain = new MemoryDomainByteArray("ROM", MemoryDomain.Endian.Little, RomData, true, 1);
addr => RomData[addr],
(addr, value) => RomData[addr] = value);
var SystemBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little, var SystemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
@ -41,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
} }
Cpu.WriteMemory((ushort)addr, value); Cpu.WriteMemory((ushort)addr, value);
}); }, 1);
domains.Add(MainMemoryDomain); domains.Add(MainMemoryDomain);
domains.Add(VRamDomain); domains.Add(VRamDomain);
@ -50,17 +44,15 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
if (SaveRAM != null) if (SaveRAM != null)
{ {
var SaveRamDomain = new MemoryDomain("Save RAM", SaveRAM.Length, MemoryDomain.Endian.Little, var SaveRamDomain = new MemoryDomainDelegate("Save RAM", SaveRAM.Length, MemoryDomain.Endian.Little,
addr => SaveRAM[addr], addr => SaveRAM[addr],
(addr, value) => { SaveRAM[addr] = value; SaveRamModified = true; }); (addr, value) => { SaveRAM[addr] = value; SaveRamModified = true; }, 1);
domains.Add(SaveRamDomain); domains.Add(SaveRamDomain);
} }
if (ExtRam != null) if (ExtRam != null)
{ {
var ExtRamDomain = new MemoryDomain("Cart (Volatile) RAM", ExtRam.Length, MemoryDomain.Endian.Little, var ExtRamDomain = new MemoryDomainByteArray("Cart (Volatile) RAM", MemoryDomain.Endian.Little, ExtRam, true, 1);
addr => ExtRam[addr],
(addr, value) => { ExtRam[addr] = value; });
domains.Add(ExtRamDomain); domains.Add(ExtRamDomain);
} }

View File

@ -29,9 +29,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
public string Disassemble(MemoryDomain m, uint addr, out int length) public string Disassemble(MemoryDomain m, uint addr, out int length)
{ {
_disassemblerInstance.ReadWord = (a) => (short)m.PeekWord(a, m.EndianType == MemoryDomain.Endian.Big); _disassemblerInstance.ReadWord = (a) => (short)m.PeekUshort(a, m.EndianType == MemoryDomain.Endian.Big);
_disassemblerInstance.ReadByte = (a) => (sbyte)m.PeekByte(a); _disassemblerInstance.ReadByte = (a) => (sbyte)m.PeekByte(a);
_disassemblerInstance.ReadLong = (a) => (int)m.PeekDWord(a, m.EndianType == MemoryDomain.Endian.Big); _disassemblerInstance.ReadLong = (a) => (int)m.PeekUint(a, m.EndianType == MemoryDomain.Endian.Big);
var info = _disassemblerInstance.Disassemble((int)addr); var info = _disassemblerInstance.Disassemble((int)addr);
length = info.Length; length = info.Length;

View File

@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{ {
// vram pokes need to go through hook which invalidates cached tiles // 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 MemoryDomainDelegate(name, size, MemoryDomain.Endian.Unknown,
delegate(long addr) delegate(long addr)
{ {
if (addr < 0 || addr >= 65536) if (addr < 0 || addr >= 65536)
@ -38,17 +38,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
Core.gpgx_poke_vram(((int)addr) ^ 1, val); Core.gpgx_poke_vram(((int)addr) ^ 1, val);
}, },
byteSize: 2)); wordSize: 2));
} }
else else
{ {
var byteSize = name.Contains("Z80") ? 1 : 2; // TODO: are the Z80 domains really Swap16 in the core? Check this
mm.Add(MemoryDomain.FromIntPtrSwap16(name, size, mm.Add(MemoryDomain.FromIntPtrSwap16(name, size,
MemoryDomain.Endian.Big, area, name != "MD CART" && name != "CD BOOT ROM", byteSize)); MemoryDomain.Endian.Big, area, name != "MD CART" && name != "CD BOOT ROM"));
} }
} }
var m68Bus = new MemoryDomain("M68K BUS", 0x1000000, MemoryDomain.Endian.Big, var m68Bus = new MemoryDomainDelegate("M68K BUS", 0x1000000, MemoryDomain.Endian.Big,
delegate (long addr) delegate (long addr)
{ {
var a = (uint)addr; var a = (uint)addr;
@ -66,7 +66,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
mm.Add(m68Bus); mm.Add(m68Bus);
var s68Bus = new MemoryDomain("S68K BUS", 0x1000000, MemoryDomain.Endian.Big, var s68Bus = new MemoryDomainDelegate("S68K BUS", 0x1000000, MemoryDomain.Endian.Big,
delegate (long addr) delegate (long addr)
{ {
var a = (uint)addr; var a = (uint)addr;