| 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 |
|
| 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 |
|
| 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 |
|
| 70 |
|
| 71 |
static constexpr uint8_t REL = 0x04; |
| 72 |
|
| 73 |
static constexpr uint8_t I_O = 0x02; |
| 74 |
|
| 75 |
static constexpr uint8_t C_D = 0x01; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
void startPacketReadTransfer(unsigned count); |
| 81 |
|
| 82 |
void executePacketCommand(AlignedBuffer& packet); |
| 83 |
|
| 84 |
std::string name; |
| 85 |
std::optional<CDXCommand> cdxCommand; |
| 86 |
File file; |
| 87 |
std::string filename; |
| 88 |
unsigned byteCountLimit; |
| 89 |
unsigned transferOffset; |
| 90 |
|
| 91 |
unsigned senseKey; |
| 92 |
|
| 93 |
bool readSectorData; |
| 94 |
|
| 95 |
|
| 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 |
} |
| 107 |
|
| 108 |
#endif |