-d is now debugger and -t is now tracing to stderr

This commit is contained in:
folkert van heusden 2022-04-11 20:55:59 +02:00
parent 4b3c61dc4f
commit 9d367e02ae
4 changed files with 29 additions and 22 deletions

14
cpu.cpp
View file

@ -48,11 +48,6 @@ void cpu::reset()
runMode = false; runMode = false;
} }
void cpu::setDisassemble(const bool state)
{
disas = state;
}
uint16_t cpu::getRegister(const int nr, const bool prev_mode) const uint16_t cpu::getRegister(const int nr, const bool prev_mode) const
{ {
if (nr < 6) if (nr < 6)
@ -1494,8 +1489,8 @@ cpu::operand_parameters cpu::addressing_to_string(const uint8_t mode_register, c
std::map<std::string, std::vector<std::string> > cpu::disassemble(const uint16_t addr) const std::map<std::string, std::vector<std::string> > cpu::disassemble(const uint16_t addr) const
{ {
bool old_debug_output = debug_output; bool old_trace_output = trace_output;
debug_output = false; trace_output = false;
uint16_t pc = getPC(); uint16_t pc = getPC();
uint16_t instruction = b->peekWord(pc); uint16_t instruction = b->peekWord(pc);
@ -1907,7 +1902,7 @@ std::map<std::string, std::vector<std::string> > cpu::disassemble(const uint16_t
work_values_str.push_back(format("%06o", v)); work_values_str.push_back(format("%06o", v));
out.insert({ "work-values", work_values_str }); out.insert({ "work-values", work_values_str });
debug_output = old_debug_output; trace_output = old_trace_output;
return out; return out;
} }
@ -1959,9 +1954,6 @@ void cpu::step()
busError(); busError();
try { try {
if (disas)
disassemble();
uint16_t instr = b->readWord(temp_pc); uint16_t instr = b->readWord(temp_pc);
addRegister(7, false, 2); addRegister(7, false, 2);

2
cpu.h
View file

@ -13,7 +13,6 @@
class cpu class cpu
{ {
private: private:
bool disas { false };
uint16_t regs0_5[2][6]; // R0...5, selected by bit 11 in PSW, 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 sp[3 + 1]; // stackpointers, MF../MT.. select via 12/13 from PSW, others via 14/15
uint16_t pc { 0 }; uint16_t pc { 0 };
@ -63,7 +62,6 @@ public:
explicit cpu(bus *const b, uint32_t *const event); explicit cpu(bus *const b, uint32_t *const event);
~cpu(); ~cpu();
void setDisassemble(const bool state);
void disassemble(void) const; void disassemble(void) const;
std::map<std::string, std::vector<std::string> > disassemble(const uint16_t addr) const; std::map<std::string, std::vector<std::string> > disassemble(const uint16_t addr) const;

4
gen.h
View file

@ -2,13 +2,13 @@
// Released under Apache License v2.0 // Released under Apache License v2.0
#pragma once #pragma once
extern bool debug_output; extern bool trace_output;
#if defined(ESP32) #if defined(ESP32)
#define D(...) do { } while(0); #define D(...) do { } while(0);
#else #else
#ifndef NDEBUG #ifndef NDEBUG
#define D(x) do { if (debug_output) { x } } while(0); #define D(x) do { if (trace_output) { x } } while(0);
#else #else
#define D(...) do { } while(0); #define D(...) do { } while(0);
#endif #endif

View file

@ -22,7 +22,7 @@ bool withUI { false };
uint32_t event { 0 }; uint32_t event { 0 };
std::atomic_bool terminate { false }; std::atomic_bool terminate { false };
std::atomic_bool *running { nullptr }; 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) 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("-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("-L f.bin load file into memory at address given by -p (and run it)\n");
printf("-n ncurses UI\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[]) int main(int argc, char *argv[])
@ -163,7 +164,9 @@ int main(int argc, char *argv[])
std::vector<std::string> rk05_files; std::vector<std::string> rk05_files;
bool testCases = false; 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) while((opt = getopt(argc, argv, "hm:T:R:p:ndL:")) != -1)
{ {
switch(opt) { switch(opt) {
@ -172,8 +175,12 @@ int main(int argc, char *argv[])
return 1; return 1;
case 'd': case 'd':
c->setDisassemble(true); debugger = true;
debug_output = true; break;
case 't':
tracing = true;
trace_output = true;
break; break;
case 'n': case 'n':
@ -261,8 +268,18 @@ int main(int argc, char *argv[])
c->emulation_start(); // for statistics c->emulation_start(); // for statistics
while(!event && !terminate) if (debugger) {
c->step(); while(!event && !terminate) {
if (tracing)
c->disassemble();
c->step();
}
}
else {
while(!event && !terminate)
c->step();
}
*running = false; *running = false;