diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 13d2fab0b0..bfae8f383b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -13,7 +13,46 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 { public List> GetCpuFlagsAndRegisters() { - throw new NotImplementedException(); + List> ret = new List>(); + byte[] data = new byte[32 * 8 + 4 + 4 + 8 + 8 + 4 + 4 + 32 * 4 + 32 * 8]; + api.getRegisters(data); + + Int64[] reg = new Int64[32]; + for (int i = 0; i < 32; i++) + { + reg[i] = BitConverter.ToInt64(data, i * 8); + ret.Add(new KeyValuePair("REG" + i, (int)reg[i])); + } + + UInt32 PC = BitConverter.ToUInt32(data, 32 * 8); + ret.Add(new KeyValuePair("PC", (int)PC)); + + ret.Add(new KeyValuePair("LL", BitConverter.ToInt32(data, 32 * 8 + 4))); + + Int64 Lo = BitConverter.ToInt64(data, 32 * 8 + 4 + 4); + ret.Add(new KeyValuePair("LO", (int)Lo)); + + Int64 Hi = BitConverter.ToInt64(data, 32 * 8 + 4 + 4 + 8); + ret.Add(new KeyValuePair("HI", (int)Hi)); + + ret.Add(new KeyValuePair("FCR0", BitConverter.ToInt32(data, 32 * 8 + 4 + 4 + 8 + 8))); + ret.Add(new KeyValuePair("FCR31", BitConverter.ToInt32(data, 32 * 8 + 4 + 4 + 8 + 8 + 4))); + + UInt32[] reg_cop0 = new UInt32[32]; + for (int i = 0; i < 32; i++) + { + reg_cop0[i] = BitConverter.ToUInt32(data, 32 * 8 + 4 + 4 + 8 + 8 + 4 + 4 + i * 4); + ret.Add(new KeyValuePair("CP0 REG" + i, (int)reg_cop0[i])); + } + + Int64[] reg_cop1_fgr_64 = new Int64[32]; + for (int i = 0; i < 32; i++) + { + reg_cop1_fgr_64[i] = BitConverter.ToInt64(data, 32 * 8 + 4 + 4 + 8 + 8 + 4 + 4 + 32 * 4 + i * 8); + ret.Add(new KeyValuePair("CP1 FGR REG" + i, (int)reg_cop1_fgr_64[i])); + } + + return ret; } public string SystemId { get { return "N64"; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs index 9bb66014af..748578ca34 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs @@ -422,6 +422,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public delegate void SetWriteCallback(MemoryCallback callback); SetWriteCallback m64pSetWriteCallback; + /// + /// Gets the CPU registers + /// + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void GetRegisters(byte[] dest); + GetRegisters m64pGetRegisters; + // DLL handles IntPtr CoreDll; IntPtr GfxDll; @@ -581,6 +588,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 m64pSetReadCallback = (SetReadCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "SetReadCallback"), typeof(SetReadCallback)); m64pSetWriteCallback = (SetWriteCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "SetWriteCallback"), typeof(SetWriteCallback)); + m64pGetRegisters = (GetRegisters)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "GetRegisters"), typeof(GetRegisters)); + GfxPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(GfxDll, "PluginStartup"), typeof(PluginStartup)); GfxPluginShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(GfxDll, "PluginShutdown"), typeof(PluginShutdown)); GFXReadScreen2 = (ReadScreen2)Marshal.GetDelegateForFunctionPointer(GetProcAddress(GfxDll, "ReadScreen2"), typeof(ReadScreen2)); @@ -820,6 +829,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 m64pSetWriteCallback(callback); } + public void getRegisters(byte[] dest) + { + m64pGetRegisters(dest); + } + public void Dispose() { if (!disposed) diff --git a/libmupen64plus/mupen64plus-core/src/r4300/r4300.c b/libmupen64plus/mupen64plus-core/src/r4300/r4300.c index 7d1ae69e80..1f413ceed0 100644 --- a/libmupen64plus/mupen64plus-core/src/r4300/r4300.c +++ b/libmupen64plus/mupen64plus-core/src/r4300/r4300.c @@ -1106,3 +1106,28 @@ void r4300_execute(void (*startcb)(void)) } #endif } + +EXPORT void CALL GetRegisters(unsigned char * dest) +{ + memcpy(dest, reg, 8 * 32); + dest += 8 * 32; + memcpy(dest, &(PC->addr), 4); + dest += 4; + memcpy(dest, &llbit, 4); + dest += 4; + memcpy(dest, &lo, 8); + dest += 8; + memcpy(dest, &hi, 8); + dest += 8; + memcpy(dest, &FCR0, 4); + dest += 4; + memcpy(dest, &FCR31, 4); + dest += 4; + + memcpy(dest, reg_cop0, 4 * 32); + dest += 4 * 32; + + memcpy(dest, reg_cop1_fgr_64, 8 * 32); + dest += 8 * 32; + +} \ No newline at end of file diff --git a/output/dll/mupen64plus.dll b/output/dll/mupen64plus.dll index ec968d66ad..bcde1f877d 100644 Binary files a/output/dll/mupen64plus.dll and b/output/dll/mupen64plus.dll differ