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 "MSXCliComm.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::bankSwitch(unsigned page, unsigned block)
39{
40 setRom(page, block);
41
42 // Note: the mirror behavior is different from RomKonamiSCC !
43 if (page == 2 || page == 3) {
44 // [0x4000-0x8000), mirrored in [0x0000-0x4000)
45 setRom(page - 2, block);
46 } else if (page == 4 || page == 5) {
47 // [0x8000-0xC000), mirrored in [0xC000-0x10000)
48 setRom(page + 2, block);
49 } else {
50 assert(false);
51 }
52}
53
54void RomKonami::reset(EmuTime::param /*time*/)
55{
56 for (auto i : xrange(2, 6)) {
57 bankSwitch(i, i - 2);
58 }
59}
60
61void RomKonami::writeMem(word address, byte value, EmuTime::param /*time*/)
62{
63 // Note: [0x4000..0x6000) is fixed at segment 0.
64 if (0x6000 <= address && address < 0xC000) {
65 bankSwitch(address >> 13, value);
66 }
67}
68
70{
71 return (0x6000 <= address && address < 0xC000) ? nullptr : unmappedWrite.data();
72}
73
74template<typename Archive>
75void RomKonami::serialize(Archive& ar, unsigned /*version*/)
76{
77 ar.template serializeBase<Rom8kBBlocks>(*this);
78}
81
82} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:354
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:305
void setBlockMask(int mask)
Sets a mask for the block numbers.
Definition RomBlocks.hh:74
void setRom(unsigned region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition RomBlocks.cc:104
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:54
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:61
void serialize(Archive &ar, unsigned version)
Definition RomKonami.cc:75
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition RomKonami.cc:69
auto size() const
Definition Rom.hh:36
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr auto xrange(T e)
Definition xrange.hh:132