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

@@ -47,6 +47,7 @@
#include "6502.h"
#include "error.h"
#include "memory.h"
#include "peripherals.h"
#include "paravirt.h"
@@ -60,9 +61,6 @@
/* Name of program file */
const char* ProgramFile;
/* count of total cycles executed */
unsigned long long TotalCycles = 0;
/* exit simulator after MaxCycles Cccles */
unsigned long long MaxCycles = 0;
@@ -309,6 +307,7 @@ int main (int argc, char* argv[])
}
MemInit ();
PeripheralsInit ();
SPAddr = ReadProgramFile ();
ParaVirtInit (I, SPAddr);
@@ -318,7 +317,6 @@ int main (int argc, char* argv[])
RemainCycles = MaxCycles;
while (1) {
Cycles = ExecuteInsn ();
TotalCycles += Cycles;
if (MaxCycles) {
if (Cycles > RemainCycles) {
ErrorCode (SIM65_ERROR_TIMEOUT, "Maximum number of cycles reached.");