openMSX
EmuTimer.cc
Go to the documentation of this file.
1 #include "EmuTimer.hh"
2 #include "serialize.hh"
3 #include <memory>
4 
5 using std::unique_ptr;
6 
7 namespace openmsx {
8 
9 unique_ptr<EmuTimer> EmuTimer::createOPM_1(
10  Scheduler& scheduler, EmuTimerCallback& cb)
11 {
12  return std::make_unique<EmuTimer>(
13  scheduler, cb, 0x40, 3579545, 64 * 2 , 1024);
14 }
15 
16 unique_ptr<EmuTimer> EmuTimer::createOPM_2(
17  Scheduler& scheduler, EmuTimerCallback& cb)
18 {
19  return std::make_unique<EmuTimer>(
20  scheduler, cb, 0x20, 3579545, 64 * 2 * 16, 256);
21 }
22 
23 unique_ptr<EmuTimer> EmuTimer::createOPL3_1(
24  Scheduler& scheduler, EmuTimerCallback& cb)
25 {
26  return std::make_unique<EmuTimer>(
27  scheduler, cb, 0x40, 3579545, 72 * 4 , 256);
28 }
29 
30 unique_ptr<EmuTimer> EmuTimer::createOPL3_2(
31  Scheduler& scheduler, EmuTimerCallback& cb)
32 {
33  return std::make_unique<EmuTimer>(
34  scheduler, cb, 0x20, 3579545, 72 * 4 * 4, 256);
35 }
36 
37 unique_ptr<EmuTimer> EmuTimer::createOPL4_1(
38  Scheduler& scheduler, EmuTimerCallback& cb)
39 {
40  return std::make_unique<EmuTimer>(
41  scheduler, cb, 0x40, 33868800, 72 * 38 , 256);
42 }
43 
44 unique_ptr<EmuTimer> EmuTimer::createOPL4_2(
45  Scheduler& scheduler, EmuTimerCallback& cb)
46 {
47  return std::make_unique<EmuTimer>(
48  scheduler, cb, 0x20, 33868800, 72 * 38 * 4, 256);
49 }
50 
51 
53  byte flag_, unsigned freq_num, unsigned freq_denom,
54  unsigned maxval_)
55  : Schedulable(scheduler_), cb(cb_)
56  , clock(EmuTime::dummy())
57  , maxval(maxval_), count(maxval_)
58  , flag(flag_), counting(false)
59 {
60  clock.setFreq(freq_num, freq_denom);
61 }
62 
63 void EmuTimer::setValue(int value)
64 {
65  count = maxval - value;
66 }
67 
68 void EmuTimer::setStart(bool start, EmuTime::param time)
69 {
70  if (start != counting) {
71  counting = start;
72  if (start) {
73  schedule(time);
74  } else {
75  unschedule();
76  }
77  }
78 }
79 
80 void EmuTimer::schedule(EmuTime::param time)
81 {
82  clock.reset(time);
83  clock += count;
84  setSyncPoint(clock.getTime());
85 }
86 
87 void EmuTimer::unschedule()
88 {
90 }
91 
92 void EmuTimer::executeUntil(EmuTime::param time)
93 {
94  cb.callback(flag);
95  schedule(time);
96 }
97 
98 template<typename Archive>
99 void EmuTimer::serialize(Archive& ar, unsigned /*version*/)
100 {
101  ar.template serializeBase<Schedulable>(*this);
102  ar.serialize("count", count,
103  "counting", counting);
104 }
106 
107 } // namespace openmsx
openmsx::EmuTimer::EmuTimer
EmuTimer(Scheduler &scheduler, EmuTimerCallback &cb, byte flag, unsigned freq_num, unsigned freq_denom, unsigned maxval)
Definition: EmuTimer.cc:52
openmsx::DynamicClock::setFreq
void setFreq(unsigned freq)
Change the frequency at which this clock ticks.
Definition: DynamicClock.hh:105
openmsx::Scheduler
Definition: Scheduler.hh:34
serialize.hh
openmsx::EmuTimerCallback::callback
virtual void callback(byte value)=0
openmsx::EmuTimer::createOPM_2
static std::unique_ptr< EmuTimer > createOPM_2(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:16
openmsx::EmuTimer::setValue
void setValue(int value)
Definition: EmuTimer.cc:63
LZ4::count
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:207
openmsx::Schedulable
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
openmsx::Schedulable::setSyncPoint
void setSyncPoint(EmuTime::param timestamp)
Definition: Schedulable.cc:23
openmsx::EmuTimer::createOPM_1
static std::unique_ptr< EmuTimer > createOPM_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:9
openmsx::EmuTimer::setStart
void setStart(bool start, EmuTime::param time)
Definition: EmuTimer.cc:68
openmsx::EmuTimer::createOPL4_1
static std::unique_ptr< EmuTimer > createOPL4_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:37
openmsx::EmuTimer::serialize
void serialize(Archive &ar, unsigned version)
Definition: EmuTimer.cc:99
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::EmuTimer
Definition: EmuTimer.hh:22
openmsx::DynamicClock::getTime
EmuTime::param getTime() const
Gets the time at which the last clock tick occurred.
Definition: DynamicClock.hh:38
openmsx::EmuTimer::createOPL3_2
static std::unique_ptr< EmuTimer > createOPL3_2(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:30
openmsx::EmuTimer::createOPL4_2
static std::unique_ptr< EmuTimer > createOPL4_2(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:44
openmsx::EmuTimerCallback
Definition: EmuTimer.hh:12
openmsx::EmuTimer::createOPL3_1
static std::unique_ptr< EmuTimer > createOPL3_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:23
openmsx::DynamicClock::reset
void reset(EmuTime::param e)
Reset the clock to start ticking at the given time.
Definition: DynamicClock.hh:143
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
EmuTimer.hh
openmsx::Schedulable::removeSyncPoint
bool removeSyncPoint()
Definition: Schedulable.cc:28