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