From 4eaf17c6c15618f9d1b82602510c6c318e804729 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 14 May 2017 13:50:28 -0500 Subject: [PATCH] snes: support trace logging GB and SMP cores --- libsnes/bsnes/gameboy/cpu/cpu.cpp | 9 ++++++-- libsnes/bsnes/snes/cpu/cpu.cpp | 8 +++---- libsnes/bsnes/snes/interface/interface.cpp | 2 +- libsnes/bsnes/snes/interface/interface.hpp | 13 ++++++++++-- libsnes/bsnes/snes/smp/smp.cpp | 5 +++++ libsnes/bsnes/target-libsnes/libsnes.cpp | 21 +++++++------------ libsnes/bsnes/target-libsnes/libsnes.hpp | 5 +++-- .../bsnes/target-libsnes/libsnes_pwrap.cpp | 7 +++---- 8 files changed, 42 insertions(+), 28 deletions(-) diff --git a/libsnes/bsnes/gameboy/cpu/cpu.cpp b/libsnes/bsnes/gameboy/cpu/cpu.cpp index 0e226a113f..f1367423ac 100644 --- a/libsnes/bsnes/gameboy/cpu/cpu.cpp +++ b/libsnes/bsnes/gameboy/cpu/cpu.cpp @@ -21,8 +21,13 @@ void CPU::main() { scheduler.sync = Scheduler::SynchronizeMode::All; scheduler.exit(Scheduler::ExitReason::SynchronizeEvent); } - - if(trace) print(disassemble(r[PC]), "\n"); + + if(SNES::interface()->wanttrace & TRACE_GB_MASK) + { + auto disasm = disassemble(r[PC]); + SNES::interface()->cpuTrace(TRACE_GB, (const char*)disasm); + } + //if(trace) print(disassemble(r[PC]), "\n"); interrupt_test(); cdlInfo.currFlags = eCDLog_Flags_ExecFirst; uint8 opcode = op_read(r[PC]++); diff --git a/libsnes/bsnes/snes/cpu/cpu.cpp b/libsnes/bsnes/snes/cpu/cpu.cpp index 8ecd3c9e7d..398ac0e7dd 100644 --- a/libsnes/bsnes/snes/cpu/cpu.cpp +++ b/libsnes/bsnes/snes/cpu/cpu.cpp @@ -91,12 +91,12 @@ void CPU::enter() { void CPU::op_step() { debugger.op_exec(regs.pc.d); - if (interface()->wanttrace) + if (interface()->wanttrace & TRACE_CPU_MASK) { char tmp[512]; - disassemble_opcode(tmp, regs.pc.d); - tmp[511] = 0; - interface()->cpuTrace(tmp); + disassemble_opcode(tmp, regs.pc.d); + tmp[511] = 0; + interface()->cpuTrace(TRACE_CPU, tmp); } (this->*opcode_table[op_readpcfirst()])(); diff --git a/libsnes/bsnes/snes/interface/interface.cpp b/libsnes/bsnes/snes/interface/interface.cpp index 596bf75d97..03d3e207f3 100644 --- a/libsnes/bsnes/snes/interface/interface.cpp +++ b/libsnes/bsnes/snes/interface/interface.cpp @@ -39,7 +39,7 @@ int Interface::getBackdropColor() return -1; } -void Interface::cpuTrace(const char *msg) { +void Interface::cpuTrace(uint32_t which, const char *msg) { } } diff --git a/libsnes/bsnes/snes/interface/interface.hpp b/libsnes/bsnes/snes/interface/interface.hpp index 9760893aae..af94e1955d 100644 --- a/libsnes/bsnes/snes/interface/interface.hpp +++ b/libsnes/bsnes/snes/interface/interface.hpp @@ -1,4 +1,13 @@ +#define TRACE_CPU 0 +#define TRACE_SMP 1 +#define TRACE_GB 2 + +#define TRACE_MASK_NONE (0) +#define TRACE_CPU_MASK (1<wanttrace & TRACE_SMP_MASK) + { + auto str = disassemble_opcode(regs.pc); + interface()->cpuTrace(TRACE_SMP, (const char*)str); + } op_step(); } } diff --git a/libsnes/bsnes/target-libsnes/libsnes.cpp b/libsnes/bsnes/target-libsnes/libsnes.cpp index d62a8e9f1b..9e13608d53 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.cpp +++ b/libsnes/bsnes/target-libsnes/libsnes.cpp @@ -84,9 +84,9 @@ struct Interface : public SNES::Interface { messages.push(text); } - void cpuTrace(const char *msg) { + void cpuTrace(uint32_t which, const char *msg) { if (ptrace) - ptrace((const char *)msg); + ptrace(which, (const char *)msg); } string path(SNES::Cartridge::Slot slot, const string &hint) @@ -760,16 +760,11 @@ void snes_set_backdropColor(int color) iface->backdropColor = color; } -void snes_set_trace_callback(snes_trace_t callback) +void snes_set_trace_callback(uint32_t mask, snes_trace_t callback) { - if (callback) - { - iface->wanttrace = true; - iface->ptrace = callback; - } - else - { - iface->wanttrace = false; - iface->ptrace = 0; - } + iface->wanttrace = mask; + if (mask) + iface->ptrace = callback; + else + iface->ptrace = nullptr; } \ No newline at end of file diff --git a/libsnes/bsnes/target-libsnes/libsnes.hpp b/libsnes/bsnes/target-libsnes/libsnes.hpp index 9b34a937f3..4d22dea1fc 100644 --- a/libsnes/bsnes/target-libsnes/libsnes.hpp +++ b/libsnes/bsnes/target-libsnes/libsnes.hpp @@ -88,7 +88,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); +typedef void (*snes_trace_t)(uint32_t which, const char *msg); typedef void* (*snes_allocSharedMemory_t)(const char* memtype, size_t amt); typedef void (*snes_freeSharedMemory_t)(void* ptr); @@ -169,12 +169,13 @@ 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 *)); +void snes_set_trace_callback(uint32_t mask, void (*callback)(uint32_t mask, const char *)); // system bus implementation uint8_t bus_read(unsigned addr); void bus_write(unsigned addr, uint8_t val); + //$2105 #define SNES_REG_BG_MODE 0 #define SNES_REG_BG3_PRIORITY 1 diff --git a/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp b/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp index 1efd0b0554..302dcde6f5 100644 --- a/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp +++ b/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp @@ -258,8 +258,9 @@ void snes_input_notify(int index) BREAK(eMessage_SIG_input_notify); } -void snes_trace(const char *msg) +void snes_trace(uint32_t which, const char *msg) { + comm.value = which; comm.str = (char*) msg; BREAK(eMessage_SIG_trace_callback); } @@ -456,9 +457,7 @@ void QUERY_state_hook_irq() { SNES::cpu.debugger.op_irq = comm.value ? debug_op_irq : hook(); } void QUERY_state_enable_trace() { - if (comm.value) - snes_set_trace_callback(snes_trace); - else snes_set_trace_callback(nullptr); + snes_set_trace_callback(comm.value, snes_trace); } void QUERY_state_enable_scanline() { if (comm.value)