18[[nodiscard]]
static byte calcReadBackMask(MSXMotherBoard& motherBoard)
20 std::string_view type = motherBoard.getMachineConfig()->getConfig().getChildData(
21 "MapperReadBackBits",
"largest");
22 if (type ==
"largest") {
25 auto bits = StringOp::stringTo<int>(type);
27 throw FatalError(
"Unknown mapper type: \"", type,
"\".");
29 if (*bits < 0 || *bits > 8) {
30 throw FatalError(
"MapperReadBackBits out of range: \"", type,
"\".");
32 return byte(~(
unsigned(-1) << *bits));
37 , debuggable(getMotherBoard(), getName())
38 , mask(calcReadBackMask(getMotherBoard()))
40 reset(EmuTime::dummy());
47 baseValue = baseValue_;
52 mappers.push_back(mapper);
65 for (
auto* mapper : mappers) {
66 result &= mapper->readIO(port, time);
70 return registers[port & 3];
73 return (value & mask) | (baseValue & ~mask);
81 for (
const auto* mapper : mappers) {
82 result &= mapper->peekIO(port, time);
86 return registers[port & 3];
89 return (value & mask) | (baseValue & ~mask);
94 registers[port & 3] = value;
98 for (
auto* mapper : mappers) {
99 mapper->writeIO(port, value, time);
109 const std::string& name_)
114byte MSXMapperIO::Debuggable::read(
unsigned address)
117 auto& mapperIO =
OUTER(MSXMapperIO, debuggable);
118 return mapperIO.registers[address & 3];
121void MSXMapperIO::Debuggable::write(
unsigned address,
byte value,
124 auto& mapperIO =
OUTER(MSXMapperIO, debuggable);
125 mapperIO.writeIO(narrow_cast<word>(address), value, time);
129template<
typename Archive>
132 if (ar.versionBelow(version, 2)) {
135 assert(Archive::IS_LOADER);
136 ar.serialize(
"registers", registers);
137 for (
auto [page, reg] :
enumerate(registers)) {
141 if (ar.versionAtLeast(version, 3)) {
148 ar.serialize(
"registers", registers);
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
virtual void reset(EmuTime::param time)
This method is called on reset.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void registerMapper(MSXMemoryMapperInterface *mapper)
MSXMapperIO(const DeviceConfig &config)
void serialize(Archive &ar, unsigned version)
void unregisterMapper(MSXMemoryMapperInterface *mapper)
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.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void setMode(Mode mode, byte mask, byte baseValue)
constexpr auto enumerate(Iterable &&iterable)
Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta....
This file implemented 3 utility functions:
uint8_t byte
8 bit unsigned integer
uint16_t word
16 bit unsigned integer
#define OUTER(type, member)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.