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,
30  EmuDuration::param hi, EmuTime::param time);
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;
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, int userData) 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:135
void setState(bool status, EmuTime::param time)
Definition: ClockPin.cc:16
void serialize(Archive &ar, unsigned version)
Definition: ClockPin.cc:139
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:16
virtual void signal(ClockPin &pin, EmuTime::param time)=0
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:7
EmuDuration::param getTotalDuration() const
Definition: ClockPin.cc:67
virtual void signalPosEdge(ClockPin &pin, EmuTime::param time)=0
ClockPin(Scheduler &scheduler, ClockPinListener *listener=nullptr)
Definition: ClockPin.cc:9
bool getState(EmuTime::param time) const
Definition: ClockPin.cc:58
void generateEdgeSignals(bool wanted, EmuTime::param time)
Definition: ClockPin.cc:97
string_ref::const_iterator begin(const string_ref &x)
Definition: string_ref.hh:134
int getTicksBetween(EmuTime::param begin, EmuTime::param end) const
Definition: ClockPin.cc:79
void setPeriodicState(EmuDuration::param total, EmuDuration::param hi, EmuTime::param time)
Definition: ClockPin.cc:36
EmuDuration::param getHighDuration() const
Definition: ClockPin.cc:73