resonance 1.0.1
Loading...
Searching...
No Matches
cycles.h File Reference
#include "os/timer.h"
Include dependency graph for cycles.h:

Go to the source code of this file.

Functions

unsigned ReadCycleCount ()
 Read the free-running cycle counter.
int GetElapsedMilliseconds ()
 Report the milliseconds elapsed since the machine started.
int GetMillisecondsPerSecond ()
 Report how many units GetElapsedMilliseconds() counts in one second.

Variables

constexpr unsigned kCyclesPerMillisecond = 294912
 EE clock in cycles per millisecond, which is the divisor the elapsed time is computed with.
constexpr int kMillisecondsPerSecond = 1000
 Milliseconds in one second, the rate GetMillisecondsPerSecond() reports.

Function Documentation

◆ ReadCycleCount()

unsigned ReadCycleCount ( )

Read the free-running cycle counter.

Every caller in the image inlines the read, so the image has no out-of-line copy and there is no address to record. On the shipped target the read is the EE Count coprocessor register, which is the one genuinely machine-specific part of the timing instrumentation, so a port supplies its own implementation file for this declaration.

Returns
The counter, which wraps.

◆ GetElapsedMilliseconds()

int GetElapsedMilliseconds ( )
inline

Report the milliseconds elapsed since the machine started.

The body is here rather than in a source file because around thirty routines across the engine inline it, among them MainLoop::PumpTimers(), Sch::SystemTime::Mark(), and the per-frame slots of MetRenderer. Only one out-of-line copy exists, at the address below, and the two routines in the asynchronous file layer are its only callers.

The result is returned as an int and widened by its callers, which puts the ceiling at about 24 days of running time.

The name is inferred from the arithmetic. Nothing in the image attests it.

Returns
The elapsed milliseconds.
Ghidra address:
NTSC-U/C: 0x00466300
Ghidra address:
PAL: 0x004a3d30

◆ GetMillisecondsPerSecond()

int GetMillisecondsPerSecond ( )
inline

Report how many units GetElapsedMilliseconds() counts in one second.

The body is here rather than in a source file for the reason recorded on GetElapsedMilliseconds(). Its one out-of-line copy follows that routine's copy directly, in the unit whose static initialiser is at 0x004662d0 and which also defines ShowReportedMessage(). HudScreenFlash's constructor calls that copy, and Sch::SystemTime divides its scale by the result.

The name is inferred from the value. Nothing in the image attests it.

Returns
1000.
Ghidra address:
NTSC-U/C: 0x00466360
Ghidra address:
PAL: 0x004a3d90

Variable Documentation

◆ kCyclesPerMillisecond

unsigned kCyclesPerMillisecond = 294912
constexpr

EE clock in cycles per millisecond, which is the divisor the elapsed time is computed with.

◆ kMillisecondsPerSecond

int kMillisecondsPerSecond = 1000
constexpr

Milliseconds in one second, the rate GetMillisecondsPerSecond() reports.