diff --git a/source/quickerNES/core/cpu.cpp b/source/quickerNES/core/cpu.cpp index 318bd1c..0da010c 100644 --- a/source/quickerNES/core/cpu.cpp +++ b/source/quickerNES/core/cpu.cpp @@ -262,6 +262,22 @@ loop: if ( clock_count >= clock_limit ) [[unlikely]] goto stop; + // If traceback support is enabled, trigger it here + #ifdef _QUICKERNES_ENABLE_TRACEBACK_SUPPORT + if (tracecb) + { + unsigned int scratch[7]; + scratch[0] = a; + scratch[1] = x; + scratch[2] = y; + scratch[3] = sp; + scratch[4] = pc - 1; + scratch[5] = status; + scratch[6] = opcode; + tracecb(scratch); + } + #endif + clock_count += clock_table [opcode]; switch ( opcode ) diff --git a/source/quickerNES/core/cpu.hpp b/source/quickerNES/core/cpu.hpp index aa43cc9..9eb1857 100644 --- a/source/quickerNES/core/cpu.hpp +++ b/source/quickerNES/core/cpu.hpp @@ -14,6 +14,14 @@ typedef unsigned nes_addr_t; // 16-bit address class Cpu { public: + + void set_tracecb(void (*cb)(unsigned int *data)) + { + tracecb = cb; + } + + void (*tracecb)(unsigned int *dest); + // NES 6502 registers. *Not* kept updated during a call to run(). struct registers_t { diff --git a/source/quickerNES/core/emu.hpp b/source/quickerNES/core/emu.hpp index fa914a3..f77c287 100644 --- a/source/quickerNES/core/emu.hpp +++ b/source/quickerNES/core/emu.hpp @@ -45,7 +45,8 @@ class Emu const uint8_t *getHostPixels() const { return emu.ppu.host_pixels; } int get_joypad_read_count() const { return emu.joypad_read_count; } - + void set_tracecb(void (*cb)(unsigned int *dest)) { emu.set_tracecb(cb); } + // Save emulator state variants void serializeState(jaffarCommon::serializer::Base& serializer) const { emu.serializeState(serializer); } void deserializeState(jaffarCommon::deserializer::Base& deserializer) { emu.deserializeState(deserializer); }