openMSX
EmuTimer.hh
Go to the documentation of this file.
1#ifndef EMUTIMER_HH
2#define EMUTIMER_HH
3
4#include "Schedulable.hh"
5#include "DynamicClock.hh"
6#include "openmsx.hh"
7#include <memory>
8
9namespace openmsx {
10
12{
13public:
14 virtual void callback(byte value) = 0;
15
16protected:
17 ~EmuTimerCallback() = default;
18};
19
20
21class EmuTimer final : public Schedulable
22{
23public:
24 EmuTimer(Scheduler& scheduler, EmuTimerCallback& cb,
25 byte flag, unsigned freq_num, unsigned freq_denom,
26 int maxVal);
27
28 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPM_1(
29 Scheduler& scheduler, EmuTimerCallback& cb);
30 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPM_2(
31 Scheduler& scheduler, EmuTimerCallback& cb);
32 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPP_2(
33 Scheduler& scheduler, EmuTimerCallback& cb);
34 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL3_1(
35 Scheduler& scheduler, EmuTimerCallback& cb);
36 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL3_2(
37 Scheduler& scheduler, EmuTimerCallback& cb);
38 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL4_1(
39 Scheduler& scheduler, EmuTimerCallback& cb);
40 [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL4_2(
41 Scheduler& scheduler, EmuTimerCallback& cb);
42
43 void setValue(int value);
44 void setStart(bool start, EmuTime::param time);
45
46 template<typename Archive>
47 void serialize(Archive& ar, unsigned version);
48
49private:
50 void executeUntil(EmuTime::param time) override;
51 void schedule(EmuTime::param time);
52 void unschedule();
53
54private:
56 DynamicClock clock{EmuTime::zero()};
57 const int maxVal;
58 int count;
59 const byte flag;
60 bool counting = false;
61};
62
63} // namespace openmsx
64
65#endif
Represents a clock with a variable frequency.
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
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.
This file implemented 3 utility functions:
Definition Autofire.cc:11