snes: support trace logging GB and SMP cores

This commit is contained in:
zeromus 2017-05-14 13:50:28 -05:00
parent 618951403d
commit 4eaf17c6c1
8 changed files with 42 additions and 28 deletions

View File

@ -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]++);

View File

@ -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()])();

View File

@ -39,7 +39,7 @@ int Interface::getBackdropColor()
return -1;
}
void Interface::cpuTrace(const char *msg) {
void Interface::cpuTrace(uint32_t which, const char *msg) {
}
}

View File

@ -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<<TRACE_CPU)
#define TRACE_SMP_MASK (1<<TRACE_SMP)
#define TRACE_GB_MASK (1<<TRACE_GB)
struct Interface {
Interface();
virtual void videoRefresh(const uint32_t *data, bool hires, bool interlace, bool overscan);
@ -18,8 +27,8 @@ struct Interface {
//zero 17-oct-2012
virtual int getBackdropColor();
bool wanttrace;
virtual void cpuTrace(const char *msg);
uint32_t wanttrace;
virtual void cpuTrace(uint32_t which, const char *msg);
//zero 23-dec-2012
virtual void* allocSharedMemory(const char* memtype, size_t amt, int initialByte = -1) = 0;

View File

@ -58,6 +58,11 @@ void SMP::enter() {
}
debugger.op_exec(regs.pc);
if(interface()->wanttrace & TRACE_SMP_MASK)
{
auto str = disassemble_opcode(regs.pc);
interface()->cpuTrace(TRACE_SMP, (const char*)str);
}
op_step();
}
}

View File

@ -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;
}

View File

@ -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

View File

@ -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()>();
}
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)