31static constexpr auto sectorInfo = [] {
33 using Info = AmdFlash::SectorInfo;
34 std::array<Info, 8 + 127> result = {};
35 std::fill(result.begin(), result.begin() + 8,
Info{ 8 * 1024, false});
36 std::fill(result.begin() + 8, result.end(),
Info{64 * 1024, false});
43 , flash(rom, sectorInfo, 0x207E,
44 AmdFlash::Addressing::BITS_12, config)
45 , scc(
"ReproCartV1 SCC", config, getCurrentTime(),
SCC::SCC_Compatible)
71 flashRomWriteEnabled =
false;
85unsigned ReproCartridgeV1::getFlashAddr(
unsigned addr)
const
87 unsigned page8kB = (addr >> 13) - 2;
88 if (page8kB >= 4)
return unsigned(-1);
90 byte bank = bankRegs[page8kB];
91 return (mainBankReg << 21) | (bank << 13) | (addr & 0x1FFF);
95bool ReproCartridgeV1::isSCCAccess(
word addr)
const
97 if (sccMode & 0x10)
return false;
107 if (sccMode & 0x20) {
109 return (bankRegs[3] & 0x80) && (0xB800 <= addr) && (addr < 0xBFFE);
112 return ((bankRegs[2] & 0x3F) == 0x3F) && (0x9800 <= addr) && (addr < 0x9FFE);
118 if (isSCCAccess(addr)) {
119 return scc.
readMem(narrow_cast<uint8_t>(addr & 0xFF), time);
122 unsigned flashAddr = getFlashAddr(addr);
123 return (flashAddr !=
unsigned(-1))
124 ? flash.
read(flashAddr)
130 if (isSCCAccess(addr)) {
131 return scc.
peekMem(narrow_cast<uint8_t>(addr & 0xFF), time);
134 unsigned flashAddr = getFlashAddr(addr);
135 return (flashAddr !=
unsigned(-1))
136 ? flash.
peek(flashAddr)
142 if (isSCCAccess(addr))
return nullptr;
144 unsigned flashAddr = getFlashAddr(addr);
145 return (flashAddr !=
unsigned(-1))
152 unsigned page8kB = (addr >> 13) - 2;
153 if (page8kB >= 4)
return;
162 if (isSCCAccess(addr)) {
163 scc.
writeMem(narrow_cast<uint8_t>(addr & 0xFF), value, time);
168 unsigned flashAddr = getFlashAddr(addr);
171 if (addr == 0x7FFF) {
172 flashRomWriteEnabled = (value == 0x50);
176 if (!flashRomWriteEnabled) {
178 if ((addr & 0x1800) == 0x1000) {
181 bankRegs[page8kB] = value;
186 if ((addr & 0xFFFE) == 0xBFFE) {
194 if (flashAddr !=
unsigned(-1)) {
195 flash.
write(flashAddr, value);
202 return ((0x4000 <= addr) && (addr < 0xC000))
212 psgLatch = value & 0x0F;
218 mainBankReg = value & 3;
225template<
typename Archive>
229 ar.template serializeBase<MSXDevice>(*
this);
231 ar.serialize(
"flash", flash,
234 "psgLatch", psgLatch,
235 "flashRomWriteEnabled", flashRomWriteEnabled,
236 "mainBankReg", mainBankReg,
238 "bankRegs", bankRegs);
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 peek(size_t address) const
uint8_t read(size_t address) const
void register_IO_Out(byte port, MSXDevice *device)
Devices can register their Out ports.
void unregister_IO_Out(byte port, MSXDevice *device)
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.
ReproCartridgeV1(const DeviceConfig &config, Rom &&rom)
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
~ReproCartridgeV1() override
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
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 reset(EmuTime::param time) override
This method is called on reset.
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.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
void setChipMode(ChipMode 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)
This file implemented 3 utility functions:
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
AmdFlash::SectorInfo Info
uint16_t word
16 bit unsigned integer
constexpr void fill(ForwardRange &&range, const T &value)
constexpr void iota(ForwardIt first, ForwardIt last, T value)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)