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 
9 namespace openmsx {
10 
12 {
13 public:
14  explicit MSXMemoryMapperBase(const DeviceConfig& config);
15 
20  [[nodiscard]] byte getSelectedSegment(byte page) const override { return registers[page]; }
21 
22  [[nodiscard]] unsigned getSizeInBlocks() { return checkedRam.getSize() / 0x4000; }
23 
24  void reset(EmuTime::param time) override;
25  void powerUp(EmuTime::param time) override;
26  [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
27  [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
28  [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
29  void writeMem(word address, byte value, EmuTime::param time) override;
30  [[nodiscard]] const byte* getReadCacheLine(word start) const override;
31  [[nodiscard]] byte* getWriteCacheLine(word start) const override;
32  [[nodiscard]] byte peekMem(word address, EmuTime::param time) const override;
33  [[nodiscard]] unsigned getBaseSizeAlignment() const override;
34 
35  // Subclasses _must_ override this method and
36  // - call MSXMemoryMapperBase::writeIOImpl()
37  // - handle CPU cacheline stuff (e.g. invalidate)
38  void writeIO(word port, byte value, EmuTime::param time) override = 0;
39 
40  template<typename Archive>
41  void serialize(Archive& ar, unsigned version);
42 
43 protected:
48  [[nodiscard]] unsigned calcAddress(word address) const;
49  [[nodiscard]] unsigned segmentOffset(byte page) const;
50 
51  void writeIOImpl(word port, byte value, EmuTime::param time);
52 
54  byte registers[4];
55 
56 private:
57  struct Debuggable final : SimpleDebuggable {
58  Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
59  [[nodiscard]] byte read(unsigned address) override;
60  void write(unsigned address, byte value) override;
61  } debuggable;
62 };
64 
65 REGISTER_BASE_NAME_HELPER(MSXMemoryMapperBase, "MemoryMapper"); // keep old name for bw-compat
66 
67 } // namespace openmsx
68 
69 #endif
This class keeps track of which bytes in the Ram have been written to.
Definition: CheckedRam.hh:28
unsigned getSize() const
Definition: CheckedRam.hh:42
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:33
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.
MSXMemoryMapperBase(const DeviceConfig &config)
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
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
REGISTER_BASE_NAME_HELPER(MSXFDC, "FDC")