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 
9 namespace openmsx {
10 
12 {
13 public:
14  virtual void callback(byte value) = 0;
15 
16 protected:
17  ~EmuTimerCallback() = default;
18 };
19 
20 
21 class EmuTimer final : public Schedulable
22 {
23 public:
24  EmuTimer(Scheduler& scheduler, EmuTimerCallback& cb,
25  byte flag, unsigned freq_num, unsigned freq_denom,
26  unsigned 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> createOPL3_1(
33  Scheduler& scheduler, EmuTimerCallback& cb);
34  [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL3_2(
35  Scheduler& scheduler, EmuTimerCallback& cb);
36  [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL4_1(
37  Scheduler& scheduler, EmuTimerCallback& cb);
38  [[nodiscard]] static std::unique_ptr<EmuTimer> createOPL4_2(
39  Scheduler& scheduler, EmuTimerCallback& cb);
40 
41  void setValue(int value);
42  void setStart(bool start, EmuTime::param time);
43 
44  template<typename Archive>
45  void serialize(Archive& ar, unsigned version);
46 
47 private:
48  void executeUntil(EmuTime::param time) override;
49  void schedule(EmuTime::param time);
50  void unschedule();
51 
52 private:
53  EmuTimerCallback& cb;
54  DynamicClock clock;
55  const unsigned maxval;
56  int count;
57  const byte flag;
58  bool counting;
59 };
60 
61 } // namespace openmsx
62 
63 #endif
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:16
virtual void callback(byte value)=0
static std::unique_ptr< EmuTimer > createOPM_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:9
EmuTimer(Scheduler &scheduler, EmuTimerCallback &cb, byte flag, unsigned freq_num, unsigned freq_denom, unsigned maxval)
Definition: EmuTimer.cc:52
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:68
static std::unique_ptr< EmuTimer > createOPL4_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:37
void setValue(int value)
Definition: EmuTimer.cc:63
static std::unique_ptr< EmuTimer > createOPL3_1(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:23
void serialize(Archive &ar, unsigned version)
Definition: EmuTimer.cc:99
static std::unique_ptr< EmuTimer > createOPL3_2(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:30
static std::unique_ptr< EmuTimer > createOPL4_2(Scheduler &scheduler, EmuTimerCallback &cb)
Definition: EmuTimer.cc:44
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
This file implemented 3 utility functions:
Definition: Autofire.cc:9