This adds timer functionality to sim65.

It provides access to a handful of 64-bit counters that count different things:
- clock cycles
- instructions
- number of IRQ processed
- number of NMIs processed
- nanoseconds since 1-1-1970.

This in not ready yet to be pushed as a merge request into the upstream CC65
repository. What's lacking:

- documentation
- tests

And to be discussed:

- do we agree on this implementation direction and interface in principe?
- can I include inttypes.h for printing a 64-bit unsigned value?
- will clock_gettime() work on a Windows build?
This commit is contained in:
Sidney Cadot
2024-12-17 23:24:35 +01:00
parent a53524b9de
commit 6f9406bbe3
8 changed files with 293 additions and 15 deletions

View File

@@ -42,6 +42,7 @@
*/
#include "memory.h"
#include "peripherals.h"
#include "error.h"
#include "6502.h"
#include "paravirt.h"
@@ -391,7 +392,7 @@ CPUType CPU;
typedef void (*OPFunc) (void);
/* The CPU registers */
static CPURegs Regs;
CPURegs Regs;
/* Cycles for the current insn */
static unsigned Cycles;
@@ -4107,6 +4108,8 @@ unsigned ExecuteInsn (void)
if (HaveNMIRequest) {
HaveNMIRequest = 0;
PRegs.counter_nmi_events += 1;
PUSH (PCH);
PUSH (PCL);
PUSH (Regs.SR & ~BF);
@@ -4121,6 +4124,8 @@ unsigned ExecuteInsn (void)
} else if (HaveIRQRequest && GET_IF () == 0) {
HaveIRQRequest = 0;
PRegs.counter_irq_events += 1;
PUSH (PCH);
PUSH (PCL);
PUSH (Regs.SR & ~BF);
@@ -4139,8 +4144,14 @@ unsigned ExecuteInsn (void)
/* Execute it */
Handlers[CPU][OPC] ();
/* Increment the instruction counter by one.NMIs and IRQs are counted separately. */
PRegs.counter_instructions += 1;
}
/* Increment the 64-bit clock cycle counter with the cycle count for the instruction that we just executed */
PRegs.counter_clock_cycles += Cycles;
/* Return the number of clock cycles needed by this insn */
return Cycles;
}