| 1 |
#include "MSXModem.hh" |
| 2 |
|
| 3 |
#include "CacheLine.hh" |
| 4 |
#include "MSXException.hh" |
| 5 |
#include "serialize.hh" |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
MSXModem::MSXModem(DeviceConfig& config) |
| 18 |
: MSXDevice(config) |
| 19 |
, rom(getName() + " ROM", "rom", config) |
| 20 |
, sram(getName() + " SRAM", 0x2000, config) |
| 21 |
{ |
| 22 |
if (rom.size() != 0x10000) { |
| 23 |
throw MSXException("ROM must be exactly 64kB in size!"); |
| 24 |
} |
| 25 |
reset(EmuTime::dummy()); |
| 26 |
} |
| 27 |
|
| 28 |
void MSXModem::reset(EmuTime ) |
| 29 |
{ |
| 30 |
bank = 0; |
| 31 |
selectedNCUreg = 0; |
| 32 |
} |
| 33 |
|
| 34 |
void MSXModem::writeMem(uint16_t address, uint8_t value, EmuTime ) |
| 35 |
{ |
| 36 |
if (address == 0x7FC0) { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
if (uint8_t newBank = value & 0b111; bank != newBank) { |
| 42 |
bank = newBank; |
| 43 |
invalidateDeviceRCache(); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
} else if (address == 0x7F00) { |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
} else if (address == 0x7F40) { |
| 59 |
|
| 60 |
selectedNCUreg = value; |
| 61 |
|
| 62 |
} else if ((0x6000 <= address) && (address < 0x8000)) { |
| 63 |
sram.write(address & 0x1FFF, value); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
uint8_t* MSXModem::getWriteCacheLine(uint16_t address) |
| 68 |
{ |
| 69 |
if (address == (0x7FC0 & CacheLine::HIGH)) return nullptr; |
| 70 |
if (address == (0x7F40 & CacheLine::HIGH)) return nullptr; |
| 71 |
if (address == (0x7F00 & CacheLine::HIGH)) return nullptr; |
| 72 |
if ((0x6000 <= address) && (address < 0x8000)) { |
| 73 |
return nullptr; |
| 74 |
} |
| 75 |
return unmappedWrite.data(); |
| 76 |
} |
| 77 |
|
| 78 |
uint8_t MSXModem::readMem(uint16_t address, EmuTime time) |
| 79 |
{ |
| 80 |
return peekMem(address, time); |
| 81 |
} |
| 82 |
|
| 83 |
uint8_t MSXModem::peekMem(uint16_t address, EmuTime ) const |
| 84 |
{ |
| 85 |
if (address == 0x7FC0) { |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
return 0; |
| 90 |
} else if (address == 0x7F00) { |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
static constexpr std::array<uint8_t, 4> ncuRegsRead = {0x00, 0x08, 0x00, 0x00}; |
| 111 |
|
| 112 |
return ncuRegsRead[selectedNCUreg & 0b11]; |
| 113 |
} else if ((0x4000 <= address) && (address < 0x6000)) { |
| 114 |
return rom[bank * 0x2000 + (address & 0x1FFF)]; |
| 115 |
} else if ((0x6000 <= address) && (address < 0x8000)) { |
| 116 |
return sram[address & 0x1FFF]; |
| 117 |
} else { |
| 118 |
return 0xFF; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
const uint8_t* MSXModem::getReadCacheLine(uint16_t address) const |
| 123 |
{ |
| 124 |
if (address == (0x7FC0 & CacheLine::HIGH)) return nullptr; |
| 125 |
if (address == (0x7F00 & CacheLine::HIGH)) return nullptr; |
| 126 |
if ((0x4000 <= address) && (address < 0x6000)) { |
| 127 |
return &rom[bank * 0x2000 + (address & 0x1FFF)]; |
| 128 |
} |
| 129 |
if ((0x6000 <= address) && (address < 0x8000)) { |
| 130 |
return &sram[address & 0x1FFF]; |
| 131 |
} |
| 132 |
return unmappedRead.data(); |
| 133 |
} |
| 134 |
|
| 135 |
template<typename Archive> |
| 136 |
void MSXModem::serialize(Archive& ar, unsigned ) |
| 137 |
{ |
| 138 |
ar.template serializeBase<MSXDevice>(*this); |
| 139 |
ar.serialize("SRAM", sram, |
| 140 |
"bank", bank, |
| 141 |
"selectedNCUreg", selectedNCUreg); |
| 142 |
} |
| 143 |
INSTANTIATE_SERIALIZE_METHODS(MSXModem); |
| 144 |
REGISTER_MSXDEVICE(MSXModem, "MSXModem"); |
| 145 |
|
| 146 |
} |