openMSX
IDECDROM.hh
Go to the documentation of this file.
1 #ifndef IDECDROM_HH
2 #define IDECDROM_HH
3 
4 #include "AbstractIDEDevice.hh"
5 #include "File.hh"
6 #include "RecordedCommand.hh"
7 #include <bitset>
8 #include <memory>
9 #include <optional>
10 
11 namespace openmsx {
12 
13 class DeviceConfig;
14 class IDECDROM;
15 
16 class CDXCommand final : public RecordedCommand
17 {
18 public:
19  CDXCommand(CommandController& commandController,
20  StateChangeDistributor& stateChangeDistributor,
21  Scheduler& scheduler, IDECDROM& cd);
22  void execute(span<const TclObject> tokens,
23  TclObject& result, EmuTime::param time) override;
24  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
25  void tabCompletion(std::vector<std::string>& tokens) const override;
26 private:
27  IDECDROM& cd;
28 };
29 
30 class IDECDROM final : public AbstractIDEDevice
31 {
32 public:
33  IDECDROM(const IDECDROM&) = delete;
34  IDECDROM& operator=(const IDECDROM&) = delete;
35 
36  explicit IDECDROM(const DeviceConfig& config);
37  ~IDECDROM() override;
38 
39  void eject();
40  void insert(const std::string& filename);
41 
42  template<typename Archive>
43  void serialize(Archive& ar, unsigned version);
44 
45 protected:
46  // AbstractIDEDevice:
47  [[nodiscard]] bool isPacketDevice() override;
48  [[nodiscard]] std::string_view getDeviceName() override;
49  void fillIdentifyBlock (AlignedBuffer& buffer) override;
50  [[nodiscard]] unsigned readBlockStart(AlignedBuffer& buffer, unsigned count) override;
51  void readEnd() override;
52  void writeBlockComplete(AlignedBuffer& buffer, unsigned count) override;
53  void executeCommand(byte cmd) override;
54 
55 private:
56  // Flags for the interrupt reason register:
58  static constexpr byte REL = 0x04;
60  static constexpr byte I_O = 0x02;
62  static constexpr byte C_D = 0x01;
63 
67  void startPacketReadTransfer(unsigned count);
68 
69  void executePacketCommand(AlignedBuffer& packet);
70 
71  std::string name;
72  std::optional<CDXCommand> cdxCommand; // delayed init
73  File file;
74  unsigned byteCountLimit;
75  unsigned transferOffset;
76 
77  unsigned senseKey;
78 
79  bool readSectorData;
80 
81  // Removable Media Status Notification Feature Set
82  bool remMedStatNotifEnabled;
83  bool mediaChanged;
84 
85  static constexpr unsigned MAX_CD = 26;
86  using CDInUse = std::bitset<MAX_CD>;
87  std::shared_ptr<CDInUse> cdInUse;
88 
89  friend class CDXCommand;
90 };
91 
92 } // namespace openmsx
93 
94 #endif
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: IDECDROM.cc:371
void execute(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:322
CDXCommand(CommandController &commandController, StateChangeDistributor &stateChangeDistributor, Scheduler &scheduler, IDECDROM &cd)
Definition: IDECDROM.cc:313
std::string help(span< const TclObject > tokens) const override
Print help for this command.
Definition: IDECDROM.cc:362
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:68
void serialize(Archive &ar, unsigned version)
Definition: IDECDROM.cc:380
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:93
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:115
~IDECDROM() override
Definition: IDECDROM.cc:54
void readEnd() override
Called when a read transfer completes.
Definition: IDECDROM.cc:110
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:73
IDECDROM & operator=(const IDECDROM &)=delete
void executeCommand(byte cmd) override
Starts execution of an IDE command.
Definition: IDECDROM.cc:123
bool isPacketDevice() override
Is this device a packet (ATAPI) device?
Definition: IDECDROM.cc:63
void insert(const std::string &filename)
Definition: IDECDROM.cc:302
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Definition: span.hh:126
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition: lz4.cc:207
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename