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& operator=(const IntHelper&) = delete;
52
56 template<typename ...Args>
57 IntHelper(MSXMotherBoard& motherboard, const std::string& name,
58 Args&& ...args)
59 : SOURCE(motherboard.getCPU(), std::forward<Args>(args)...)
60 , request(motherboard.getDebugger(), name,
61 "Outgoing IRQ signal.", false)
62 {
63 }
64
69 reset();
70 }
71
74 inline void set() {
75 if (!request) {
76 request = true;
77 SOURCE::raise();
78 }
79 }
80
83 inline void reset() {
84 if (request) {
85 request = false;
86 SOURCE::lower();
87 }
88 }
89
92 inline void set(bool s) {
93 if (s) {
94 set();
95 } else {
96 reset();
97 }
98 }
99
103 [[nodiscard]] inline bool getState() const {
104 return request;
105 }
106
107 template<typename Archive>
108 void serialize(Archive& ar, unsigned /*version*/)
109 {
110 bool pending = request;
111 ar.serialize("pending", pending);
112 if constexpr (Archive::IS_LOADER) {
113 set(pending);
114 }
115 }
116
117private:
118 Probe<bool> request;
119};
120
121// convenience types
124
125} // namespace openmsx
126
127#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:74
IntHelper(const IntHelper &)=delete
void reset()
Reset the interrupt request on the bus.
Definition IRQHelper.hh:83
~IntHelper()
Destroy this IntHelper.
Definition IRQHelper.hh:68
void serialize(Archive &ar, unsigned)
Definition IRQHelper.hh:108
bool getState() const
Get the interrupt state.
Definition IRQHelper.hh:103
void set(bool s)
Convenience function: calls set() or reset().
Definition IRQHelper.hh:92
IntHelper(MSXMotherBoard &motherboard, const std::string &name, Args &&...args)
Create a new IntHelper.
Definition IRQHelper.hh:57
IntHelper & operator=(const IntHelper &)=delete
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.