-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;
}
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<std::string, std::vector<std::string> > 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<std::string, std::vector<std::string> > 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);

2
cpu.h
View file

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

View file

@ -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,6 +164,8 @@ int main(int argc, char *argv[])
std::vector<std::string> rk05_files;
bool testCases = false;
bool debugger = false;
bool tracing = false;
int opt = -1;
while((opt = getopt(argc, argv, "hm:T:R:p:ndL:")) != -1)
{
@ -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
if (debugger) {
while(!event && !terminate) {
if (tracing)
c->disassemble();
c->step();
}
}
else {
while(!event && !terminate)
c->step();
}
*running = false;