OXYGENHUB
◆ main openmsx / src / ide / IDECDROM.hh
2.8 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef IDECDROM_HH
2
#define IDECDROM_HH
3
4
#include "AbstractIDEDevice.hh"
5
6
#include "File.hh"
7
#include "MSXMotherBoard.hh"
8
#include "RecordedCommand.hh"
9
10
#include <bitset>
11
#include <memory>
12
#include <optional>
13
14
namespace openmsx {
15
16
class DeviceConfig;
17
class IDECDROM;
18
19
class CDXCommand final : public RecordedCommand
20
{
21
public:
22
	CDXCommand(CommandController& commandController,
23
	           StateChangeDistributor& stateChangeDistributor,
24
	           Scheduler& scheduler, IDECDROM& cd);
25
	void execute(std::span<const TclObject> tokens,
26
		TclObject& result, EmuTime time) override;
27
	[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
28
	void tabCompletion(std::vector<std::string>& tokens) const override;
29
private:
30
	IDECDROM& cd;
31
};
32
33
class IDECDROM final : public AbstractIDEDevice, public MediaProvider
34
{
35
public:
36
	static constexpr unsigned MAX_CD = 26;
37
	using CDInUse = std::bitset<MAX_CD>;
38
	static std::shared_ptr<CDInUse> getDrivesInUse(MSXMotherBoard& motherBoard);
39
40
public:
41
	explicit IDECDROM(const DeviceConfig& config);
42
	IDECDROM(const IDECDROM&) = delete;
43
	IDECDROM(IDECDROM&&) = delete;
44
	IDECDROM& operator=(const IDECDROM&) = delete;
45
	IDECDROM& operator=(IDECDROM&&) = delete;
46
	~IDECDROM() override;
47
48
	void eject();
49
	void insert(zstring_view filename);
50
51
	// MediaInfoProvider
52
	void getMediaInfo(TclObject& result) override;
53
	void setMedia(const TclObject& info, EmuTime time) override;
54
55
	template<typename Archive>
56
	void serialize(Archive& ar, unsigned version);
57
58
protected:
59
	// AbstractIDEDevice:
60
	[[nodiscard]] bool isPacketDevice() override;
61
	[[nodiscard]] std::string_view getDeviceName() override;
62
	void fillIdentifyBlock (AlignedBuffer& buffer) override;
63
	[[nodiscard]] unsigned readBlockStart(AlignedBuffer& buffer, unsigned count) override;
64
	void readEnd() override;
65
	void writeBlockComplete(AlignedBuffer& buffer, unsigned count) override;
66
	void executeCommand(uint8_t cmd) override;
67
68
private:
69
	// Flags for the interrupt reason register:
70
	/** Bus release: 0 = normal, 1 = bus release */
71
	static constexpr uint8_t REL = 0x04;
72
	/** I/O direction: 0 = host->device, 1 = device->host */
73
	static constexpr uint8_t I_O = 0x02;
74
	/** Command/data: 0 = data, 1 = command */
75
	static constexpr uint8_t C_D = 0x01;
76
77
	/** Indicates the start of a read data transfer performed in packets.
78
	  * @param count Total number of bytes to transfer.
79
	  */
80
	void startPacketReadTransfer(unsigned count);
81
82
	void executePacketCommand(AlignedBuffer& packet);
83
84
	std::string name;
85
	std::optional<CDXCommand> cdxCommand; // delayed init
86
	File file;
87
	std::string filename;
88
	unsigned byteCountLimit;
89
	unsigned transferOffset;
90
91
	unsigned senseKey;
92
93
	bool readSectorData;
94
95
	// Removable Media Status Notification Feature Set
96
	bool remMedStatNotifEnabled;
97
	bool mediaChanged;
98
99
	std::shared_ptr<CDInUse> cdInUse;
100
101
	friend class CDXCommand;
102
103
	const std::string devName;
104
};
105
106
} // namespace openmsx
107
108
#endif