diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index 4487879cd6..ea814b2ca4 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -79,6 +79,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES public delegate void snes_scanlineStart_t(int line); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate string snes_path_request_t(int slot, string hint); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void snes_trace_t(string msg); [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_set_video_refresh(snes_video_refresh_t video_refresh); @@ -132,6 +134,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_dequeue_message(IntPtr strBuffer); + [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void snes_set_trace_callback(snes_trace_t callback); + [DllImport("libsneshawk.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void snes_set_color_lut(IntPtr colors); @@ -394,6 +399,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES return test; } + void snes_trace(string msg) + { + CoreInputComm.Tracer.Put(msg); + } + public SnesColors.ColorType CurrPalette { get; private set; } public void SetPalette(SnesColors.ColorType pal) @@ -439,9 +449,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES pathRequest_cb = new LibsnesDll.snes_path_request_t(snes_path_request); BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_set_path_request(pathRequest_cb); - scanlineStart_cb = new LibsnesDll.snes_scanlineStart_t(snes_scanlineStart); + tracecb = new LibsnesDll.snes_trace_t(snes_trace); + // set default palette. Should be overridden by frontend probably SetPalette(SnesColors.ColorType.BizHawk); @@ -483,6 +494,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES CoreOutputComm.VsyncDen = 1; } + CoreOutputComm.CpuTraceAvailable = true; + LibsnesDll.snes_power(); SetupMemoryDomains(romData); @@ -509,6 +522,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES LibsnesDll.snes_audio_sample_t soundcb; LibsnesDll.snes_scanlineStart_t scanlineStart_cb; LibsnesDll.snes_path_request_t pathRequest_cb; + LibsnesDll.snes_trace_t tracecb; ushort snes_input_state(int port, int device, int index, int id) { @@ -628,6 +642,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES savestatebuff = ms.ToArray(); } + if (!nocallbacks && CoreInputComm.Tracer.Enabled) + LibsnesDll.snes_set_trace_callback(tracecb); + else + LibsnesDll.snes_set_trace_callback(null); + // speedup when sound rendering is not needed if (!rendersound) LibsnesDll.snes_set_audio_sample(null); @@ -1039,9 +1058,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES public IList MemoryDomains { get; private set; } public MemoryDomain MainMemory { get; private set; } - - - #region audio stuff Sound.Utilities.SpeexResampler resampler; diff --git a/BizHawk.MultiClient/output/dll/libsneshawk.dll b/BizHawk.MultiClient/output/dll/libsneshawk.dll index 2e42ae821f..89875bf9ad 100644 Binary files a/BizHawk.MultiClient/output/dll/libsneshawk.dll and b/BizHawk.MultiClient/output/dll/libsneshawk.dll differ diff --git a/libsnes/bsnes/snes/cpu/cpu.cpp b/libsnes/bsnes/snes/cpu/cpu.cpp index 4561bee804..55afe6fa69 100644 --- a/libsnes/bsnes/snes/cpu/cpu.cpp +++ b/libsnes/bsnes/snes/cpu/cpu.cpp @@ -86,7 +86,15 @@ void CPU::enter() { void CPU::op_step() { debugger.op_exec(regs.pc.d); - + + if (interface->wanttrace) + { + char tmp[512]; + disassemble_opcode(tmp, regs.pc.d); + tmp[511] = 0; + interface->cpuTrace(tmp); + } + (this->*opcode_table[op_readpc()])(); } diff --git a/libsnes/bsnes/snes/interface/interface.cpp b/libsnes/bsnes/snes/interface/interface.cpp index fac56532fc..de37f297be 100644 --- a/libsnes/bsnes/snes/interface/interface.cpp +++ b/libsnes/bsnes/snes/interface/interface.cpp @@ -34,6 +34,9 @@ time_t Interface::randomSeed() int Interface::getBackdropColor() { return -1; +} + +void Interface::cpuTrace(const char *msg) { } } diff --git a/libsnes/bsnes/snes/interface/interface.hpp b/libsnes/bsnes/snes/interface/interface.hpp index 7833881de9..e63c42df0f 100644 --- a/libsnes/bsnes/snes/interface/interface.hpp +++ b/libsnes/bsnes/snes/interface/interface.hpp @@ -10,11 +10,14 @@ struct Interface { virtual time_t currentTime(); virtual time_t randomSeed(); - //zero 27-sep-2012 - virtual void scanlineStart(int line) = 0; + //zero 27-sep-2012 + virtual void scanlineStart(int line) = 0; - //zero 17-oct-2012 - virtual int getBackdropColor(); + //zero 17-oct-2012 + virtual int getBackdropColor(); + + bool wanttrace = false; + virtual void cpuTrace(const char *msg); }; extern Interface *interface; diff --git a/libsnes/bsnes/target-libsnes/libsnes.cpp b/libsnes/bsnes/target-libsnes/libsnes.cpp index 1410926286..a34eab084f 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.cpp +++ b/libsnes/bsnes/target-libsnes/libsnes.cpp @@ -14,7 +14,8 @@ struct Interface : public SNES::Interface { snes_input_poll_t pinput_poll; snes_input_state_t pinput_state; snes_input_notify_t pinput_notify; - snes_path_request_t ppath_request; + snes_path_request_t ppath_request; + snes_trace_t ptrace; string basename; uint32_t *buffer; uint32_t *palette; @@ -74,6 +75,11 @@ struct Interface : public SNES::Interface { void message(const string &text) { messages.push(text); } + + void cpuTrace(const char *msg) { + if (ptrace) + ptrace((const char *)msg); + } string path(SNES::Cartridge::Slot slot, const string &hint) { @@ -93,7 +99,8 @@ struct Interface : public SNES::Interface { pinput_state(0), pinput_notify(0), ppath_request(0), - backdropColor(-1) + backdropColor(-1), + ptrace(0) { buffer = new uint32_t[512 * 480]; palette = new uint32_t[16 * 32768]; @@ -582,4 +589,18 @@ void snes_dequeue_message(char* buffer) void snes_set_backdropColor(int color) { interface.backdropColor = color; -} \ No newline at end of file +} + +void snes_set_trace_callback(snes_trace_t callback) +{ + if (callback) + { + interface.wanttrace = true; + interface.ptrace = callback; + } + else + { + interface.wanttrace = false; + interface.ptrace = 0; + } +} diff --git a/libsnes/bsnes/target-libsnes/libsnes.hpp b/libsnes/bsnes/target-libsnes/libsnes.hpp index c194bb3721..55455c395c 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.hpp +++ b/libsnes/bsnes/target-libsnes/libsnes.hpp @@ -72,6 +72,7 @@ typedef void (*snes_audio_sample_t)(uint16_t left, uint16_t right); typedef void (*snes_input_poll_t)(void); typedef int16_t (*snes_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id); typedef void (*snes_input_notify_t)(int index); +typedef void (*snes_trace_t)(const char *msg); const char* snes_library_id(void); unsigned snes_library_revision_major(void); @@ -145,6 +146,8 @@ void snes_set_path_request(snes_path_request_t path_request); void snes_set_color_lut(uint32_t * colors); +void snes_set_trace_callback(void (*callback)(const char *)); + // system bus implementation uint8_t bus_read(unsigned addr); void bus_write(unsigned addr, uint8_t val);