wonderswan: debugging callbacks

This commit is contained in:
goyuken 2014-06-19 15:57:07 +00:00
parent 5145ef3f97
commit 90f627d883
10 changed files with 123 additions and 7 deletions

View File

@ -150,6 +150,9 @@ namespace BizHawk.Emulation.Common
{ {
_list.Clear(); _list.Clear();
} }
// why was this missing?
public bool Has { get { return _list.Any(); } }
} }
public class MemoryCallbackSystem public class MemoryCallbackSystem

View File

@ -127,6 +127,18 @@ namespace BizHawk.Emulation.Cores.WonderSwan
[DllImport(dd, CallingConvention = cc)] [DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_txtstateload(IntPtr core, [In]ref TextStateFPtrs ff); public static extern void bizswan_txtstateload(IntPtr core, [In]ref TextStateFPtrs ff);
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_setmemorycallbacks(IntPtr core, MemoryCallback rcb, MemoryCallback ecb, MemoryCallback wcb);
[DllImport(dd, CallingConvention = cc)]
public static extern void bizswan_setbuttoncallback(IntPtr core, ButtonCallback bcb);
[UnmanagedFunctionPointer(cc)]
public delegate void MemoryCallback(uint addr);
[UnmanagedFunctionPointer(cc)]
public delegate void ButtonCallback();
/// <summary> /// <summary>
/// return a CPU register /// return a CPU register
/// </summary> /// </summary>

View File

@ -120,6 +120,8 @@ namespace BizHawk.Emulation.Cores.WonderSwan
savebuff = new byte[BizSwan.bizswan_binstatesize(Core)]; savebuff = new byte[BizSwan.bizswan_binstatesize(Core)];
savebuff2 = new byte[savebuff.Length + 13]; savebuff2 = new byte[savebuff.Length + 13];
InitDebugCallbacks();
} }
catch catch
{ {
@ -142,6 +144,8 @@ namespace BizHawk.Emulation.Cores.WonderSwan
Frame++; Frame++;
IsLagFrame = true; IsLagFrame = true;
SetDebugCallbacks();
if (Controller["Power"]) if (Controller["Power"])
BizSwan.bizswan_reset(Core); BizSwan.bizswan_reset(Core);
@ -352,6 +356,46 @@ namespace BizHawk.Emulation.Cores.WonderSwan
throw new NotImplementedException(); throw new NotImplementedException();
} }
BizSwan.MemoryCallback ReadCallbackD;
BizSwan.MemoryCallback WriteCallbackD;
BizSwan.MemoryCallback ExecCallbackD;
BizSwan.ButtonCallback ButtonCallbackD;
void ReadCallback(uint addr)
{
CoreComm.MemoryCallbackSystem.CallRead(addr);
}
void WriteCallback(uint addr)
{
CoreComm.MemoryCallbackSystem.CallWrite(addr);
}
void ExecCallback(uint addr)
{
CoreComm.MemoryCallbackSystem.CallExecute(addr);
}
void ButtonCallback()
{
CoreComm.InputCallback.Call();
}
void InitDebugCallbacks()
{
ReadCallbackD = new BizSwan.MemoryCallback(ReadCallback);
WriteCallbackD = new BizSwan.MemoryCallback(WriteCallback);
ExecCallbackD = new BizSwan.MemoryCallback(ExecCallback);
ButtonCallbackD = new BizSwan.ButtonCallback(ButtonCallback);
}
void SetDebugCallbacks()
{
BizSwan.bizswan_setmemorycallbacks(Core,
CoreComm.MemoryCallbackSystem.HasReads ? ReadCallbackD : null,
CoreComm.MemoryCallbackSystem.HasWrites ? WriteCallbackD : null,
CoreComm.MemoryCallbackSystem.HasExecutes ? ExecCallbackD : null);
BizSwan.bizswan_setbuttoncallback(Core,
CoreComm.InputCallback.Has ? ButtonCallbackD : null);
}
#endregion #endregion
#region Settings #region Settings

Binary file not shown.

View File

@ -183,6 +183,9 @@ namespace MDFN_IEN_WSWAN
} }
case 0xb5: case 0xb5:
{ {
Lagged = false;
if (ButtonHook)
ButtonHook();
uint8 ret = (ButtonWhich << 4) | ButtonReadLatch; uint8 ret = (ButtonWhich << 4) | ButtonReadLatch;
return(ret); return(ret);
} }
@ -252,7 +255,7 @@ namespace MDFN_IEN_WSWAN
case 0xB3: CommControl = V & 0xF0; break; case 0xB3: CommControl = V & 0xF0; break;
case 0xb5: ButtonWhich = V >> 4; case 0xb5: ButtonWhich = V >> 4;
Lagged = false; // Lagged = false; // why was this being set here?
ButtonReadLatch = 0; ButtonReadLatch = 0;
if(ButtonWhich & 0x4) /*buttons*/ if(ButtonWhich & 0x4) /*buttons*/

View File

@ -51,6 +51,9 @@ private:
bool language; bool language;
public:
void (*ButtonHook)();
public: public:
System *sys; System *sys;
template<bool isReader>void SyncState(NewState *ns); template<bool isReader>void SyncState(NewState *ns);

View File

@ -203,6 +203,8 @@ namespace MDFN_IEN_WSWAN
return true; return true;
} }
// this is more than just being defensive; these classes do
// in some cases rely on zero filled constuct state
void *System::operator new(std::size_t size) void *System::operator new(std::size_t size)
{ {
void *p = ::operator new(size); void *p = ::operator new(size);
@ -404,4 +406,16 @@ namespace MDFN_IEN_WSWAN
{ {
s->SaveRamClearHacky(*settings); s->SaveRamClearHacky(*settings);
} }
EXPORT void bizswan_setmemorycallbacks(System *s, void (*rcb)(uint32), void (*ecb)(uint32), void (*wcb)(uint32))
{
s->cpu.ReadHook = rcb;
s->cpu.WriteHook = wcb;
s->cpu.ExecHook = ecb;
}
EXPORT void bizswan_setbuttoncallback(System *s, void (*bcb)())
{
s->memory.ButtonHook = bcb;
}
} }

View File

@ -1,9 +1,9 @@
#define cpu_readop sys->memory.Read20 //#define cpu_readop sys->memory.Read20
//cpu_readmem20 //cpu_readmem20
#define cpu_readop_arg sys->memory.Read20 //#define cpu_readop_arg sys->memory.Read20
//cpu_readmem20 //cpu_readmem20
#define cpu_readmem20 sys->memory.Read20 //#define cpu_readmem20 sys->memory.Read20
#define cpu_writemem20 sys->memory.Write20 //#define cpu_writemem20 sys->memory.Write20
#define cpu_readport sys->memory.readport #define cpu_readport sys->memory.readport
#define cpu_writeport sys->memory.writeport #define cpu_writeport sys->memory.writeport

View File

@ -1027,6 +1027,33 @@ namespace MDFN_IEN_WSWAN
} }
uint8 V30MZ::cpu_readop(uint32 addr)
{
if (ExecHook)
ExecHook(addr);
return sys->memory.Read20(addr);
}
uint8 V30MZ::cpu_readop_arg(uint32 addr)
{
// only forward the first opcode byte to callback
return sys->memory.Read20(addr);
}
uint8 V30MZ::cpu_readmem20(uint32 addr)
{
if (ReadHook)
ReadHook(addr);
return sys->memory.Read20(addr);
}
void V30MZ::cpu_writemem20(uint32 addr, uint8 val)
{
sys->memory.Write20(addr, val);
if (WriteHook)
WriteHook(addr);
}
SYNCFUNC(V30MZ) SYNCFUNC(V30MZ)
{ {
NSS(old_CS); NSS(old_CS);

View File

@ -80,8 +80,6 @@ private:
} RM; } RM;
} Mod_RM; } Mod_RM;
private:
private: private:
void nec_interrupt(unsigned int_num); void nec_interrupt(unsigned int_num);
bool CheckInHLT(); bool CheckInHLT();
@ -139,6 +137,18 @@ private:
typedef unsigned(V30MZ::*EAFPtr)(); typedef unsigned(V30MZ::*EAFPtr)();
EAFPtr GetEA[192]; EAFPtr GetEA[192];
// memory callback system plumbing
public:
void (*ReadHook)(uint32 addr);
void (*WriteHook)(uint32 addr);
void (*ExecHook)(uint32 addr);
private:
uint8 cpu_readop(uint32 addr);
uint8 cpu_readop_arg(uint32 addr);
uint8 cpu_readmem20(uint32 addr);
void cpu_writemem20(uint32 addr, uint8 val);
public: public:
System *sys; System *sys;
template<bool isReader>void SyncState(NewState *ns); template<bool isReader>void SyncState(NewState *ns);