openMSX

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...  
std::pair< unsigned, float >  getTicksTillAsIntFloat (EmuTime::param e) const 
Like getTicksTill(), but also returns the fractional part (in range [0, 1)). 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 clockcycle. More...  
void  setPeriod (EmuDuration period) 
Set the duration of a clock tick. 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...  
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) 
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 16 of file DynamicClock.hh.

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

inline 
Create a new clock, which starts ticking at given time with given frequency.
Definition at line 30 of file DynamicClock.hh.
References setFreq().

inline 
Definition at line 185 of file DynamicClock.hh.
Referenced by openmsx::CPUClock::calcTime(), and getFastAdd().

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 151 of file DynamicClock.hh.
References openmsx::DivModBySame::mod().
Referenced by openmsx::CPUClock::advanceTime(), and openmsx::MC6850::writeDataReg().

inline 
Checks whether this clock's last tick is or is not before the given time stamp.
Definition at line 45 of file DynamicClock.hh.

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 175 of file DynamicClock.hh.
Referenced by openmsx::CPUClock::sync().

inline 
Definition at line 182 of file DynamicClock.hh.
References add().
Referenced by openmsx::CPUClock::getTimeFast().

inline 
Returns the frequency (in Hz) at which this clock ticks.
Definition at line 124 of file DynamicClock.hh.
References openmsx::MAIN_FREQ, and step.
Referenced by openmsx::CPUClock::getFreq(), openmsx::WavImage::getFrequency(), openmsx::ResampleLQDown< CHANNELS >::ResampleLQDown(), openmsx::ResampleLQUp< CHANNELS >::ResampleLQUp(), and openmsx::LaserdiscPlayer::serialize().

inline 
Returns the length of one clockcycle.
Definition at line 131 of file DynamicClock.hh.
Referenced by openmsx::ResampleLQ< CHANNELS >::create(), openmsx::ResampledSoundDevice::createResampler(), openmsx::Autofire::getSignal(), openmsx::ResampleBlip< CHANNELS >::ResampleBlip(), openmsx::ResampleLQ< CHANNELS >::ResampleLQ(), and serialize().

inline 
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 52 of file DynamicClock.hh.
References openmsx::DivModBySame::div().
Referenced by openmsx::Autofire::getSignal(), openmsx::MSXMixer::updateStream(), and openmsx::DACSound16S::writeDAC().

inline 
Definition at line 74 of file DynamicClock.hh.
References openmsx::IDEDeviceFactory::create(), and openmsx::DivModBySame::div().

inline 
Like getTicksTill(), but also returns the fractional part (in range [0, 1)).
This is equivalent to, but numerically more stable than: EmuDuration dur = e  this>getTime(); double d = dur / this>getPeriod(); int i = int(d); double frac = d  i; return {i, frac};
Definition at line 64 of file DynamicClock.hh.
References openmsx::DivModBySame::divMod().
Referenced by openmsx::WavImage::getSampleAt(), and openmsx::YM2413::writePort().

inline 
Definition at line 89 of file DynamicClock.hh.

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 84 of file DynamicClock.hh.
References openmsx::DivModBySame::div().
Referenced by openmsx::CPUClock::advanceHalt(), and openmsx::CPUClock::setLimit().

inline 
Gets the time at which the last clock tick occurred.
Definition at line 38 of file DynamicClock.hh.
Referenced by openmsx::ResampledSoundDevice::createResampler(), openmsx::WavImage::getEndTime(), openmsx::CPUClock::getTime(), openmsx::WD2793::peekDTRQ(), and openmsx::MC6850::writeDataReg().

inline 
Definition at line 94 of file DynamicClock.hh.
Referenced by openmsx::CPUClock::waitForEvenCycle().

inline 
Calculate the time at which this clock will have ticked the given number of times (counted from its last tick).
Definition at line 165 of file DynamicClock.hh.

inline 
Advance this clock by the given number of ticks.
Definition at line 158 of file DynamicClock.hh.

inline 
Reset the clock to start ticking at the given time.
Definition at line 143 of file DynamicClock.hh.
Referenced by openmsx::ResampledSoundDevice::createResampler(), openmsx::WD2793::getDataReg(), openmsx::MSXMixer::reInit(), openmsx::WD2793::reset(), openmsx::MC6850::reset(), openmsx::TC8566AF::serialize(), openmsx::WD2793::serialize(), openmsx::WD2793::setDataReg(), openmsx::CPUClock::setTime(), and openmsx::MC6850::writeControlReg().
void openmsx::DynamicClock::serialize  (  Archive &  ar, 
unsigned  version  
) 
Definition at line 8 of file DynamicClock.cc.
References getPeriod(), setFreq(), and setPeriod().

inline 
Change the frequency at which this clock ticks.
When possible prefer setPeriod() over this method because it may introduce less rounding errors.
freq  New frequency in Hertz. 
Definition at line 105 of file DynamicClock.hh.
References openmsx::MAIN_FREQ32, and setPeriod().
Referenced by DynamicClock(), openmsx::EmuTimer::EmuTimer(), openmsx::MSXMixer::reInit(), openmsx::MC6850::reset(), serialize(), openmsx::TC8566AF::serialize(), openmsx::WD2793::serialize(), openmsx::LaserdiscPlayer::serialize(), openmsx::CPUClock::setFreq(), openmsx::WavImage::WavImage(), and openmsx::MC6850::writeControlReg().

inline 
Equivalent to setFreq(freq_num / freq_denom), but possibly with less rounding errors.
When possible prefer setPeriod() over this method because it may introduce less rounding errors.
Definition at line 114 of file DynamicClock.hh.
References openmsx::MAIN_FREQ, and setPeriod().

inline 
Set the duration of a clock tick.
See also setFreq().
Definition at line 136 of file DynamicClock.hh.
References openmsx::EmuDuration::length(), and openmsx::DivModBySame::setDivisor().
Referenced by openmsx::ResampledSoundDevice::createResampler(), serialize(), and setFreq().