openMSX
PanasonicRam.cc
Go to the documentation of this file.
1 #include "PanasonicRam.hh"
2 #include "MSXMotherBoard.hh"
3 #include "PanasonicMemory.hh"
4 #include "serialize.hh"
5 
6 namespace openmsx {
7 
9  : MSXMemoryMapperBase(config)
10  , panasonicMemory(getMotherBoard().getPanasonicMemory())
11 {
12  panasonicMemory.registerRam(checkedRam.getUncheckedRam());
13 }
14 
15 void PanasonicRam::writeMem(word address, byte value, EmuTime::param /*time*/)
16 {
17  unsigned addr = calcAddress(address);
18  if (panasonicMemory.isWritable(addr)) {
19  checkedRam.write(addr, value);
20  }
21 }
22 
24 {
25  unsigned addr = calcAddress(start);
26  if (panasonicMemory.isWritable(addr)) {
27  return checkedRam.getWriteCacheLine(addr);
28  } else {
29  return unmappedWrite;
30  }
31 }
32 
33 void PanasonicRam::writeIO(word port, byte value, EmuTime::param time)
34 {
35  MSXMemoryMapperBase::writeIOImpl(port, value, time);
36  byte page = port & 3;
37  unsigned addr = segmentOffset(page);
38  if (byte* data = checkedRam.getRWCacheLines(addr, 0x4000)) {
39  const byte* rData = data;
40  byte* wData = panasonicMemory.isWritable(addr) ? data : unmappedWrite;
41  fillDeviceRWCache(page * 0x4000, 0x4000, rData, wData);
42  } else {
43  invalidateDeviceRWCache(page * 0x4000, 0x4000);
44  }
45 }
46 
47 template<typename Archive>
48 void PanasonicRam::serialize(Archive& ar, unsigned /*version*/)
49 {
50  ar.template serializeBase<MSXMemoryMapperBase>(*this);
51 }
54 
55 } // namespace openmsx
PanasonicRam.hh
openmsx::MSXMemoryMapperBase::checkedRam
CheckedRam checkedRam
Definition: MSXMemoryMapperBase.hh:53
openmsx::PanasonicRam::writeIO
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition: PanasonicRam.cc:33
openmsx::CheckedRam::getWriteCacheLine
byte * getWriteCacheLine(unsigned addr) const
Definition: CheckedRam.cc:53
openmsx::MSXMemoryMapperBase::calcAddress
unsigned calcAddress(word address) const
Converts a Z80 address to a RAM address.
Definition: MSXMemoryMapperBase.cc:74
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::CheckedRam::getRWCacheLines
byte * getRWCacheLines(unsigned addr, unsigned size) const
Definition: CheckedRam.cc:59
openmsx::PanasonicMemory::isWritable
bool isWritable(unsigned address) const
Definition: PanasonicMemory.cc:106
openmsx::PanasonicRam::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: PanasonicRam.cc:15
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::PanasonicRam::PanasonicRam
PanasonicRam(const DeviceConfig &config)
Definition: PanasonicRam.cc:8
openmsx::PanasonicRam::getWriteCacheLine
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: PanasonicRam.cc:23
openmsx::PanasonicMemory::registerRam
void registerRam(Ram &ram)
Pass reference of the actual Ram block for use in DRAM mode and RAM access via the ROM mapper.
Definition: PanasonicMemory.cc:37
openmsx::CheckedRam::write
void write(unsigned addr, byte value)
Definition: CheckedRam.cc:72
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::PanasonicRam::serialize
void serialize(Archive &ar, unsigned version)
Definition: PanasonicRam.cc:48
openmsx::MSXMemoryMapperBase::writeIOImpl
void writeIOImpl(word port, byte value, EmuTime::param time)
Definition: MSXMemoryMapperBase.cc:59
openmsx::MSXDevice::invalidateDeviceRWCache
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition: MSXDevice.hh:208
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXMemoryMapperBase
Definition: MSXMemoryMapperBase.hh:12
openmsx::CheckedRam::getUncheckedRam
Ram & getUncheckedRam()
Give access to the unchecked Ram.
Definition: CheckedRam.hh:51
openmsx::MSXMemoryMapperBase::segmentOffset
unsigned segmentOffset(byte page) const
Definition: MSXMemoryMapperBase.cc:66
PanasonicMemory.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
MSXMotherBoard.hh
openmsx::PanasonicRam
Definition: PanasonicRam.hh:11
openmsx::MSXDevice::fillDeviceRWCache
void fillDeviceRWCache(unsigned start, unsigned size, byte *rwData)
Calls MSXCPUInterface::fillXXCache() for the specific (part of) the slot that this device is located ...
Definition: MSXDevice.cc:511