| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "RomRamFile.hh" |
| 28 |
#include "MSXCPU.hh" |
| 29 |
#include "narrow.hh" |
| 30 |
#include "serialize.hh" |
| 31 |
#include <memory> |
| 32 |
|
| 33 |
namespace openmsx { |
| 34 |
|
| 35 |
RomRamFile::RomRamFile(const DeviceConfig& config, Rom&& rom_) |
| 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 |
|
| 43 |
void RomRamFile::reset(EmuTime ) |
| 44 |
{ |
| 45 |
shiftValue = 0; |
| 46 |
} |
| 47 |
|
| 48 |
byte RomRamFile::readMem(uint16_t address, EmuTime ) |
| 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 |
|
| 64 |
byte RomRamFile::peekMem(uint16_t address, EmuTime ) 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 |
|
| 75 |
const byte* RomRamFile::getReadCacheLine(uint16_t address) const |
| 76 |
{ |
| 77 |
if ((0x4000 <= address) && (address < 0x8000)) { |
| 78 |
|
| 79 |
return nullptr; |
| 80 |
} else if ((0x8000 <= address) && (address < 0xC000)) { |
| 81 |
return &(*sram)[address & 0x3fff]; |
| 82 |
} else { |
| 83 |
return unmappedRead.data(); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void RomRamFile::writeMem(uint16_t address, byte value, EmuTime ) |
| 88 |
{ |
| 89 |
if ((0x8000 <= address) && (address < 0xC000) && |
| 90 |
((shiftValue & 0x31) == 0x11)) { |
| 91 |
sram->write(address & 0x3fff, value); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
byte* RomRamFile::getWriteCacheLine(uint16_t address) |
| 96 |
{ |
| 97 |
if ((0x8000 <= address) && (address < 0xC000)) { |
| 98 |
|
| 99 |
return nullptr; |
| 100 |
} else { |
| 101 |
return unmappedWrite.data(); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
template<typename Archive> |
| 106 |
void RomRamFile::serialize(Archive& ar, unsigned ) |
| 107 |
{ |
| 108 |
|
| 109 |
ar.template serializeBase<MSXDevice>(*this); |
| 110 |
ar.serialize("shiftValue", shiftValue); |
| 111 |
} |
| 112 |
INSTANTIATE_SERIALIZE_METHODS(RomRamFile); |
| 113 |
REGISTER_MSXDEVICE(RomRamFile, "RomRamFile"); |
| 114 |
|
| 115 |
} |