snes9x - cleanup usage of the IMonitor semantics. This makes memory domains slower.
This commit is contained in:
parent
6c2d4ff044
commit
7d0330bb9e
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using BizHawk.Common;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Common
|
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 unsafe class MemoryDomainIntPtrSwap16 : MemoryDomain
|
||||||
{
|
{
|
||||||
public IntPtr Data { get; set; }
|
public IntPtr Data { get; set; }
|
||||||
|
|
|
@ -39,46 +39,38 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
|
||||||
SpecialHeapSizeKB = 64
|
SpecialHeapSizeKB = 64
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
_core = BizInvoker.GetInvoker<LibSnes9x>(_exe, _exe);
|
||||||
|
if (!_core.biz_init())
|
||||||
{
|
{
|
||||||
_core = BizInvoker.GetInvoker<LibSnes9x>(_exe, _exe);
|
throw new InvalidOperationException("Init() failed");
|
||||||
if (!_core.biz_init())
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Init() failed");
|
|
||||||
}
|
|
||||||
if (!_core.biz_load_rom(rom, rom.Length))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("LoadRom() failed");
|
|
||||||
}
|
|
||||||
_exe.Seal();
|
|
||||||
|
|
||||||
if (_core.biz_is_ntsc())
|
|
||||||
{
|
|
||||||
Console.WriteLine("NTSC rom loaded");
|
|
||||||
VsyncNumerator = 21477272;
|
|
||||||
VsyncDenominator = 357366;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("PAL rom loaded");
|
|
||||||
VsyncNumerator = 21281370;
|
|
||||||
VsyncDenominator = 425568;
|
|
||||||
}
|
|
||||||
|
|
||||||
_nsampTarget = (int)Math.Round(44100.0 * VsyncDenominator / VsyncNumerator);
|
|
||||||
_nsampWarn = (int)Math.Round(1.05 * 44100.0 * VsyncDenominator / VsyncNumerator);
|
|
||||||
|
|
||||||
_syncSettings = syncSettings;
|
|
||||||
InitControllers();
|
|
||||||
PutSettings(settings);
|
|
||||||
InitMemoryDomains();
|
|
||||||
InitSaveram();
|
|
||||||
}
|
}
|
||||||
catch
|
if (!_core.biz_load_rom(rom, rom.Length))
|
||||||
{
|
{
|
||||||
Dispose();
|
throw new InvalidOperationException("LoadRom() failed");
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
_exe.Seal();
|
||||||
|
|
||||||
|
if (_core.biz_is_ntsc())
|
||||||
|
{
|
||||||
|
Console.WriteLine("NTSC rom loaded");
|
||||||
|
VsyncNumerator = 21477272;
|
||||||
|
VsyncDenominator = 357366;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("PAL rom loaded");
|
||||||
|
VsyncNumerator = 21281370;
|
||||||
|
VsyncDenominator = 425568;
|
||||||
|
}
|
||||||
|
|
||||||
|
_nsampTarget = (int)Math.Round(44100.0 * VsyncDenominator / VsyncNumerator);
|
||||||
|
_nsampWarn = (int)Math.Round(1.05 * 44100.0 * VsyncDenominator / VsyncNumerator);
|
||||||
|
|
||||||
|
_syncSettings = syncSettings;
|
||||||
|
InitControllers();
|
||||||
|
PutSettings(settings);
|
||||||
|
InitMemoryDomains();
|
||||||
|
InitSaveram();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region controller
|
#region controller
|
||||||
|
@ -319,8 +311,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
|
||||||
LibSnes9x.frame_info frame = new LibSnes9x.frame_info();
|
LibSnes9x.frame_info frame = new LibSnes9x.frame_info();
|
||||||
|
|
||||||
_core.biz_run(frame, _inputState);
|
_core.biz_run(frame, _inputState);
|
||||||
Blit(frame);
|
using (_exe.EnterExit())
|
||||||
Sblit(frame);
|
{
|
||||||
|
Blit(frame);
|
||||||
|
Sblit(frame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Frame { get; private set; }
|
public int Frame { get; private set; }
|
||||||
|
@ -644,8 +639,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
|
||||||
_core.biz_get_memory_area(index++, native);
|
_core.biz_get_memory_area(index++, native);
|
||||||
if (native.ptr != IntPtr.Zero && native.size > 0)
|
if (native.ptr != IntPtr.Zero && native.size > 0)
|
||||||
{
|
{
|
||||||
domains.Add(new MemoryDomainIntPtr(s, MemoryDomain.Endian.Little,
|
domains.Add(new MemoryDomainIntPtrMonitor(s, MemoryDomain.Endian.Little,
|
||||||
native.ptr, native.size, true, 2));
|
native.ptr, native.size, true, 2, _exe));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(new MemoryDomainList(domains)
|
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(new MemoryDomainList(domains)
|
||||||
|
@ -678,27 +673,31 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
|
||||||
|
|
||||||
public byte[] CloneSaveRam()
|
public byte[] CloneSaveRam()
|
||||||
{
|
{
|
||||||
var ret = new byte[_saveramSize];
|
using (_exe.EnterExit())
|
||||||
var offset = 0;
|
|
||||||
foreach (var area in _saveramMemoryAreas)
|
|
||||||
{
|
{
|
||||||
Marshal.Copy(area.ptr, ret, offset, area.size);
|
var ret = new byte[_saveramSize];
|
||||||
offset += area.size;
|
var offset = 0;
|
||||||
|
foreach (var area in _saveramMemoryAreas)
|
||||||
|
{
|
||||||
|
Marshal.Copy(area.ptr, ret, offset, area.size);
|
||||||
|
offset += area.size;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StoreSaveRam(byte[] data)
|
public void StoreSaveRam(byte[] data)
|
||||||
{
|
{
|
||||||
if (data.Length != _saveramSize)
|
using (_exe.EnterExit())
|
||||||
throw new InvalidOperationException("Saveram size mismatch");
|
|
||||||
|
|
||||||
var offset = 0;
|
|
||||||
foreach (var area in _saveramMemoryAreas)
|
|
||||||
{
|
{
|
||||||
Marshal.Copy(data, offset, area.ptr, area.size);
|
if (data.Length != _saveramSize)
|
||||||
offset += area.size;
|
throw new InvalidOperationException("Saveram size mismatch");
|
||||||
|
var offset = 0;
|
||||||
|
foreach (var area in _saveramMemoryAreas)
|
||||||
|
{
|
||||||
|
Marshal.Copy(data, offset, area.ptr, area.size);
|
||||||
|
offset += area.size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -565,9 +565,8 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
||||||
public PeRunner(PeRunnerOptions opt)
|
public PeRunner(PeRunnerOptions opt)
|
||||||
{
|
{
|
||||||
Initialize(_nextStart);
|
Initialize(_nextStart);
|
||||||
Enter();
|
using (this.EnterExit())
|
||||||
try
|
{
|
||||||
{
|
|
||||||
// load any predefined exports
|
// load any predefined exports
|
||||||
_psx = new Psx(this);
|
_psx = new Psx(this);
|
||||||
_exports.Add("libpsxscl.so", BizExvoker.GetExvoker(_psx));
|
_exports.Add("libpsxscl.so", BizExvoker.GetExvoker(_psx));
|
||||||
|
@ -644,15 +643,6 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
||||||
m.RunGlobalCtors();
|
m.RunGlobalCtors();
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPtr Resolve(string entryPoint)
|
public IntPtr Resolve(string entryPoint)
|
||||||
|
|
Loading…
Reference in New Issue