OXYGENHUB
◆ main openmsx / src / memory / MSXMemoryMapperBase.hh
2.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MSXMEMORYMAPPERBASE_HH
2
#define MSXMEMORYMAPPERBASE_HH
3
4
#include "CheckedRam.hh"
5
6
#include "MSXDevice.hh"
7
#include "MSXMapperIO.hh"
8
#include "SimpleDebuggable.hh"
9
10
#include "narrow.hh"
11
12
#include <array>
13
14
namespace openmsx {
15
16
class MSXMemoryMapperBase : public MSXDevice, public MSXMapperIOClient
17
{
18
public:
19
	explicit MSXMemoryMapperBase(const DeviceConfig& config);
20
21
	/**
22
	 * Returns the currently selected segment for the given page.
23
	 * @param page Z80 address page (0-3).
24
	 */
25
	[[nodiscard]] byte getSelectedSegment(byte page) const override { return registers[page]; }
26
27
	[[nodiscard]] unsigned getSizeInBlocks() const {
28
		return narrow<unsigned>(checkedRam.size() / 0x4000);
29
	}
30
31
	void reset(EmuTime time) override;
32
	void powerUp(EmuTime time) override;
33
	[[nodiscard]] byte readIO(uint16_t port, EmuTime time) override;
34
	[[nodiscard]] byte peekIO(uint16_t port, EmuTime time) const override;
35
	[[nodiscard]] byte readMem(uint16_t address, EmuTime time) override;
36
	void writeMem(uint16_t address, byte value, EmuTime time) override;
37
	[[nodiscard]] const byte* getReadCacheLine(uint16_t start) const override;
38
	[[nodiscard]] byte* getWriteCacheLine(uint16_t start) override;
39
	[[nodiscard]] byte peekMem(uint16_t address, EmuTime time) const override;
40
	[[nodiscard]] unsigned getBaseSizeAlignment() const override;
41
42
	// Subclasses _must_ override this method and
43
	//  - call MSXMemoryMapperBase::writeIOImpl()
44
	//  - handle CPU cacheline stuff (e.g. invalidate)
45
	void writeIO(uint16_t port, byte value, EmuTime time) override = 0;
46
47
	template<typename Archive>
48
	void serialize(Archive& ar, unsigned version);
49
50
protected:
51
	/** Converts a Z80 address to a RAM address.
52
	  * @param address Index in Z80 address space.
53
	  * @return Index in RAM address space.
54
	  */
55
	[[nodiscard]] unsigned calcAddress(uint16_t address) const;
56
	[[nodiscard]] unsigned segmentOffset(byte page) const;
57
58
	void writeIOImpl(uint16_t port, byte value, EmuTime time);
59
60
	CheckedRam checkedRam;
61
	std::array<byte, 4> registers;
62
63
private:
64
	struct Debuggable final : SimpleDebuggable {
65
		Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
66
		[[nodiscard]] byte read(unsigned address) override;
67
		void write(unsigned address, byte value) override;
68
		void readBlock(unsigned start, std::span<byte> output) override;
69
	} debuggable;
70
};
71
SERIALIZE_CLASS_VERSION(MSXMemoryMapperBase, 2);
72
73
REGISTER_BASE_NAME_HELPER(MSXMemoryMapperBase, "MemoryMapper"); // keep old name for bw-compat
74
75
} // namespace openmsx
76
77
#endif