Fix the Write callback for the MemoryCallBackSystem and refactor the object more appropriately

This commit is contained in:
adelikat 2012-10-14 14:08:25 +00:00
parent 597f5419a2
commit 6fedb67949
9 changed files with 53 additions and 29 deletions

View File

@ -96,7 +96,7 @@ namespace BizHawk
{
byte temp = mapper.ReadMemory((ushort)(addr&0x1FFF));
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(addr);
}
@ -108,9 +108,9 @@ namespace BizHawk
{
mapper.WriteMemory((ushort)(addr & 0x1FFF), value);
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr);
}
}

View File

@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Consoles.Calculator
ret = rom[romPage * 0x4000 + addr - 0x4000]; //other rom page
else ret = ram[addr - 0x8000];
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(addr);
}
@ -55,9 +55,9 @@ namespace BizHawk.Emulation.Consoles.Calculator
return; //other rom page
else ram[addr - 0x8000] = value;
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr);
}
}

View File

@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Consoles.Coleco
ret = 0xFF;
}
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(addr);
}
@ -55,9 +55,9 @@ namespace BizHawk.Emulation.Consoles.Coleco
ram[addr] = value;
}
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr);
}
}

View File

@ -115,7 +115,7 @@ namespace BizHawk.Emulation.Consoles.Intellivision
break;
}
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(addr);
}
@ -286,9 +286,9 @@ namespace BizHawk.Emulation.Consoles.Intellivision
}
}
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr);
}
return (cart || stic || psg);

View File

@ -369,7 +369,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
ret = sysbus_watch[addr].ApplyGameGenie(ret);
}
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(addr);
}
@ -426,9 +426,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
board.WritePRG(addr - 0x8000, value);
}
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr);
}
}

View File

@ -33,7 +33,7 @@
return 0xFF;
}
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(addr);
}
@ -74,9 +74,9 @@
else
Log.Error("MEM", "UNHANDLED WRITE: {0:X6}:{1:X2}", addr, value);
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr);
}
}
}

View File

@ -43,7 +43,7 @@
ret = SystemRam[address & RamSizeMask];
}
if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasRead)
{
CoreInputComm.MemoryCallbackSystem.TriggerRead(address);
}
@ -81,9 +81,9 @@
return;
}
if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null)
if (CoreInputComm.MemoryCallbackSystem.HasWrite)
{
CoreInputComm.MemoryCallbackSystem.WriteCallback();
CoreInputComm.MemoryCallbackSystem.TriggerWrite(address);
}
}

View File

@ -99,7 +99,19 @@ namespace BizHawk
public class MemoryCallbackSystem
{
public int? ReadAddr = null;
public System.Action ReadCallback = null;
private System.Action ReadCallback = null;
public void SetReadCallback(System.Action func)
{
ReadCallback = func;
}
public bool HasRead
{
get
{
return ReadCallback != null;
}
}
public void TriggerRead(int addr)
{
@ -120,7 +132,19 @@ namespace BizHawk
}
public int? WriteAddr = null;
public System.Action WriteCallback = null;
private System.Action WriteCallback = null;
public void SetWriteCallback(System.Action func)
{
WriteCallback = func;
}
public bool HasWrite
{
get
{
return WriteCallback != null;
}
}
public void TriggerWrite(int addr)
{

View File

@ -2698,7 +2698,7 @@ namespace BizHawk.MultiClient
}
Global.Emulator.CoreInputComm.MemoryCallbackSystem.ReadAddr = _addr;
Global.Emulator.CoreInputComm.MemoryCallbackSystem.ReadCallback = delegate()
Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetReadCallback(delegate()
{
try
{
@ -2710,12 +2710,12 @@ namespace BizHawk.MultiClient
"error running function attached by lua function event.onmemoryread" +
"\nError message: " + e.Message);
}
};
});
}
else
{
Global.Emulator.CoreInputComm.MemoryCallbackSystem.ReadCallback = null;
Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetReadCallback(null);
}
}
@ -2736,7 +2736,7 @@ namespace BizHawk.MultiClient
}
Global.Emulator.CoreInputComm.MemoryCallbackSystem.WriteAddr = _addr;
Global.Emulator.CoreInputComm.MemoryCallbackSystem.WriteCallback = delegate()
Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetWriteCallback(delegate()
{
try
{
@ -2748,11 +2748,11 @@ namespace BizHawk.MultiClient
"error running function attached by lua function event.onmemoryread" +
"\nError message: " + e.Message);
}
};
});
}
else
{
Global.Emulator.CoreInputComm.MemoryCallbackSystem.WriteCallback = null;
Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetWriteCallback(null);
}
}
}