openMSX
RealDrive.hh
Go to the documentation of this file.
1 #ifndef REALDRIVE_HH
2 #define REALDRIVE_HH
3 
4 #include "DiskDrive.hh"
5 #include "Clock.hh"
6 #include "Schedulable.hh"
7 #include "ThrottleManager.hh"
8 #include "outer.hh"
9 #include "serialize_meta.hh"
10 #include <bitset>
11 #include <memory>
12 #include <optional>
13 
14 namespace openmsx {
15 
16 class MSXMotherBoard;
17 class DiskChanger;
18 
21 class RealDrive final : public DiskDrive
22 {
23 public:
24  RealDrive(MSXMotherBoard& motherBoard, EmuDuration::param motorTimeout,
25  bool signalsNeedMotorOn, bool doubleSided,
26  DiskDrive::TrackMode trackMode);
27  ~RealDrive() override;
28 
29  // DiskDrive interface
30  bool isDiskInserted() const override;
31  bool isWriteProtected() const override;
32  bool isDoubleSided() const override;
33  bool isTrack00() const override;
34  void setSide(bool side) override;
35  bool getSide() const override;
36  void step(bool direction, EmuTime::param time) override;
37  void setMotor(bool status, EmuTime::param time) override;
38  bool getMotor() const override;
39  bool indexPulse(EmuTime::param time) override;
40  EmuTime getTimeTillIndexPulse(EmuTime::param time, int count) override;
41 
42  unsigned getTrackLength() override;
43  void writeTrackByte(int idx, byte val, bool addIdam) override;
44  byte readTrackByte(int idx) override;
45  EmuTime getNextSector(EmuTime::param time, RawTrack::Sector& sector) override;
46  void flushTrack() override;
47  bool diskChanged() override;
48  bool peekDiskChanged() const override;
49  bool isDummyDrive() const override;
50 
51  void applyWd2793ReadTrackQuirk() override;
52  void invalidateWd2793ReadTrackQuirk() override;
53 
54  template<typename Archive>
55  void serialize(Archive& ar, unsigned version);
56 
57 private:
58  struct SyncLoadingTimeout final : Schedulable {
59  friend class RealDrive;
60  explicit SyncLoadingTimeout(Scheduler& s) : Schedulable(s) {}
61  void executeUntil(EmuTime::param /*time*/) override {
62  auto& drive = OUTER(RealDrive, syncLoadingTimeout);
63  drive.execLoadingTimeout();
64  }
65  } syncLoadingTimeout;
66 
67  struct SyncMotorTimeout final : Schedulable {
68  friend class RealDrive;
69  explicit SyncMotorTimeout(Scheduler& s) : Schedulable(s) {}
70  void executeUntil(EmuTime::param time) override {
71  auto& drive = OUTER(RealDrive, syncMotorTimeout);
72  drive.execMotorTimeout(time);
73  }
74  } syncMotorTimeout;
75 
76  void execLoadingTimeout();
77  void execMotorTimeout(EmuTime::param time);
78  EmuTime::param getCurrentTime() const { return syncLoadingTimeout.getCurrentTime(); }
79 
80  void doSetMotor(bool status, EmuTime::param time);
81  void setLoading(EmuTime::param time);
82  unsigned getCurrentAngle(EmuTime::param time) const;
83 
84  unsigned getMaxTrack() const;
85  std::optional<unsigned> getDiskReadTrack() const;
86  std::optional<unsigned> getDiskWriteTrack() const;
87  void getTrack();
88  void invalidateTrack();
89 
90  static constexpr unsigned TICKS_PER_ROTATION = 200000;
91  static constexpr unsigned INDEX_DURATION = TICKS_PER_ROTATION / 50;
92 
93  MSXMotherBoard& motherBoard;
94  LoadingIndicator loadingIndicator;
95  const EmuDuration motorTimeout;
96 
98  MotorClock motorTimer;
99  std::unique_ptr<DiskChanger> changer;
100  unsigned headPos;
101  unsigned side;
102  unsigned startAngle;
103  bool motorStatus;
104  const bool doubleSizedDrive;
105  const bool signalsNeedMotorOn;
106  const DiskDrive::TrackMode trackMode;
107 
108  static constexpr unsigned MAX_DRIVES = 26; // a-z
109  using DrivesInUse = std::bitset<MAX_DRIVES>;
110  std::shared_ptr<DrivesInUse> drivesInUse;
111 
112  RawTrack track;
113  bool trackValid;
114  bool trackDirty;
115 };
117 
118 } // namespace openmsx
119 
120 #endif
Clock.hh
openmsx::Scheduler
Definition: Scheduler.hh:34
openmsx::RealDrive::getMotor
bool getMotor() const override
Returns the previously set motor status.
Definition: RealDrive.cc:259
openmsx::DiskDrive
This (abstract) class defines the DiskDrive interface.
Definition: DiskDrive.hh:13
openmsx::EmuDuration
Definition: EmuDuration.hh:19
DiskDrive.hh
serialize_meta.hh
openmsx::RealDrive::serialize
void serialize(Archive &ar, unsigned version)
Definition: RealDrive.cc:463
openmsx::RealDrive::flushTrack
void flushTrack() override
Definition: RealDrive.cc:420
openmsx::RawTrack
Definition: RawTrack.hh:62
LZ4::count
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:207
openmsx::RealDrive::~RealDrive
~RealDrive() override
Definition: RealDrive.cc:55
openmsx::RealDrive::getSide
bool getSide() const override
Definition: RealDrive.cc:111
openmsx::Schedulable
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
Schedulable.hh
openmsx::RealDrive::isDummyDrive
bool isDummyDrive() const override
Is there a dummy (unconncted) drive?
Definition: RealDrive.cc:440
openmsx::RealDrive::setSide
void setSide(bool side) override
Side select.
Definition: RealDrive.cc:105
openmsx::DiskChanger
DiskChanger
Definition: DiskChanger.cc:415
openmsx::RealDrive::writeTrackByte
void writeTrackByte(int idx, byte val, bool addIdam) override
Definition: RealDrive.cc:373
openmsx::RealDrive::RealDrive
RealDrive(MSXMotherBoard &motherBoard, EmuDuration::param motorTimeout, bool signalsNeedMotorOn, bool doubleSided, DiskDrive::TrackMode trackMode)
Definition: RealDrive.cc:19
openmsx::RealDrive
This class implements a real drive, single or double sided.
Definition: RealDrive.hh:22
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::LoadingIndicator
Used by a device to indicate when it is loading.
Definition: ThrottleManager.hh:58
openmsx::RealDrive::getTrackLength
unsigned getTrackLength() override
Definition: RealDrive.cc:367
openmsx::RealDrive::setMotor
void setMotor(bool status, EmuTime::param time) override
Set motor on/off.
Definition: RealDrive.cc:204
OUTER
#define OUTER(type, member)
Definition: outer.hh:41
openmsx::RealDrive::isDiskInserted
bool isDiskInserted() const override
Is drive ready?
Definition: RealDrive.cc:72
openmsx::RealDrive::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: RealDrive.cc:328
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:60
openmsx::RealDrive::isDoubleSided
bool isDoubleSided() const override
Is disk double sided?
Definition: RealDrive.cc:99
openmsx::RealDrive::indexPulse
bool indexPulse(EmuTime::param time) override
Gets the state of the index pulse.
Definition: RealDrive.cc:317
openmsx::RealDrive::getNextSector
EmuTime getNextSector(EmuTime::param time, RawTrack::Sector &sector) override
Definition: RealDrive.cc:392
openmsx::RealDrive::diskChanged
bool diskChanged() override
Is disk changed?
Definition: RealDrive.cc:430
openmsx::RealDrive::peekDiskChanged
bool peekDiskChanged() const override
Definition: RealDrive.cc:435
ThrottleManager.hh
openmsx::RealDrive::applyWd2793ReadTrackQuirk
void applyWd2793ReadTrackQuirk() override
See RawTrack::applyWd2793ReadTrackQuirk()
Definition: RealDrive.cc:445
openmsx::RealDrive::isWriteProtected
bool isWriteProtected() const override
Is disk write protected?
Definition: RealDrive.cc:91
openmsx::RawTrack::Sector
Definition: RawTrack.hh:74
outer.hh
openmsx::Schedulable
Schedulable
Definition: Schedulable.cc:69
openmsx::RealDrive::invalidateWd2793ReadTrackQuirk
void invalidateWd2793ReadTrackQuirk() override
Definition: RealDrive.cc:450
openmsx::RealDrive::readTrackByte
byte readTrackByte(int idx) override
Definition: RealDrive.cc:382
openmsx::RealDrive::step
void step(bool direction, EmuTime::param time) override
Step head.
Definition: RealDrive.cc:173
openmsx::Clock< TICKS_PER_ROTATION *ROTATIONS_PER_SECOND >
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::RealDrive::isTrack00
bool isTrack00() const override
Head above track 0.
Definition: RealDrive.cc:194
openmsx::DiskDrive::TrackMode
TrackMode
Definition: DiskDrive.hh:15