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(Archive::IS_LOADER);
21  unsigned freq = 0;
22  ar.serialize("freq", freq);
23  setFreq(freq);
24  }
25 }
27 
28 } // namespace openmsx
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:17
void serialize(Archive &ar, unsigned version)
Definition: DynamicClock.cc:8
EmuDuration getPeriod() const
Returns the length of one clock-cycle.
void setPeriod(EmuDuration period)
Set the duration of a clock tick.
void setFreq(unsigned freq)
Change the frequency at which this clock ticks.
This file implemented 3 utility functions:
Definition: Autofire.cc:5
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983