OXYGENHUB
◆ main openmsx / src / memory / MSXMirrorDevice.cc
1.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#include "MSXMirrorDevice.hh"
2
3
#include "MSXCPUInterface.hh"
4
#include "MSXException.hh"
5
#include "serialize.hh"
6
7
namespace openmsx {
8
9
[[nodiscard]] static unsigned getAddressHigh(const DeviceConfig& config)
10
{
11
	unsigned prim = config.getChildDataAsInt("ps", 0);
12
	unsigned sec  = config.getChildDataAsInt("ss", 0);
13
	if ((prim >= 4) || (sec >= 4)) {
14
		throw MSXException("Invalid slot in mirror device.");
15
	}
16
	return (prim << 18) | (sec << 16);
17
}
18
19
MSXMirrorDevice::MSXMirrorDevice(const DeviceConfig& config)
20
	: MSXDevice(config)
21
	, interface(getCPUInterface()) // frequently used, so cache
22
	, addressHigh(getAddressHigh(config))
23
{
24
}
25
26
byte MSXMirrorDevice::peekMem(uint16_t address, EmuTime time) const
27
{
28
	return interface.peekSlottedMem(addressHigh | address, time);
29
}
30
31
byte MSXMirrorDevice::readMem(uint16_t address, EmuTime time)
32
{
33
	return interface.readSlottedMem(addressHigh | address, time);
34
}
35
36
void MSXMirrorDevice::writeMem(uint16_t address, byte value, EmuTime time)
37
{
38
	interface.writeSlottedMem(addressHigh | address, value, time);
39
}
40
41
const byte* MSXMirrorDevice::getReadCacheLine(uint16_t /*start*/) const
42
{
43
	return nullptr;
44
}
45
46
byte* MSXMirrorDevice::getWriteCacheLine(uint16_t /*start*/)
47
{
48
	return nullptr;
49
}
50
51
bool MSXMirrorDevice::allowUnaligned() const
52
{
53
	// OK, because this device doesn't call any 'fillDeviceXXXCache()'functions.
54
	return true;
55
}
56
57
template<typename Archive>
58
void MSXMirrorDevice::serialize(Archive& ar, unsigned /*version*/)
59
{
60
	ar.template serializeBase<MSXDevice>(*this);
61
}
62
INSTANTIATE_SERIALIZE_METHODS(MSXMirrorDevice);
63
REGISTER_MSXDEVICE(MSXMirrorDevice, "Mirror");
64
65
} // namespace openmsx