openMSX
MSXMultiMemDevice.hh
Go to the documentation of this file.
1 #ifndef MSXMULTIMEMDEVICE_HH
2 #define MSXMULTIMEMDEVICE_HH
3 
4 #include "MSXMultiDevice.hh"
5 #include <vector>
6 
7 namespace openmsx {
8 
9 class MSXMultiMemDevice final : public MSXMultiDevice
10 {
11 public:
12  explicit MSXMultiMemDevice(const HardwareConfig& hwConf);
13  ~MSXMultiMemDevice() override;
14 
15  bool canAdd(int base, int size);
16  void add(MSXDevice& device, int base, int size);
17  void remove(MSXDevice& device, int base, int size);
18  bool empty() const { return ranges.size() == 1; }
19  std::vector<MSXDevice*> getDevices() const;
20 
21  // MSXDevice
22  std::string getName() const override;
23  void getNameList(TclObject& result) const override;
24  byte readMem(word address, EmuTime::param time) override;
25  byte peekMem(word address, EmuTime::param time) const override;
26  void writeMem(word address, byte value, EmuTime::param time) override;
27  const byte* getReadCacheLine(word start) const override;
28  byte* getWriteCacheLine(word start) const override;
29 
30 private:
31  struct Range {
32  Range(unsigned base_, unsigned size_, MSXDevice& device_);
33  bool operator==(const Range& other) const;
34 
35  unsigned base;
36  unsigned size;
37  MSXDevice* device;
38  };
39 
40  const Range& searchRange(unsigned address) const;
41  MSXDevice* searchDevice(unsigned address) const;
42 
43  std::vector<Range> ranges; // ordered (sentinel at the back)
44 };
45 
46 } // namespace openmsx
47 
48 #endif
openmsx::MSXMultiMemDevice::writeMem
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition: MSXMultiMemDevice.cc:117
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:31
openmsx::MSXDevice::MSXDevice
MSXDevice(const MSXDevice &)=delete
openmsx::MSXMultiMemDevice::~MSXMultiMemDevice
~MSXMultiMemDevice() override
Definition: MSXMultiMemDevice.cc:35
openmsx::MSXMultiMemDevice::empty
bool empty() const
Definition: MSXMultiMemDevice.hh:18
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
openmsx::MSXMultiMemDevice::getWriteCacheLine
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: MSXMultiMemDevice.cc:137
openmsx::MSXMultiDevice
Definition: MSXMultiDevice.hh:8
ranges
Definition: ranges.hh:20
openmsx::MSXMultiMemDevice::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: MSXMultiMemDevice.cc:112
MSXMultiDevice.hh
openmsx::MSXMultiMemDevice::MSXMultiMemDevice
MSXMultiMemDevice(const HardwareConfig &hwConf)
Definition: MSXMultiMemDevice.cc:28
openmsx::MSXMultiMemDevice::remove
void remove(MSXDevice &device, int base, int size)
Definition: MSXMultiMemDevice.cc:65
openmsx::MSXMultiMemDevice::add
void add(MSXDevice &device, int base, int size)
Definition: MSXMultiMemDevice.cc:59
openmsx::MSXMultiMemDevice::getNameList
void getNameList(TclObject &result) const override
Returns list of name(s) of this device.
Definition: MSXMultiMemDevice.cc:82
openmsx::MSXMultiMemDevice::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: MSXMultiMemDevice.cc:107
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
operator==
constexpr bool operator==(const uint128 &a, const uint128 &b)
Definition: uint128.hh:238
openmsx::MSXMultiMemDevice::getReadCacheLine
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: MSXMultiMemDevice.cc:122
openmsx::HardwareConfig
Definition: HardwareConfig.hh:21
openmsx::TclObject
Definition: TclObject.hh:21
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::MSXMultiMemDevice
Definition: MSXMultiMemDevice.hh:9
openmsx::MSXMultiMemDevice::canAdd
bool canAdd(int base, int size)
Definition: MSXMultiMemDevice.cc:52
openmsx::MSXMultiMemDevice::getName
std::string getName() const override
Returns a human-readable name for this device.
Definition: MSXMultiMemDevice.cc:76
openmsx::MSXMultiMemDevice::getDevices
std::vector< MSXDevice * > getDevices() const
Definition: MSXMultiMemDevice.cc:70