openMSX
DynamicClock.cc
Go to the documentation of this file.
1 #include "DynamicClock.hh"
2 #include "serialize.hh"
3 #include <cassert>
4 
5 namespace openmsx {
6 
7 template<typename Archive>
8 void DynamicClock::serialize(Archive& ar, unsigned version)
9 {
10  ar.serialize("lastTick", lastTick);
11  if (ar.versionAtLeast(version, 2)) {
12  EmuDuration period = getPeriod();
13  ar.serialize("period", period);
14  setPeriod(period);
15  } else {
16  // Because of possible rounding errors 'auto f = getFreq()'
17  // followed by 'setFreq(f)' is not guaranteed to reproduce the
18  // exact same result. So in newer versions serialize the period
19  // instead of the frequency.
20  assert(ar.isLoader());
21  unsigned freq = 0;
22  ar.serialize("freq", freq);
23  setFreq(freq);
24  }
25 }
27 
28 } // namespace openmsx
openmsx::DynamicClock::setFreq
void setFreq(unsigned freq)
Change the frequency at which this clock ticks.
Definition: DynamicClock.hh:105
serialize.hh
openmsx::EmuDuration
Definition: EmuDuration.hh:19
openmsx::DynamicClock::serialize
void serialize(Archive &ar, unsigned version)
Definition: DynamicClock.cc:8
openmsx::DynamicClock
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:17
openmsx::DynamicClock::setPeriod
void setPeriod(EmuDuration period)
Set the duration of a clock tick.
Definition: DynamicClock.hh:136
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:982
openmsx::DynamicClock::getPeriod
EmuDuration getPeriod() const
Returns the length of one clock-cycle.
Definition: DynamicClock.hh:131
DynamicClock.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5