openMSX
MSXMultiIODevice.cc
Go to the documentation of this file.
1#include "MSXMultiIODevice.hh"
2#include "MSXException.hh"
3#include "TclObject.hh"
4#include "stl.hh"
5#include <cassert>
6
7namespace openmsx {
8
13
15{
16 assert(devices.empty());
17}
18
20{
21 if (contains(devices, device)) {
22 throw MSXException(
23 "Overlapping IO-port ranges for \"",
24 device->getName(), "\".");
25 }
26 devices.push_back(device);
27}
28
30{
31 devices.erase(rfind_unguarded(devices, device));
32}
33
34const std::string& MSXMultiIODevice::getName() const
35{
36 TclObject list;
37 getNameList(list);
38 const_cast<std::string&>(deviceName) = list.getString();
39 return deviceName;
40}
42{
43 for (auto* dev : devices) {
44 const auto& name = dev->getName();
45 if (!name.empty()) {
46 result.addListElement(name);
47 }
48 }
49}
50
51byte MSXMultiIODevice::readIO(word port, EmuTime::param time)
52{
53 // conflict: In practice, pull down seems to win over pull up,
54 // so a logical AND over the read values most accurately
55 // resembles what real hardware does.
56 byte result = 0xFF;
57 for (auto& dev : devices) {
58 result &= dev->readIO(port, time);
59 }
60 return result;
61}
62
63byte MSXMultiIODevice::peekIO(word port, EmuTime::param time) const
64{
65 // conflict: Handle this in the same way as readIO.
66 byte result = 0xFF;
67 for (const auto& dev : devices) {
68 result &= dev->peekIO(port, time);
69 }
70 return result;
71}
72
73void MSXMultiIODevice::writeIO(word port, byte value, EmuTime::param time)
74{
75 for (auto& dev : devices) {
76 dev->writeIO(port, value, time);
77 }
78}
79
80} // namespace openmsx
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
std::string deviceName
Definition MSXDevice.hh:324
virtual const std::string & getName() const
Returns a human-readable name for this device.
Definition MSXDevice.cc:375
void addDevice(MSXDevice *device)
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void getNameList(TclObject &result) const override
Returns list of name(s) of this device.
void removeDevice(MSXDevice *device)
MSXMultiIODevice(const HardwareConfig &hwConf)
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
const std::string & getName() const override
Returns a human-readable name for this device.
void addListElement(const T &t)
Definition TclObject.hh:127
zstring_view getString() const
Definition TclObject.cc:142
This file implemented 3 utility functions:
Definition Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.
Definition stl.hh:109
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
Definition stl.hh:32