From 01def1ba15c69ac56cb9de039aefa2c50e91565d Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sun, 24 Jan 2016 11:55:50 +0000 Subject: [PATCH] remove _debug make status header optional --- CPU.h | 7 +++---- i8080.cpp | 7 ++++--- i8080.h | 2 +- r6502.cpp | 14 +++++++------- r6502.h | 2 +- z80.cpp | 11 +++++------ z80.h | 2 +- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/CPU.h b/CPU.h index 794a913..5a66014 100644 --- a/CPU.h +++ b/CPU.h @@ -8,18 +8,17 @@ public: virtual void run(unsigned instructions) =0; virtual void reset() =0; virtual void raise(int level) =0; - virtual char *status(char *buf, size_t n) =0; + virtual char *status(char *buf, size_t n, bool hdr) =0; virtual void checkpoint(Stream &s) = 0; virtual void restore(Stream &s) = 0; - inline void debug() { _debug = !_debug; } inline bool halted() { return _halted; } protected: - CPU(Memory &mem): _mem(mem), _debug(false), _halted(false) {} + CPU(Memory &mem): _mem(mem), _halted(false) {} Memory &_mem; Memory::address PC; - bool _debug, _halted; + bool _halted; }; #endif diff --git a/i8080.cpp b/i8080.cpp index af58097..7e4039d 100644 --- a/i8080.cpp +++ b/i8080.cpp @@ -39,10 +39,11 @@ void i8080::ei() { raise(_irq_pending); } -char *i8080::status(char *buf, size_t n) { +char *i8080::status(char *buf, size_t n, bool hdr) { byte op = _mem[PC]; - snprintf(buf, n, "_pc_ op aa _bc_ _de_ _hl_ _sp_ szih_p_c\r" - "%04x %02x %02x %04x %04x %04x %04x %d%d%d%d%d%d%d%d\r", + snprintf(buf, n, + "%s%04x %02x %02x %04x %04x %04x %04x %d%d%d%d%d%d%d%d", + hdr? "_pc_ op aa _bc_ _de_ _hl_ _sp_ szih_p_c\r": "", PC, op, A, BC, DE, HL, SP, flags.S, flags.Z, flags.I, flags.H, flags._, flags.P, flags.__, flags.C); return buf; diff --git a/i8080.h b/i8080.h index c84bdce..93dff8b 100644 --- a/i8080.h +++ b/i8080.h @@ -11,7 +11,7 @@ public: void run(unsigned); void reset(); void raise(int); - char *status(char *buf, size_t n); + char *status(char *buf, size_t n, bool hdr); void checkpoint(Stream &); void restore(Stream &); diff --git a/r6502.cpp b/r6502.cpp index ae0de96..b96a694 100644 --- a/r6502.cpp +++ b/r6502.cpp @@ -24,13 +24,13 @@ byte r6502::flags() { return P.flags; } -char *r6502::status(char *buf, size_t n) { +char *r6502::status(char *buf, size_t n, bool hdr) { flags(); - snprintf(buf, n, "aa xx yy sp nv_bdizc _pc_\r" - "%02x %02x %02x %02x %d%d%d%d%d%d%d%d %04x\r", - A, X, Y, S, P.bits.N, P.bits.V, P.bits._, P.bits.B, - P.bits.D, P.bits.I, P.bits.Z, P.bits.C, PC); - + snprintf(buf, n, + "%s%02x %02x %02x %02x %d%d%d%d%d%d%d%d %04x", + hdr? "aa xx yy sp nv_bdizc _pc_\r\n": "", + A, X, Y, S, P.bits.N, P.bits.V, P.bits._, P.bits.B, + P.bits.D, P.bits.I, P.bits.Z, P.bits.C, PC); return buf; } @@ -177,7 +177,7 @@ void r6502::ill() { void r6502::reset() { - _debug = _halted = false; + _halted = false; P.flags = 0; P.bits._ = 1; P.bits.B = 1; diff --git a/r6502.h b/r6502.h index 8e2c617..3c0c2f2 100644 --- a/r6502.h +++ b/r6502.h @@ -9,7 +9,7 @@ public: void raise(int); void reset(); void run(unsigned); - char *status(char *buf, size_t n); + char *status(char *buf, size_t n, bool hdr); void checkpoint(Stream &); void restore(Stream &); diff --git a/z80.cpp b/z80.cpp index d500fbb..d7350eb 100644 --- a/z80.cpp +++ b/z80.cpp @@ -5,12 +5,12 @@ #include "CPU.h" #include "z80.h" -char *z80::status(char *buf, size_t n) { +char *z80::status(char *buf, size_t n, bool hdr) { byte op = _mem[PC]; - snprintf(buf, n, "_pc_ op _af_ _bc_ _de_ _hl_ _af' _bc' _de' _hl' _ir_ imff " - "_sp_ sz5h3pnc\r\n" - "%04x %02x %04x %04x %04x %04x %04x %04x %04x %04x %04x %d%d%d " - "%04x %d%d%d%d%d%d%d%d\r\n", + snprintf(buf, n, + "%s%04x %02x %04x %04x %04x %04x %04x %04x %04x %04x %04x %d%d%d " + "%04x %d%d%d%d%d%d%d%d", + hdr? "_pc_ op _af_ _bc_ _de_ _hl_ _af' _bc' _de' _hl' _ir_ imff _sp_ sz5h3pnc\r\n": "", PC, op, AF, BC, DE, HL, AF_, BC_, DE_, HL_, IR, _im, _iff1, _iff2, SP, flags.S, flags.Z, flags._5, flags.H, flags._3, flags.P, flags.N, flags.C); return buf; @@ -873,7 +873,6 @@ int z80::parity_table[] = { z80::z80(Memory &m, PortDevice &ports): CPU(m) { _ports = &ports; - _debug = false; OP *p = _ops; diff --git a/z80.h b/z80.h index b1afaea..0f76e77 100644 --- a/z80.h +++ b/z80.h @@ -11,7 +11,7 @@ public: void run(unsigned); void reset(); void raise(int level) { _irq_pending = level; } - char *status(char *buf, size_t n); + char *status(char *buf, size_t n, bool hdr); void checkpoint(Stream &); void restore(Stream &);