openMSX
RomKonami.cc
Go to the documentation of this file.
1 // KONAMI 8kB cartridges (without SCC)
2 //
3 // this type is used by Konami cartridges without SCC and some others
4 // examples of cartridges: Nemesis, Penguin Adventure, Usas, Metal Gear, Shalom,
5 // The Maze of Galious, Aleste 1, 1942, Heaven, Mystery World, ...
6 // (the latter four are hacked ROM images with modified mappers)
7 //
8 // page at 4000 is fixed, other banks are switched by writting at
9 // 0x6000, 0x8000 and 0xA000 (those addresses are used by the games, but any
10 // other address in a page switches that page as well)
11 
12 #include "RomKonami.hh"
13 #include "MSXMotherBoard.hh"
14 #include "CliComm.hh"
15 #include "serialize.hh"
16 
17 namespace openmsx {
18 
19 RomKonami::RomKonami(const DeviceConfig& config, Rom&& rom_)
20  : Rom8kBBlocks(config, std::move(rom_))
21 {
22  // Konami mapper is 256kB in size, even if ROM is smaller.
23  setBlockMask(31);
24 
25  // warn if a ROM is used that would not work on a real Konami mapper
26  if (rom.getSize() > 256 * 1024) {
28  "The size of this ROM image is larger than 256kB, "
29  "which is not supported on real Konami mapper chips!");
30  }
31 
32  // Do not call reset() here, since it can be overridden and the subclass
33  // constructor has not been run yet. And there will be a reset() at power
34  // up anyway.
35 }
36 
37 void RomKonami::reset(EmuTime::param /*time*/)
38 {
39  setUnmapped(0);
40  setUnmapped(1);
41  for (int i = 2; i < 6; i++) {
42  setRom(i, i - 2);
43  }
44  setUnmapped(6);
45  setUnmapped(7);
46 }
47 
48 void RomKonami::writeMem(word address, byte value, EmuTime::param /*time*/)
49 {
50  // Note: [0x4000..0x6000) is fixed at segment 0.
51  if (0x6000 <= address && address < 0xC000) {
52  setRom(address >> 13, value);
53  }
54 }
55 
57 {
58  return (0x6000 <= address && address < 0xC000) ? nullptr : unmappedWrite;
59 }
60 
61 template<typename Archive>
62 void RomKonami::serialize(Archive& ar, unsigned /*version*/)
63 {
64  ar.template serializeBase<Rom8kBBlocks>(*this);
65 }
67 REGISTER_MSXDEVICE(RomKonami, "RomKonami");
68 
69 } // namespace openmsx
RomKonami(const DeviceConfig &config, Rom &&rom)
Definition: RomKonami.cc:19
void serialize(Archive &ar, unsigned version)
Definition: RomKonami.cc:62
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:104
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.
Definition: RomKonami.cc:48
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:74
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomKonami.cc:37
void printWarning(std::string_view message)
Definition: CliComm.cc:10
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
Definition: RomKonami.cc:56
unsigned getSize() const
Definition: Rom.hh:32
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:293
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
void setUnmapped(byte region)
Select &#39;unmapped&#39; memory for this region.
Definition: RomBlocks.cc:91
void setBlockMask(int mask)
Sets a mask for the block numbers.
Definition: RomBlocks.hh:73