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
Definition: one_of.hh:7
void invalidateDeviceRCache()
Definition: MSXDevice.hh:210
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomBlocks.cc:66
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:105
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:72
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:92
void reset(EmuTime::param time) override
This method is called on reset.
RomColecoMegaCart(const DeviceConfig &config, Rom &&rom)
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
unsigned getSize() const
Definition: Rom.hh:34
constexpr unsigned HIGH
Definition: CacheLine.hh:10
constexpr unsigned SIZE
Definition: CacheLine.hh:7
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
size_t size(std::string_view utf8)