37[[nodiscard]]
static unsigned getNumBlocks(
const DeviceConfig& config)
39 int size = config.getChildDataAsInt(
"size", 0);
40 if (
auto err = [&]() ->
const char* {
41 if (
size < 0)
return "Cannot be negative.";
42 if (
size > (8 * 256))
return "Cannot be larger than 2048.";
43 if ((
size % 8) != 0)
return "Must be a multiple of 8.";
46 throw MSXException(
"Invalid MegaRam size: ",
size,
". ", err);
53 , numBlocks(getNumBlocks(config))
54 , ram(config, getName() +
" RAM",
"Mega-RAM", numBlocks * 0x2000)
55 , rom(config.findChild(
"rom")
56 ?
std::make_unique<
Rom>(getName() +
" ROM",
"Mega-RAM DiskROM", config)
58 , romBlockDebug(*this, bank, 0x0000, 0x10000, 13, 0, 3)
68 for (
auto i :
xrange(
byte(4))) {
79 romMode = rom !=
nullptr;
90 if (address >= 0x4000 && address <= 0xBFFF) {
91 return &(*rom)[address - 0x4000];
95 unsigned block = bank[(address & 0x7FFF) / 0x2000];
96 return (block < numBlocks)
97 ? &ram[(block * 0x2000) + (address & 0x1FFF)]
106 assert(!romMode && !writeMode);
107 setBank(narrow<byte>((address & 0x7FFF) / 0x2000), value);
115 unsigned block = bank[(address & 0x7FFF) / 0x2000];
116 return (block < numBlocks)
117 ?
const_cast<byte*
>(&ram[(block * 0x2000) + (address & 0x1FFF)])
133 if (rom) romMode =
true;
154 if (rom) romMode =
true;
160void MSXMegaRam::setBank(
byte page,
byte block)
162 bank[page] = block & maskBlocks;
163 word adr = page * 0x2000;
168template<
typename Archive>
171 ar.template serializeBase<MSXDevice>(*
this);
172 ar.serialize(
"ram", ram,
174 "writeMode", writeMode,
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
static std::array< byte, 0x10000 > unmappedRead
static std::array< byte, 0x10000 > unmappedWrite
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
void reset(EmuTime::param time) override
This method is called on reset.
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
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 * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void serialize(Archive &ar, unsigned version)
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
MSXMegaRam(const DeviceConfig &config)
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
This file implemented 3 utility functions:
uint8_t byte
8 bit unsigned integer
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
size_t size(std::string_view utf8)
constexpr To narrow(From from) noexcept
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr auto xrange(T e)