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 writing 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#include "xrange.hh"
17
18namespace openmsx {
19
21 : Rom8kBBlocks(config, std::move(rom_))
22{
23 // Konami mapper is 256kB in size, even if ROM is smaller.
24 setBlockMask(31);
25
26 // warn if a ROM is used that would not work on a real Konami mapper
27 if (rom.size() > 256 * 1024) {
29 "The size of this ROM image is larger than 256kB, "
30 "which is not supported on real Konami mapper chips!");
31 }
32
33 // Do not call reset() here, since it can be overridden and the subclass
34 // constructor has not been run yet. And there will be a reset() at power
35 // up anyway.
36}
37
38void RomKonami::reset(EmuTime::param /*time*/)
39{
40 setUnmapped(0);
41 setUnmapped(1);
42 for (auto i : xrange(2, 6)) {
43 setRom(i, i - 2);
44 }
45 setUnmapped(6);
46 setUnmapped(7);
47}
48
49void RomKonami::writeMem(word address, byte value, EmuTime::param /*time*/)
50{
51 // Note: [0x4000..0x6000) is fixed at segment 0.
52 if (0x6000 <= address && address < 0xC000) {
53 setRom(address >> 13, value);
54 }
55}
56
58{
59 return (0x6000 <= address && address < 0xC000) ? nullptr : unmappedWrite.data();
60}
61
62template<typename Archive>
63void RomKonami::serialize(Archive& ar, unsigned /*version*/)
64{
65 ar.template serializeBase<Rom8kBBlocks>(*this);
66}
69
70} // namespace openmsx
void printWarning(std::string_view message)
Definition: CliComm.cc:10
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:70
static std::array< byte, 0x10000 > unmappedWrite
Definition: MSXDevice.hh:303
void setBlockMask(int mask)
Sets a mask for the block numbers.
Definition: RomBlocks.hh:74
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:103
void setUnmapped(byte region)
Select 'unmapped' memory for this region.
Definition: RomBlocks.cc:91
RomKonami(const DeviceConfig &config, Rom &&rom)
Definition: RomKonami.cc:20
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomKonami.cc:38
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:49
void serialize(Archive &ar, unsigned version)
Definition: RomKonami.cc:63
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomKonami.cc:57
auto size() const
Definition: Rom.hh:36
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