OXYGENHUB
◆ main openmsx / src / fdc / DiskDrive.hh
3.9 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef DISKDRIVE_HH
2
#define DISKDRIVE_HH
3
4
#include "EmuTime.hh"
5
#include "RawTrack.hh"
6
7
#include <cstdint>
8
9
namespace openmsx {
10
11
/**
12
 * This (abstract) class defines the DiskDrive interface
13
 */
14
class DiskDrive
15
{
16
public:
17
	enum class TrackMode : uint8_t {
18
		NORMAL, YAMAHA_FD_03,
19
	};
20
21
public:
22
	static constexpr unsigned ROTATIONS_PER_SECOND = 5; // 300rpm
23
24
	virtual ~DiskDrive() = default;
25
26
	/** Is drive ready?
27
	 */
28
	[[nodiscard]] virtual bool isDiskInserted() const = 0;
29
30
	/** Is disk write protected?
31
	 */
32
	[[nodiscard]] virtual bool isWriteProtected() const = 0;
33
34
	/** Is disk double sided?
35
	 */
36
	[[nodiscard]] virtual bool isDoubleSided() = 0;
37
38
	/** Head above track 0
39
	 */
40
	[[nodiscard]] virtual bool isTrack00() const = 0;
41
42
	/** Side select.
43
	 * @param side false = side 0,
44
	 *             true  = side 1.
45
	 */
46
	virtual void setSide(bool side) = 0;
47
48
	/* Returns the previously selected side.
49
	 */
50
	[[nodiscard]] virtual bool getSide() const = 0;
51
52
	/** Step head
53
	 * @param direction false = out,
54
	 *                  true  = in.
55
	 * @param time The moment in emulated time this action takes place.
56
	 */
57
	virtual void step(bool direction, EmuTime time) = 0;
58
59
	/** Set motor on/off
60
	 * @param status false = off,
61
	 *               true  = on.
62
	 * @param time The moment in emulated time this action takes place.
63
	 */
64
	virtual void setMotor(bool status, EmuTime time) = 0;
65
66
	/** Returns the previously set motor status.
67
	 */
68
	[[nodiscard]] virtual bool getMotor() const = 0;
69
70
	/** Gets the state of the index pulse.
71
	 * @param time The moment in emulated time to get the pulse state for.
72
	 */
73
	[[nodiscard]] virtual bool indexPulse(EmuTime time) = 0;
74
75
	/** Return the time till the start of the next index pulse
76
	 * When there is no disk in the drive or when the disk is not spinning,
77
	 * this function returns the current time.
78
	 * @param time The current time
79
	 * @param count Number of required index pulses.
80
	 */
81
	[[nodiscard]] virtual EmuTime getTimeTillIndexPulse(EmuTime time, int count = 1) = 0;
82
83
	[[nodiscard]] virtual unsigned getTrackLength() = 0;
84
	virtual void writeTrackByte(int idx, uint8_t val, bool addIdam = false) = 0;
85
	[[nodiscard]] virtual uint8_t readTrackByte(int idx) = 0;
86
	virtual EmuTime getNextSector(EmuTime time, RawTrack::Sector& sector) = 0;
87
	virtual void flushTrack() = 0;
88
89
	/** Is disk changed?
90
	 */
91
	virtual bool diskChanged() = 0;           // read and reset
92
	[[nodiscard]] virtual bool peekDiskChanged() const = 0; // read without reset
93
94
	/** Is there a dummy (unconnected) drive?
95
	 */
96
	[[nodiscard]] virtual bool isDummyDrive() const = 0;
97
98
	/** See RawTrack::applyWd2793ReadTrackQuirk() */
99
	virtual void applyWd2793ReadTrackQuirk() = 0;
100
	virtual void invalidateWd2793ReadTrackQuirk() = 0;
101
};
102
103
104
/**
105
 * This class implements a not connected disk drive.
106
 */
107
class DummyDrive final : public DiskDrive
108
{
109
public:
110
	[[nodiscard]] bool isDiskInserted() const override;
111
	[[nodiscard]] bool isWriteProtected() const override;
112
	[[nodiscard]] bool isDoubleSided() override;
113
	[[nodiscard]] bool isTrack00() const override;
114
	void setSide(bool side) override;
115
	[[nodiscard]] bool getSide() const override;
116
	void step(bool direction, EmuTime time) override;
117
	void setMotor(bool status, EmuTime time) override;
118
	[[nodiscard]] bool getMotor() const override;
119
	[[nodiscard]] bool indexPulse(EmuTime time) override;
120
	[[nodiscard]] EmuTime getTimeTillIndexPulse(EmuTime time, int count) override;
121
	[[nodiscard]] unsigned getTrackLength() override;
122
	void writeTrackByte(int idx, uint8_t val, bool addIdam) override;
123
	[[nodiscard]] uint8_t readTrackByte(int idx) override;
124
	EmuTime getNextSector(EmuTime time, RawTrack::Sector& sector) override;
125
	void flushTrack() override;
126
	bool diskChanged() override;
127
	[[nodiscard]] bool peekDiskChanged() const override;
128
	[[nodiscard]] bool isDummyDrive() const override;
129
	void applyWd2793ReadTrackQuirk() override;
130
	void invalidateWd2793ReadTrackQuirk() override;
131
};
132
133
} // namespace openmsx
134
135
#endif