diff --git a/cpu.cpp b/cpu.cpp index 9f56170..3dfd105 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -48,11 +48,6 @@ void cpu::reset() runMode = false; } -void cpu::setDisassemble(const bool state) -{ - disas = state; -} - uint16_t cpu::getRegister(const int nr, const bool prev_mode) const { if (nr < 6) @@ -1494,8 +1489,8 @@ cpu::operand_parameters cpu::addressing_to_string(const uint8_t mode_register, c std::map > cpu::disassemble(const uint16_t addr) const { - bool old_debug_output = debug_output; - debug_output = false; + bool old_trace_output = trace_output; + trace_output = false; uint16_t pc = getPC(); uint16_t instruction = b->peekWord(pc); @@ -1907,7 +1902,7 @@ std::map > cpu::disassemble(const uint16_t work_values_str.push_back(format("%06o", v)); out.insert({ "work-values", work_values_str }); - debug_output = old_debug_output; + trace_output = old_trace_output; return out; } @@ -1959,9 +1954,6 @@ void cpu::step() busError(); try { - if (disas) - disassemble(); - uint16_t instr = b->readWord(temp_pc); addRegister(7, false, 2); diff --git a/cpu.h b/cpu.h index e309ecc..d98cfe0 100644 --- a/cpu.h +++ b/cpu.h @@ -13,7 +13,6 @@ class cpu { private: - bool disas { false }; uint16_t regs0_5[2][6]; // R0...5, selected by bit 11 in PSW, uint16_t sp[3 + 1]; // stackpointers, MF../MT.. select via 12/13 from PSW, others via 14/15 uint16_t pc { 0 }; @@ -63,7 +62,6 @@ public: explicit cpu(bus *const b, uint32_t *const event); ~cpu(); - void setDisassemble(const bool state); void disassemble(void) const; std::map > disassemble(const uint16_t addr) const; diff --git a/gen.h b/gen.h index e633e04..a5b3e2e 100644 --- a/gen.h +++ b/gen.h @@ -2,13 +2,13 @@ // Released under Apache License v2.0 #pragma once -extern bool debug_output; +extern bool trace_output; #if defined(ESP32) #define D(...) do { } while(0); #else #ifndef NDEBUG -#define D(x) do { if (debug_output) { x } } while(0); +#define D(x) do { if (trace_output) { x } } while(0); #else #define D(...) do { } while(0); #endif diff --git a/main.cpp b/main.cpp index 5527da1..cf5944d 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,7 @@ bool withUI { false }; uint32_t event { 0 }; std::atomic_bool terminate { false }; std::atomic_bool *running { nullptr }; -bool debug_output { false }; +bool trace_output { false }; void loadbin(bus *const b, uint16_t base, const char *const file) { @@ -148,7 +148,8 @@ void help() printf("-p 123 set CPU start pointer to decimal(!) value\n"); printf("-L f.bin load file into memory at address given by -p (and run it)\n"); printf("-n ncurses UI\n"); - printf("-d enable disassemble\n"); + printf("-d enable debugger\n"); + printf("-t enable tracing (disassemble to stderr, requires -d as well)\n"); } int main(int argc, char *argv[]) @@ -163,7 +164,9 @@ int main(int argc, char *argv[]) std::vector rk05_files; bool testCases = false; - int opt = -1; + bool debugger = false; + bool tracing = false; + int opt = -1; while((opt = getopt(argc, argv, "hm:T:R:p:ndL:")) != -1) { switch(opt) { @@ -172,8 +175,12 @@ int main(int argc, char *argv[]) return 1; case 'd': - c->setDisassemble(true); - debug_output = true; + debugger = true; + break; + + case 't': + tracing = true; + trace_output = true; break; case 'n': @@ -261,8 +268,18 @@ int main(int argc, char *argv[]) c->emulation_start(); // for statistics - while(!event && !terminate) - c->step(); + if (debugger) { + while(!event && !terminate) { + if (tracing) + c->disassemble(); + + c->step(); + } + } + else { + while(!event && !terminate) + c->step(); + } *running = false;