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  byte getSelectedSegment(byte page) const override { return registers[page]; }
21 
22  unsigned getSizeInBlocks() { return checkedRam.getSize() / 0x4000; }
23 
24  void reset(EmuTime::param time) override;
25  void powerUp(EmuTime::param time) override;
26  byte readIO(word port, EmuTime::param time) override;
27  byte peekIO(word port, EmuTime::param time) const override;
28  byte readMem(word address, EmuTime::param time) override;
29  void writeMem(word address, byte value, EmuTime::param time) override;
30  const byte* getReadCacheLine(word start) const override;
31  byte* getWriteCacheLine(word start) const override;
32  byte peekMem(word address, EmuTime::param time) const override;
33  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  unsigned calcAddress(word address) const;
49  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  unsigned getRamSize() const;
58 
59  struct Debuggable final : SimpleDebuggable {
60  Debuggable(MSXMotherBoard& motherBoard, const std::string& name);
61  byte read(unsigned address) override;
62  void write(unsigned address, byte value) override;
63  } debuggable;
64 };
66 
67 REGISTER_BASE_NAME_HELPER(MSXMemoryMapperBase, "MemoryMapper"); // keep old name for bw-compat
68 
69 } // namespace openmsx
70 
71 #endif
openmsx::MSXMemoryMapperBase::checkedRam
CheckedRam checkedRam
Definition: MSXMemoryMapperBase.hh:53
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::MSXMemoryMapperBase::powerUp
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: MSXMemoryMapperBase.cc:35
openmsx::MSXMemoryMapperBase::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXMemoryMapperBase.cc:128
openmsx::CheckedRam::getSize
unsigned getSize() const
Definition: CheckedRam.hh:42
openmsx::MSXMemoryMapperBase::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: MSXMemoryMapperBase.cc:84
openmsx::MSXMemoryMapperBase::getReadCacheLine
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: MSXMemoryMapperBase.cc:94
openmsx::MSXMemoryMapperBase::calcAddress
unsigned calcAddress(word address) const
Converts a Z80 address to a RAM address.
Definition: MSXMemoryMapperBase.cc:74
openmsx::REGISTER_BASE_NAME_HELPER
REGISTER_BASE_NAME_HELPER(MSXFDC, "FDC")
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::SimpleDebuggable
Definition: SimpleDebuggable.hh:12
openmsx::MSXMemoryMapperBase::registers
byte registers[4]
Definition: MSXMemoryMapperBase.hh:54
openmsx::MSXMemoryMapperBase::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMemoryMapperBase.cc:53
openmsx::MSXMemoryMapperBase::MSXMemoryMapperBase
MSXMemoryMapperBase(const DeviceConfig &config)
Definition: MSXMemoryMapperBase.cc:22
openmsx::MSXMemoryMapperBase::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXMemoryMapperBase.cc:41
CheckedRam.hh
openmsx::MSXMemoryMapperBase::writeMem
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.
Definition: MSXMemoryMapperBase.cc:89
openmsx::MSXMemoryMapperBase::getSizeInBlocks
unsigned getSizeInBlocks()
Definition: MSXMemoryMapperBase.hh:22
MSXMapperIO.hh
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::MSXMemoryMapperBase::writeIO
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.
openmsx::MSXMemoryMapperBase::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: MSXMemoryMapperBase.cc:79
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:60
MSXDevice.hh
openmsx::MSXMemoryMapperBase::getBaseSizeAlignment
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
Definition: MSXMemoryMapperBase.cc:30
openmsx::MSXMemoryMapperBase::getSelectedSegment
byte getSelectedSegment(byte page) const override
Returns the currently selected segment for the given page.
Definition: MSXMemoryMapperBase.hh:20
SimpleDebuggable.hh
openmsx::MSXMemoryMapperBase::writeIOImpl
void writeIOImpl(word port, byte value, EmuTime::param time)
Definition: MSXMemoryMapperBase.cc:59
openmsx::MSXMemoryMapperBase::getWriteCacheLine
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: MSXMemoryMapperBase.cc:99
openmsx::CheckedRam
This class keeps track of which bytes in the Ram have been written to.
Definition: CheckedRam.hh:28
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXMapperIOClient
Definition: MSXMapperIO.hh:56
openmsx::MSXMemoryMapperBase
Definition: MSXMemoryMapperBase.hh:12
openmsx::MSXMemoryMapperBase::segmentOffset
unsigned segmentOffset(byte page) const
Definition: MSXMemoryMapperBase.cc:66
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MSXMemoryMapperBase::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXMemoryMapperBase.cc:48