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:
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  static std::unique_ptr<EmuTimer> createOPM_1(
29  Scheduler& scheduler, EmuTimerCallback& cb);
30  static std::unique_ptr<EmuTimer> createOPM_2(
31  Scheduler& scheduler, EmuTimerCallback& cb);
32  static std::unique_ptr<EmuTimer> createOPL3_1(
33  Scheduler& scheduler, EmuTimerCallback& cb);
34  static std::unique_ptr<EmuTimer> createOPL3_2(
35  Scheduler& scheduler, EmuTimerCallback& cb);
36  static std::unique_ptr<EmuTimer> createOPL4_1(
37  Scheduler& scheduler, EmuTimerCallback& cb);
38  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  EmuTimerCallback& cb;
53  DynamicClock clock;
54  const unsigned maxval;
55  int count;
56  const byte flag;
57  bool counting;
58 };
59 
60 } // namespace openmsx
61 
62 #endif
virtual void callback(byte value)=0
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:15
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void serialize(Archive &ar, T &t, unsigned version)