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