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  bool getState(EmuTime::param time) const;
34  bool isPeriodic() const { return periodic; }
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
openmsx::ClockPin::setPeriodicState
void setPeriodicState(EmuDuration::param total, EmuDuration::param hi, EmuTime::param time)
Definition: ClockPin.cc:36
openmsx::ClockPin::getHighDuration
EmuDuration::param getHighDuration() const
Definition: ClockPin.cc:73
openmsx::Scheduler
Definition: Scheduler.hh:33
openmsx::ClockPinListener::signal
virtual void signal(ClockPin &pin, EmuTime::param time)=0
openmsx::ClockPin::getTotalDuration
EmuDuration::param getTotalDuration() const
Definition: ClockPin.cc:67
openmsx::ClockPin
Definition: ClockPin.hh:22
openmsx::EmuDuration
Definition: EmuDuration.hh:18
openmsx::ClockPin::getTicksBetween
int getTicksBetween(EmuTime::param begin, EmuTime::param end) const
Definition: ClockPin.cc:79
openmsx::Schedulable
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
Schedulable.hh
openmsx::ClockPin::getState
bool getState(EmuTime::param time) const
Definition: ClockPin.cc:58
openmsx::ClockPin
ClockPin
Definition: ClockPin.cc:149
openmsx::ClockPinListener::~ClockPinListener
~ClockPinListener()=default
openmsx::ClockPinListener
Definition: ClockPin.hh:12
openmsx::ClockPin::generateEdgeSignals
void generateEdgeSignals(bool wanted, EmuTime::param time)
Definition: ClockPin.cc:97
EmuTime.hh
openmsx::ClockPin::serialize
void serialize(Archive &ar, unsigned version)
Definition: ClockPin.cc:139
openmsx::ClockPin::isPeriodic
bool isPeriodic() const
Definition: ClockPin.hh:34
openmsx::ClockPin::ClockPin
ClockPin(Scheduler &scheduler, ClockPinListener *listener=nullptr)
Definition: ClockPin.cc:9
openmsx::ClockPinListener::signalPosEdge
virtual void signalPosEdge(ClockPin &pin, EmuTime::param time)=0
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:133
openmsx::ClockPin::setState
void setState(bool status, EmuTime::param time)
Definition: ClockPin.cc:16
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5