| 1 |
#include "DriveMultiplexer.hh" |
| 2 |
|
| 3 |
#include "serialize.hh" |
| 4 |
|
| 5 |
namespace openmsx { |
| 6 |
|
| 7 |
DriveMultiplexer::DriveMultiplexer(std::span<std::unique_ptr<DiskDrive>, 4> drv) |
| 8 |
{ |
| 9 |
drive[Drive::A] = drv[0].get(); |
| 10 |
drive[Drive::B] = drv[1].get(); |
| 11 |
drive[Drive::C] = drv[2].get(); |
| 12 |
drive[Drive::D] = drv[3].get(); |
| 13 |
drive[Drive::NONE] = &dummyDrive; |
| 14 |
} |
| 15 |
|
| 16 |
void DriveMultiplexer::selectDrive(Drive num, EmuTime time) |
| 17 |
{ |
| 18 |
if (selected != num) { |
| 19 |
drive[selected]->setMotor(false, time); |
| 20 |
selected = num; |
| 21 |
drive[selected]->setSide(side); |
| 22 |
drive[selected]->setMotor(motor, time); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
bool DriveMultiplexer::isDiskInserted() const |
| 27 |
{ |
| 28 |
return drive[selected]->isDiskInserted(); |
| 29 |
} |
| 30 |
|
| 31 |
bool DriveMultiplexer::isDiskInserted(Drive num) const |
| 32 |
{ |
| 33 |
return drive[num]->isDiskInserted(); |
| 34 |
} |
| 35 |
|
| 36 |
bool DriveMultiplexer::isWriteProtected() const |
| 37 |
{ |
| 38 |
return drive[selected]->isWriteProtected(); |
| 39 |
} |
| 40 |
|
| 41 |
bool DriveMultiplexer::isDoubleSided() |
| 42 |
{ |
| 43 |
return drive[selected]->isDoubleSided(); |
| 44 |
} |
| 45 |
|
| 46 |
void DriveMultiplexer::setSide(bool side_) |
| 47 |
{ |
| 48 |
side = side_; |
| 49 |
drive[selected]->setSide(side); |
| 50 |
} |
| 51 |
|
| 52 |
bool DriveMultiplexer::getSide() const |
| 53 |
{ |
| 54 |
return side; |
| 55 |
} |
| 56 |
|
| 57 |
void DriveMultiplexer::step(bool direction, EmuTime time) |
| 58 |
{ |
| 59 |
drive[selected]->step(direction, time); |
| 60 |
} |
| 61 |
|
| 62 |
bool DriveMultiplexer::isTrack00() const |
| 63 |
{ |
| 64 |
return drive[selected]->isTrack00(); |
| 65 |
} |
| 66 |
|
| 67 |
void DriveMultiplexer::setMotor(bool status, EmuTime time) |
| 68 |
{ |
| 69 |
motor = status; |
| 70 |
drive[selected]->setMotor(status, time); |
| 71 |
} |
| 72 |
|
| 73 |
bool DriveMultiplexer::getMotor() const |
| 74 |
{ |
| 75 |
return motor; |
| 76 |
} |
| 77 |
|
| 78 |
bool DriveMultiplexer::indexPulse(EmuTime time) |
| 79 |
{ |
| 80 |
return drive[selected]->indexPulse(time); |
| 81 |
} |
| 82 |
|
| 83 |
EmuTime DriveMultiplexer::getTimeTillIndexPulse(EmuTime time, int count) |
| 84 |
{ |
| 85 |
return drive[selected]->getTimeTillIndexPulse(time, count); |
| 86 |
} |
| 87 |
|
| 88 |
unsigned DriveMultiplexer::getTrackLength() |
| 89 |
{ |
| 90 |
return drive[selected]->getTrackLength(); |
| 91 |
} |
| 92 |
|
| 93 |
void DriveMultiplexer::writeTrackByte(int idx, uint8_t val, bool addIdam) |
| 94 |
{ |
| 95 |
drive[selected]->writeTrackByte(idx, val, addIdam); |
| 96 |
} |
| 97 |
|
| 98 |
uint8_t DriveMultiplexer::readTrackByte(int idx) |
| 99 |
{ |
| 100 |
return drive[selected]->readTrackByte(idx); |
| 101 |
} |
| 102 |
|
| 103 |
EmuTime DriveMultiplexer::getNextSector(EmuTime time, RawTrack::Sector& sector) |
| 104 |
{ |
| 105 |
return drive[selected]->getNextSector(time, sector); |
| 106 |
} |
| 107 |
|
| 108 |
void DriveMultiplexer::flushTrack() |
| 109 |
{ |
| 110 |
drive[selected]->flushTrack(); |
| 111 |
} |
| 112 |
|
| 113 |
bool DriveMultiplexer::diskChanged() |
| 114 |
{ |
| 115 |
return drive[selected]->diskChanged(); |
| 116 |
} |
| 117 |
|
| 118 |
bool DriveMultiplexer::diskChanged(Drive num) |
| 119 |
{ |
| 120 |
return drive[num]->diskChanged(); |
| 121 |
} |
| 122 |
|
| 123 |
bool DriveMultiplexer::peekDiskChanged() const |
| 124 |
{ |
| 125 |
return drive[selected]->peekDiskChanged(); |
| 126 |
} |
| 127 |
|
| 128 |
bool DriveMultiplexer::peekDiskChanged(Drive num) const |
| 129 |
{ |
| 130 |
return drive[num]->peekDiskChanged(); |
| 131 |
} |
| 132 |
|
| 133 |
bool DriveMultiplexer::isDummyDrive() const |
| 134 |
{ |
| 135 |
return drive[selected]->isDummyDrive(); |
| 136 |
} |
| 137 |
|
| 138 |
void DriveMultiplexer::applyWd2793ReadTrackQuirk() |
| 139 |
{ |
| 140 |
drive[selected]->applyWd2793ReadTrackQuirk(); |
| 141 |
} |
| 142 |
|
| 143 |
void DriveMultiplexer::invalidateWd2793ReadTrackQuirk() |
| 144 |
{ |
| 145 |
drive[selected]->invalidateWd2793ReadTrackQuirk(); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
static constexpr auto driveNumInfo = std::to_array<enum_string<DriveMultiplexer::Drive>>({ |
| 150 |
{ "A", DriveMultiplexer::Drive::A }, |
| 151 |
{ "B", DriveMultiplexer::Drive::B }, |
| 152 |
{ "C", DriveMultiplexer::Drive::C }, |
| 153 |
{ "D", DriveMultiplexer::Drive::D }, |
| 154 |
{ "none", DriveMultiplexer::Drive::NONE }, |
| 155 |
}); |
| 156 |
SERIALIZE_ENUM(DriveMultiplexer::Drive, driveNumInfo); |
| 157 |
|
| 158 |
template<typename Archive> |
| 159 |
void DriveMultiplexer::serialize(Archive& ar, unsigned ) |
| 160 |
{ |
| 161 |
ar.serialize("selected", selected, |
| 162 |
"motor", motor, |
| 163 |
"side", side); |
| 164 |
} |
| 165 |
INSTANTIATE_SERIALIZE_METHODS(DriveMultiplexer); |
| 166 |
|
| 167 |
} |