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 "CliComm.hh"
18 #include "sha1.hh"
19 #include "serialize.hh"
20 
21 namespace openmsx {
22 
23 // minimal attempt to avoid seeing this warning too often
24 static Sha1Sum alreadyWarnedForSha1Sum;
25 
27  : Rom8kBBlocks(config, std::move(rom_))
28  , scc("SCC", config, getCurrentTime())
29 {
30  // warn if a ROM is used that would not work on a real KonamiSCC mapper
31  if ((rom.getSize() > 512 * 1024) && alreadyWarnedForSha1Sum != rom.getOriginalSHA1()) {
33  "The size of this ROM image is larger than 512kB, "
34  "which is not supported on real Konami SCC mapper "
35  "chips!");
36  alreadyWarnedForSha1Sum = rom.getOriginalSHA1();
37  }
39 }
40 
41 void RomKonamiSCC::powerUp(EmuTime::param time)
42 {
43  scc.powerUp(time);
44  reset(time);
45 }
46 
47 void RomKonamiSCC::reset(EmuTime::param time)
48 {
49  setUnmapped(0);
50  setUnmapped(1);
51  for (int i = 2; i < 6; i++) {
52  setRom(i, i - 2);
53  }
54  setUnmapped(6);
55  setUnmapped(7);
56 
57  sccEnabled = false;
58  scc.reset(time);
59 }
60 
61 byte RomKonamiSCC::peekMem(word address, EmuTime::param time) const
62 {
63  if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
64  return scc.peekMem(address & 0xFF, time);
65  } else {
66  return Rom8kBBlocks::peekMem(address, time);
67  }
68 }
69 
70 byte RomKonamiSCC::readMem(word address, EmuTime::param time)
71 {
72  if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
73  return scc.readMem(address & 0xFF, time);
74  } else {
75  return Rom8kBBlocks::readMem(address, time);
76  }
77 }
78 
80 {
81  if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
82  // don't cache SCC
83  return nullptr;
84  } else {
85  return Rom8kBBlocks::getReadCacheLine(address);
86  }
87 }
88 
89 void RomKonamiSCC::writeMem(word address, byte value, EmuTime::param time)
90 {
91  if ((address < 0x5000) || (address >= 0xC000)) {
92  return;
93  }
94  if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
95  // write to SCC
96  scc.writeMem(address & 0xFF, value, time);
97  return;
98  }
99  if ((address & 0xF800) == 0x9000) {
100  // SCC enable/disable
101  sccEnabled = ((value & 0x3F) == 0x3F);
102  invalidateMemCache(0x9800, 0x0800);
103  }
104  if ((address & 0x1800) == 0x1000) {
105  // page selection
106  setRom(address >> 13, value);
107  }
108 }
109 
111 {
112  if ((address < 0x5000) || (address >= 0xC000)) {
113  return unmappedWrite;
114  } else if (sccEnabled && (0x9800 <= address) && (address < 0xA000)) {
115  // write to SCC
116  return nullptr;
117  } else if ((address & 0xF800) == (0x9000 & CacheLine::HIGH)) {
118  // SCC enable/disable
119  return nullptr;
120  } else if ((address & 0x1800) == (0x1000 & CacheLine::HIGH)) {
121  // page selection
122  return nullptr;
123  } else {
124  return unmappedWrite;
125  }
126 }
127 
128 template<typename Archive>
129 void RomKonamiSCC::serialize(Archive& ar, unsigned /*version*/)
130 {
131  ar.template serializeBase<Rom8kBBlocks>(*this);
132  ar.serialize("scc", scc,
133  "sccEnabled", sccEnabled);
134 }
136 REGISTER_MSXDEVICE(RomKonamiSCC, "RomKonamiSCC");
137 
138 } // namespace openmsx
RomKonamiSCC(const DeviceConfig &config, Rom &&rom)
Definition: RomKonamiSCC.cc:26
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:98
void writeMem(byte address, byte value, EmuTime::param time)
Definition: SCC.cc:289
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: RomKonamiSCC.cc:89
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
STL namespace.
void reset(EmuTime::param time)
Definition: SCC.cc:172
constexpr unsigned HIGH
Definition: CacheLine.hh:10
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomKonamiSCC.cc:61
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
void serialize(Archive &ar, unsigned version)
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomKonamiSCC.cc:70
byte readMem(byte address, EmuTime::param time)
Definition: SCC.cc:192
const Sha1Sum & getOriginalSHA1() const
Definition: Rom.cc:354
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:129
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:53
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomBlocks.cc:59
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:73
byte peekMem(byte address, EmuTime::param time) const
Definition: SCC.cc:205
void printWarning(std::string_view message)
Definition: CliComm.cc:10
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: RomKonamiSCC.cc:41
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:65
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:275
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading...
Definition: RomKonamiSCC.cc:79
void setUnmapped(byte region)
Select &#39;unmapped&#39; memory for this region.
Definition: RomBlocks.cc:85
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomKonamiSCC.cc:47
void powerUp(EmuTime::param time)
Definition: SCC.cc:140
void invalidateMemCache(word start, unsigned size)
Invalidate CPU memory-mapping cache.
Definition: MSXDevice.cc:454
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...