make MemoryDomain implement IMonitor (default is no-op Enter/Exit), cleanup, remove wrapper use (has a lot of churn itself), probably better performance with bulk functions
This commit is contained in:
parent
fe22d61b3a
commit
9e90290b87
|
@ -198,18 +198,13 @@ namespace BizHawk.Client.Common.RamSearchEngine
|
|||
{
|
||||
if (_settings.IsDetailed())
|
||||
{
|
||||
try
|
||||
using (_settings.Domain.EnterExit())
|
||||
{
|
||||
_settings.Domain.Monitor?.Enter();
|
||||
foreach (IMiniWatchDetails watch in _watchList)
|
||||
{
|
||||
watch.Update(_settings.PreviousType, _settings.Domain, _settings.BigEndian);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_settings.Domain.Monitor?.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Common
|
|||
/// as required by the IMemoryDomains service.
|
||||
/// </summary>
|
||||
/// <seealso cref="IMemoryDomains" />
|
||||
public abstract class MemoryDomain
|
||||
public abstract class MemoryDomain : IMonitor
|
||||
{
|
||||
public enum Endian
|
||||
{
|
||||
|
@ -27,12 +27,6 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public bool Writable { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// only use this if you are expecting to do a lot of peeks/pokes
|
||||
/// MAY BE NULL
|
||||
/// </summary>
|
||||
public IMonitor Monitor { get; protected set; }
|
||||
|
||||
public abstract byte PeekByte(long addr);
|
||||
|
||||
public abstract void PokeByte(long addr, byte val);
|
||||
|
@ -121,9 +115,12 @@ namespace BizHawk.Emulation.Common
|
|||
throw new InvalidOperationException("Invalid length of values array");
|
||||
}
|
||||
|
||||
for (var i = addresses.Start; i <= addresses.EndInclusive; i++)
|
||||
using (this.EnterExit())
|
||||
{
|
||||
values[i - addresses.Start] = PeekByte(i);
|
||||
for (var i = addresses.Start; i <= addresses.EndInclusive; i++)
|
||||
{
|
||||
values[i - addresses.Start] = PeekByte(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,8 +142,11 @@ namespace BizHawk.Emulation.Common
|
|||
throw new InvalidOperationException("Invalid length of values array");
|
||||
}
|
||||
|
||||
for (var i = 0; i < values.Length; i++, start += 2)
|
||||
values[i] = PeekUshort(start, bigEndian);
|
||||
using (this.EnterExit())
|
||||
{
|
||||
for (var i = 0; i < values.Length; i++, start += 2)
|
||||
values[i] = PeekUshort(start, bigEndian);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void BulkPeekUint(Range<long> addresses, bool bigEndian, uint[] values)
|
||||
|
@ -167,10 +167,25 @@ namespace BizHawk.Emulation.Common
|
|||
throw new InvalidOperationException("Invalid length of values array");
|
||||
}
|
||||
|
||||
for (var i = 0; i < values.Length; i++, start += 4)
|
||||
values[i] = PeekUint(start, bigEndian);
|
||||
using (this.EnterExit())
|
||||
{
|
||||
for (var i = 0; i < values.Length; i++, start += 4)
|
||||
values[i] = PeekUint(start, bigEndian);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SendCheatToCore(int addr, byte value, int compare, int compare_type) { }
|
||||
|
||||
/// <summary>
|
||||
/// only use this if you are expecting to do a lot of peeks/pokes
|
||||
/// no-op if the domain has no monitor
|
||||
/// </summary>
|
||||
public virtual void Enter() { }
|
||||
|
||||
/// <summary>
|
||||
/// only use this if you are expecting to do a lot of peeks/pokes
|
||||
/// no-op if the domain has no monitor
|
||||
/// </summary>
|
||||
public virtual void Exit() { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,10 +251,15 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
return ((byte*)Data)[addr];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(addr));
|
||||
|
@ -266,10 +271,15 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
((byte*)Data)[addr] = val;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -293,8 +303,13 @@ namespace BizHawk.Emulation.Common
|
|||
Writable = writable;
|
||||
WordSize = wordSize;
|
||||
_monitor = monitor;
|
||||
Monitor = _monitor;
|
||||
}
|
||||
|
||||
public override void Enter()
|
||||
=> _monitor.Enter();
|
||||
|
||||
public override void Exit()
|
||||
=> _monitor.Exit();
|
||||
}
|
||||
|
||||
public unsafe class MemoryDomainIntPtrSwap16 : MemoryDomain
|
||||
|
@ -346,10 +361,15 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
return ((byte*)Data)[addr ^ 1];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(addr));
|
||||
|
@ -361,10 +381,15 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
((byte*)Data)[addr ^ 1] = val;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -383,8 +408,13 @@ namespace BizHawk.Emulation.Common
|
|||
Writable = writable;
|
||||
WordSize = 2;
|
||||
_monitor = monitor;
|
||||
Monitor = _monitor;
|
||||
}
|
||||
|
||||
public override void Enter()
|
||||
=> _monitor.Enter();
|
||||
|
||||
public override void Exit()
|
||||
=> _monitor.Exit();
|
||||
}
|
||||
|
||||
public class MemoryDomainDelegateSysBusNES : MemoryDomain
|
||||
|
|
|
@ -51,8 +51,13 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
_addressMangler = 0;
|
||||
}
|
||||
Definition = m;
|
||||
Monitor = _monitor;
|
||||
}
|
||||
|
||||
public override void Enter()
|
||||
=> _monitor.Enter();
|
||||
|
||||
public override void Exit()
|
||||
=> _monitor.Exit();
|
||||
}
|
||||
|
||||
public unsafe class WaterboxMemoryDomainPointer : WaterboxMemoryDomain
|
||||
|
@ -68,10 +73,15 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
return ((byte*)_data)[addr ^ _addressMangler];
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(addr));
|
||||
|
@ -83,10 +93,15 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
{
|
||||
if ((ulong)addr < (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
((byte*)_data)[addr ^ _addressMangler] = val;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -108,10 +123,15 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
if (start < (ulong)Size && (start + count) <= (ulong)Size)
|
||||
{
|
||||
using (_monitor.EnterExit())
|
||||
try
|
||||
{
|
||||
_monitor.Enter();
|
||||
Marshal.Copy(Z.US((ulong)_data + start), values, 0, (int)count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_monitor.Exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue