OXYGENHUB
◆ main openmsx / src / cpu / MSXMultiIODevice.cc
1.7 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "MSXMultiIODevice.hh"
2
3
#include "MSXException.hh"
4
#include "TclObject.hh"
5
6
#include "stl.hh"
7
8
#include <cassert>
9
10
namespace openmsx {
11
12
MSXMultiIODevice::MSXMultiIODevice(HardwareConfig& hwConf)
13
	: MSXMultiDevice(hwConf)
14
{
15
}
16
17
MSXMultiIODevice::~MSXMultiIODevice()
18
{
19
	assert(devices.empty());
20
}
21
22
void MSXMultiIODevice::addDevice(MSXDevice* device)
23
{
24
	if (contains(devices, device)) {
25
		throw MSXException(
26
			"Overlapping IO-port ranges for \"",
27
			device->getName(), "\".");
28
	}
29
	devices.push_back(device);
30
}
31
32
void MSXMultiIODevice::removeDevice(MSXDevice* device)
33
{
34
	devices.erase(rfind_unguarded(devices, device));
35
}
36
37
const std::string& MSXMultiIODevice::getName() const
38
{
39
	TclObject list;
40
	getNameList(list);
41
	deviceName = list.getString();
42
	return deviceName;
43
}
44
void MSXMultiIODevice::getNameList(TclObject& result) const
45
{
46
	for (const auto* dev : devices) {
47
		const auto& name = dev->getName();
48
		if (!name.empty()) {
49
			result.addListElement(name);
50
		}
51
	}
52
}
53
54
uint8_t MSXMultiIODevice::readIO(uint16_t port, EmuTime time)
55
{
56
	// conflict: In practice, pull down seems to win over pull up,
57
	//           so a logical AND over the read values most accurately
58
	//           resembles what real hardware does.
59
	uint8_t result = 0xFF;
60
	for (auto& dev : devices) {
61
		result &= dev->readIO(port, time);
62
	}
63
	return result;
64
}
65
66
uint8_t MSXMultiIODevice::peekIO(uint16_t port, EmuTime time) const
67
{
68
	// conflict: Handle this in the same way as readIO.
69
	uint8_t result = 0xFF;
70
	for (const auto& dev : devices) {
71
		result &= dev->peekIO(port, time);
72
	}
73
	return result;
74
}
75
76
void MSXMultiIODevice::writeIO(uint16_t port, uint8_t value, EmuTime time)
77
{
78
	for (auto& dev : devices) {
79
		dev->writeIO(port, value, time);
80
	}
81
}
82
83
} // namespace openmsx