| 1 |
#include "SpectravideoFDC.hh" |
| 2 |
|
| 3 |
#include "DriveMultiplexer.hh" |
| 4 |
#include "WD2793.hh" |
| 5 |
|
| 6 |
#include "CacheLine.hh" |
| 7 |
#include "MSXException.hh" |
| 8 |
#include "serialize.hh" |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace openmsx { |
| 24 |
|
| 25 |
SpectravideoFDC::SpectravideoFDC(DeviceConfig& config) |
| 26 |
: WD2793BasedFDC(config, "msxdos") |
| 27 |
, cpmRom(getName() + " CP/M ROM", "rom", config, "cpm") |
| 28 |
{ |
| 29 |
if (cpmRom.size() != 0x1000) { |
| 30 |
throw MSXException("CP/M ROM must be exactly 4kB in size."); |
| 31 |
} |
| 32 |
reset(getCurrentTime()); |
| 33 |
} |
| 34 |
|
| 35 |
void SpectravideoFDC::reset(EmuTime ) |
| 36 |
{ |
| 37 |
cpmRomEnabled = true; |
| 38 |
invalidateDeviceRCache(0x4000, 0x4000); |
| 39 |
} |
| 40 |
|
| 41 |
byte SpectravideoFDC::readMem(uint16_t address, EmuTime time) |
| 42 |
{ |
| 43 |
switch (address & 0x3FFF) { |
| 44 |
case 0x3FB8: |
| 45 |
return controller.getStatusReg(time); |
| 46 |
case 0x3FB9: |
| 47 |
return controller.getTrackReg(time); |
| 48 |
case 0x3FBA: |
| 49 |
return controller.getSectorReg(time); |
| 50 |
case 0x3FBB: |
| 51 |
return controller.getDataReg(time); |
| 52 |
case 0x3FBC: { |
| 53 |
byte value = 0; |
| 54 |
if ( controller.getIRQ (time)) value |= 0x80; |
| 55 |
if (!controller.getDTRQ(time)) value |= 0x40; |
| 56 |
return value; |
| 57 |
} |
| 58 |
case 0x3FBE: |
| 59 |
|
| 60 |
cpmRomEnabled = true; |
| 61 |
invalidateDeviceRCache(0x4000, 0x4000); |
| 62 |
return 0xFF; |
| 63 |
case 0x3FBF: |
| 64 |
|
| 65 |
cpmRomEnabled = false; |
| 66 |
invalidateDeviceRCache(0x4000, 0x4000); |
| 67 |
return 0xFF; |
| 68 |
default: |
| 69 |
return SpectravideoFDC::peekMem(address, time); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
byte SpectravideoFDC::peekMem(uint16_t address, EmuTime time) const |
| 74 |
{ |
| 75 |
switch (address & 0x3FFF) { |
| 76 |
case 0x3FB8: |
| 77 |
return controller.peekStatusReg(time); |
| 78 |
case 0x3FB9: |
| 79 |
return controller.peekTrackReg(time); |
| 80 |
case 0x3FBA: |
| 81 |
return controller.peekSectorReg(time); |
| 82 |
case 0x3FBB: |
| 83 |
return controller.peekDataReg(time); |
| 84 |
case 0x3FBC: { |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
byte value = 0; |
| 90 |
if ( controller.peekIRQ (time)) value |= 0x80; |
| 91 |
if (!controller.peekDTRQ(time)) value |= 0x40; |
| 92 |
return value; |
| 93 |
} |
| 94 |
default: |
| 95 |
if ((0x4000 <= address) && (address < 0x8000) && !cpmRomEnabled) { |
| 96 |
|
| 97 |
return MSXFDC::peekMem(address, time); |
| 98 |
} else if ((0x4000 <= address) && (address < 0x5000) && cpmRomEnabled) { |
| 99 |
|
| 100 |
return cpmRom[address & 0x0FFF]; |
| 101 |
} else { |
| 102 |
return 0xFF; |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
const byte* SpectravideoFDC::getReadCacheLine(uint16_t start) const |
| 108 |
{ |
| 109 |
if ((start & 0x3FFF & CacheLine::HIGH) == (0x3FB8 & CacheLine::HIGH)) { |
| 110 |
|
| 111 |
return nullptr; |
| 112 |
} else if ((0x4000 <= start) && (start < 0x8000) && !cpmRomEnabled) { |
| 113 |
|
| 114 |
return MSXFDC::getReadCacheLine(start); |
| 115 |
} else if ((0x4000 <= start) && (start < 0x5000) && cpmRomEnabled) { |
| 116 |
|
| 117 |
return &cpmRom[start & 0x0FFF]; |
| 118 |
} else { |
| 119 |
return unmappedRead.data(); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
void SpectravideoFDC::writeMem(uint16_t address, byte value, EmuTime time) |
| 124 |
{ |
| 125 |
switch (address & 0x3FFF) { |
| 126 |
case 0x3FB8: |
| 127 |
controller.setCommandReg(value, time); |
| 128 |
break; |
| 129 |
case 0x3FB9: |
| 130 |
controller.setTrackReg(value, time); |
| 131 |
break; |
| 132 |
case 0x3FBA: |
| 133 |
controller.setSectorReg(value, time); |
| 134 |
break; |
| 135 |
case 0x3FBB: |
| 136 |
controller.setDataReg(value, time); |
| 137 |
break; |
| 138 |
case 0x3FBC: |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
multiplexer.selectDrive((value & 0x01) != 0 ? DriveMultiplexer::Drive::A : DriveMultiplexer::Drive::NONE, time); |
| 143 |
multiplexer.setSide ((value & 0x04) != 0); |
| 144 |
multiplexer.setMotor ((value & 0x08) != 0, time); |
| 145 |
break; |
| 146 |
case 0x3FBE: |
| 147 |
|
| 148 |
invalidateDeviceRCache(0x4000, 0x4000); |
| 149 |
cpmRomEnabled = true; |
| 150 |
break; |
| 151 |
case 0x3FBF: |
| 152 |
|
| 153 |
invalidateDeviceRCache(0x4000, 0x4000); |
| 154 |
cpmRomEnabled = false; |
| 155 |
break; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
byte* SpectravideoFDC::getWriteCacheLine(uint16_t address) |
| 160 |
{ |
| 161 |
if ((address & 0x3FFF & CacheLine::HIGH) == (0x3FB8 & CacheLine::HIGH)) { |
| 162 |
|
| 163 |
return nullptr; |
| 164 |
} else { |
| 165 |
return unmappedWrite.data(); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
template<typename Archive> |
| 170 |
void SpectravideoFDC::serialize(Archive& ar, unsigned ) |
| 171 |
{ |
| 172 |
ar.template serializeBase<WD2793BasedFDC>(*this); |
| 173 |
ar.serialize("cpmRomEnabled", cpmRomEnabled); |
| 174 |
} |
| 175 |
INSTANTIATE_SERIALIZE_METHODS(SpectravideoFDC); |
| 176 |
REGISTER_MSXDEVICE(SpectravideoFDC, "SpectravideoFDC"); |
| 177 |
|
| 178 |
} |