openMSX
RomKonamiSCC.cc
Go to the documentation of this file.
1// KONAMI 8kB cartridges with SCC
2//
3// this type is used by Konami cartridges that do have an SCC and some others
4// examples of cartridges: Nemesis 2, Nemesis 3, King's Valley 2, Space Manbow
5// Solid Snake, Quarth, Ashguine 1, Animal, Arkanoid 2, ...
6// Those last 3 were probably modified ROM images, they should be ASCII8
7//
8// The address to change banks:
9// bank 1: 0x5000 - 0x57ff (0x5000 used)
10// bank 2: 0x7000 - 0x77ff (0x7000 used)
11// bank 3: 0x9000 - 0x97ff (0x9000 used)
12// bank 4: 0xB000 - 0xB7ff (0xB000 used)
13
14#include "RomKonamiSCC.hh"
15#include "CacheLine.hh"
16#include "MSXMotherBoard.hh"
17#include "MSXCliComm.hh"
18#include "sha1.hh"
19#include "serialize.hh"
20#include "xrange.hh"
21
22namespace openmsx {
23
25 : Rom8kBBlocks(config, std::move(rom_))
26 , scc("SCC", config, getCurrentTime())
27{
28 // warn if a ROM is used that would not work on a real KonamiSCC mapper
29 if (rom.size() > 512 * 1024) {
31 "The size of this ROM image is larger than 512kB, "
32 "which is not supported on real Konami SCC mapper "
33 "chips!");
34 }
36}
37
38void RomKonamiSCC::powerUp(EmuTime::param time)
39{
40 scc.powerUp(time);
41 reset(time);
42}
43
44void RomKonamiSCC::bankSwitch(unsigned page, unsigned block)
45{
46 setRom(page, block);
47
48 // Note: the mirror behavior is different from RomKonami !
49 if (page == 2 || page == 3) {
50 // [0x4000-0x8000), mirrored in [0xC000-0x10000)
51 setRom(page + 4, block);
52 } else if (page == 4 || page == 5) {
53 // [0x8000-0xC000), mirrored in [0x0000-0x4000)
54 setRom(page - 4, block);
55 } else {
56 assert(false);
57 }
58}
59
60void RomKonamiSCC::reset(EmuTime::param time)
61{
62 for (auto i : xrange(2, 6)) {
63 bankSwitch(i, i - 2);
64 }
65
66 sccEnabled = false;
67 scc.reset(time);
68}
69
70byte RomKonamiSCC::peekMem(word address, EmuTime::param time) const
71{
72 if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
73 return scc.peekMem(narrow_cast<uint8_t>(address & 0xFF), time);
74 } else {
75 return Rom8kBBlocks::peekMem(address, time);
76 }
77}
78
79byte RomKonamiSCC::readMem(word address, EmuTime::param time)
80{
81 if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
82 return scc.readMem(narrow_cast<uint8_t>(address & 0xFF), time);
83 } else {
84 return Rom8kBBlocks::readMem(address, time);
85 }
86}
87
88const byte* RomKonamiSCC::getReadCacheLine(word address) const
89{
90 if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
91 // don't cache SCC
92 return nullptr;
93 } else {
94 return Rom8kBBlocks::getReadCacheLine(address);
95 }
96}
97
98void RomKonamiSCC::writeMem(word address, byte value, EmuTime::param time)
99{
100 if ((address < 0x5000) || (address >= 0xC000)) {
101 return;
102 }
103 if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
104 // write to SCC
105 scc.writeMem(narrow_cast<uint8_t>(address & 0xFF), value, time);
106 return;
107 }
108 if ((address & 0xF800) == 0x9000) {
109 // SCC enable/disable
110 bool newSccEnabled = ((value & 0x3F) == 0x3F);
111 if (newSccEnabled != sccEnabled) {
112 sccEnabled = newSccEnabled;
113 invalidateDeviceRWCache(0x9800, 0x0800);
114 }
115 }
116 if ((address & 0x1800) == 0x1000) {
117 // page selection
118 auto region = address >> 13;
119 bankSwitch(region, value);
120 if ((region == 4) && sccEnabled) {
121 invalidateDeviceRCache(0x9800, 0x0800);
122 }
123 }
124}
125
127{
128 if ((address < 0x5000) || (address >= 0xC000)) {
129 return unmappedWrite.data();
130 } else if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
131 // write to SCC
132 return nullptr;
133 } else if ((address & 0xF800) == (0x9000 & CacheLine::HIGH)) {
134 // SCC enable/disable
135 return nullptr;
136 } else if ((address & 0x1800) == (0x1000 & CacheLine::HIGH)) {
137 // page selection
138 return nullptr;
139 } else {
140 return unmappedWrite.data();
141 }
142}
143
144template<typename Archive>
145void RomKonamiSCC::serialize(Archive& ar, unsigned /*version*/)
146{
147 ar.template serializeBase<Rom8kBBlocks>(*this);
148 ar.serialize("scc", scc,
149 "sccEnabled", sccEnabled);
150}
153
154} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
void printWarning(std::string_view message)
Definition CliComm.cc:12
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition MSXDevice.cc:70
void invalidateDeviceRCache()
Definition MSXDevice.hh:215
static std::array< byte, 0x10000 > unmappedWrite
Definition MSXDevice.hh:307
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition MSXDevice.hh:214
EmuTime::param getCurrentTime() const
Definition MSXDevice.cc:125
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition RomBlocks.cc:60
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition RomBlocks.cc:66
void setRom(unsigned region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition RomBlocks.cc:104
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition RomBlocks.cc:72
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
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 peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
RomKonamiSCC(const DeviceConfig &config, Rom &&rom)
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
void serialize(Archive &ar, unsigned version)
byte * getWriteCacheLine(word address) 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.
auto size() const
Definition Rom.hh:36
void powerUp(EmuTime::param time)
Definition SCC.cc:141
uint8_t readMem(uint8_t address, EmuTime::param time)
Definition SCC.cc:193
void reset(EmuTime::param time)
Definition SCC.cc:173
uint8_t peekMem(uint8_t address, EmuTime::param time) const
Definition SCC.cc:206
void writeMem(uint8_t address, uint8_t value, EmuTime::param time)
Definition SCC.cc:285
constexpr unsigned HIGH
Definition CacheLine.hh:10
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