openMSX
SCSILS120.hh
Go to the documentation of this file.
1 /* Ported from:
2 ** Source: /cvsroot/bluemsx/blueMSX/Src/IoDevice/ScsiDevice.h,v
3 ** Revision: 1.6
4 ** Date: 2007-05-22 20:05:38 +0200 (Tue, 22 May 2007)
5 **
6 ** More info: http://www.bluemsx.com
7 **
8 ** Copyright (C) 2003-2007 Daniel Vik, white cat
9 */
10 #ifndef SCSILS120_HH
11 #define SCSILS120_HH
12 
13 #include "RecordedCommand.hh"
14 #include "SCSIDevice.hh"
15 #include "SectorAccessibleDisk.hh"
16 #include "DiskContainer.hh"
17 #include "File.hh"
18 #include <bitset>
19 #include <optional>
20 
21 namespace openmsx {
22 
23 class DeviceConfig;
24 class MSXMotherBoard;
25 class SCSILS120;
26 
27 class LSXCommand final : public RecordedCommand
28 {
29 public:
30  LSXCommand(CommandController& commandController,
31  StateChangeDistributor& stateChangeDistributor,
32  Scheduler& scheduler, SCSILS120& ls);
33  void execute(span<const TclObject> tokens,
34  TclObject& result, EmuTime::param time) override;
35  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
36  void tabCompletion(std::vector<std::string>& tokens) const override;
37 private:
38  SCSILS120& ls;
39 };
40 
41 class SCSILS120 final : public SCSIDevice, public SectorAccessibleDisk
42  , public DiskContainer
43 {
44 public:
45  SCSILS120(const SCSILS120&) = delete;
46  SCSILS120 operator=(const SCSILS120&) = delete;
47 
48  SCSILS120(const DeviceConfig& targetconfig,
49  AlignedBuffer& buf, unsigned mode);
50  ~SCSILS120() override;
51 
52  template<typename Archive>
53  void serialize(Archive& ar, unsigned version);
54 
55 private:
56  // SectorAccessibleDisk:
57  void readSectorsImpl(
58  SectorBuffer* buffers, size_t startSector, size_t num) override;
59  void writeSectorImpl(size_t sector, const SectorBuffer& buf) override;
60  [[nodiscard]] size_t getNbSectorsImpl() const override;
61  [[nodiscard]] bool isWriteProtectedImpl() const override;
62  [[nodiscard]] Sha1Sum getSha1SumImpl(FilePool& filePool) override;
63 
64  // Diskcontainer:
65  [[nodiscard]] SectorAccessibleDisk* getSectorAccessibleDisk() override;
66  [[nodiscard]] std::string_view getContainerName() const override;
67  [[nodiscard]] bool diskChanged() override;
68  int insertDisk(const std::string& filename) override;
69 
70  // SCSI Device
71  void reset() override;
72  [[nodiscard]] bool isSelected() override;
73  [[nodiscard]] unsigned executeCmd(const byte* cdb, SCSI::Phase& phase, unsigned& blocks) override;
74  [[nodiscard]] unsigned executingCmd(SCSI::Phase& phase, unsigned& blocks) override;
75  [[nodiscard]] byte getStatusCode() override;
76  int msgOut(byte value) override;
77  byte msgIn() override;
78  void disconnect() override;
79  void busReset() override;
80  [[nodiscard]] unsigned dataIn(unsigned& blocks) override;
81  [[nodiscard]] unsigned dataOut(unsigned& blocks) override;
82 
83  void eject();
84  void insert(const std::string& filename);
85 
86  [[nodiscard]] bool getReady();
87  void testUnitReady();
88  void startStopUnit();
89  [[nodiscard]] unsigned inquiry();
90  [[nodiscard]] unsigned modeSense();
91  [[nodiscard]] unsigned requestSense();
92  [[nodiscard]] bool checkReadOnly();
93  [[nodiscard]] unsigned readCapacity();
94  [[nodiscard]] bool checkAddress();
95  [[nodiscard]] unsigned readSector(unsigned& blocks);
96  [[nodiscard]] unsigned writeSector(unsigned& blocks);
97  void formatUnit();
98 
99 private:
100  MSXMotherBoard& motherBoard;
101  AlignedBuffer& buffer;
102  File file;
103  std::optional<LSXCommand> lsxCommand; // delayed init
104  std::string name;
105  const int mode;
106  unsigned keycode; // Sense key, ASC, ASCQ
107  unsigned currentSector;
108  unsigned currentLength;
109  const byte scsiId; // SCSI ID 0..7
110  bool unitAttention; // Unit Attention (was: reset)
111  bool mediaChanged; // Enhanced change flag for MEGA-SCSI driver
112  byte message;
113  byte lun;
114  byte cdb[12]; // Command Descriptor Block
115 
116  static constexpr unsigned MAX_LS = 26;
117  using LSInUse = std::bitset<MAX_LS>;
118  std::shared_ptr<LSInUse> lsInUse;
119 
120  friend class LSXCommand;
121 };
122 
123 } // namespace openmsx
124 
125 #endif
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: SCSILS120.cc:795
std::string help(span< const TclObject > tokens) const override
Print help for this command.
Definition: SCSILS120.cc:786
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: SCSILS120.cc:749
LSXCommand(CommandController &commandController, StateChangeDistributor &stateChangeDistributor, Scheduler &scheduler, SCSILS120 &ls)
Definition: SCSILS120.cc:740
Commands that directly influence the MSX state should send and events so that they can be recorded by...
SCSILS120 operator=(const SCSILS120 &)=delete
~SCSILS120() override
Definition: SCSILS120.cc:109
SCSILS120(const SCSILS120 &)=delete
void serialize(Archive &ar, unsigned version)
Definition: SCSILS120.cc:804
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:22
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename