openMSX
ClockPin.hh
Go to the documentation of this file.
1 #ifndef CLOCKPIN_HH
2 #define CLOCKPIN_HH
3 
4 #include "EmuTime.hh"
5 #include "Schedulable.hh"
6 
7 namespace openmsx {
8 
9 class Scheduler;
10 class ClockPin;
11 
13 {
14 public:
15  virtual void signal(ClockPin& pin, EmuTime::param time) = 0;
16  virtual void signalPosEdge(ClockPin& pin, EmuTime::param time) = 0;
17 
18 protected:
20 };
21 
22 class ClockPin final : public Schedulable
23 {
24 public:
25  explicit ClockPin(Scheduler& scheduler, ClockPinListener* listener = nullptr);
26 
27  // input side
28  void setState(bool status, EmuTime::param time);
29  void setPeriodicState(EmuDuration::param total,
31 
32  // output side
33  bool getState(EmuTime::param time) const;
34  bool isPeriodic() const { return periodic; }
35  EmuDuration::param getTotalDuration() const;
36  EmuDuration::param getHighDuration() const;
37  int getTicksBetween(EmuTime::param begin,
38  EmuTime::param end) const;
39 
40  // control
41  void generateEdgeSignals(bool wanted, EmuTime::param time);
42 
43  template<typename Archive>
44  void serialize(Archive& ar, unsigned version);
45 
46 private:
47  void unschedule();
48  void schedule(EmuTime::param time);
49  void executeUntil(EmuTime::param time) override;
50 
51  ClockPinListener* const listener;
52 
53  EmuDuration totalDur;
54  EmuDuration hiDur;
55  EmuTime referenceTime;
56 
57  bool periodic;
58  bool status;
59  bool signalEdge;
60 };
61 
62 } // namespace openmsx
63 
64 #endif
string_ref::const_iterator end(const string_ref &x)
Definition: string_ref.hh:167
bool isPeriodic() const
Definition: ClockPin.hh:34
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
virtual void signal(ClockPin &pin, EmuTime::param time)=0
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
virtual void signalPosEdge(ClockPin &pin, EmuTime::param time)=0
string_ref::const_iterator begin(const string_ref &x)
Definition: string_ref.hh:166
void serialize(Archive &ar, T &t, unsigned version)