60 , flash(rom, AmdFlashChip::M29W640GB, {}, config)
67 powerUp(getCurrentTime());
68 auto& cpuInterface = getCPUInterface();
69 for (
auto port : {0x10, 0x11, 0x31, 0x33, 0xA0, 0xA1}) {
70 cpuInterface.register_IO_Out(narrow_cast<byte>(port),
this);
77 for (
auto port : {0x10, 0x11, 0x31, 0x33, 0xA0, 0xA1}) {
78 cpuInterface.unregister_IO_Out(narrow_cast<byte>(port),
this);
90 flashRomWriteEnabled =
false;
108unsigned ReproCartridgeV2::getFlashAddr(
unsigned addr)
const
110 unsigned page8kB = (addr >> 13) - 2;
111 if (page8kB >= 4)
return unsigned(-1);
113 byte bank = bankRegs[page8kB] & 127;
114 return (mainBankReg << 20) | (bank << 13) | (addr & 0x1FFF);
118bool ReproCartridgeV2::isSCCAccess(
word addr)
const
120 if ((mapperTypeReg != 0) || (sccMode & 0x10))
return false;
130 if (sccMode & 0x20) {
132 return (bankRegs[3] & 0x80) && (0xB800 <= addr) && (addr < 0xBFFE);
135 return ((bankRegs[2] & 0x3F) == 0x3F) && (0x9800 <= addr) && (addr < 0x9FFE);
141 if (isSCCAccess(addr)) {
142 return scc.
readMem(narrow_cast<uint8_t>(addr & 0xFF), time);
145 unsigned flashAddr = getFlashAddr(addr);
146 return (flashAddr !=
unsigned(-1))
147 ? flash.
read(flashAddr)
153 if (isSCCAccess(addr)) {
154 return scc.
peekMem(narrow_cast<uint8_t>(addr & 0xFF), time);
157 unsigned flashAddr = getFlashAddr(addr);
158 return (flashAddr !=
unsigned(-1))
159 ? flash.
peek(flashAddr)
165 if (isSCCAccess(addr))
return nullptr;
167 unsigned flashAddr = getFlashAddr(addr);
168 return (flashAddr !=
unsigned(-1))
175 unsigned page8kB = (addr >> 13) - 2;
176 if (page8kB >= 4)
return;
185 if (isSCCAccess(addr)) {
186 scc.
writeMem(narrow_cast<uint8_t>(addr & 0xFF), value, time);
191 unsigned flashAddr = getFlashAddr(addr);
194 if (addr == 0x7FFF) {
195 flashRomWriteEnabled = (value == 0x50);
199 if (addr == 0x7FFE) {
200 mapperTypeReg = value & 3;
204 if (!flashRomWriteEnabled) {
205 switch (mapperTypeReg) {
208 if ((addr & 0x1800) == 0x1000) {
211 bankRegs[page8kB] = value;
216 if ((addr & 0xFFFE) == 0xBFFE) {
230 if ((addr < 0x5000) || ((0x5800 <= addr) && (addr < 0x6000)))
break;
231 bankRegs[page8kB] = value & 0x7F;
238 if ((0x6000 <= addr) && (addr < 0x8000)) {
239 byte bank = (addr >> 11) & 0x03;
240 bankRegs[bank] = value;
253 if ((0x6000 <= addr) && (addr < 0x6800)) {
254 bankRegs[0] = narrow_cast<byte>(2 * value + 0);
255 bankRegs[1] = narrow_cast<byte>(2 * value + 1);
258 if ((0x7000 <= addr) && (addr < 0x7800)) {
259 bankRegs[2] = narrow_cast<byte>(2 * value + 0);
260 bankRegs[3] = narrow_cast<byte>(2 * value + 1);
268 if (flashAddr !=
unsigned(-1)) {
269 flash.
write(flashAddr, value);
276 return ((0x4000 <= addr) && (addr < 0xC000))
286 psg0x10Latch = value & 0x0F;
292 psg0xA0Latch = value & 0x0F;
301 mainBankReg = value & 7;
320template<
typename Archive>
324 ar.template serializeBase<MSXDevice>(*
this);
326 ar.serialize(
"flash", flash,
329 "psg0x10Latch", psg0x10Latch,
331 "psg0xA0Latch", psg0xA0Latch,
332 "flashRomWriteEnabled", flashRomWriteEnabled,
333 "mainBankReg", mainBankReg,
334 "volumeReg", volumeReg,
335 "mapperTypeReg", mapperTypeReg,
337 "bankRegs", bankRegs);
339 if constexpr (Archive::IS_LOADER) {
#define REGISTER_MSXDEVICE(CLASS, NAME)
void reset(EmuTime::param time)
void writeRegister(unsigned reg, uint8_t value, EmuTime::param time)
void write(size_t address, uint8_t value)
const uint8_t * getReadCacheLine(size_t address) const
uint8_t read(size_t address)
uint8_t peek(size_t address) const
static DummyAY8910Periphery & instance()
void invalidateDeviceRCache()
static std::array< byte, 0x10000 > unmappedRead
static std::array< byte, 0x10000 > unmappedWrite
EmuTime::param getCurrentTime() const
MSXCPUInterface & getCPUInterface() const
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 readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
~ReproCartridgeV2() override
byte * getWriteCacheLine(word address) override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
void reset(EmuTime::param time) override
This method is called on reset.
ReproCartridgeV2(const DeviceConfig &config, Rom &&rom)
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.
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.
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
void setVolume(EmuTime::param time, byte value)
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
void setMode(Mode newMode)
void powerUp(EmuTime::param time)
uint8_t readMem(uint8_t address, EmuTime::param time)
void reset(EmuTime::param time)
uint8_t peekMem(uint8_t address, EmuTime::param time) const
void writeMem(uint8_t address, uint8_t value, EmuTime::param time)
void setSoftwareVolume(float volume, EmuTime::param time)
Change the 'software volume' of this sound device.
This file implemented 3 utility functions:
uint16_t word
16 bit unsigned integer
constexpr void iota(ForwardIt first, ForwardIt last, T value)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)