openMSX
IRQHelper.cc
Go to the documentation of this file.
1 #include "IRQHelper.hh"
2 #include "DeviceConfig.hh"
3 #include "MSXCPU.hh"
4 #include "MSXException.hh"
5 #include <memory>
6 
7 namespace openmsx {
8 
9 // class IRQSource
10 
12  : cpu(cpu_)
13 {
14 }
15 
17 {
18  cpu.raiseIRQ();
19 }
20 
22 {
23  cpu.lowerIRQ();
24 }
25 
26 
27 // IRQ sinks (used to implement OptionalIRQ)
28 
30 {
31 public:
32  void raise() override {}
33  void lower() override {}
34 };
35 
36 class MaskableIRQSink : public IRQSink
37 {
38 public:
39  MaskableIRQSink(MSXCPU& cpu_) : cpu(cpu_) {}
40  void raise() override { cpu.raiseIRQ(); }
41  void lower() override { cpu.lowerIRQ(); }
42 private:
43  MSXCPU& cpu;
44 };
45 
47 {
48 public:
49  NonMaskableIRQSink(MSXCPU& cpu_) : cpu(cpu_) {}
50  void raise() override { cpu.raiseNMI(); }
51  void lower() override { cpu.lowerNMI(); }
52 private:
53  MSXCPU& cpu;
54 };
55 
56 
57 // class OptionalIRQ
58 
60 {
61  auto connected = config.getChildData("irq_connected", "irq");
62  if (connected == "irq" || connected == "true") {
63  sink = std::make_unique<MaskableIRQSink>(cpu);
64  } else if (connected == "nmi") {
65  sink = std::make_unique<NonMaskableIRQSink>(cpu);
66  } else if (connected == "false") {
67  sink = std::make_unique<NotConnectedIRQSink>();
68  } else {
69  throw MSXException(
70  "Unknown IRQ sink \"", connected, "\" in <irq_connected>");
71  }
72 }
73 
74 } // namespace openmsx
void lower() override
Definition: IRQHelper.cc:51
void lowerIRQ()
This methods lowers the maskable interrupt again.
Definition: MSXCPU.cc:158
NonMaskableIRQSink(MSXCPU &cpu_)
Definition: IRQHelper.cc:49
OptionalIRQ(MSXCPU &cpu, const DeviceConfig &config)
Definition: IRQHelper.cc:59
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
const std::string & getChildData(std::string_view name) const
Definition: DeviceConfig.cc:43
MaskableIRQSink(MSXCPU &cpu_)
Definition: IRQHelper.cc:39
IRQSource(MSXCPU &cpu)
Definition: IRQHelper.cc:11
void raiseIRQ()
This method raises a maskable interrupt.
Definition: MSXCPU.cc:153
void lower() override
Definition: IRQHelper.cc:41