12 [[nodiscard]]
static constexpr
bool isInside(
unsigned x,
unsigned start,
unsigned len)
14 unsigned tmp =
x - start;
18 [[nodiscard]]
static std::string toString(
unsigned start,
unsigned len)
20 return strCat(
"[0x", hex_string<4>(start),
", "
21 "0x", hex_string<4>(start + len),
')');
27 unsigned windowBase = 0x0000;
28 unsigned windowSize = 0x10000;
29 if (
const auto* mem = config.
findChild(
"mem")) {
30 windowBase = mem->getAttributeAsInt(
"base");
31 windowSize = mem->getAttributeAsInt(
"size");
35 if ((romSize > 0x10000) || (romSize & 0x1FFF)) {
37 ": invalid rom size: must be smaller than or equal to 64kB "
38 "and must be a multiple of 8kB.");
41 const int start = [&] {
60 unsigned romBase = (start == -1)
61 ? guessLocation(windowBase, windowSize)
64 (!isInside(romBase, windowBase, windowSize) ||
65 !isInside(romBase + romSize - 1, windowBase, windowSize))) {
70 ": invalid rom position: interval ",
71 toString(romBase, romSize),
" must fit in ",
72 toString(windowBase, windowSize),
'.');
74 if ((romBase & 0x1FFF)) {
76 ": invalid rom position: must start at a 8kB boundary.");
79 unsigned firstPage = romBase / 0x2000;
80 unsigned numPages = romSize / 0x2000;
81 for (
auto page :
xrange(8)) {
82 unsigned romPage = page - firstPage;
83 if (romPage < numPages) {
87 setRom(page, romPage & (numPages - 1));
110 void RomPlain::guessHelper(
unsigned offset,
int* pages)
112 if ((
rom[offset++] ==
'A') && (
rom[offset++] ==
'B')) {
113 for (
auto i :
xrange(4)) {
114 if (
word addr =
rom[offset + 2 * i + 0] +
115 rom[offset + 2 * i + 1] * 256) {
116 int page = (addr >> 14) - (offset >> 14);
117 if ((0 <= page) && (page <= 2)) {
125 unsigned RomPlain::guessLocation(
unsigned windowBase,
unsigned windowSize)
127 int pages[3] = { 0, 0, 0 };
131 guessHelper(0x0000, pages);
134 guessHelper(0x4000, pages);
138 if (!isInside(0x0000, windowBase, windowSize)) pages[0] = 0;
139 if (!isInside(0x4000, windowBase, windowSize)) pages[1] = 0;
140 if (!isInside(0x8000, windowBase, windowSize)) pages[2] = 0;
143 if (pages[1] && (pages[1] >= pages[0]) && (pages[1] >= pages[2])) {
145 }
else if (pages[0] && pages[0] >= pages[2]) {
147 }
else if (pages[2]) {
const XMLElement * findChild(std::string_view name) const
void invalidateDeviceRCache()
virtual unsigned getBaseSizeAlignment() const
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
unsigned getBaseSizeAlignment() const override
The 'base' and 'size' attribute values need to be at least aligned to CacheLine::SIZE.
RomPlain(const DeviceConfig &config, Rom &&rom, RomType type)
const std::string & getName() const
This file implemented 3 utility functions:
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
constexpr KeyMatrixPosition x
Keyboard bindings.
std::string strCat(Ts &&...ts)
constexpr auto xrange(T e)