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 
7 namespace openmsx {
8 
10  : MSXMultiDevice(hwConf)
11 {
12 }
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 
34 std::string MSXMultiIODevice::getName() const
35 {
36  TclObject list;
37  getNameList(list);
38  return std::string(list.getString());
39 }
41 {
42  for (auto* dev : devices) {
43  const auto& name = dev->getName();
44  if (!name.empty()) {
45  result.addListElement(name);
46  }
47  }
48 }
49 
50 byte MSXMultiIODevice::readIO(word port, EmuTime::param time)
51 {
52  // conflict: In practice, pull down seems to win over pull up,
53  // so a logical AND over the read values most accurately
54  // resembles what real hardware does.
55  byte result = 0xFF;
56  for (auto& dev : devices) {
57  result &= dev->readIO(port, time);
58  }
59  return result;
60 }
61 
62 byte MSXMultiIODevice::peekIO(word port, EmuTime::param time) const
63 {
64  // conflict: Handle this in the same way as readIO.
65  byte result = 0xFF;
66  for (auto& dev : devices) {
67  result &= dev->peekIO(port, time);
68  }
69  return result;
70 }
71 
72 void MSXMultiIODevice::writeIO(word port, byte value, EmuTime::param time)
73 {
74  for (auto& dev : devices) {
75  dev->writeIO(port, value, time);
76  }
77 }
78 
79 } // namespace openmsx
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.
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
Definition: stl.hh:92
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:379
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void removeDevice(MSXDevice *device)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
std::string_view getString() const
Definition: TclObject.cc:102
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
void addListElement(T t)
Definition: TclObject.hh:121
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
MSXMultiIODevice(const HardwareConfig &hwConf)
void addDevice(MSXDevice *device)
std::string getName() const override
Returns a human-readable name for this device.
auto rfind_unguarded(RANGE &range, const VAL &val)
Similar to the find(_if)_unguarded functions above, but searches from the back to front...
Definition: stl.hh:152
void getNameList(TclObject &result) const override
Returns list of name(s) of this device.