openMSX
IDECDROM.hh
Go to the documentation of this file.
1#ifndef IDECDROM_HH
2#define IDECDROM_HH
3
5#include "MSXMotherBoard.hh"
6#include "File.hh"
7#include "RecordedCommand.hh"
8#include <bitset>
9#include <memory>
10#include <optional>
11
12namespace openmsx {
13
14class DeviceConfig;
15class IDECDROM;
16
17class CDXCommand final : public RecordedCommand
18{
19public:
20 CDXCommand(CommandController& commandController,
21 StateChangeDistributor& stateChangeDistributor,
22 Scheduler& scheduler, IDECDROM& cd);
23 void execute(std::span<const TclObject> tokens,
24 TclObject& result, EmuTime::param time) override;
25 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
26 void tabCompletion(std::vector<std::string>& tokens) const override;
27private:
28 IDECDROM& cd;
29};
30
31class IDECDROM final : public AbstractIDEDevice, public MediaInfoProvider
32{
33public:
34 static constexpr unsigned MAX_CD = 26;
35 using CDInUse = std::bitset<MAX_CD>;
36 static std::shared_ptr<CDInUse> getDrivesInUse(MSXMotherBoard& motherBoard);
37
38public:
39 IDECDROM(const IDECDROM&) = delete;
40 IDECDROM& operator=(const IDECDROM&) = delete;
41
42 explicit IDECDROM(const DeviceConfig& config);
43 ~IDECDROM() override;
44
45 void eject();
46 void insert(const std::string& filename);
47
48 // MediaInfoProvider
49 void getMediaInfo(TclObject& result) override;
50
51 template<typename Archive>
52 void serialize(Archive& ar, unsigned version);
53
54protected:
55 // AbstractIDEDevice:
56 [[nodiscard]] bool isPacketDevice() override;
57 [[nodiscard]] std::string_view getDeviceName() override;
58 void fillIdentifyBlock (AlignedBuffer& buffer) override;
59 [[nodiscard]] unsigned readBlockStart(AlignedBuffer& buffer, unsigned count) override;
60 void readEnd() override;
61 void writeBlockComplete(AlignedBuffer& buffer, unsigned count) override;
62 void executeCommand(byte cmd) override;
63
64private:
65 // Flags for the interrupt reason register:
67 static constexpr byte REL = 0x04;
69 static constexpr byte I_O = 0x02;
71 static constexpr byte C_D = 0x01;
72
76 void startPacketReadTransfer(unsigned count);
77
78 void executePacketCommand(AlignedBuffer& packet);
79
80 std::string name;
81 std::optional<CDXCommand> cdxCommand; // delayed init
82 File file;
83 unsigned byteCountLimit;
84 unsigned transferOffset;
85
86 unsigned senseKey;
87
88 bool readSectorData;
89
90 // Removable Media Status Notification Feature Set
91 bool remMedStatNotifEnabled;
92 bool mediaChanged;
93
94 std::shared_ptr<CDInUse> cdInUse;
95
96 friend class CDXCommand;
97};
98
99} // namespace openmsx
100
101#endif
void execute(std::span< const TclObject > tokens, TclObject &result, EmuTime::param time) override
This is like the execute() method of the Command class, it only has an extra time parameter.
Definition: IDECDROM.cc:335
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
Definition: IDECDROM.cc:375
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: IDECDROM.cc:384
CDXCommand(CommandController &commandController, StateChangeDistributor &stateChangeDistributor, Scheduler &scheduler, IDECDROM &cd)
Definition: IDECDROM.cc:326
IDECDROM(const IDECDROM &)=delete
std::string_view getDeviceName() override
Gets the device name to insert as "model number" into the identify block.
Definition: IDECDROM.cc:81
void serialize(Archive &ar, unsigned version)
Definition: IDECDROM.cc:393
std::bitset< MAX_CD > CDInUse
Definition: IDECDROM.hh:35
IDECDROM & operator=(const IDECDROM &)=delete
unsigned readBlockStart(AlignedBuffer &buffer, unsigned count) override
Called when a block of read data should be buffered by the controller: when the buffer is empty or at...
Definition: IDECDROM.cc:106
void writeBlockComplete(AlignedBuffer &buffer, unsigned count) override
Called when a block of written data has been buffered by the controller: when the buffer is full or a...
Definition: IDECDROM.cc:128
~IDECDROM() override
Definition: IDECDROM.cc:61
void readEnd() override
Called when a read transfer completes.
Definition: IDECDROM.cc:123
void fillIdentifyBlock(AlignedBuffer &buffer) override
Tells a subclass to fill the device specific parts of the identify block located in the buffer.
Definition: IDECDROM.cc:86
static constexpr unsigned MAX_CD
Definition: IDECDROM.hh:34
void getMediaInfo(TclObject &result) override
This method gets called when information is required on the media inserted in the media slot of the p...
Definition: IDECDROM.cc:71
void executeCommand(byte cmd) override
Starts execution of an IDE command.
Definition: IDECDROM.cc:136
bool isPacketDevice() override
Is this device a packet (ATAPI) device?
Definition: IDECDROM.cc:76
static std::shared_ptr< CDInUse > getDrivesInUse(MSXMotherBoard &motherBoard)
Definition: IDECDROM.cc:23
void insert(const std::string &filename)
Definition: IDECDROM.cc:315
Commands that directly influence the MSX state should send and events so that they can be recorded by...
This file implemented 3 utility functions:
Definition: Autofire.cc:9