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 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
openmsx::DriveMultiplexer::DRIVE_C
@ DRIVE_C
Definition: DriveMultiplexer.hh:18
openmsx::DriveMultiplexer::applyWd2793ReadTrackQuirk
void applyWd2793ReadTrackQuirk() override
See RawTrack::applyWd2793ReadTrackQuirk()
Definition: DriveMultiplexer.cc:140
openmsx::DiskDrive::step
virtual void step(bool direction, EmuTime::param time)=0
Step head.
serialize.hh
openmsx::DiskDrive::isWriteProtected
virtual bool isWriteProtected() const =0
Is disk write protected?
openmsx::DriveMultiplexer::peekDiskChanged
bool peekDiskChanged() const override
Definition: DriveMultiplexer.cc:125
openmsx::DiskDrive
This (abstract) class defines the DiskDrive interface.
Definition: DiskDrive.hh:12
openmsx::DriveMultiplexer::invalidateWd2793ReadTrackQuirk
void invalidateWd2793ReadTrackQuirk() override
Definition: DriveMultiplexer.cc:145
openmsx::DriveMultiplexer::getMotor
bool getMotor() const override
Returns the previously set motor status.
Definition: DriveMultiplexer.cc:75
openmsx::DriveMultiplexer::getNextSector
EmuTime getNextSector(EmuTime::param time, RawTrack::Sector &sector) override
Definition: DriveMultiplexer.cc:105
openmsx::SERIALIZE_ENUM
SERIALIZE_ENUM(CassettePlayer::State, stateInfo)
openmsx::DiskDrive::isDiskInserted
virtual bool isDiskInserted() const =0
Is drive ready?
openmsx::DiskDrive::isTrack00
virtual bool isTrack00() const =0
Head above track 0.
openmsx::DriveMultiplexer::writeTrackByte
void writeTrackByte(int idx, byte val, bool addIdam) override
Definition: DriveMultiplexer.cc:95
LZ4::count
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:207
openmsx::DiskDrive::readTrackByte
virtual byte readTrackByte(int idx)=0
openmsx::DriveMultiplexer::isDoubleSided
bool isDoubleSided() const override
Is disk double sided?
Definition: DriveMultiplexer.cc:43
openmsx::DiskDrive::isDummyDrive
virtual bool isDummyDrive() const =0
Is there a dummy (unconncted) drive?
openmsx::DiskDrive::getTrackLength
virtual unsigned getTrackLength()=0
openmsx::DriveMultiplexer::readTrackByte
byte readTrackByte(int idx) override
Definition: DriveMultiplexer.cc:100
openmsx::DriveMultiplexer::setMotor
void setMotor(bool status, EmuTime::param time) override
Set motor on/off.
Definition: DriveMultiplexer.cc:69
openmsx::DriveMultiplexer::isDummyDrive
bool isDummyDrive() const override
Is there a dummy (unconncted) drive?
Definition: DriveMultiplexer.cc:135
openmsx::DiskDrive::flushTrack
virtual void flushTrack()=0
openmsx::DriveMultiplexer::NO_DRIVE
@ NO_DRIVE
Definition: DriveMultiplexer.hh:20
openmsx::DiskDrive::writeTrackByte
virtual void writeTrackByte(int idx, byte val, bool addIdam=false)=0
openmsx::DiskDrive::isDoubleSided
virtual bool isDoubleSided() const =0
Is disk double sided?
openmsx::DriveMultiplexer::setSide
void setSide(bool side) override
Side select.
Definition: DriveMultiplexer.cc:48
openmsx::DriveMultiplexer::isTrack00
bool isTrack00() const override
Head above track 0.
Definition: DriveMultiplexer.cc:64
openmsx::DiskDrive::invalidateWd2793ReadTrackQuirk
virtual void invalidateWd2793ReadTrackQuirk()=0
openmsx::DriveMultiplexer::serialize
void serialize(Archive &ar, unsigned version)
Definition: DriveMultiplexer.cc:161
openmsx::DriveMultiplexer::DRIVE_B
@ DRIVE_B
Definition: DriveMultiplexer.hh:17
openmsx::DriveMultiplexer::DriveMultiplexer
DriveMultiplexer(DiskDrive *drv[4])
Definition: DriveMultiplexer.cc:6
openmsx::DriveMultiplexer::DRIVE_D
@ DRIVE_D
Definition: DriveMultiplexer.hh:19
openmsx::DriveMultiplexer::isDiskInserted
bool isDiskInserted() const override
Is drive ready?
Definition: DriveMultiplexer.cc:28
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::DiskDrive::setSide
virtual void setSide(bool side)=0
Side select.
openmsx::DriveMultiplexer::DRIVE_A
@ DRIVE_A
Definition: DriveMultiplexer.hh:16
openmsx::DriveMultiplexer::indexPulse
bool indexPulse(EmuTime::param time) override
Gets the state of the index pulse.
Definition: DriveMultiplexer.cc:80
openmsx::DriveMultiplexer::getTrackLength
unsigned getTrackLength() override
Definition: DriveMultiplexer.cc:90
openmsx::DriveMultiplexer::getTimeTillIndexPulse
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...
Definition: DriveMultiplexer.cc:85
openmsx::DiskDrive::getTimeTillIndexPulse
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...
openmsx::DiskDrive::peekDiskChanged
virtual bool peekDiskChanged() const =0
DriveMultiplexer.hh
openmsx::RawTrack::Sector
Definition: RawTrack.hh:73
openmsx::DiskDrive::applyWd2793ReadTrackQuirk
virtual void applyWd2793ReadTrackQuirk()=0
See RawTrack::applyWd2793ReadTrackQuirk()
openmsx::DiskDrive::indexPulse
virtual bool indexPulse(EmuTime::param time)=0
Gets the state of the index pulse.
openmsx::DiskDrive::setMotor
virtual void setMotor(bool status, EmuTime::param time)=0
Set motor on/off.
openmsx::DriveMultiplexer::flushTrack
void flushTrack() override
Definition: DriveMultiplexer.cc:110
openmsx::DriveMultiplexer::getSide
bool getSide() const override
Definition: DriveMultiplexer.cc:54
openmsx::DriveMultiplexer::selectDrive
void selectDrive(DriveNum num, EmuTime::param time)
Definition: DriveMultiplexer.cc:18
openmsx::DiskDrive::getNextSector
virtual EmuTime getNextSector(EmuTime::param time, RawTrack::Sector &sector)=0
openmsx::DriveMultiplexer::DriveNum
DriveNum
Definition: DriveMultiplexer.hh:15
openmsx::DriveMultiplexer
This class connects to a FDC as a normal DiskDrive and deligates all requests to one of four other Di...
Definition: DriveMultiplexer.hh:12
openmsx::DriveMultiplexer::diskChanged
bool diskChanged() override
Is disk changed?
Definition: DriveMultiplexer.cc:115
openmsx::DriveMultiplexer::isWriteProtected
bool isWriteProtected() const override
Is disk write protected?
Definition: DriveMultiplexer.cc:38
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::DiskDrive::diskChanged
virtual bool diskChanged()=0
Is disk changed?
openmsx::DriveMultiplexer::step
void step(bool direction, EmuTime::param time) override
Step head.
Definition: DriveMultiplexer.cc:59