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"
16#include "DiskContainer.hh"
17#include "MSXMotherBoard.hh"
18#include "File.hh"
19#include <bitset>
20#include <optional>
21
22namespace openmsx {
23
24class DeviceConfig;
25class SCSILS120;
26
27class LSXCommand final : public RecordedCommand
28{
29public:
30 LSXCommand(CommandController& commandController,
31 StateChangeDistributor& stateChangeDistributor,
32 Scheduler& scheduler, SCSILS120& ls);
33 void execute(std::span<const TclObject> tokens,
34 TclObject& result, EmuTime::param time) override;
35 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
36 void tabCompletion(std::vector<std::string>& tokens) const override;
37private:
38 SCSILS120& ls;
39};
40
41class SCSILS120 final : public SCSIDevice, public SectorAccessibleDisk
42 , public DiskContainer, public MediaInfoProvider
43{
44public:
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 // MediaInfoProvider
53 void getMediaInfo(TclObject& result);
54
55 template<typename Archive>
56 void serialize(Archive& ar, unsigned version);
57
58private:
59 // SectorAccessibleDisk:
60 void readSectorsImpl(
61 SectorBuffer* buffers, size_t startSector, size_t num) override;
62 void writeSectorImpl(size_t sector, const SectorBuffer& buf) override;
63 [[nodiscard]] size_t getNbSectorsImpl() const override;
64 [[nodiscard]] bool isWriteProtectedImpl() const override;
65 [[nodiscard]] Sha1Sum getSha1SumImpl(FilePool& filePool) override;
66
67 // Diskcontainer:
68 [[nodiscard]] SectorAccessibleDisk* getSectorAccessibleDisk() override;
69 [[nodiscard]] std::string_view getContainerName() const override;
70 [[nodiscard]] bool diskChanged() override;
71 int insertDisk(const std::string& filename) override;
72
73 // SCSI Device
74 void reset() override;
75 [[nodiscard]] bool isSelected() override;
76 [[nodiscard]] unsigned executeCmd(const byte* cdb, SCSI::Phase& phase, unsigned& blocks) override;
77 [[nodiscard]] unsigned executingCmd(SCSI::Phase& phase, unsigned& blocks) override;
78 [[nodiscard]] byte getStatusCode() override;
79 int msgOut(byte value) override;
80 byte msgIn() override;
81 void disconnect() override;
82 void busReset() override;
83 [[nodiscard]] unsigned dataIn(unsigned& blocks) override;
84 [[nodiscard]] unsigned dataOut(unsigned& blocks) override;
85
86 void eject();
87 void insert(const std::string& filename);
88
89 [[nodiscard]] bool getReady();
90 void testUnitReady();
91 void startStopUnit();
92 [[nodiscard]] unsigned inquiry();
93 [[nodiscard]] unsigned modeSense();
94 [[nodiscard]] unsigned requestSense();
95 [[nodiscard]] bool checkReadOnly();
96 [[nodiscard]] unsigned readCapacity();
97 [[nodiscard]] bool checkAddress();
98 [[nodiscard]] unsigned readSector(unsigned& blocks);
99 [[nodiscard]] unsigned writeSector(unsigned& blocks);
100 void formatUnit();
101
102private:
103 MSXMotherBoard& motherBoard;
104 AlignedBuffer& buffer;
105 File file;
106 std::optional<LSXCommand> lsxCommand; // delayed init
107 std::string name;
108 const int mode;
109 unsigned keycode; // Sense key, ASC, ASCQ
110 unsigned currentSector;
111 unsigned currentLength;
112 const byte scsiId; // SCSI ID 0..7
113 bool unitAttention; // Unit Attention (was: reset)
114 bool mediaChanged; // Enhanced change flag for MEGA-SCSI driver
115 byte message;
116 byte lun;
117 byte cdb[12]; // Command Descriptor Block
118
119 static constexpr unsigned MAX_LS = 26;
120 using LSInUse = std::bitset<MAX_LS>;
121 std::shared_ptr<LSInUse> lsInUse;
122
123 friend class LSXCommand;
124};
125
126} // namespace openmsx
127
128#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: SCSILS120.cc:759
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: SCSILS120.cc:805
LSXCommand(CommandController &commandController, StateChangeDistributor &stateChangeDistributor, Scheduler &scheduler, SCSILS120 &ls)
Definition: SCSILS120.cc:750
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
Definition: SCSILS120.cc:796
Commands that directly influence the MSX state should send and events so that they can be recorded by...
SCSILS120 operator=(const SCSILS120 &)=delete
void getMediaInfo(TclObject &result)
This method gets called when information is required on the media inserted in the media slot of the p...
Definition: SCSILS120.cc:123
~SCSILS120() override
Definition: SCSILS120.cc:112
SCSILS120(const SCSILS120 &)=delete
void serialize(Archive &ar, unsigned version)
Definition: SCSILS120.cc:814
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:22
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename