openMSX
MSXRam.cc
Go to the documentation of this file.
1 #include "MSXRam.hh"
2 #include "CheckedRam.hh"
3 #include "XMLElement.hh"
4 #include "serialize.hh"
5 #include <cassert>
6 #include <memory>
7 
8 namespace openmsx {
9 
11  : MSXDevice(config)
12 {
13  // Actual initialization is done in init() because <mem> tags
14  // are not yet processed.
15 }
16 
17 MSXRam::~MSXRam() = default;
18 
19 void MSXRam::init()
20 {
21  MSXDevice::init(); // parse mem regions
22 
23  // by default get base/size from the (union of) the <mem> tag(s)
24  getVisibleMemRegion(base, size);
25  // but allow to override these two parameters
26  base = getDeviceConfig().getChildDataAsInt("base", base);
27  size = getDeviceConfig().getChildDataAsInt("size", size);
28  assert( base < 0x10000);
29  assert((base + size) <= 0x10000);
30 
31  checkedRam = std::make_unique<CheckedRam>(
32  getDeviceConfig2(), getName(), "ram", size);
33 }
34 
35 void MSXRam::powerUp(EmuTime::param /*time*/)
36 {
37  checkedRam->clear();
38 }
39 
40 unsigned MSXRam::translate(unsigned address) const
41 {
42  address -= base;
43  if (address >= size) address &= (size - 1);
44  return address;
45 }
46 
47 byte MSXRam::peekMem(word address, EmuTime::param /*time*/) const
48 {
49  return checkedRam->peek(translate(address));
50 }
51 
52 byte MSXRam::readMem(word address, EmuTime::param /*time*/)
53 {
54  return checkedRam->read(translate(address));
55 }
56 
57 void MSXRam::writeMem(word address, byte value, EmuTime::param /*time*/)
58 {
59  checkedRam->write(translate(address), value);
60 }
61 
62 const byte* MSXRam::getReadCacheLine(word start) const
63 {
64  return checkedRam->getReadCacheLine(translate(start));
65 }
66 
67 byte* MSXRam::getWriteCacheLine(word start) const
68 {
69  return checkedRam->getWriteCacheLine(translate(start));
70 }
71 
72 template<typename Archive>
73 void MSXRam::serialize(Archive& ar, unsigned /*version*/)
74 {
75  ar.template serializeBase<MSXDevice>(*this);
76  // TODO ar.serialize("checkedRam", checkedRam);
77  ar.serialize("ram", checkedRam->getUncheckedRam());
78 }
81 
82 } // namespace openmsx
openmsx::MSXRam::getWriteCacheLine
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: MSXRam.cc:67
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::MSXRam::~MSXRam
~MSXRam() override
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXRam::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXRam.cc:73
openmsx::MSXRam
Definition: MSXRam.hh:12
openmsx::MSXRam::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: MSXRam.cc:52
XMLElement.hh
CheckedRam.hh
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXRam::powerUp
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: MSXRam.cc:35
openmsx::MSXDevice::getVisibleMemRegion
void getVisibleMemRegion(unsigned &base, unsigned &size) const
Returns the range where this device is visible in memory.
Definition: MSXDevice.cc:309
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
MSXRam.hh
openmsx::MSXRam::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: MSXRam.cc:47
openmsx::MSXDevice::getDeviceConfig2
const DeviceConfig & getDeviceConfig2() const
Definition: MSXDevice.hh:233
openmsx::MSXRam::getReadCacheLine
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: MSXRam.cc:62
openmsx::MSXDevice::getName
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:381
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXDevice::init
virtual void init()
Definition: MSXDevice.cc:49
openmsx::MSXRam::MSXRam
MSXRam(const DeviceConfig &config)
Definition: MSXRam.cc:10
openmsx::XMLElement::getChildDataAsInt
int getChildDataAsInt(std::string_view childName, int defaultValue=0) const
Definition: XMLElement.cc:185
openmsx::MSXRam::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: MSXRam.cc:57
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MSXDevice::getDeviceConfig
const XMLElement & getDeviceConfig() const
Get the configuration section for this device.
Definition: MSXDevice.hh:230