openMSX
RomRamFile.cc
Go to the documentation of this file.
1 
27 #include "RomRamFile.hh"
28 #include "MSXCPU.hh"
29 #include "serialize.hh"
30 #include <memory>
31 
32 namespace openmsx {
33 
34 RomRamFile::RomRamFile(const DeviceConfig& config, Rom&& rom_)
35  : MSXRom(config, std::move(rom_))
36  , cpu(getCPU())
37 {
38  sram = std::make_unique<SRAM>(getName() + " SRAM", 0x4000, config);
39  reset(EmuTime::dummy());
40 }
41 
42 void RomRamFile::reset(EmuTime::param /*time*/)
43 {
44  shiftValue = 0;
45 }
46 
47 byte RomRamFile::readMem(word address, EmuTime::param /*time*/)
48 {
49  if ((0x4000 <= address) && (address < 0x8000)) {
50  byte result = rom[address & 0x1fff];
51  if (cpu.isM1Cycle(address)) {
52  bool tmp = (result & 0x44) == 0x44;
53  shiftValue = (shiftValue << 1) | byte(tmp);
54  }
55  return result;
56  } else if ((0x8000 <= address) && (address < 0xC000)) {
57  return (*sram)[address & 0x3fff];
58  } else {
59  return 0xff;
60  }
61 }
62 
63 byte RomRamFile::peekMem(word address, EmuTime::param /*time*/) const
64 {
65  if ((0x4000 <= address) && (address < 0x8000)) {
66  return rom[address & 0x1fff];
67  } else if ((0x8000 <= address) && (address < 0xC000)) {
68  return (*sram)[address & 0x3fff];
69  } else {
70  return 0xff;
71  }
72 }
73 
74 const byte* RomRamFile::getReadCacheLine(word address) const
75 {
76  if ((0x4000 <= address) && (address < 0x8000)) {
77  // reads from ROM are not cacheable because of the M1 stuff
78  return nullptr;
79  } else if ((0x8000 <= address) && (address < 0xC000)) {
80  return &(*sram)[address & 0x3fff];
81  } else {
82  return unmappedRead;
83  }
84 }
85 
86 void RomRamFile::writeMem(word address, byte value, EmuTime::param /*time*/)
87 {
88  if ((0x8000 <= address) && (address < 0xC000) &&
89  ((shiftValue & 0x31) == 0x11)) {
90  sram->write(address & 0x3fff, value);
91  }
92 }
93 
94 byte* RomRamFile::getWriteCacheLine(word address) const
95 {
96  if ((0x8000 <= address) && (address < 0xC000)) {
97  // writes to SRAM are not cacheable because of sync-to-disk
98  return nullptr;
99  } else {
100  return unmappedWrite;
101  }
102 }
103 
104 template<typename Archive>
105 void RomRamFile::serialize(Archive& ar, unsigned /*version*/)
106 {
107  // skip MSXRom base class
108  ar.template serializeBase<MSXDevice>(*this);
109  ar.serialize("shiftValue", shiftValue);
110 }
112 REGISTER_MSXDEVICE(RomRamFile, "RomRamFile");
113 
114 } // namespace openmsx
openmsx::RomRamFile::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomRamFile.cc:63
openmsx::RomRamFile::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomRamFile.cc:74
serialize.hh
openmsx::RomRamFile::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomRamFile.cc:47
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
MSXCPU.hh
openmsx::RomRamFile::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomRamFile.cc:105
RomRamFile.hh
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXRom
Definition: MSXRom.hh:9
openmsx::MSXCPU::isM1Cycle
bool isM1Cycle(unsigned address) const
Should only be used from within a MSXDevice::readMem() method.
Definition: MSXCPU.cc:310
openmsx::RomRamFile::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomRamFile.cc:42
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::MSXRom::rom
Rom rom
Definition: MSXRom.hh:20
openmsx::Rom
Definition: Rom.hh:20
openmsx::RomRamFile::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomRamFile.cc:94
openmsx::MSXDevice::getName
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:381
openmsx::MSXDevice::unmappedRead
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:300
openmsx::RomRamFile::writeMem
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: RomRamFile.cc:86
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomRamFile
Definition: RomRamFile.hh:11
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::RomRamFile::RomRamFile
RomRamFile(const DeviceConfig &config, Rom &&rom)
Definition: RomRamFile.cc:34