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:
19  ~ClockPinListener() = default;
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);
30  EmuDuration::param hi, EmuTime::param time);
31 
32  // output side
33  [[nodiscard]] bool getState(EmuTime::param time) const;
34  [[nodiscard]] bool isPeriodic() const { return periodic; }
35  [[nodiscard]] EmuDuration::param getTotalDuration() const;
36  [[nodiscard]] EmuDuration::param getHighDuration() const;
37  [[nodiscard]] 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 private:
52  ClockPinListener* const listener;
53 
54  EmuDuration totalDur;
55  EmuDuration hiDur;
56  EmuTime referenceTime;
57 
58  bool periodic;
59  bool status;
60  bool signalEdge;
61 };
62 
63 } // namespace openmsx
64 
65 #endif
virtual void signal(ClockPin &pin, EmuTime::param time)=0
virtual void signalPosEdge(ClockPin &pin, EmuTime::param time)=0
bool isPeriodic() const
Definition: ClockPin.hh:34
ClockPin(Scheduler &scheduler, ClockPinListener *listener=nullptr)
Definition: ClockPin.cc:7
void generateEdgeSignals(bool wanted, EmuTime::param time)
Definition: ClockPin.cc:95
void setState(bool status, EmuTime::param time)
Definition: ClockPin.cc:14
void serialize(Archive &ar, unsigned version)
Definition: ClockPin.cc:137
int getTicksBetween(EmuTime::param begin, EmuTime::param end) const
Definition: ClockPin.cc:77
bool getState(EmuTime::param time) const
Definition: ClockPin.cc:56
EmuDuration::param getHighDuration() const
Definition: ClockPin.cc:71
void setPeriodicState(EmuDuration::param total, EmuDuration::param hi, EmuTime::param time)
Definition: ClockPin.cc:34
EmuDuration::param getTotalDuration() const
Definition: ClockPin.cc:65
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
constexpr auto begin(const zstring_view &x)
Definition: zstring_view.hh:83
constexpr auto end(const zstring_view &x)
Definition: zstring_view.hh:84