53static constexpr byte SPC = 0x7F;
55size_t MegaSCSI::getSramSize()
const
58 if (sramSize !=
one_of(1024u, 512u, 256u, 128u)) {
61 " should be 128, 256, 512 or 1024kB and not ",
64 return sramSize * 1024;
70 , sram(getName() +
" SRAM", getSramSize(), config)
71 , romBlockDebug(*this, mapped, 0x4000, 0x8000, 13)
72 , blockMask(
narrow<
byte>((sram.size() / 0x2000) - 1))
86 if ((0x4000 <= address) && (address < 0xC000)) {
87 unsigned page = (address / 0x2000) - 2;
88 word addr = address & 0x1FFF;
89 if (mapped[page] == SPC) {
98 return sram[0x2000 * mapped[page] + addr];
111 if (address < 0x1000) {
121 if ((0x4000 <= address) && (address < 0xC000)) {
122 unsigned page = (address / 0x2000) - 2;
124 if (mapped[page] == SPC) {
127 return &sram[0x2000 * mapped[page] + address];
136 if ((0x6000 <= address) && (address < 0x8000)) {
137 byte region = ((address >> 11) & 3);
138 setSRAM(region, value);
139 }
else if ((0x4000 <= address) && (address < 0xC000)) {
140 unsigned page = (address / 0x2000) - 2;
142 if (mapped[page] == SPC) {
143 if (address < 0x1000) {
148 }
else if (isWriteable[page]) {
149 sram.
write(0x2000 * mapped[page] + address, value);
156 if ((0x6000 <= address) && (address < 0x8000)) {
158 }
else if ((0x4000 <= address) && (address < 0xC000)) {
159 unsigned page = (address / 0x2000) - 2;
160 if (mapped[page] == SPC) {
162 }
else if (isWriteable[page]) {
169void MegaSCSI::setSRAM(
unsigned region,
byte block)
173 isWriteable[region] = (block & 0x80) != 0;
174 mapped[region] = ((block & 0xC0) == 0x40) ? 0x7F : (block & blockMask);
177template<
typename Archive>
180 ar.serialize(
"SRAM", sram,
182 "isWriteable", isWriteable,
#define REGISTER_MSXDEVICE(CLASS, NAME)
uint8_t peekRegister(uint8_t reg) const
void reset(bool scsiReset)
void writeRegister(uint8_t reg, uint8_t value)
uint8_t readRegister(uint8_t reg)
void writeDREG(uint8_t value)
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
static std::array< byte, 0x10000 > unmappedRead
virtual const std::string & getName() const
Returns a human-readable name for this device.
static std::array< byte, 0x10000 > unmappedWrite
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
const XMLElement & getDeviceConfig() const
Get the configuration section for this device.
byte * getWriteCacheLine(word address) override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
void serialize(Archive &ar, unsigned version)
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
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.
MegaSCSI(const DeviceConfig &config)
void reset(EmuTime::param time) override
This method is called on reset.
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
void write(size_t addr, byte value)
int getChildDataAsInt(std::string_view childName, int defaultValue) const
This file implemented 3 utility functions:
uint8_t byte
8 bit unsigned integer
uint16_t word
16 bit unsigned integer
constexpr To narrow(From from) noexcept
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr auto xrange(T e)