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