13static constexpr unsigned MAIN_RAM_AREA_START = 0x6000;
14static constexpr unsigned MAIN_RAM_SIZE = 0x400;
15static constexpr unsigned SGM_RAM_SIZE = 0x8000;
16static constexpr unsigned BIOS_ROM_SIZE = 0x2000;
21 , sgmRam(config, getName() +
" RAM",
"SGM RAM", SGM_RAM_SIZE)
22 , mainRam(config,
"Main RAM",
"Main RAM", MAIN_RAM_SIZE)
23 , biosRom(getName(),
"BIOS ROM", config)
25 if (biosRom.
size() != BIOS_ROM_SIZE) {
26 throw MSXException(
"ColecoVision BIOS ROM must be exactly 8kB in size.");
29 for (
auto port : {0x50, 0x51, 0x53, 0x7F}) {
30 cpuInterface.register_IO_Out(narrow_cast<byte>(port),
this);
32 cpuInterface.register_IO_In(0x52,
this);
39 for (
auto port : {0x50, 0x51, 0x53, 0x7F}) {
40 cpuInterface.unregister_IO_Out(narrow_cast<byte>(port),
this);
42 cpuInterface.unregister_IO_In(0x52,
this);
45static constexpr unsigned translateMainRamAddress(
unsigned address)
47 return address & (MAIN_RAM_SIZE - 1);
53 ramAtBiosEnabled =
false;
61 if ((port & 0xFF) == 0x52) {
69 if ((port & 0xFF) == 0x52) {
77 switch (port & 0xFF) {
79 psgLatch = value & 0x0F;
85 ramEnabled = (value & 1) != 0;
89 ramAtBiosEnabled = (value & 2) == 0;
100 if (address < BIOS_ROM_SIZE) {
101 return ramAtBiosEnabled ? sgmRam.
peek(address) : biosRom[address];
102 }
else if (address < SGM_RAM_SIZE) {
104 return sgmRam.
peek(address);
105 }
else if (address >= MAIN_RAM_AREA_START) {
106 return mainRam.
peek(translateMainRamAddress(address));
114 if (address < BIOS_ROM_SIZE) {
115 return ramAtBiosEnabled ? sgmRam.
read(address) : biosRom[address];
116 }
else if (address < SGM_RAM_SIZE) {
118 return sgmRam.
read(address);
119 }
else if (address >= MAIN_RAM_AREA_START) {
120 return mainRam.
read(translateMainRamAddress(address));
128 if (address < BIOS_ROM_SIZE) {
129 if (ramAtBiosEnabled) {
130 sgmRam.
write(address, value);
132 }
else if (address < SGM_RAM_SIZE) {
134 sgmRam.
write(address, value);
135 }
else if (address >= MAIN_RAM_AREA_START) {
136 mainRam.
write(translateMainRamAddress(address), value);
143 if (start < BIOS_ROM_SIZE) {
145 }
else if (start < SGM_RAM_SIZE) {
148 }
else if (start >= MAIN_RAM_AREA_START) {
157 if (start < BIOS_ROM_SIZE) {
158 if (ramAtBiosEnabled) {
161 }
else if (start < SGM_RAM_SIZE) {
164 }
else if (start >= MAIN_RAM_AREA_START) {
171template<
typename Archive>
177 "psgLatch", psgLatch,
178 "ramEnabled", ramEnabled,
179 "ramAtBiosEnabled", ramAtBiosEnabled);
#define REGISTER_MSXDEVICE(CLASS, NAME)
uint8_t readRegister(unsigned reg, EmuTime::param time)
void reset(EmuTime::param time)
void writeRegister(unsigned reg, uint8_t value, EmuTime::param time)
uint8_t peekRegister(unsigned reg, EmuTime::param time) const
byte * getWriteCacheLine(size_t addr)
Ram & getUncheckedRam()
Give access to the unchecked Ram.
void write(size_t addr, byte value)
byte peek(size_t addr) const
const byte * getReadCacheLine(size_t addr) const
~ColecoSuperGameModule() override
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
void serialize(Archive &ar, unsigned version)
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
ColecoSuperGameModule(const DeviceConfig &config)
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 peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
void reset(EmuTime::param time) override
This method is called on reset.
byte * getWriteCacheLine(word start) override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
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.
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
static std::array< byte, 0x10000 > unmappedRead
static std::array< byte, 0x10000 > unmappedWrite
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
EmuTime::param getCurrentTime() const
MSXCPUInterface & getCPUInterface() const
This file implemented 3 utility functions:
uint16_t word
16 bit unsigned integer
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)