13static Sha1Sum alreadyWarnedForSha1Sum;
15template<
unsigned BANK_SIZE>
18 unsigned debugBankSizeShift)
21 *this, blockNr, 0x0000, 0x10000,
22 std::bit_width(BANK_SIZE) - 1, debugBankSizeShift)
24 static_assert(std::has_single_bit(
BANK_SIZE),
"BANK_SIZE must be a power of two");
28 "(uncompressed) ROM image filesize was not a multiple "
29 "of ",
BANK_SIZE / 1024,
"kB (which is required for mapper type ",
31 "padded it to be correct. But if the ROM you are "
32 "running was just dumped, the dump is probably not "
44 blockMask = nrBlocks - 1;
50template<
unsigned BANK_SIZE>
53template<
unsigned BANK_SIZE>
59template<
unsigned BANK_SIZE>
62 return bankPtr[address / BANK_SIZE][address & BANK_MASK];
65template<
unsigned BANK_SIZE>
71template<
unsigned BANK_SIZE>
74 return &bankPtr[address / BANK_SIZE][address & BANK_MASK];
77template<
unsigned BANK_SIZE>
80 assert(
"address passed to setBank() is not serializable" &&
81 ((adr == unmappedRead.data()) ||
82 ((&rom[0] <= adr) && (adr <= &rom[rom.size() - 1])) ||
83 (sram && (&(*sram)[0] <= adr) &&
84 (adr <= &(*sram)[sram->size() - 1])) ||
85 (!extraMem.empty() && (&extraMem.front() <= adr) && (adr <= &extraMem.back()))));
86 bankPtr[region] = adr;
87 blockNr[region] = block;
88 fillDeviceRCache(region * BANK_SIZE, BANK_SIZE, adr);
91template<
unsigned BANK_SIZE>
94 setBank(region, unmappedRead.data(), 255);
97template<
unsigned BANK_SIZE>
103template<
unsigned BANK_SIZE>
108 block = (block < nrBlocks) ? block : block & blockMask;
109 if (block < nrBlocks) {
110 setBank(region, &rom[block * BANK_SIZE],
111 narrow_cast<byte>(block));
113 setBank(region, unmappedRead.data(), 255);
119template<
unsigned BANK_SIZE>
120template<
typename Archive>
124 ar.template serializeBase<MSXDevice>(*
this);
126 if (sram) ar.serialize(
"sram", *sram);
128 std::array<size_t, NUM_BANKS> offsets;
129 auto romSize = rom.size();
130 auto sramSize = sram ? sram->size() : 0;
131 if constexpr (Archive::IS_LOADER) {
132 ar.serialize(
"banks", offsets);
133 for (
auto i :
xrange(NUM_BANKS)) {
134 if (offsets[i] ==
size_t(-1) ||
135 offsets[i] == unsigned(-1)) {
136 bankPtr[i] = unmappedRead.data();
137 }
else if (offsets[i] < romSize) {
138 bankPtr[i] = &rom[offsets[i]];
139 }
else if (offsets[i] < (romSize + sramSize)) {
141 bankPtr[i] = &(*sram)[offsets[i] - romSize];
142 }
else if (offsets[i] < (romSize + sramSize + extraMem.size())) {
143 bankPtr[i] = &extraMem[offsets[i] - romSize - sramSize];
150 for (
auto i :
xrange(NUM_BANKS)) {
151 if (bankPtr[i] == unmappedRead.data()) {
152 offsets[i] = size_t(-1);
153 }
else if ((&rom[0] <= bankPtr[i]) &&
154 (bankPtr[i] <= &rom[romSize - 1])) {
155 offsets[i] = size_t(bankPtr[i] - &rom[0]);
156 }
else if (sram && (&(*sram)[0] <= bankPtr[i]) &&
157 (bankPtr[i] <= &(*sram)[sramSize - 1])) {
158 offsets[i] = size_t(bankPtr[i] - &(*sram)[0] + romSize);
159 }
else if (!extraMem.empty() &&
160 (&extraMem.front() <= bankPtr[i]) &&
161 (bankPtr[i] <= &extraMem.back())) {
162 offsets[i] = size_t(bankPtr[i] - extraMem.data() + romSize + sramSize);
167 ar.serialize(
"banks", offsets);
void printWarning(std::string_view message)
MSXCliComm & getCliComm() const
const XMLElement * findChild(std::string_view name) const
void setBank(unsigned region, const byte *adr, byte block)
Sets the memory visible for reading in a certain region.
void setUnmapped(unsigned region)
Select 'unmapped' memory for this region.
void setExtraMemory(std::span< const byte > mem)
Inform this base class of extra mappable memory block.
RomBlocks(const DeviceConfig &config, Rom &&rom, unsigned debugBankSizeShift=0)
Constructor.
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
static constexpr unsigned NUM_BANKS
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
void setRom(unsigned region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
void serialize(Archive &ar, unsigned version)
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
static constexpr unsigned BANK_SIZE
const Sha1Sum & getOriginalSHA1() const
void addPadding(size_t newSize, byte filler=0xff)
std::string_view getData() const
This file implemented 3 utility functions:
uint16_t word
16 bit unsigned integer
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr auto xrange(T e)