openMSX
IRQHelper.hh
Go to the documentation of this file.
1#ifndef IRQHELPER_HH
2#define IRQHELPER_HH
3
4#include "Probe.hh"
5#include "MSXMotherBoard.hh"
6#include "serialize.hh"
7#include <string>
8
9namespace openmsx {
10
11class MSXCPU;
12class DeviceConfig;
13
21// policy class for IRQ source
23{
24protected:
25 explicit IRQSource(MSXCPU& cpu);
26 void raise();
27 void lower();
28private:
29 MSXCPU& cpu;
30};
31
32// supports <irq_connected> tag in hardware config
34{
35protected:
36 OptionalIRQ(MSXCPU& cpu, const DeviceConfig& config);
37 void raise();
38 void lower();
39private:
40 MSXCPU& cpu;
41 enum Type { NotConnected, Maskable, NonMaskable };
42 const Type type;
43};
44
45
46// generic implementation
47template<typename SOURCE> class IntHelper : public SOURCE
48{
49public:
50 IntHelper(const IntHelper&) = delete;
51 IntHelper(IntHelper&&) = delete;
52 IntHelper& operator=(const IntHelper&) = delete;
54
58 template<typename ...Args>
59 IntHelper(MSXMotherBoard& motherboard, const std::string& name,
60 Args&& ...args)
61 : SOURCE(motherboard.getCPU(), std::forward<Args>(args)...)
62 , request(motherboard.getDebugger(), name,
63 "Outgoing IRQ signal.", false)
64 {
65 }
66
71 reset();
72 }
73
76 inline void set() {
77 if (!request) {
78 request = true;
79 SOURCE::raise();
80 }
81 }
82
85 inline void reset() {
86 if (request) {
87 request = false;
88 SOURCE::lower();
89 }
90 }
91
94 inline void set(bool s) {
95 if (s) {
96 set();
97 } else {
98 reset();
99 }
100 }
101
105 [[nodiscard]] inline bool getState() const {
106 return request;
107 }
108
109 template<typename Archive>
110 void serialize(Archive& ar, unsigned /*version*/)
111 {
112 bool pending = request;
113 ar.serialize("pending", pending);
114 if constexpr (Archive::IS_LOADER) {
115 set(pending);
116 }
117 }
118
119private:
120 Probe<bool> request;
121};
122
123// convenience types
126
127} // namespace openmsx
128
129#endif
Helper class for doing interrupt request (IRQ) administration.
Definition IRQHelper.hh:23
void set()
Set the interrupt request on the bus.
Definition IRQHelper.hh:76
IntHelper & operator=(IntHelper &&)=delete
IntHelper(const IntHelper &)=delete
void reset()
Reset the interrupt request on the bus.
Definition IRQHelper.hh:85
~IntHelper()
Destroy this IntHelper.
Definition IRQHelper.hh:70
void serialize(Archive &ar, unsigned)
Definition IRQHelper.hh:110
bool getState() const
Get the interrupt state.
Definition IRQHelper.hh:105
void set(bool s)
Convenience function: calls set() or reset().
Definition IRQHelper.hh:94
IntHelper(MSXMotherBoard &motherboard, const std::string &name, Args &&...args)
Create a new IntHelper.
Definition IRQHelper.hh:59
IntHelper(IntHelper &&)=delete
IntHelper & operator=(const IntHelper &)=delete
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.