mgba - pass in mgba class instead of core pointer to MGBAMemoryCallbackSystem, seems cleaner either way. Still crash
This commit is contained in:
parent
fc5d8b2de6
commit
f97ef09c41
|
@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
|
||||
{
|
||||
var values = new int[RegisterNames.Length];
|
||||
LibmGBA.BizGetRegisters(_core, values);
|
||||
LibmGBA.BizGetRegisters(Core, values);
|
||||
var ret = new Dictionary<string, RegisterValue>();
|
||||
for (var i = 0; i < RegisterNames.Length; i++)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return LibmGBA.BizReadBus(_core, a);
|
||||
return LibmGBA.BizReadBus(Core, a);
|
||||
},
|
||||
delegate (long addr, byte val)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
LibmGBA.BizWriteBus(_core, a, val);
|
||||
LibmGBA.BizWriteBus(Core, a, val);
|
||||
}, 4));
|
||||
|
||||
_memoryDomains = new MemoryDomainList(mm);
|
||||
|
@ -63,7 +63,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
private void WireMemoryDomainPointers()
|
||||
{
|
||||
var s = new LibmGBA.MemoryAreas();
|
||||
LibmGBA.BizGetMemoryAreas(_core, s);
|
||||
LibmGBA.BizGetMemoryAreas(Core, s);
|
||||
|
||||
_iwram.Data = s.iwram;
|
||||
_ewram.Data = s.wram;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
public byte[] CloneSaveRam()
|
||||
{
|
||||
int len = LibmGBA.BizGetSaveRam(_core, _saveScratch, _saveScratch.Length);
|
||||
int len = LibmGBA.BizGetSaveRam(Core, _saveScratch, _saveScratch.Length);
|
||||
if (len == _saveScratch.Length)
|
||||
{
|
||||
throw new InvalidOperationException("Save buffer not long enough");
|
||||
|
@ -33,10 +33,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
data = LegacyFix(data);
|
||||
}
|
||||
|
||||
LibmGBA.BizPutSaveRam(_core, data, data.Length);
|
||||
LibmGBA.BizPutSaveRam(Core, data, data.Length);
|
||||
}
|
||||
|
||||
public bool SaveRamModified => LibmGBA.BizGetSaveRam(_core, _saveScratch, _saveScratch.Length) > 0;
|
||||
public bool SaveRamModified => LibmGBA.BizGetSaveRam(Core, _saveScratch, _saveScratch.Length) > 0;
|
||||
|
||||
private static byte[] LegacyFix(byte[] saveram)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
if (o.DisplayBG2) mask |= LibmGBA.Layers.BG2;
|
||||
if (o.DisplayBG3) mask |= LibmGBA.Layers.BG3;
|
||||
if (o.DisplayOBJ) mask |= LibmGBA.Layers.OBJ;
|
||||
LibmGBA.BizSetLayerMask(_core, mask);
|
||||
LibmGBA.BizSetLayerMask(Core, mask);
|
||||
|
||||
LibmGBA.Sounds smask = 0;
|
||||
if (o.PlayCh0) smask |= LibmGBA.Sounds.CH0;
|
||||
|
@ -32,7 +32,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
if (o.PlayCh3) smask |= LibmGBA.Sounds.CH3;
|
||||
if (o.PlayChA) smask |= LibmGBA.Sounds.CHA;
|
||||
if (o.PlayChB) smask |= LibmGBA.Sounds.CHB;
|
||||
LibmGBA.BizSetSoundMask(_core, smask);
|
||||
LibmGBA.BizSetSoundMask(Core, smask);
|
||||
|
||||
var palette = new int[65536];
|
||||
GBColors.ColorType c = GBColors.ColorType.vivid;
|
||||
|
@ -48,7 +48,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
GBColors.GetLut(c, palette);
|
||||
for (var i = 32768; i < 65536; i++)
|
||||
palette[i] = palette[i - 32768];
|
||||
LibmGBA.BizSetPalette(_core, palette);
|
||||
LibmGBA.BizSetPalette(Core, palette);
|
||||
|
||||
_settings = o;
|
||||
return false;
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
IntPtr p = IntPtr.Zero;
|
||||
int size = 0;
|
||||
if (!LibmGBA.BizStartGetState(_core, ref p, ref size))
|
||||
if (!LibmGBA.BizStartGetState(Core, ref p, ref size))
|
||||
{
|
||||
throw new InvalidOperationException("Core failed to save!");
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
}
|
||||
|
||||
reader.Read(_savebuff, 0, length);
|
||||
if (!LibmGBA.BizPutState(_core, _savebuff, length))
|
||||
if (!LibmGBA.BizPutState(Core, _savebuff, length))
|
||||
{
|
||||
throw new InvalidOperationException("Core rejected the savestate!");
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
|
||||
var skipBios = !DeterministicEmulation && _syncSettings.SkipBios;
|
||||
|
||||
_core = LibmGBA.BizCreate(bios, file, file.Length, GetOverrideInfo(game), skipBios);
|
||||
if (_core == IntPtr.Zero)
|
||||
Core = LibmGBA.BizCreate(bios, file, file.Length, GetOverrideInfo(game), skipBios);
|
||||
if (Core == IntPtr.Zero)
|
||||
{
|
||||
throw new InvalidOperationException($"{nameof(LibmGBA.BizCreate)}() returned NULL! Bad BIOS? and/or ROM?");
|
||||
}
|
||||
|
@ -60,11 +60,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
};
|
||||
_tracecb = new LibmGBA.TraceCallback((msg) => _tracer.Put(_traceInfo(msg)));
|
||||
ser.Register(_tracer);
|
||||
MemoryCallbacks = new MGBAMemoryCallbackSystem(_core);
|
||||
MemoryCallbacks = new MGBAMemoryCallbackSystem(this);
|
||||
}
|
||||
catch
|
||||
{
|
||||
LibmGBA.BizDestroy(_core);
|
||||
LibmGBA.BizDestroy(Core);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
Frame++;
|
||||
if (controller.IsPressed("Power"))
|
||||
{
|
||||
LibmGBA.BizReset(_core);
|
||||
LibmGBA.BizReset(Core);
|
||||
|
||||
// BizReset caused memorydomain pointers to change.
|
||||
WireMemoryDomainPointers();
|
||||
|
@ -114,7 +114,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
LibmGBA.BizSetTraceCallback(_tracer.Enabled ? _tracecb : null);
|
||||
|
||||
IsLagFrame = LibmGBA.BizAdvance(
|
||||
_core,
|
||||
Core,
|
||||
VBANext.GetButtons(controller),
|
||||
render ? _videobuff : _dummyvideobuff,
|
||||
ref _nsamp,
|
||||
|
@ -151,10 +151,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_core != IntPtr.Zero)
|
||||
if (Core != IntPtr.Zero)
|
||||
{
|
||||
LibmGBA.BizDestroy(_core);
|
||||
_core = IntPtr.Zero;
|
||||
LibmGBA.BizDestroy(Core);
|
||||
Core = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
}
|
||||
|
||||
private readonly byte[] _saveScratch = new byte[262144];
|
||||
private IntPtr _core;
|
||||
internal IntPtr Core;
|
||||
|
||||
private static LibmGBA.OverrideInfo GetOverrideInfo(GameInfo game)
|
||||
{
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
public class MGBAMemoryCallbackSystem : IMemoryCallbackSystem
|
||||
{
|
||||
private readonly IntPtr _core;
|
||||
private readonly MGBAHawk _mgba;
|
||||
|
||||
public MGBAMemoryCallbackSystem(IntPtr core)
|
||||
public MGBAMemoryCallbackSystem(MGBAHawk mgba)
|
||||
{
|
||||
_core = core;
|
||||
_mgba = mgba;
|
||||
}
|
||||
|
||||
private readonly List<CallbackContainer> _callbacks = new List<CallbackContainer>();
|
||||
|
@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
else
|
||||
{
|
||||
LibmGBA.BizSetMemCallback(container.Call);
|
||||
container.ID = LibmGBA.BizSetWatchpoint(_core, callback.Address.Value, container.WatchPointType);
|
||||
container.ID = LibmGBA.BizSetWatchpoint(_mgba.Core, callback.Address.Value, container.WatchPointType);
|
||||
}
|
||||
|
||||
_callbacks.Add(container);
|
||||
|
@ -62,7 +62,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
var cbToRemove = _callbacks.Where(container => container.Callback.Callback == action).FirstOrDefault();
|
||||
|
||||
if (LibmGBA.BizClearWatchpoint(_core, cbToRemove.ID) == true)
|
||||
if (LibmGBA.BizClearWatchpoint(_mgba.Core, cbToRemove.ID) == true)
|
||||
{
|
||||
_callbacks.Remove(cbToRemove);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
foreach (var cb in _callbacks)
|
||||
{
|
||||
if (LibmGBA.BizClearWatchpoint(_core, cb.ID) == true)
|
||||
if (LibmGBA.BizClearWatchpoint(_mgba.Core, cb.ID) == true)
|
||||
{
|
||||
_callbacks.Remove(cb);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue