openMSX
RomColecoMegaCart.cc
Go to the documentation of this file.
1 #include "RomColecoMegaCart.hh"
2 #include "serialize.hh"
3 #include "MSXException.hh"
4 #include "CacheLine.hh"
5 #include "one_of.hh"
6 
7 // information source:
8 // https://github.com/openMSX/openMSX/files/2118720/MegaCart.FAQ.V1-2.pdf
9 
10 namespace openmsx {
11 
13  : Rom16kBBlocks(config, std::move(rom_))
14 {
15  auto size = rom.getSize() / 1024;
16  if (size != one_of(128u, 256u, 512u, 1024u)) {
17  throw MSXException(
18  "MegaCart only supports ROMs of 128kB, 256kB, 512kB and 1024kB "
19  "size and not of ", size, "kB.");
20  }
21  reset(EmuTime::dummy());
22 }
23 
24 void RomColecoMegaCart::reset(EmuTime::param /*time*/)
25 {
26  setUnmapped(0);
27  setUnmapped(1);
28  // The first 16K of the cartridge (CV 8000h-BFFFh) is fixed and will
29  // always contain the highest/last 16K segment of the EPROM.
30  setRom(2, unsigned(-1)); // select last block
31  setRom(3, 0);
33 }
34 
35 byte RomColecoMegaCart::readMem(word address, EmuTime::param time)
36 {
37  // The last 64 locations will switch banks (FFC0-FFFF). If you have
38  // fewer than 64 banks, then the strobe addresses simply repeat where
39  // they end. If you have 16 banks, then bank 0 can be strobed at FFC0,
40  // FFD0, FFE0, or FFF0.
41  if (address >= 0xFFC0) {
42  setRom(3, address); // mirroring is handled in superclass
44  }
45  return Rom16kBBlocks::readMem(address, time);
46 }
47 
48 const byte* RomColecoMegaCart::getReadCacheLine(word start) const
49 {
50  if (start >= (0xFFC0 & CacheLine::HIGH)) {
51  return nullptr;
52  } else {
53  return Rom16kBBlocks::getReadCacheLine(start);
54  }
55 }
56 
57 REGISTER_MSXDEVICE(RomColecoMegaCart, "RomColecoMegaCart");
58 
59 } // namespace openmsx
one_of.hh
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:10
openmsx::CacheLine::HIGH
constexpr unsigned HIGH
Definition: CacheLine.hh:10
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
RomColecoMegaCart.hh
openmsx::RomColecoMegaCart::getReadCacheLine
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomColecoMegaCart.cc:48
openmsx::RomBlocks::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomBlocks.cc:71
openmsx::RomBlocks::setRom
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:104
one_of
Definition: one_of.hh:7
openmsx::RomBlocks::setUnmapped
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:91
openmsx::RomBlocks
Definition: RomBlocks.hh:14
openmsx::CacheLine::SIZE
constexpr unsigned SIZE
Definition: CacheLine.hh:7
CacheLine.hh
openmsx::RomColecoMegaCart
Definition: RomColecoMegaCart.hh:9
openmsx::MSXRom::rom
Rom rom
Definition: MSXRom.hh:20
openmsx::Rom
Definition: Rom.hh:21
openmsx::MSXDevice::invalidateDeviceRCache
void invalidateDeviceRCache()
Definition: MSXDevice.hh:209
openmsx::RomBlocks::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomBlocks.cc:65
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomColecoMegaCart::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomColecoMegaCart.cc:35
openmsx::RomColecoMegaCart::RomColecoMegaCart
RomColecoMegaCart(const DeviceConfig &config, Rom &&rom)
Definition: RomColecoMegaCart.cc:12
openmsx::RomColecoMegaCart::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomColecoMegaCart.cc:24
openmsx::Rom::getSize
unsigned getSize() const
Definition: Rom.hh:32
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5