| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "RomAscii16_2.hh" |
| 18 |
#include "SRAM.hh" |
| 19 |
#include "serialize.hh" |
| 20 |
#include <memory> |
| 21 |
|
| 22 |
namespace openmsx { |
| 23 |
|
| 24 |
RomAscii16_2::RomAscii16_2(const DeviceConfig& config, Rom&& rom_, SubType subType) |
| 25 |
: RomAscii16kB(config, std::move(rom_)) |
| 26 |
{ |
| 27 |
unsigned size = (subType == SubType::ASCII16_8) ? 0x2000 |
| 28 |
: 0x0800; |
| 29 |
sram = std::make_unique<SRAM>(getName() + " SRAM", size, config); |
| 30 |
reset(EmuTime::dummy()); |
| 31 |
} |
| 32 |
|
| 33 |
void RomAscii16_2::reset(EmuTime time) |
| 34 |
{ |
| 35 |
sramEnabled = 0; |
| 36 |
RomAscii16kB::reset(time); |
| 37 |
} |
| 38 |
|
| 39 |
byte RomAscii16_2::readMem(uint16_t address, EmuTime time) |
| 40 |
{ |
| 41 |
if ((1 << (address >> 14)) & sramEnabled) { |
| 42 |
return (*sram)[address & (sram->size() - 1)]; |
| 43 |
} else { |
| 44 |
return RomAscii16kB::readMem(address, time); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
const byte* RomAscii16_2::getReadCacheLine(uint16_t address) const |
| 49 |
{ |
| 50 |
if ((1 << (address >> 14)) & sramEnabled) { |
| 51 |
return &(*sram)[address & (sram->size() - 1)]; |
| 52 |
} else { |
| 53 |
return RomAscii16kB::getReadCacheLine(address); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
void RomAscii16_2::writeMem(uint16_t address, byte value, EmuTime ) |
| 58 |
{ |
| 59 |
if ((0x6000 <= address) && (address < 0x7800) && !(address & 0x0800)) { |
| 60 |
|
| 61 |
byte region = ((address >> 12) & 1) + 1; |
| 62 |
if (value == 0x10) { |
| 63 |
|
| 64 |
sramEnabled |= (1 << region); |
| 65 |
} else { |
| 66 |
|
| 67 |
setRom(region, value); |
| 68 |
sramEnabled &= byte(~(1 << region)); |
| 69 |
} |
| 70 |
invalidateDeviceRWCache(0x4000 * region, 0x4000); |
| 71 |
} else { |
| 72 |
|
| 73 |
if ((1 << (address >> 14)) & sramEnabled & 0x04) { |
| 74 |
sram->write(address & (sram->size() - 1), value); |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
byte* RomAscii16_2::getWriteCacheLine(uint16_t address) |
| 80 |
{ |
| 81 |
if ((1 << (address >> 14)) & sramEnabled & 0x04) { |
| 82 |
|
| 83 |
return nullptr; |
| 84 |
} else { |
| 85 |
return RomAscii16kB::getWriteCacheLine(address); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
template<typename Archive> |
| 90 |
void RomAscii16_2::serialize(Archive& ar, unsigned ) |
| 91 |
{ |
| 92 |
ar.template serializeBase<RomAscii16kB>(*this); |
| 93 |
ar.serialize("sramEnabled", sramEnabled); |
| 94 |
} |
| 95 |
INSTANTIATE_SERIALIZE_METHODS(RomAscii16_2); |
| 96 |
REGISTER_MSXDEVICE(RomAscii16_2, "RomAscii16_2"); |
| 97 |
|
| 98 |
} |