OXYGENHUB
◆ main openmsx / src / cpu / IRQHelper.cc
1.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "IRQHelper.hh"
2
3
#include "DeviceConfig.hh"
4
#include "MSXCPU.hh"
5
#include "MSXException.hh"
6
7
#include "one_of.hh"
8
#include "unreachable.hh"
9
10
namespace openmsx {
11
12
// class IRQSource
13
14
IRQSource::IRQSource(MSXCPU& cpu_)
15
	: cpu(cpu_)
16
{
17
}
18
19
void IRQSource::raise()
20
{
21
	cpu.raiseIRQ();
22
}
23
24
void IRQSource::lower()
25
{
26
	cpu.lowerIRQ();
27
}
28
29
30
// class OptionalIRQ
31
32
OptionalIRQ::OptionalIRQ(MSXCPU& cpu_, const DeviceConfig& config)
33
	: cpu(cpu_)
34
	, type([&] {
35
		auto connected = config.getChildData("irq_connected", "irq");
36
		if (connected == one_of("irq", "true")) {
37
			return Maskable;
38
		} else if (connected == "nmi") {
39
			return NonMaskable;
40
		} else if (connected == "false") {
41
			return NotConnected;
42
		} else {
43
			throw MSXException(
44
				"Unknown IRQ sink \"", connected, "\" in <irq_connected>");
45
		}
46
	}())
47
{
48
}
49
50
void OptionalIRQ::raise()
51
{
52
	switch (type) {
53
		case NotConnected:
54
			// nothing
55
			break;
56
		case Maskable:
57
			cpu.raiseIRQ();
58
			break;
59
		case NonMaskable:
60
			cpu.raiseNMI();
61
			break;
62
		default:
63
			UNREACHABLE;
64
	}
65
}
66
67
void OptionalIRQ::lower()
68
{
69
	switch (type) {
70
		case NotConnected:
71
			// nothing
72
			break;
73
		case Maskable:
74
			cpu.lowerIRQ();
75
			break;
76
		case NonMaskable:
77
			cpu.lowerNMI();
78
			break;
79
		default:
80
			UNREACHABLE;
81
	}
82
}
83
84
} // namespace openmsx