snes9x - cleanup usage of the IMonitor semantics. This makes memory domains slower.

This commit is contained in:
nattthebear 2017-05-28 13:12:48 -04:00
parent 6c2d4ff044
commit 7d0330bb9e
3 changed files with 111 additions and 67 deletions

View File

@ -1,4 +1,5 @@
using System;
using BizHawk.Common;
using System;
namespace BizHawk.Emulation.Common
{
@ -134,6 +135,60 @@ namespace BizHawk.Emulation.Common
}
}
public unsafe class MemoryDomainIntPtrMonitor : MemoryDomain
{
public IntPtr Data { get; set; }
private readonly IMonitor _monitor;
public override byte PeekByte(long addr)
{
if ((ulong)addr < (ulong)Size)
{
using (_monitor.EnterExit())
{
return ((byte*)Data)[addr];
}
}
throw new ArgumentOutOfRangeException(nameof(addr));
}
public override void PokeByte(long addr, byte val)
{
if (Writable)
{
if ((ulong)addr < (ulong)Size)
{
using (_monitor.EnterExit())
{
((byte*)Data)[addr] = val;
}
}
else
{
throw new ArgumentOutOfRangeException(nameof(addr));
}
}
}
public void SetSize(long size)
{
Size = size;
}
public MemoryDomainIntPtrMonitor(string name, Endian endian, IntPtr data, long size, bool writable, int wordSize,
IMonitor monitor)
{
Name = name;
EndianType = endian;
Data = data;
Size = size;
Writable = writable;
WordSize = wordSize;
_monitor = monitor;
}
}
public unsafe class MemoryDomainIntPtrSwap16 : MemoryDomain
{
public IntPtr Data { get; set; }

View File

@ -39,8 +39,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
SpecialHeapSizeKB = 64
});
try
{
_core = BizInvoker.GetInvoker<LibSnes9x>(_exe, _exe);
if (!_core.biz_init())
{
@ -74,12 +72,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
InitMemoryDomains();
InitSaveram();
}
catch
{
Dispose();
throw;
}
}
#region controller
@ -319,9 +311,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
LibSnes9x.frame_info frame = new LibSnes9x.frame_info();
_core.biz_run(frame, _inputState);
using (_exe.EnterExit())
{
Blit(frame);
Sblit(frame);
}
}
public int Frame { get; private set; }
@ -644,8 +639,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
_core.biz_get_memory_area(index++, native);
if (native.ptr != IntPtr.Zero && native.size > 0)
{
domains.Add(new MemoryDomainIntPtr(s, MemoryDomain.Endian.Little,
native.ptr, native.size, true, 2));
domains.Add(new MemoryDomainIntPtrMonitor(s, MemoryDomain.Endian.Little,
native.ptr, native.size, true, 2, _exe));
}
}
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(new MemoryDomainList(domains)
@ -677,6 +672,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
public bool SaveRamModified => _saveramSize > 0;
public byte[] CloneSaveRam()
{
using (_exe.EnterExit())
{
var ret = new byte[_saveramSize];
var offset = 0;
@ -685,15 +682,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
Marshal.Copy(area.ptr, ret, offset, area.size);
offset += area.size;
}
return ret;
}
}
public void StoreSaveRam(byte[] data)
{
using (_exe.EnterExit())
{
if (data.Length != _saveramSize)
throw new InvalidOperationException("Saveram size mismatch");
var offset = 0;
foreach (var area in _saveramMemoryAreas)
{
@ -701,6 +699,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
offset += area.size;
}
}
}
#endregion
}

View File

@ -565,8 +565,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
public PeRunner(PeRunnerOptions opt)
{
Initialize(_nextStart);
Enter();
try
using (this.EnterExit())
{
// load any predefined exports
_psx = new Psx(this);
@ -644,15 +643,6 @@ namespace BizHawk.Emulation.Cores.Waterbox
m.RunGlobalCtors();
}*/
}
catch
{
Dispose();
throw;
}
finally
{
Exit();
}
}
public IntPtr Resolve(string entryPoint)