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