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