openMSX
DriveMultiplexer.cc
Go to the documentation of this file.
1 #include "DriveMultiplexer.hh"
2 #include "serialize.hh"
3 
4 namespace openmsx {
5 
7 {
8  motor = false;
9  side = false;
10  selected = NO_DRIVE;
11  drive[DRIVE_A] = drv[0];
12  drive[DRIVE_B] = drv[1];
13  drive[DRIVE_C] = drv[2];
14  drive[DRIVE_D] = drv[3];
15  drive[NO_DRIVE] = &dummyDrive;
16 }
17 
18 void DriveMultiplexer::selectDrive(DriveNum num, EmuTime::param time)
19 {
20  if (selected != num) {
21  drive[selected]->setMotor(false, time);
22  selected = num;
23  drive[selected]->setSide(side);
24  drive[selected]->setMotor(motor, time);
25  }
26 }
27 
29 {
30  return drive[selected]->isDiskInserted();
31 }
32 
34 {
35  return drive[num]->isDiskInserted();
36 }
37 
39 {
40  return drive[selected]->isWriteProtected();
41 }
42 
44 {
45  return drive[selected]->isDoubleSided();
46 }
47 
48 void DriveMultiplexer::setSide(bool side_)
49 {
50  side = side_;
51  drive[selected]->setSide(side);
52 }
53 
55 {
56  return side;
57 }
58 
59 void DriveMultiplexer::step(bool direction, EmuTime::param time)
60 {
61  drive[selected]->step(direction, time);
62 }
63 
65 {
66  return drive[selected]->isTrack00();
67 }
68 
69 void DriveMultiplexer::setMotor(bool status, EmuTime::param time)
70 {
71  motor = status;
72  drive[selected]->setMotor(status, time);
73 }
74 
76 {
77  return motor;
78 }
79 
80 bool DriveMultiplexer::indexPulse(EmuTime::param time)
81 {
82  return drive[selected]->indexPulse(time);
83 }
84 
85 EmuTime DriveMultiplexer::getTimeTillIndexPulse(EmuTime::param time, int count)
86 {
87  return drive[selected]->getTimeTillIndexPulse(time, count);
88 }
89 
91 {
92  return drive[selected]->getTrackLength();
93 }
94 
95 void DriveMultiplexer::writeTrackByte(int idx, byte val, bool addIdam)
96 {
97  drive[selected]->writeTrackByte(idx, val, addIdam);
98 }
99 
101 {
102  return drive[selected]->readTrackByte(idx);
103 }
104 
105 EmuTime DriveMultiplexer::getNextSector(EmuTime::param time, RawTrack::Sector& sector)
106 {
107  return drive[selected]->getNextSector(time, sector);
108 }
109 
111 {
112  drive[selected]->flushTrack();
113 }
114 
116 {
117  return drive[selected]->diskChanged();
118 }
119 
121 {
122  return drive[num]->diskChanged();
123 }
124 
126 {
127  return drive[selected]->peekDiskChanged();
128 }
129 
131 {
132  return drive[num]->peekDiskChanged();
133 }
134 
136 {
137  return drive[selected]->isDummyDrive();
138 }
139 
141 {
142  drive[selected]->applyWd2793ReadTrackQuirk();
143 }
144 
146 {
147  drive[selected]->invalidateWd2793ReadTrackQuirk();
148 }
149 
150 
151 static constexpr std::initializer_list<enum_string<DriveMultiplexer::DriveNum>> driveNumInfo = {
152  { "A", DriveMultiplexer::DRIVE_A },
153  { "B", DriveMultiplexer::DRIVE_B },
154  { "C", DriveMultiplexer::DRIVE_C },
155  { "D", DriveMultiplexer::DRIVE_D },
156  { "none", DriveMultiplexer::NO_DRIVE }
157 };
159 
160 template<typename Archive>
161 void DriveMultiplexer::serialize(Archive& ar, unsigned /*version*/)
162 {
163  ar.serialize("selected", selected,
164  "motor", motor,
165  "side", side);
166 }
168 
169 } // namespace openmsx
This (abstract) class defines the DiskDrive interface.
Definition: DiskDrive.hh:13
virtual bool isDummyDrive() const =0
Is there a dummy (unconnected) drive?
virtual void applyWd2793ReadTrackQuirk()=0
See RawTrack::applyWd2793ReadTrackQuirk()
virtual bool peekDiskChanged() const =0
virtual bool isDiskInserted() const =0
Is drive ready?
virtual bool isWriteProtected() const =0
Is disk write protected?
virtual EmuTime getNextSector(EmuTime::param time, RawTrack::Sector &sector)=0
virtual void setMotor(bool status, EmuTime::param time)=0
Set motor on/off.
virtual void step(bool direction, EmuTime::param time)=0
Step head.
virtual bool isTrack00() const =0
Head above track 0.
virtual byte readTrackByte(int idx)=0
virtual bool indexPulse(EmuTime::param time)=0
Gets the state of the index pulse.
virtual bool isDoubleSided() const =0
Is disk double sided?
virtual void writeTrackByte(int idx, byte val, bool addIdam=false)=0
virtual EmuTime getTimeTillIndexPulse(EmuTime::param time, int count=1)=0
Return the time till the start of the next index pulse When there is no disk in the drive or when the...
virtual bool diskChanged()=0
Is disk changed?
virtual void setSide(bool side)=0
Side select.
virtual void flushTrack()=0
virtual unsigned getTrackLength()=0
virtual void invalidateWd2793ReadTrackQuirk()=0
This class connects to a FDC as a normal DiskDrive and deligates all requests to one of four other Di...
EmuTime getNextSector(EmuTime::param time, RawTrack::Sector &sector) override
void setMotor(bool status, EmuTime::param time) override
Set motor on/off.
void invalidateWd2793ReadTrackQuirk() override
byte readTrackByte(int idx) override
bool isTrack00() const override
Head above track 0.
bool isWriteProtected() const override
Is disk write protected?
bool peekDiskChanged() const override
void selectDrive(DriveNum num, EmuTime::param time)
bool isDiskInserted() const override
Is drive ready?
DriveMultiplexer(DiskDrive *drv[4])
EmuTime getTimeTillIndexPulse(EmuTime::param time, int count) override
Return the time till the start of the next index pulse When there is no disk in the drive or when the...
bool getMotor() const override
Returns the previously set motor status.
bool getSide() const override
bool diskChanged() override
Is disk changed?
void serialize(Archive &ar, unsigned version)
bool isDummyDrive() const override
Is there a dummy (unconnected) drive?
void applyWd2793ReadTrackQuirk() override
See RawTrack::applyWd2793ReadTrackQuirk()
bool indexPulse(EmuTime::param time) override
Gets the state of the index pulse.
void step(bool direction, EmuTime::param time) override
Step head.
bool isDoubleSided() const override
Is disk double sided?
void writeTrackByte(int idx, byte val, bool addIdam) override
void setSide(bool side) override
Side select.
unsigned getTrackLength() override
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:207
This file implemented 3 utility functions:
Definition: Autofire.cc:5
SERIALIZE_ENUM(CassettePlayer::State, stateInfo)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983