OXYGENHUB
◆ main openmsx / src / memory / MSXRam.cc
1.9 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "MSXRam.hh"
2
3
#include "XMLElement.hh"
4
#include "serialize.hh"
5
6
#include "narrow.hh"
7
8
#include <cassert>
9
10
namespace openmsx {
11
12
MSXRam::MSXRam(const DeviceConfig& config)
13
	: MSXDevice(config)
14
{
15
	// Actual initialization is done in init() because <mem> tags
16
	// are not yet processed.
17
}
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", narrow_cast<int>(base));
27
	size = getDeviceConfig().getChildDataAsInt("size", narrow_cast<int>(size));
28
	assert( base         <  0x10000);
29
	assert((base + size) <= 0x10000);
30
31
	checkedRam.emplace(getDeviceConfig2(), getName(), "ram", size);
32
	powerUp(getCurrentTime());
33
}
34
35
void MSXRam::powerUp(EmuTime /*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(uint16_t address, EmuTime /*time*/) const
48
{
49
	return checkedRam->peek(translate(address));
50
}
51
52
byte MSXRam::readMem(uint16_t address, EmuTime /*time*/)
53
{
54
	return checkedRam->read(translate(address));
55
}
56
57
void MSXRam::writeMem(uint16_t address, byte value, EmuTime /*time*/)
58
{
59
	checkedRam->write(translate(address), value);
60
}
61
62
const byte* MSXRam::getReadCacheLine(uint16_t start) const
63
{
64
	return checkedRam->getReadCacheLine(translate(start));
65
}
66
67
byte* MSXRam::getWriteCacheLine(uint16_t start)
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
}
79
INSTANTIATE_SERIALIZE_METHODS(MSXRam);
80
REGISTER_MSXDEVICE(MSXRam, "Ram");
81
82
} // namespace openmsx