openMSX
MSXMemoryMapperBase.hh
Go to the documentation of this file.
1#ifndef MSXMEMORYMAPPERBASE_HH
2#define MSXMEMORYMAPPERBASE_HH
3
4#include "MSXDevice.hh"
5#include "MSXMapperIO.hh"
6#include "CheckedRam.hh"
7#include "SimpleDebuggable.hh"
8#include "narrow.hh"
9#include <array>
10
11namespace openmsx {
12
14{
15public:
16 explicit MSXMemoryMapperBase(const DeviceConfig& config);
17
22 [[nodiscard]] byte getSelectedSegment(byte page) const override { return registers[page]; }
23
24 [[nodiscard]] unsigned getSizeInBlocks() const {
25 return narrow<unsigned>(checkedRam.size() / 0x4000);
26 }
27
28 void reset(EmuTime::param time) override;
29 void powerUp(EmuTime::param time) override;
30 [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
31 [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
32 [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
33 void writeMem(word address, byte value, EmuTime::param time) override;
34 [[nodiscard]] const byte* getReadCacheLine(word start) const override;
35 [[nodiscard]] byte* getWriteCacheLine(word start) const override;
36 [[nodiscard]] byte peekMem(word address, EmuTime::param time) const override;
37 [[nodiscard]] unsigned getBaseSizeAlignment() const override;
38
39 // Subclasses _must_ override this method and
40 // - call MSXMemoryMapperBase::writeIOImpl()
41 // - handle CPU cacheline stuff (e.g. invalidate)
42 void writeIO(word port, byte value, EmuTime::param time) override = 0;
43
44 template<typename Archive>
45 void serialize(Archive& ar, unsigned version);
46
47protected:
52 [[nodiscard]] unsigned calcAddress(word address) const;
53 [[nodiscard]] unsigned segmentOffset(byte page) const;
54
55 void writeIOImpl(word port, byte value, EmuTime::param time);
56
58 std::array<byte, 4> registers;
59
60private:
61 struct Debuggable final : SimpleDebuggable {
62 Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
63 [[nodiscard]] byte read(unsigned address) override;
64 void write(unsigned address, byte value) override;
65 } debuggable;
66};
68
69REGISTER_BASE_NAME_HELPER(MSXMemoryMapperBase, "MemoryMapper"); // keep old name for bw-compat
70
71} // namespace openmsx
72
73#endif
This class keeps track of which bytes in the Ram have been written to.
Definition CheckedRam.hh:28
size_t size() const
Definition CheckedRam.hh:42
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
unsigned calcAddress(word address) const
Converts a Z80 address to a RAM address.
void writeIOImpl(word port, byte value, EmuTime::param time)
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
void serialize(Archive &ar, unsigned version)
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.
byte getSelectedSegment(byte page) const override
Returns the currently selected segment for the given page.
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
void writeIO(word port, byte value, EmuTime::param time) override=0
Write a byte to a given IO port at a certain time to this device.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
unsigned segmentOffset(byte page) const
void reset(EmuTime::param time) override
This method is called on reset.
This file implemented 3 utility functions:
Definition Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define REGISTER_BASE_NAME_HELPER(B, N)
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)