OXYGENHUB
◆ main openmsx / src / cpu / MSXMultiMemDevice.hh
1.9 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MSXMULTIMEMDEVICE_HH
2
#define MSXMULTIMEMDEVICE_HH
3
4
#include "MSXMultiDevice.hh"
5
#include <span>
6
#include <vector>
7
8
namespace openmsx {
9
10
class MSXMultiMemDevice final : public MSXMultiDevice
11
{
12
public:
13
	struct Range {
14
		Range(unsigned base_, unsigned size_, MSXDevice& device_);
15
		[[nodiscard]] constexpr bool operator==(const Range&) const = default;
16
17
		unsigned base;
18
		unsigned size;
19
		MSXDevice* device;
20
	};
21
22
public:
23
	explicit MSXMultiMemDevice(HardwareConfig& hwConf);
24
	~MSXMultiMemDevice() override;
25
26
	[[nodiscard]] bool canAdd(unsigned base, unsigned size);
27
	void add(MSXDevice& device, unsigned base, unsigned size);
28
	void remove(MSXDevice& device, unsigned base, unsigned size);
29
	[[nodiscard]] bool empty() const { return ranges.size() == 1; }
30
	[[nodiscard]] std::vector<MSXDevice*> getDevices() const;
31
32
	/** The address ranges actually in use, in no particular order.
33
	  * The sentinel is not included. */
34
	[[nodiscard]] std::span<const Range> getRanges() const {
35
		return {ranges.data(), ranges.size() - 1};
36
	}
37
38
	// MSXDevice
39
	[[nodiscard]] const std::string& getName() const override;
40
	void getNameList(TclObject& result) const override;
41
	[[nodiscard]] uint8_t readMem(uint16_t address, EmuTime time) override;
42
	[[nodiscard]] uint8_t peekMem(uint16_t address, EmuTime time) const override;
43
	void writeMem(uint16_t address, uint8_t value, EmuTime time) override;
44
	[[nodiscard]] const uint8_t* getReadCacheLine(uint16_t start) const override;
45
	[[nodiscard]] uint8_t* getWriteCacheLine(uint16_t start) override;
46
47
private:
48
	[[nodiscard]] const Range& searchRange(unsigned address) const;
49
	[[nodiscard]] MSXDevice* searchDevice(unsigned address) const;
50
51
	// In no particular order, except that the sentinel is at the back: it
52
	// covers the whole address space, so searching front-to-back finds the
53
	// real ranges first and always finds something.
54
	std::vector<Range> ranges;
55
};
56
57
} // namespace openmsx
58
59
#endif