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

@@ -36,9 +36,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <inttypes.h>
#include "error.h"
#include "peripherals.h"
/*****************************************************************************/
@@ -50,9 +51,6 @@
/* flag to print cycles at program termination */
int PrintCycles = 0;
/* cycles are counted by main.c */
extern unsigned long long TotalCycles;
/*****************************************************************************/
@@ -120,7 +118,7 @@ void SimExit (int Code)
/* Exit the simulation with an exit code */
{
if (PrintCycles) {
fprintf (stdout, "%llu cycles\n", TotalCycles);
fprintf (stdout, PRIu64 " cycles\n", PRegs.counter_clock_cycles);
}
exit (Code);
}