SaturnRingLibrary 0.9.2
SGL wrapper
Loading...
Searching...
No Matches
SRL::Timer Class Referencefinal

Detailed Description

High-precision hardware timer with DVU-accelerated conversions.

The Timer class provides Sega Saturn game developers with precise, hardware-accelerated timing capabilities. It combines the SH-2's FRT (Free Running Timer) for counting and DVU (Division Unit) for fast fixed-point conversions.

Key Features:
  • 48-bit timer range: Up to ~673 days of continuous timing
  • Hardware acceleration: DVU provides single-cycle division
  • Fixed-point output: Native Fxp 16.16 compatibility (no float conversion needed)
  • Frame-rate independent: Delta time calculations for smooth animation
  • Regional support: Automatic NTSC/PAL frequency handling
Architecture:
The timer uses a two-tier counting system:
  1. FRT (16-bit): Hardware counter running at ~222 kHz (PHI_128)
  2. Timer32 (32-bit): Software overflow counter incremented via interrupt
  3. Combined: 48-bit range with ~4.47μs precision (PHI_128)
Precision (PHI_128 mode, SGL default):
Tick Rate Precision Hardware Max
~222 kHz ~4.47 μs ~673 days
Basic Usage:
// Use delta time for animation (called automatically by Core::Synchronize)
Fxp delta = Timer::DeltaSeconds();
position = position + velocity * delta;
static const Math::Types::Fxp & DeltaSeconds() noexcept
Frame delta time in seconds (fixed-point 16.16).
Definition srl_timer.hpp:983
Manual Timing:
// ... operation to measure ...
Tickstamp elapsed = end - start;
Fxp seconds = elapsed.ToSeconds();
Math::Types::Fxp ToSeconds() const noexcept
Converts ticks to seconds using DVU hardware acceleration.
Definition srl_timer.hpp:528
High-precision 48-bit timestamp with DVU hardware acceleration.
Definition srl_timer.hpp:58
static Tickstamp Capture() noexcept
Captures current hardware state into a Tickstamp.
Definition srl_timer.hpp:1082
Warning
The hardware can track up to ~673 days, but the Fxp 16.16 format limits conversions: ToMilliseconds() to ~32.8s, ToSeconds() to ~9.1h, ToMinutes() to ~22.7 days. For GUI display use ToClock() which returns a ClockTime struct with no Fxp limitation (up to ~546 hours).
See also
Tickstamp

#include <srl_timer.hpp>

Static Public Member Functions

Timing State

Pre-calculated timing values for frame-rate independent operations.

static const TickstampDeltaTicks () noexcept
 Frame delta ticks (raw elapsed ticks between frames).
static const TickstampCurrentTickstamp () noexcept
 Current frame timestamp (const reference).
static const Math::Types::FxpDeltaSeconds () noexcept
 Frame delta time in seconds (fixed-point 16.16).
static const Math::Types::FxpDeltaMilliseconds () noexcept
 Frame delta time in milliseconds (fixed-point 16.16).
static const Math::Types::FxpDeltaMinutes () noexcept
 Frame delta time in minutes (fixed-point 16.16).
Core Operations

Fundamental timer operations for frame updates and timestamp capture.

static Tickstamp Capture () noexcept
 Captures current hardware state into a Tickstamp.