diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 08a2c251f..549cd1dcb 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -802,6 +802,7 @@ Debugger::BuiltinFunction Debugger::ourBuiltinFunctions[NUM_BUILTIN_FUNCS] = { Debugger::PseudoRegister Debugger::ourPseudoRegisters[NUM_PSEUDO_REGS] = { { "_bank", "Currently selected bank" }, { "_cclocks", "Color clocks on current scanline" }, + { "_cycles", "Number of cycles of last instruction" }, { "_cycleshi", "Higher 32 bits of number of cycles since emulation started" }, { "_cycleslo", "Lower 32 bits of number of cycles since emulation started" }, { "_fcount", "Number of frames since emulation started" }, diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index f3fdcd30c..293063b22 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -315,7 +315,7 @@ class Debugger : public DialogContainer string name, help; }; static const uInt32 NUM_BUILTIN_FUNCS = 18; - static const uInt32 NUM_PSEUDO_REGS = 11; + static const uInt32 NUM_PSEUDO_REGS = 12; static BuiltinFunction ourBuiltinFunctions[NUM_BUILTIN_FUNCS]; static PseudoRegister ourPseudoRegisters[NUM_PSEUDO_REGS]; diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index 2df1db8eb..ae16b9f64 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -52,6 +52,7 @@ M6502::M6502(const Settings& settings) mySettings(settings), A(0), X(0), Y(0), SP(0), IR(0), PC(0), N(false), V(false), B(false), D(false), I(false), notZ(false), C(false), + cycles(0), myNumberOfDistinctAccesses(0), myLastAddress(0), myLastPeekAddress(0), @@ -99,6 +100,8 @@ void M6502::reset() PS(BSPF::containsIgnoreCase(cpurandom, "P") ? mySystem->randGenerator().next() : 0x20); + cycles = 0; + // Load PC from the reset vector PC = uInt16(mySystem->peek(0xfffc)) | (uInt16(mySystem->peek(0xfffd)) << 8); @@ -124,6 +127,7 @@ inline uInt8 M6502::peek(uInt16 address, uInt8 flags) } //////////////////////////////////////////////// mySystem->incrementCycles(SYSTEM_CYCLES_PER_CPU); + cycles += SYSTEM_CYCLES_PER_CPU; uInt8 result = mySystem->peek(address, flags); myLastPeekAddress = address; @@ -157,6 +161,7 @@ inline void M6502::poke(uInt16 address, uInt8 value, uInt8 flags) } //////////////////////////////////////////////// mySystem->incrementCycles(SYSTEM_CYCLES_PER_CPU); + cycles += SYSTEM_CYCLES_PER_CPU; mySystem->poke(address, value, flags); myLastPokeAddress = address; @@ -238,6 +243,7 @@ bool M6502::execute(uInt32 number) // Reset the peek/poke address pointers myLastPeekAddress = myLastPokeAddress = myDataAddressForPoke = 0; + cycles = 0; // Fetch instruction at the program counter IR = peek(PC++, DISASM_CODE); // This address represents a code section @@ -251,6 +257,7 @@ bool M6502::execute(uInt32 number) // Oops, illegal instruction executed so set fatal error flag myExecutionStatus |= FatalErrorBit; } + //cycles = mySystem->cycles() - c0; } // See if we need to handle an interrupt diff --git a/src/emucore/M6502.hxx b/src/emucore/M6502.hxx index 96a890b7a..8a5a38dc3 100644 --- a/src/emucore/M6502.hxx +++ b/src/emucore/M6502.hxx @@ -348,6 +348,8 @@ class M6502 : public Serializable bool notZ; // Z flag complement for processor status register bool C; // C flag for processor status register + uInt8 cycles; // cycles of last instruction + /// Indicates the numer of distinct memory accesses uInt32 myNumberOfDistinctAccesses; diff --git a/src/yacc/YaccParser.cxx b/src/yacc/YaccParser.cxx index 80bc01551..891989d87 100644 --- a/src/yacc/YaccParser.cxx +++ b/src/yacc/YaccParser.cxx @@ -219,6 +219,8 @@ CpuMethod getCpuSpecial(char* ch) return &CpuDebug::i; else if(BSPF::equalsIgnoreCase(ch, "b")) return &CpuDebug::b; + else if(BSPF::equalsIgnoreCase(ch, "_cycles")) + return &CpuDebug::cycles; else return nullptr; }