openMSX
Public Member Functions | Static Public Member Functions | List of all members
openmsx::Clock< FREQ_NUM, FREQ_DENOM > Class Template Reference

Represents a clock with a fixed frequency. More...

#include <Clock.hh>

Inheritance diagram for openmsx::Clock< FREQ_NUM, FREQ_DENOM >:
Inheritance graph
[legend]

Public Member Functions

constexpr Clock (EmuTime::param e)
 Create a new clock, which starts ticking at the given time.
 
constexpr EmuTime::param getTime () const
 Gets the time at which the last clock tick occurred.
 
constexpr bool before (EmuTime::param e) const
 Checks whether this clock's last tick is or is not before the given time stamp.
 
constexpr unsigned getTicksTill (EmuTime::param e) const
 Calculate the number of ticks for this clock until the given time.
 
constexpr unsigned getTicksTill_fast (EmuTime::param e) const
 Same as above, only faster, Though the time interval may not be too large.
 
constexpr uint64_t getTicksTillUp (EmuTime::param e) const
 Calculate the number of ticks this clock has to tick to reach or go past the given time.
 
constexpr EmuTime operator+ (uint64_t n) const
 Calculate the time at which this clock will have ticked the given number of times (counted from its last tick).
 
constexpr EmuTime getFastAdd (unsigned n) const
 Like operator+() but faster, though the step can't be too big (max a little over 1 second).
 
constexpr void reset (EmuTime::param e)
 Reset the clock to start ticking at the given time.
 
constexpr void advance (EmuTime::param e)
 Advance this clock in time until the last tick which is not past the given time.
 
constexpr void advance_fast (EmuTime::param e)
 Same as above, only faster, Though the time interval may not be too large.
 
constexpr void operator+= (unsigned n)
 Advance this clock by the given number of ticks.
 
constexpr void fastAdd (unsigned n)
 Advance this clock by the given number of ticks.
 
template<typename Archive >
void serialize (Archive &ar, unsigned)
 

Static Public Member Functions

static constexpr EmuDuration duration (unsigned ticks)
 Calculates the duration of the given number of ticks at this clock's frequency.
 

Detailed Description

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
class openmsx::Clock< FREQ_NUM, FREQ_DENOM >

Represents a clock with a fixed frequency.

The frequency is in Hertz, so every tick is 1/frequency second. A clock has a current time, which can be increased by an integer number of ticks.

Definition at line 18 of file Clock.hh.

Constructor & Destructor Documentation

◆ Clock()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr openmsx::Clock< FREQ_NUM, FREQ_DENOM >::Clock ( EmuTime::param  e)
inlineexplicitconstexpr

Create a new clock, which starts ticking at the given time.

Definition at line 41 of file Clock.hh.

Member Function Documentation

◆ advance()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr void openmsx::Clock< FREQ_NUM, FREQ_DENOM >::advance ( EmuTime::param  e)
inlineconstexpr

Advance this clock in time until the last tick which is not past the given time.

It is not allowed to advance a clock to a time in the past.

Definition at line 110 of file Clock.hh.

Referenced by openmsx::Y8950Adpcm::sync(), openmsx::MSXE6Timer::writeIO(), openmsx::MSXHiResTimer::writeIO(), and openmsx::MSXTurboRPCM::writeIO().

◆ advance_fast()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr void openmsx::Clock< FREQ_NUM, FREQ_DENOM >::advance_fast ( EmuTime::param  e)
inlineconstexpr

Same as above, only faster, Though the time interval may not be too large.

Definition at line 117 of file Clock.hh.

References DivModByConst< DIVISOR >::mod().

◆ before()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr bool openmsx::Clock< FREQ_NUM, FREQ_DENOM >::before ( EmuTime::param  e) const
inlineconstexpr

Checks whether this clock's last tick is or is not before the given time stamp.

Definition at line 51 of file Clock.hh.

◆ duration()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
static constexpr EmuDuration openmsx::Clock< FREQ_NUM, FREQ_DENOM >::duration ( unsigned  ticks)
inlinestaticconstexpr

Calculates the duration of the given number of ticks at this clock's frequency.

Definition at line 35 of file Clock.hh.

◆ fastAdd()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr void openmsx::Clock< FREQ_NUM, FREQ_DENOM >::fastAdd ( unsigned  n)
inlineconstexpr

Advance this clock by the given number of ticks.

This method is similar to operator+=, but it's optimized for speed. OTOH the amount of ticks should not be too large, otherwise an overflow occurs. Use operator+() when the duration of the ticks approaches 1 second.

Definition at line 135 of file Clock.hh.

◆ getFastAdd()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr EmuTime openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getFastAdd ( unsigned  n) const
inlineconstexpr

Like operator+() but faster, though the step can't be too big (max a little over 1 second).

Definition at line 93 of file Clock.hh.

Referenced by openmsx::VDPAccessSlots::Calculator::getTime(), and openmsx::MSXTurboRPCM::writeIO().

◆ getTicksTill()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr unsigned openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTicksTill ( EmuTime::param  e) const
inlineconstexpr

Calculate the number of ticks for this clock until the given time.

It is not allowed to call this method for a time in the past.

Definition at line 58 of file Clock.hh.

Referenced by openmsx::MSXE6Timer::peekIO(), openmsx::MSXHiResTimer::peekIO(), openmsx::MSXTurboRPCM::peekIO(), openmsx::PioneerLDControl::peekMem(), openmsx::MSXHiResTimer::readIO(), openmsx::Y8950Adpcm::sync(), and openmsx::NowindInterface::writeMem().

◆ getTicksTill_fast()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr unsigned openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTicksTill_fast ( EmuTime::param  e) const
inlineconstexpr

◆ getTicksTillUp()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr uint64_t openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTicksTillUp ( EmuTime::param  e) const
inlineconstexpr

Calculate the number of ticks this clock has to tick to reach or go past the given time.

It is not allowed to call this method for a time in the past.

Definition at line 79 of file Clock.hh.

◆ getTime()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr EmuTime::param openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTime ( ) const
inlineconstexpr

◆ operator+()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr EmuTime openmsx::Clock< FREQ_NUM, FREQ_DENOM >::operator+ ( uint64_t  n) const
inlineconstexpr

Calculate the time at which this clock will have ticked the given number of times (counted from its last tick).

Definition at line 87 of file Clock.hh.

◆ operator+=()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr void openmsx::Clock< FREQ_NUM, FREQ_DENOM >::operator+= ( unsigned  n)
inlineconstexpr

Advance this clock by the given number of ticks.

Definition at line 125 of file Clock.hh.

◆ reset()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
constexpr void openmsx::Clock< FREQ_NUM, FREQ_DENOM >::reset ( EmuTime::param  e)
inlineconstexpr

◆ serialize()

template<unsigned FREQ_NUM, unsigned FREQ_DENOM = 1>
template<typename Archive >
void openmsx::Clock< FREQ_NUM, FREQ_DENOM >::serialize ( Archive &  ar,
unsigned   
)
inline

Definition at line 144 of file Clock.hh.


The documentation for this class was generated from the following file: