diff --git a/cpu.h b/cpu.h index 5810f6c..81120e9 100644 --- a/cpu.h +++ b/cpu.h @@ -7,9 +7,8 @@ class CPU: public Checkpointable { public: - virtual Memory::address run(unsigned instructions) =0; + virtual void run(unsigned instructions) =0; virtual void reset () =0; - virtual Memory::address step() =0; virtual void raise (int level) =0; virtual char *status () =0; diff --git a/r6502.cpp b/r6502.cpp index 6d7c92f..1a35ca0 100644 --- a/r6502.cpp +++ b/r6502.cpp @@ -5,25 +5,31 @@ #include "cpu.h" #include "r6502.h" -Memory::address r6502::step() { +#define CPU_STATE_FMT "%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 + +inline void r6502::step() { byte op = (*_memory)[PC]; #ifdef CPU_DEBUG - if (_debug) - _status ("%04x: %02x [%02x %02x %02x, %02x]\r", PC, op, A, X, Y, flags()); + if (_debug) { + flags(); + _status(CPU_STATE_FMT); + } #endif PC++; (this->*_ops[op])(); - return PC; } -Memory::address r6502::run(unsigned clocks) { +void r6502::run(unsigned clocks) { #ifdef CPU_DEBUG - if (_debug) - return step(); + if (_debug) { + step(); + return; + } #endif while (clocks--) step(); - return PC; } byte r6502::flags() { @@ -38,10 +44,7 @@ byte r6502::flags() { char *r6502::status () { static char buf[128]; flags(); - sprintf (buf, "aa xx yy sp nv_bdizc _pc_\r\n" - "%02x %02x %02x %02x %d%d%d%d%d%d%d%d %04x\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); + sprintf (buf, "aa xx yy sp nv_bdizc _pc_\r" CPU_STATE_FMT); return buf; } diff --git a/r6502.h b/r6502.h index 10fa98c..66ec784 100644 --- a/r6502.h +++ b/r6502.h @@ -8,8 +8,7 @@ class r6502: public CPU { public: void raise(int); void reset(); - Memory::address step(); - Memory::address run(unsigned); + void run(unsigned); char *status(); void checkpoint(Stream &); void restore(Stream &); @@ -36,6 +35,7 @@ private: byte _toBCD[256], _fromBCD[256]; // BCD maps bool _irq; // interrupt pending? + void step(); void irq(); void nmi(); byte flags();