| 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 |
|
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
void MSXRam::init() |
| 20 |
{ |
| 21 |
MSXDevice::init(); |
| 22 |
|
| 23 |
|
| 24 |
getVisibleMemRegion(base, size); |
| 25 |
|
| 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 ) |
| 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 ) const |
| 48 |
{ |
| 49 |
return checkedRam->peek(translate(address)); |
| 50 |
} |
| 51 |
|
| 52 |
byte MSXRam::readMem(uint16_t address, EmuTime ) |
| 53 |
{ |
| 54 |
return checkedRam->read(translate(address)); |
| 55 |
} |
| 56 |
|
| 57 |
void MSXRam::writeMem(uint16_t address, byte value, EmuTime ) |
| 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 ) |
| 74 |
{ |
| 75 |
ar.template serializeBase<MSXDevice>(*this); |
| 76 |
|
| 77 |
ar.serialize("ram", checkedRam->getUncheckedRam()); |
| 78 |
} |
| 79 |
INSTANTIATE_SERIALIZE_METHODS(MSXRam); |
| 80 |
REGISTER_MSXDEVICE(MSXRam, "Ram"); |
| 81 |
|
| 82 |
} |