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 unsigned maxval_)
62 : Schedulable(scheduler_), cb(cb_)
63 , clock(EmuTime::dummy())
64 , maxval(maxval_), count(maxval_)
65 , flag(flag_), counting(false)
66{
67 clock.setFreq(freq_num, freq_denom);
68}
69
70void EmuTimer::setValue(int value)
71{
72 count = maxval - value;
73}
74
75void EmuTimer::setStart(bool start, EmuTime::param time)
76{
77 if (start != counting) {
78 counting = start;
79 if (start) {
80 schedule(time);
81 } else {
82 unschedule();
83 }
84 }
85}
86
87void EmuTimer::schedule(EmuTime::param time)
88{
89 clock.reset(time);
90 clock += count;
91 setSyncPoint(clock.getTime());
92}
93
94void EmuTimer::unschedule()
95{
97}
98
99void EmuTimer::executeUntil(EmuTime::param time)
100{
101 cb.callback(flag);
102 schedule(time);
103}
104
105template<typename Archive>
106void EmuTimer::serialize(Archive& ar, unsigned /*version*/)
107{
108 ar.template serializeBase<Schedulable>(*this);
109 ar.serialize("count", count,
110 "counting", counting);
111}
113
114} // 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.
Definition: DynamicClock.hh:37
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, unsigned 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:75
static std::unique_ptr< EmuTimer > createOPL4_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:44
void setValue(int value)
Definition: EmuTimer.cc:70
static std::unique_ptr< EmuTimer > createOPL3_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:30
void serialize(Archive &ar, unsigned version)
Definition: EmuTimer.cc:106
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.
Definition: Schedulable.hh:34
void setSyncPoint(EmuTime::param timestamp)
Definition: Schedulable.cc:23
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:146
This file implemented 3 utility functions:
Definition: Autofire.cc:9
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1009