10[[nodiscard]]
static unsigned getRamSize(
const DeviceConfig& config)
12 int kSize = config.getChildDataAsInt(
"size", 0);
13 if ((kSize % 16) != 0) {
14 throw MSXException(
"Mapper size is not a multiple of 16K: ", kSize);
17 throw MSXException(
"Mapper size must be at least 16kB: ", kSize);
20 throw MSXException(
"Mapper size must not be larger than 4096kB: ", kSize);
28 , checkedRam(config, getName(),
"memory mapper", getRamSize(config))
29 , debuggable(getMotherBoard(), getName())
59 return registers[port & 0x03] |
byte(~(std::bit_ceil(numSegments) - 1));
65 registers[port & 3] = value &
byte(std::bit_ceil(numSegments) - 1);
73 segment = (segment < numSegments) ? segment : segment & (numSegments - 1);
74 return segment * 0x4000;
79 return segmentOffset(narrow<byte>(address / 0x4000)) | (address & 0x3fff);
111 const std::string& name_)
113 "Memory mapper registers", 4)
117byte MSXMemoryMapperBase::Debuggable::read(
unsigned address)
119 auto& mapper =
OUTER(MSXMemoryMapperBase, debuggable);
120 return mapper.registers[address];
123void MSXMemoryMapperBase::Debuggable::write(
unsigned address,
byte value)
125 auto& mapper =
OUTER(MSXMemoryMapperBase, debuggable);
126 mapper.writeIO(narrow<word>(address), value, EmuTime::dummy());
130template<
typename Archive>
133 ar.template serializeBase<MSXDevice>(*
this);
134 if (ar.versionAtLeast(version, 2)) {
byte * getWriteCacheLine(size_t addr)
Ram & getUncheckedRam()
Give access to the unchecked Ram.
void write(size_t addr, byte value)
byte peek(size_t addr) const
const byte * getReadCacheLine(size_t addr) const
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
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.
std::array< byte, 4 > registers
void serialize(Archive &ar, unsigned version)
byte * getWriteCacheLine(word start) override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
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.
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
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:
uint8_t byte
8 bit unsigned integer
uint16_t word
16 bit unsigned integer
constexpr void fill(ForwardRange &&range, const T &value)
#define OUTER(type, member)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)