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
MSXMultiMemDevice(const HardwareConfig &hwConf)
std::string getName() const override
Returns a human-readable name for this device.
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
size_t size(std::string_view utf8)
void add(MSXDevice &device, int base, int size)
void getNameList(TclObject &result) const override
Returns list of name(s) of this device.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
constexpr bool operator==(const uint128 &a, const uint128 &b)
Definition: uint128.hh:241
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
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
std::vector< MSXDevice * > getDevices() const
Definition: ranges.hh:20
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading...
bool canAdd(int base, int size)
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.