OXYGENHUB
◆ main openmsx / src / serial / ClockPin.hh
1.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 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
12
class ClockPinListener
13
{
14
public:
15
	virtual void signal(ClockPin& pin, EmuTime time) = 0;
16
	virtual void signalPosEdge(ClockPin& pin, EmuTime 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 time);
29
	void setPeriodicState(EmuDuration total,
30
	                      EmuDuration hi, EmuTime time);
31
32
	// output side
33
	[[nodiscard]] bool getState(EmuTime time) const;
34
	[[nodiscard]] bool isPeriodic() const { return periodic; }
35
	[[nodiscard]] EmuDuration getTotalDuration() const;
36
	[[nodiscard]] EmuDuration getHighDuration() const;
37
	[[nodiscard]] unsigned getTicksBetween(EmuTime begin,
38
	                                       EmuTime end) const;
39
40
	// control
41
	void generateEdgeSignals(bool wanted, EmuTime time);
42
43
	template<typename Archive>
44
	void serialize(Archive& ar, unsigned version);
45
46
private:
47
	void unschedule();
48
	void schedule(EmuTime time);
49
	void executeUntil(EmuTime time) override;
50
51
private:
52
	ClockPinListener* const listener;
53
54
	EmuDuration totalDur;
55
	EmuDuration hiDur;
56
	EmuTime referenceTime = EmuTime::zero();
57
58
	bool periodic = false;
59
	bool status = false;
60
	bool signalEdge = false;
61
};
62
63
} // namespace openmsx
64
65
#endif