N64: Implement GetCpuFlagsAndRegisters()

This commit is contained in:
pjgat09 2013-11-18 03:29:47 +00:00
parent fc19fe40a9
commit 3c56223d7b
4 changed files with 79 additions and 1 deletions

View File

@ -13,7 +13,46 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
{
public List<KeyValuePair<string, int>> GetCpuFlagsAndRegisters()
{
throw new NotImplementedException();
List<KeyValuePair<string, int>> ret = new List<KeyValuePair<string, int>>();
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<string, int>("REG" + i, (int)reg[i]));
}
UInt32 PC = BitConverter.ToUInt32(data, 32 * 8);
ret.Add(new KeyValuePair<string, int>("PC", (int)PC));
ret.Add(new KeyValuePair<string, int>("LL", BitConverter.ToInt32(data, 32 * 8 + 4)));
Int64 Lo = BitConverter.ToInt64(data, 32 * 8 + 4 + 4);
ret.Add(new KeyValuePair<string, int>("LO", (int)Lo));
Int64 Hi = BitConverter.ToInt64(data, 32 * 8 + 4 + 4 + 8);
ret.Add(new KeyValuePair<string, int>("HI", (int)Hi));
ret.Add(new KeyValuePair<string, int>("FCR0", BitConverter.ToInt32(data, 32 * 8 + 4 + 4 + 8 + 8)));
ret.Add(new KeyValuePair<string, int>("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<string, int>("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<string, int>("CP1 FGR REG" + i, (int)reg_cop1_fgr_64[i]));
}
return ret;
}
public string SystemId { get { return "N64"; } }

View File

@ -422,6 +422,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
public delegate void SetWriteCallback(MemoryCallback callback);
SetWriteCallback m64pSetWriteCallback;
/// <summary>
/// Gets the CPU registers
/// </summary>
[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)

View File

@ -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;
}

Binary file not shown.