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