openMSX
RomMatraCompilation.cc
Go to the documentation of this file.
1 #include "RomMatraCompilation.hh"
2 #include "serialize.hh"
3 
4 // This is basically a generic 8kB mapper (Konami like, but without fixed page
5 // at 0x4000), with an extra offset register accessible at 0xBA00.
6 // The software only writes to 0x5000, 0x6000, 0x8000, 0xA000 to switch mapper
7 // page. I took these as unique switching addresses, as some of the compilation
8 // software would write to others, causing crashes.
9 // It seems that a write of 1 (and probably 0, but the software doesn't do
10 // that) to the offset register should be ignored and will disable the mapper
11 // switch addresses. Values of 2 or larger written there must be lowered by 2
12 // to get the actual offset to use.
13 
14 namespace openmsx {
15 
17  : Rom8kBBlocks(config, std::move(rom_))
18 {
19  reset(EmuTime::dummy());
20 }
21 
22 void RomMatraCompilation::reset(EmuTime::param /*time*/)
23 {
24  setUnmapped(0);
25  setUnmapped(1);
26  for (int i = 2; i < 6; i++) {
27  setRom(i, i - 2);
28  }
29  setUnmapped(6);
30  setUnmapped(7);
31 
32  blockOffset = 2;
33 }
34 
35 void RomMatraCompilation::writeMem(word address, byte value, EmuTime::param /*time*/)
36 {
37  if (address == 0xBA00) {
38  // write of block offset
39  blockOffset = value;
40  // retro-actively select the blocks for this offset
41  if (blockOffset >= 2) {
42  for (int i = 2; i < 6; i++) {
43  setRom(i, blockNr[i] + blockOffset - 2);
44  }
45  }
46  } else if ((blockOffset >= 2) &&
47  ((address == 0x5000) || (address == 0x6000)
48  || (address == 0x8000) || (address == 0xA000))) {
49  setRom(address >> 13, value + blockOffset - 2);
50  }
51 }
52 
54 {
55  if ((0x5000 <= address) && (address < 0xC000)) {
56  return nullptr;
57  } else {
58  return unmappedWrite;
59  }
60 }
61 
62 template<typename Archive>
63 void RomMatraCompilation::serialize(Archive& ar, unsigned /*version*/)
64 {
65  ar.template serializeBase<Rom8kBBlocks>(*this);
66 
67  ar.serialize("blockOffset", blockOffset);
68 }
70 REGISTER_MSXDEVICE(RomMatraCompilation, "RomMatraCompilation");
71 
72 } // namespace openmsx
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")
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.
void serialize(Archive &ar, unsigned version)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
byte blockNr[NUM_BANKS]
Definition: RomBlocks.hh:83
void reset(EmuTime::param time) override
This method is called on reset.
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:275
void setUnmapped(byte region)
Select &#39;unmapped&#39; memory for this region.
Definition: RomBlocks.cc:85
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
RomMatraCompilation(const DeviceConfig &config, Rom &&rom)