From dfff94200c046ad9c888b341287f37f866386181 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Wed, 16 May 2018 17:46:28 -0500 Subject: [PATCH] Add some APU debugging capabilities. --- apu/bapu/smp/core.cpp | 10 ++++++++++ apu/bapu/smp/debugger/disassembler.cpp | 7 ++++++- apu/bapu/smp/smp.cpp | 12 +++++++++--- apu/bapu/smp/smp.hpp | 5 +++++ cpuexec.h | 4 ++++ debug.cpp | 27 +++++++++++++------------- snes9x.cpp | 1 + snes9x.h | 1 + 8 files changed, 50 insertions(+), 17 deletions(-) diff --git a/apu/bapu/smp/core.cpp b/apu/bapu/smp/core.cpp index b46041b4..3ad4e140 100644 --- a/apu/bapu/smp/core.cpp +++ b/apu/bapu/smp/core.cpp @@ -62,7 +62,17 @@ void SMP::op_step() { #if defined(PSEUDO_CYCLE) if(opcode_cycle == 0) + { +#ifdef DEBUGGER + if (Settings.TraceSMP) + { + disassemble_opcode(tmp, regs.pc); + S9xTraceMessage (tmp); + } +#endif opcode_number = op_readpc(); + } + switch(opcode_number) { #include "core/oppseudo_misc.cpp" diff --git a/apu/bapu/smp/debugger/disassembler.cpp b/apu/bapu/smp/debugger/disassembler.cpp index fb76ae92..624c8acb 100644 --- a/apu/bapu/smp/debugger/disassembler.cpp +++ b/apu/bapu/smp/debugger/disassembler.cpp @@ -288,7 +288,7 @@ void SMP::disassemble_opcode(char *output, uint16 addr) { strcat(s, t); sprintf(t, "A:%.2x X:%.2x Y:%.2x SP:01%.2x YA:%.4x ", - regs.a, regs.x, regs.y, regs.sp, (uint16)regs.ya); + regs.B.a, regs.x, regs.B.y, regs.sp, (uint16)regs.ya); strcat(s, t); sprintf(t, "%c%c%c%c%c%c%c%c", @@ -301,4 +301,9 @@ void SMP::disassemble_opcode(char *output, uint16 addr) { regs.p.z ? 'Z' : 'z', regs.p.c ? 'C' : 'c'); strcat(s, t); + + sprintf(t, " %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x", + apuram[0xf4], apuram[0xf5], apuram[0xf6], apuram[0xf7], + cpu.port_read(0), cpu.port_read(1), cpu.port_read(2), cpu.port_read(3)); + strcat(s, t); } diff --git a/apu/bapu/smp/smp.cpp b/apu/bapu/smp/smp.cpp index ef996933..bd633c5d 100644 --- a/apu/bapu/smp/smp.cpp +++ b/apu/bapu/smp/smp.cpp @@ -1,16 +1,22 @@ #define CYCLE_ACCURATE #define PSEUDO_CYCLE +#ifdef DEBUGGER +#include "../../../snes9x.h" +#include "../../../debug.h" +char tmp[1024]; +#endif + #include #define SMP_CPP namespace SNES { // TODO: reactivate once APU debugger works again -#if 0 // DEBUGGER - #include "debugger/debugger.cpp" +#ifdef DEBUGGER +// #include "debugger/debugger.cpp" #include "debugger/disassembler.cpp" - SMPDebugger smp; + SMP smp; #else SMP smp; #endif diff --git a/apu/bapu/smp/smp.hpp b/apu/bapu/smp/smp.hpp index c9fb7846..e8c77a9a 100644 --- a/apu/bapu/smp/smp.hpp +++ b/apu/bapu/smp/smp.hpp @@ -122,6 +122,11 @@ public: inline uint8 op_lsr (uint8 x); inline uint8 op_rol (uint8 x); inline uint8 op_ror (uint8 x); +#ifdef DEBUGGER + void disassemble_opcode(char *output, uint16 addr); + inline uint8 disassemble_read(uint16 addr); + inline uint16 relb(int8 offset, int op_len); +#endif }; // TODO: reactivate once APU debugger works again diff --git a/cpuexec.h b/cpuexec.h index 8bf32de7..8d52b697 100644 --- a/cpuexec.h +++ b/cpuexec.h @@ -198,6 +198,8 @@ #include "debug.h" #endif +#include "../apu/apu.h" + struct SOpcodes { void (*S9xOpcode) (void); @@ -289,6 +291,8 @@ static inline void S9xCheckInterrupts (void) { bool8 thisIRQ = PPU.HTimerEnabled | PPU.VTimerEnabled; + S9xAPUExecute(); + if (CPU.IRQLine & thisIRQ) CPU.IRQTransition = TRUE; diff --git a/debug.cpp b/debug.cpp index e2792498..aa023c8a 100644 --- a/debug.cpp +++ b/debug.cpp @@ -202,6 +202,8 @@ #include "debug.h" #include "missing.h" +#include "apu/bapu/snes/snes.hpp" + extern SDMA DMA[8]; extern FILE *apu_trace; FILE *trace = NULL, *trace2 = NULL; @@ -259,7 +261,7 @@ static const char *HelpMessage[] = // "ai - Shou APU vectors", // "a - Show APU status", // "x - Show Sound DSP status", -// "A - Toggle APU instruction tracing to aputrace.log", + "A - Toggle APU instruction tracing to trace.log", // "B - Toggle sound DSP register tracing to aputrace.log", // "C - Dump sound sample addresses", // "ad [Address] - Dump APU RAM from PC or [Address]", @@ -1581,8 +1583,11 @@ static void debug_process_command (char *Line) } // TODO: reactivate once APU debugger works again - /*if (*Line == 'A') - spc_core->debug_toggle_trace();*/ + if (*Line == 'A') + { + Settings.TraceSMP = !Settings.TraceSMP; + printf("SMP tracing %s\n", Settings.TraceSMP ? "enabled" : "disabled"); + } /* if (*Line == 'B') @@ -1643,20 +1648,16 @@ static void debug_process_command (char *Line) } *Line = 0; - } + }*/ + + if (*Line == 'a') { - printf("APU in-ports : %02X %02X %02X %02X\n", IAPU.RAM[0xF4], IAPU.RAM[0xF5], IAPU.RAM[0xF6], IAPU.RAM[0xF7]); - printf("APU out-ports: %02X %02X %02X %02X\n", APU.OutPorts[0], APU.OutPorts[1], APU.OutPorts[2], APU.OutPorts[3]); - printf("ROM/RAM switch: %s\n", (IAPU.RAM[0xf1] & 0x80) ? "ROM" : "RAM"); - - for (int i = 0; i < 3; i++) - if (APU.TimerEnabled[i]) - printf("Timer%d enabled, Value: 0x%03X, 4-bit: 0x%02X, Target: 0x%03X\n", - i, APU.Timer[i], IAPU.RAM[0xfd + i], APU.TimerTarget[i]); + printf("S-CPU-side ports S-CPU writes these, S-SMP reads: %02X %02X %02X %02X\n", SNES::cpu.port_read(0), SNES::cpu.port_read(1), SNES::cpu.port_read(2), SNES::cpu.port_read(3)); + printf("S-SMP-side ports S-SMP writes these, S-CPU reads: %02X %02X %02X %02X\n", SNES::smp.port_read(0), SNES::smp.port_read(1), SNES::smp.port_read(2), SNES::smp.port_read(3)); } - +/* if (*Line == 'P') { Settings.TraceDSP = !Settings.TraceDSP; diff --git a/snes9x.cpp b/snes9x.cpp index eb1173d0..a80dedaa 100644 --- a/snes9x.cpp +++ b/snes9x.cpp @@ -516,6 +516,7 @@ void S9xLoadConfigFiles (char **argv, int argc) ENSURE_TRACE_OPEN(trace,"trace.log","wb") CPU.Flags |= TRACE_FLAG; } + Settings.TraceSMP = FALSE; #endif S9xParsePortConfig(conf, 1); diff --git a/snes9x.h b/snes9x.h index ee08822a..6428f825 100644 --- a/snes9x.h +++ b/snes9x.h @@ -365,6 +365,7 @@ struct SSettings bool8 TraceUnknownRegisters; bool8 TraceDSP; bool8 TraceHCEvent; + bool8 TraceSMP; bool8 SuperFX; uint8 DSP;