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