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