openMSX
Public Member Functions | List of all members
openmsx::DynamicClock Class Reference

Represents a clock with a variable frequency. More...

#include <DynamicClock.hh>

Public Member Functions

 DynamicClock (EmuTime::param time)
 Create a new clock, which starts ticking at given time. More...
 
 DynamicClock (EmuTime::param time, unsigned freq)
 Create a new clock, which starts ticking at given time with given frequency. More...
 
EmuTime::param getTime () const
 Gets the time at which the last clock tick occurred. More...
 
bool before (EmuTime::param e) const
 Checks whether this clock's last tick is or is not before the given time stamp. More...
 
unsigned getTicksTill (EmuTime::param e) const
 Calculate the number of ticks for this clock until the given time. More...
 
template<typename FIXED >
void getTicksTill (EmuTime::param e, FIXED &result) const
 
unsigned getTicksTillUp (EmuTime::param e) const
 Calculate the number of ticks this clock has to tick to reach or go past the given time. More...
 
double getTicksTillDouble (EmuTime::param e) const
 
uint64_t getTotalTicks () const
 
void setFreq (unsigned freq)
 Change the frequency at which this clock ticks. More...
 
void setFreq (unsigned freq_num, unsigned freq_denom)
 Equivalent to setFreq(freq_num / freq_denom), but possibly with less rounding errors. More...
 
unsigned getFreq () const
 Returns the frequency (in Hz) at which this clock ticks. More...
 
EmuDuration getPeriod () const
 Returns the length of one clock-cycle. More...
 
void reset (EmuTime::param e)
 Reset the clock to start ticking at the given time. More...
 
void advance (EmuTime::param e)
 Advance this clock in time until the last tick which is not past the given time. More...
 
void operator+= (uint64_t n)
 Advance this clock by the given number of ticks. More...
 
const 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). More...
 
void fastAdd (unsigned n)
 Advance this clock by the given number of ticks. More...
 
EmuTime getFastAdd (unsigned n) const
 
EmuTime add (EmuTime::param time, unsigned n) const
 
template<typename Archive >
void serialize (Archive &ar, unsigned version)
 

Detailed Description

Represents a clock with a variable 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 15 of file DynamicClock.hh.

Constructor & Destructor Documentation

◆ DynamicClock() [1/2]

openmsx::DynamicClock::DynamicClock ( EmuTime::param  time)
inlineexplicit

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

The initial frequency is infinite; in other words, the clock stands still.

Definition at line 24 of file DynamicClock.hh.

◆ DynamicClock() [2/2]

openmsx::DynamicClock::DynamicClock ( EmuTime::param  time,
unsigned  freq 
)
inline

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

Definition at line 29 of file DynamicClock.hh.

References setFreq().

Member Function Documentation

◆ add()

EmuTime openmsx::DynamicClock::add ( EmuTime::param  time,
unsigned  n 
) const
inline

◆ advance()

void openmsx::DynamicClock::advance ( EmuTime::param  e)
inline

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 126 of file DynamicClock.hh.

References openmsx::DivModBySame::mod().

Referenced by openmsx::CPUClock::advanceTime(), openmsx::LaserdiscPlayer::setMuting(), and openmsx::MC6850::writeIO().

◆ before()

bool openmsx::DynamicClock::before ( EmuTime::param  e) const
inline

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

Definition at line 44 of file DynamicClock.hh.

Referenced by openmsx::TC8566AF::readReg(), and openmsx::TC8566AF::writeReg().

◆ fastAdd()

void openmsx::DynamicClock::fastAdd ( unsigned  n)
inline

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 150 of file DynamicClock.hh.

Referenced by openmsx::CPUClock::sync().

◆ getFastAdd()

EmuTime openmsx::DynamicClock::getFastAdd ( unsigned  n) const
inline

◆ getFreq()

unsigned openmsx::DynamicClock::getFreq ( ) const
inline

◆ getPeriod()

EmuDuration openmsx::DynamicClock::getPeriod ( ) const
inline

Returns the length of one clock-cycle.

Definition at line 112 of file DynamicClock.hh.

References openmsx::EmuDuration.

Referenced by openmsx::MC6850::writeIO().

◆ getTicksTill() [1/2]

unsigned openmsx::DynamicClock::getTicksTill ( EmuTime::param  e) const
inline

◆ getTicksTill() [2/2]

template<typename FIXED >
void openmsx::DynamicClock::getTicksTill ( EmuTime::param  e,
FIXED &  result 
) const
inline

◆ getTicksTillDouble()

double openmsx::DynamicClock::getTicksTillDouble ( EmuTime::param  e) const
inline

Definition at line 72 of file DynamicClock.hh.

Referenced by openmsx::ResampleHQ< CHANNELS >::generateOutput().

◆ getTicksTillUp()

unsigned openmsx::DynamicClock::getTicksTillUp ( EmuTime::param  e) const
inline

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 67 of file DynamicClock.hh.

References openmsx::DivModBySame::div().

Referenced by openmsx::CPUClock::advanceHalt(), and openmsx::CPUClock::setLimit().

◆ getTime()

EmuTime::param openmsx::DynamicClock::getTime ( ) const
inline

◆ getTotalTicks()

uint64_t openmsx::DynamicClock::getTotalTicks ( ) const
inline

Definition at line 77 of file DynamicClock.hh.

Referenced by openmsx::CPUClock::waitForEvenCycle().

◆ operator+()

const EmuTime openmsx::DynamicClock::operator+ ( uint64_t  n) const
inline

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

Definition at line 140 of file DynamicClock.hh.

References openmsx::EmuTime.

◆ operator+=()

void openmsx::DynamicClock::operator+= ( uint64_t  n)
inline

Advance this clock by the given number of ticks.

Definition at line 133 of file DynamicClock.hh.

◆ reset()

void openmsx::DynamicClock::reset ( EmuTime::param  e)
inline

◆ serialize()

template<typename Archive >
void openmsx::DynamicClock::serialize ( Archive &  ar,
unsigned  version 
)

Definition at line 7 of file DynamicClock.cc.

References getFreq(), and setFreq().

Referenced by add().

◆ setFreq() [1/2]

void openmsx::DynamicClock::setFreq ( unsigned  freq)
inline

◆ setFreq() [2/2]

void openmsx::DynamicClock::setFreq ( unsigned  freq_num,
unsigned  freq_denom 
)
inline

Equivalent to setFreq(freq_num / freq_denom), but possibly with less rounding errors.

Definition at line 94 of file DynamicClock.hh.

References openmsx::DivModBySame::setDivisor().


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