diff --git a/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs b/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs index 957396ae12..2080b0f72d 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/GBA/LibMeteor.cs @@ -132,5 +132,19 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA /// IntPtr.Zero if which is unrecognized [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libmeteor_getmemoryarea(MemoryArea which); + + /// + /// core callback for tracelogging + /// + /// disassembly of an instruction about to be run + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void TraceCallback(string msg); + + /// + /// set callback to run before each instruction is executed + /// + /// null to clear + [DllImport("libmeteor.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void libmeteor_settracecallback(TraceCallback callback); } } diff --git a/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs b/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs index c042116a5d..d2c21a8630 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/GBA/Meteor.cs @@ -40,6 +40,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA if (Controller["Power"]) LibMeteor.libmeteor_hardreset(); + // due to the design of the tracing api, we have to poll whether it's active each frame + LibMeteor.libmeteor_settracecallback(CoreInputComm.Tracer.Enabled ? tracecallback : null); if (!coredead) LibMeteor.libmeteor_frameadvance(); if (IsLagFrame) @@ -111,7 +113,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA CoreOutputComm _CoreOutputComm = new CoreOutputComm { VsyncNum = 262144, - VsyncDen = 4389 + VsyncDen = 4389, + CpuTraceAvailable = true }; public CoreOutputComm CoreOutputComm { get { return _CoreOutputComm; } } @@ -181,6 +184,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA LibMeteor.InputCallback inputcallback; /// true if libmeteor aborted bool coredead = false; + /// hold pointer to trace callback so it won't get GCed + LibMeteor.TraceCallback tracecallback; LibMeteor.Buttons GetInput() { @@ -279,6 +284,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA #endregion + void Trace(string msg) + { + CoreInputComm.Tracer.Put(msg); + } + void Init() { if (attachedcore != null) @@ -286,6 +296,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA messagecallback = PrintMessage; inputcallback = GetInput; + tracecallback = Trace; // don't set this callback now, only set if enabled LibMeteor.libmeteor_setmessagecallback(messagecallback); LibMeteor.libmeteor_setkeycallback(inputcallback); @@ -315,8 +326,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo.GBA LibMeteor.libmeteor_setbuffers(IntPtr.Zero, 240 * 160 * 4, IntPtr.Zero, 4); messagecallback = null; inputcallback = null; + tracecallback = null; LibMeteor.libmeteor_setmessagecallback(messagecallback); LibMeteor.libmeteor_setkeycallback(inputcallback); + LibMeteor.libmeteor_settracecallback(tracecallback); _MemoryDomains.Clear(); } } diff --git a/BizHawk.MultiClient/output/dll/libmeteor.dll b/BizHawk.MultiClient/output/dll/libmeteor.dll index 26024bf318..50f57c2b7f 100644 Binary files a/BizHawk.MultiClient/output/dll/libmeteor.dll and b/BizHawk.MultiClient/output/dll/libmeteor.dll differ diff --git a/libmeteor/cinterface.cpp b/libmeteor/cinterface.cpp index 1df9438806..36ec943370 100644 --- a/libmeteor/cinterface.cpp +++ b/libmeteor/cinterface.cpp @@ -42,6 +42,21 @@ EXPORT void libmeteor_setkeycallback(uint16_t (*callback)()) keycallback = callback; } +bool traceenabled = false; +void (*tracecallback)(const char *msg) = NULL; + +EXPORT void libmeteor_settracecallback(void (*callback)(const char*msg)) +{ + tracecallback = callback; + traceenabled = tracecallback != NULL; +} + +void trace_bizhawk(std::string msg) +{ + if (tracecallback) + tracecallback(msg.c_str()); +} + EXPORT void libmeteor_hardreset() { AMeteor::Reset(AMeteor::UNIT_ALL ^ (AMeteor::UNIT_MEMORY_BIOS | AMeteor::UNIT_MEMORY_ROM)); @@ -105,17 +120,16 @@ EXPORT void libmeteor_init() static bool first = true; if (first) { + // TODO: saveram stuff //AMeteor::_memory.LoadCartInferred(); AMeteor::_lcd.GetScreen().GetRenderer().SetFrameSlot(syg::ptr_fun(videocb)); AMeteor::_sound.GetSpeaker().SetFrameSlot(syg::ptr_fun(soundcb)); - // TODO: input first = false; } } EXPORT void libmeteor_frameadvance() { - //AMeteor::_keypad.SetPadState(0x3ff); AMeteor::Run(10000000); } diff --git a/libmeteor/libmeteor.vcxproj b/libmeteor/libmeteor.vcxproj index af4244960e..63035cb960 100644 --- a/libmeteor/libmeteor.vcxproj +++ b/libmeteor/libmeteor.vcxproj @@ -51,7 +51,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions);METDEBUG;METDEBUGLOG + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMETEOR_EXPORTS;%(PreprocessorDefinitions);METDEBUG;METDEBUGLOG;_ITERATOR_DEBUG_LEVEL=0 4800;4396 diff --git a/libmeteor/source/debug.hpp b/libmeteor/source/debug.hpp index 7c2c5236ae..fd8f7c5c2f 100644 --- a/libmeteor/source/debug.hpp +++ b/libmeteor/source/debug.hpp @@ -30,6 +30,8 @@ void print_bizhawk(const char *msg); void print_bizhawk(std::string &msg); void abort_bizhawk(const char *msg); void keyupdate_bizhawk(); +extern bool traceenabled; +void trace_bizhawk(std::string msg); #if 0 #define met_abort(str) \ diff --git a/libmeteor/source/interpreter.cpp b/libmeteor/source/interpreter.cpp index bd33e34267..242b884d82 100644 --- a/libmeteor/source/interpreter.cpp +++ b/libmeteor/source/interpreter.cpp @@ -24,6 +24,7 @@ #include "ameteor.hpp" #include "debug.hpp" +#include namespace AMeteor { @@ -70,7 +71,12 @@ namespace AMeteor met_abort("PC not 16 bit aligned : " << IOS_ADD << R(15)); code = MEM.Read16(R(15)-2); - //std::cerr << IOS_ADD << R(15) << ' ' << Disassembler::Instruction(R(15), (uint16_t)code).ToString() << std::endl; + if (traceenabled) + { + std::stringstream ss; + ss << IOS_ADD << R(15) << ' ' << Disassembler::Instruction(R(15), (uint16_t)code).ToString(); + trace_bizhawk(ss.str()); + } R(15) += 2; t_Code(); } @@ -108,7 +114,12 @@ namespace AMeteor else { code = MEM.Read32(R(15)-4); - //std::cerr << IOS_ADD << R(15) << ' ' << Disassembler::Instruction(R(15), (uint32_t)code).ToString() << std::endl; + if (traceenabled) + { + std::stringstream ss; + ss << IOS_ADD << R(15) << ' ' << Disassembler::Instruction(R(15), (uint32_t)code).ToString(); + trace_bizhawk(ss.str()); + } R(15) += 4; a_Code(); }