openMSX
RomRamFile.cc
Go to the documentation of this file.
1
27#include "RomRamFile.hh"
28#include "MSXCPU.hh"
29#include "narrow.hh"
30#include "serialize.hh"
31#include <memory>
32
33namespace openmsx {
34
36 : MSXRom(config, std::move(rom_))
37 , cpu(getCPU())
38{
39 sram = std::make_unique<SRAM>(getName() + " SRAM", 0x4000, config);
40 reset(EmuTime::dummy());
41}
42
43void RomRamFile::reset(EmuTime::param /*time*/)
44{
45 shiftValue = 0;
46}
47
48byte RomRamFile::readMem(word address, EmuTime::param /*time*/)
49{
50 if ((0x4000 <= address) && (address < 0x8000)) {
51 byte result = rom[address & 0x1fff];
52 if (cpu.isM1Cycle(address)) {
53 bool tmp = (result & 0x44) == 0x44;
54 shiftValue = narrow_cast<byte>((shiftValue << 1) | byte(tmp));
55 }
56 return result;
57 } else if ((0x8000 <= address) && (address < 0xC000)) {
58 return (*sram)[address & 0x3fff];
59 } else {
60 return 0xff;
61 }
62}
63
64byte RomRamFile::peekMem(word address, EmuTime::param /*time*/) const
65{
66 if ((0x4000 <= address) && (address < 0x8000)) {
67 return rom[address & 0x1fff];
68 } else if ((0x8000 <= address) && (address < 0xC000)) {
69 return (*sram)[address & 0x3fff];
70 } else {
71 return 0xff;
72 }
73}
74
75const byte* RomRamFile::getReadCacheLine(word address) const
76{
77 if ((0x4000 <= address) && (address < 0x8000)) {
78 // reads from ROM are not cacheable because of the M1 stuff
79 return nullptr;
80 } else if ((0x8000 <= address) && (address < 0xC000)) {
81 return &(*sram)[address & 0x3fff];
82 } else {
83 return unmappedRead.data();
84 }
85}
86
87void RomRamFile::writeMem(word address, byte value, EmuTime::param /*time*/)
88{
89 if ((0x8000 <= address) && (address < 0xC000) &&
90 ((shiftValue & 0x31) == 0x11)) {
91 sram->write(address & 0x3fff, value);
92 }
93}
94
96{
97 if ((0x8000 <= address) && (address < 0xC000)) {
98 // writes to SRAM are not cacheable because of sync-to-disk
99 return nullptr;
100 } else {
101 return unmappedWrite.data();
102 }
103}
104
105template<typename Archive>
106void RomRamFile::serialize(Archive& ar, unsigned /*version*/)
107{
108 // skip MSXRom base class
109 ar.template serializeBase<MSXDevice>(*this);
110 ar.serialize("shiftValue", shiftValue);
111}
114
115} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:354
bool isM1Cycle(unsigned address) const
Should only be used from within a MSXDevice::readMem() method.
Definition MSXCPU.cc:310
static std::array< byte, 0x10000 > unmappedRead
Definition MSXDevice.hh:304
virtual const std::string & getName() const
Returns a human-readable name for this device.
Definition MSXDevice.cc:375
static std::array< byte, 0x10000 > unmappedWrite
Definition MSXDevice.hh:305
void reset(EmuTime::param time) override
This method is called on reset.
Definition RomRamFile.cc:43
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition RomRamFile.cc:75
void serialize(Archive &ar, unsigned version)
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition RomRamFile.cc:95
RomRamFile(const DeviceConfig &config, Rom &&rom)
Definition RomRamFile.cc:35
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition RomRamFile.cc:48
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 RomRamFile.cc:87
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition RomRamFile.cc:64
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)