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,7 +36,7 @@
#include <string.h>
#include "memory.h"
#include "peripherals.h"
/*****************************************************************************/
@@ -59,7 +59,14 @@ uint8_t Mem[0x10000];
void MemWriteByte (uint16_t Addr, uint8_t Val)
/* Write a byte to a memory location */
{
Mem[Addr] = Val;
if ((PERIPHERALS_APERTURE_BASE_ADDRESS <= Addr) && (Addr <= PERIPHERALS_APERTURE_LAST_ADDRESS))
{
/* Defer the the memory-mapped peripherals handler for this write. */
PeripheralWriteByte (Addr - PERIPHERALS_APERTURE_BASE_ADDRESS, Val);
} else {
/* Write to the Mem array. */
Mem[Addr] = Val;
}
}
@@ -76,7 +83,14 @@ void MemWriteWord (uint16_t Addr, uint16_t Val)
uint8_t MemReadByte (uint16_t Addr)
/* Read a byte from a memory location */
{
return Mem[Addr];
if ((PERIPHERALS_APERTURE_BASE_ADDRESS <= Addr) && (Addr <= PERIPHERALS_APERTURE_LAST_ADDRESS))
{
/* Defer the the memory-mapped peripherals handler for this read. */
return PeripheralReadByte (Addr - PERIPHERALS_APERTURE_BASE_ADDRESS);
} else {
/* Read from the Mem array. */
return Mem[Addr];
}
}