'_cycles' pseudo register added (returns cycles of last instruction)

This commit is contained in:
thrust26 2017-12-15 18:13:29 +01:00
parent 7d40d5b1f8
commit 9f7270a70d
5 changed files with 13 additions and 1 deletions

View File

@ -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" },

View File

@ -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];

View File

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

View File

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

View File

@ -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;
}