N64: Mostly implemented the onmemorywrite and onmemoryread hooks, but some reads/writes still make it through

This commit is contained in:
pjgat09 2013-11-17 03:42:06 +00:00
parent 58336c45b2
commit 3e8596f81c
9 changed files with 428 additions and 1 deletions

View File

@ -86,6 +86,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
}
public void FrameAdvance(bool render, bool rendersound)
{
RefreshMemoryCallbacks();
if (Controller["Reset"])
{
api.soft_reset();
@ -262,6 +264,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
public bool BinarySaveStatesPreferred { get { return true; } }
#region memorycallback
mupen64plusApi.MemoryCallback readcb;
mupen64plusApi.MemoryCallback writecb;
void RefreshMemoryCallbacks()
{
var mcs = CoreComm.MemoryCallbackSystem;
// we RefreshMemoryCallbacks() after the triggers in case the trigger turns itself off at that point
if (mcs.HasReads)
readcb = delegate(uint addr) { mcs.CallRead(addr); RefreshMemoryCallbacks(); };
else
readcb = null;
if (mcs.HasWrites)
writecb = delegate(uint addr) { mcs.CallWrite(addr); RefreshMemoryCallbacks(); };
else
writecb = null;
api.setReadCallback(readcb);
api.setWriteCallback(writecb);
}
#endregion
#region memorydomains
private MemoryDomain MakeMemoryDomain(string name, mupen64plusApi.N64_MEMORY id, MemoryDomain.Endian endian)

View File

@ -401,6 +401,27 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void StartupCallback();
/// <summary>
/// Type of the read/write memory callbacks
/// </summary>
/// <param name="address">The address which the cpu is read/writing</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MemoryCallback(uint address);
/// <summary>
/// Sets the memory read callback
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetReadCallback(MemoryCallback callback);
SetReadCallback m64pSetReadCallback;
/// <summary>
/// Sets the memory write callback
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetWriteCallback(MemoryCallback callback);
SetWriteCallback m64pSetWriteCallback;
// DLL handles
IntPtr CoreDll;
IntPtr GfxDll;
@ -557,6 +578,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
m64psave_saveram = (save_saveram)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "save_saveram"), typeof(save_saveram));
m64pload_saveram = (load_saveram)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "load_saveram"), typeof(load_saveram));
m64pSetReadCallback = (SetReadCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "SetReadCallback"), typeof(SetReadCallback));
m64pSetWriteCallback = (SetWriteCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "SetWriteCallback"), typeof(SetWriteCallback));
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));
@ -786,6 +810,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
m64pload_saveram(src);
}
public void setReadCallback(MemoryCallback callback)
{
m64pSetReadCallback(callback);
}
public void setWriteCallback(MemoryCallback callback)
{
m64pSetWriteCallback(callback);
}
public void Dispose()
{
if (!disposed)

View File

@ -106,6 +106,8 @@ void dma_pi_read(void)
{
for (i=0; i < (pi_register.pi_rd_len_reg & 0xFFFFFF)+1; i++)
{
READCBADDR(0x80000000 | ((pi_register.pi_dram_addr_reg+i)^S8));
sram[((pi_register.pi_cart_addr_reg-0x08000000)+i)^S8] =
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8];
}
@ -145,6 +147,8 @@ void dma_pi_write(void)
for (i=0; i<(int)(pi_register.pi_wr_len_reg & 0xFFFFFF)+1; i++)
{
WRITECBADDR(0x80000000 | ((pi_register.pi_dram_addr_reg+i)^S8));
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8]=
sram[(((pi_register.pi_cart_addr_reg-0x08000000)&0xFFFF)+i)^S8];
}
@ -203,6 +207,9 @@ void dma_pi_write(void)
{
unsigned long rdram_address1 = pi_register.pi_dram_addr_reg+i+0x80000000;
unsigned long rdram_address2 = pi_register.pi_dram_addr_reg+i+0xa0000000;
WRITECBADDR(0x80000000 | ((pi_register.pi_dram_addr_reg+i)^S8));
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8]=
rom[(((pi_register.pi_cart_addr_reg-0x10000000)&0x3FFFFFF)+i)^S8];
@ -233,6 +240,8 @@ void dma_pi_write(void)
{
for (i=0; i<(int)longueur; i++)
{
WRITECBADDR(0x80000000 | ((pi_register.pi_dram_addr_reg+i)^S8));
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8]=
rom[(((pi_register.pi_cart_addr_reg-0x10000000)&0x3FFFFFF)+i)^S8];
}
@ -249,6 +258,8 @@ void dma_pi_write(void)
case 3:
case 6:
{
WRITECBADDR(0x80000000 | (0x318/4));
if (ConfigGetParamInt(g_CoreConfig, "DisableExtraMem"))
{
rdram[0x318/4] = 0x400000;
@ -261,6 +272,8 @@ void dma_pi_write(void)
}
case 5:
{
WRITECBADDR(0x80000000 | (0x3F0/4));
if (ConfigGetParamInt(g_CoreConfig, "DisableExtraMem"))
{
rdram[0x3F0/4] = 0x400000;
@ -299,6 +312,8 @@ void dma_sp_write(void)
for(j=0; j<count; j++) {
for(i=0; i<length; i++) {
READCBADDR(0x80000000 | (dramaddr^S8));
spmem[memaddr^S8] = dram[dramaddr^S8];
memaddr++;
dramaddr++;
@ -325,6 +340,8 @@ void dma_sp_read(void)
for(j=0; j<count; j++) {
for(i=0; i<length; i++) {
WRITECBADDR(0x80000000 | (dramaddr^S8));
dram[dramaddr^S8] = spmem[memaddr^S8];
memaddr++;
dramaddr++;
@ -345,6 +362,8 @@ void dma_si_write(void)
for (i=0; i<(64/4); i++)
{
READCBADDR(0x80000000 | (si_register.si_dram_addr/4+i));
PIF_RAM[i] = sl(rdram[si_register.si_dram_addr/4+i]);
}
@ -367,6 +386,8 @@ void dma_si_read(void)
for (i=0; i<(64/4); i++)
{
WRITECBADDR(0x80000000 | (si_register.si_dram_addr/4+i));
rdram[si_register.si_dram_addr/4+i] = sl(PIF_RAM[i]);
}

View File

@ -31,5 +31,8 @@ void dma_sp_read(void);
void sram_format(void);
extern void (*readCB)(unsigned int);
extern void (*writeCB)(unsigned int);
#endif

View File

@ -180,12 +180,17 @@ void dma_read_flashram(void)
switch (flashram_info.mode)
{
case STATUS_MODE:
WRITECBADDR(0x80000000 | (pi_register.pi_dram_addr_reg/4));
WRITECBADDR(0x80000000 | (pi_register.pi_dram_addr_reg/4+1));
rdram[pi_register.pi_dram_addr_reg/4] = (unsigned int)(flashram_info.status >> 32);
rdram[pi_register.pi_dram_addr_reg/4+1] = (unsigned int)(flashram_info.status);
break;
case READ_MODE:
for (i=0; i<(pi_register.pi_wr_len_reg & 0x0FFFFFF)+1; i++)
{
READCBADDR(0x80000000 | ((pi_register.pi_dram_addr_reg+i)^S8));
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8]=
flashram[(((pi_register.pi_cart_addr_reg-0x08000000)&0xFFFF)*2+i)^S8];
}

View File

@ -34,4 +34,7 @@ void flashram_command(unsigned int command);
unsigned int flashram_status(void);
void dma_read_flashram(void);
void dma_write_flashram(void);
void flashram_format(void);
void flashram_format(void);
extern void (*readCB)(unsigned int);
extern void (*writeCB)(unsigned int);

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,12 @@
#include "osal/preproc.h"
#define READCB() if (readCB) readCB(address)
#define WRITECB() if (writeCB) writeCB(address)
#define READCBADDR(addr) if (readCB) readCB(addr)
#define WRITECBADDR(addr) if (writeCB) writeCB(addr)
int init_memory(int DoByteSwap);
void free_memory(void);
#define read_word_in_memory() readmem[address>>16]()

Binary file not shown.