openMSX
DiskChanger.hh
Go to the documentation of this file.
1 #ifndef DISKCHANGER_HH
2 #define DISKCHANGER_HH
3 
4 #include "DiskContainer.hh"
5 #include "StateChangeListener.hh"
6 #include "RecordedCommand.hh"
7 #include "serialize_meta.hh"
8 #include "span.hh"
9 #include <functional>
10 #include <memory>
11 #include <optional>
12 #include <string>
13 
14 namespace openmsx {
15 
16 class CommandController;
17 class StateChangeDistributor;
18 class Scheduler;
19 class MSXMotherBoard;
20 class Reactor;
21 class Disk;
22 class DiskChanger;
23 class TclObject;
24 class DiskName;
25 
26 class DiskCommand final : public Command // TODO RecordedCommand
27 {
28 public:
29  DiskCommand(CommandController& commandController,
30  DiskChanger& diskChanger);
31  void execute(span<const TclObject> tokens,
32  TclObject& result) override;
33  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
34  void tabCompletion(std::vector<std::string>& tokens) const override;
35  [[nodiscard]] bool needRecord(span<const TclObject> tokens) const /*override*/;
36 private:
37  DiskChanger& diskChanger;
38 };
39 
40 class DiskChanger final : public DiskContainer, private StateChangeListener
41 {
42 public:
44  std::string driveName,
45  bool createCmd = true,
46  bool doubleSidedDrive = true,
47  std::function<void()> preChangeCallback = {});
48  DiskChanger(Reactor& reactor,
49  std::string driveName); // for virtual_drive
50  ~DiskChanger() override;
51 
52  void createCommand();
53 
54  [[nodiscard]] const std::string& getDriveName() const { return driveName; }
55  [[nodiscard]] const DiskName& getDiskName() const;
56  [[nodiscard]] bool peekDiskChanged() const { return diskChangedFlag; }
57  void forceDiskChange() { diskChangedFlag = true; }
58  [[nodiscard]] Disk& getDisk() { return *disk; }
59  [[nodiscard]] const Disk& getDisk() const { return *disk; }
60 
61  // DiskContainer
62  [[nodiscard]] SectorAccessibleDisk* getSectorAccessibleDisk() override;
63  [[nodiscard]] std::string_view getContainerName() const override;
64  bool diskChanged() override;
65  int insertDisk(const std::string& filename) override;
66 
67  // for NowindCommand
68  void changeDisk(std::unique_ptr<Disk> newDisk);
69 
70  // for DirAsDSK
71  [[nodiscard]] Scheduler* getScheduler() const { return scheduler; }
72  [[nodiscard]] bool isDoubleSidedDrive() const { return doubleSidedDrive; }
73 
74  template<typename Archive>
75  void serialize(Archive& ar, unsigned version);
76 
77 private:
78  void init(std::string_view prefix, bool createCmd);
79  void execute(span<const TclObject> tokens);
81  void ejectDisk();
82  void sendChangeDiskEvent(span<const TclObject> args);
83 
84  // StateChangeListener
85  void signalStateChange(const StateChange& event) override;
86  void stopReplay(EmuTime::param time) noexcept override;
87 
88 private:
89  Reactor& reactor;
90  CommandController& controller;
91  StateChangeDistributor* stateChangeDistributor;
92  Scheduler* scheduler;
93  std::function<void()> preChangeCallback;
94 
95  const std::string driveName;
96  std::unique_ptr<Disk> disk;
97 
98  friend class DiskCommand;
99  std::optional<DiskCommand> diskCommand; // must come after driveName
100  const bool doubleSidedDrive; // for DirAsDSK
101 
102  bool diskChangedFlag;
103 };
105 
106 } // namespace openmsx
107 
108 #endif
bool peekDiskChanged() const
Definition: DiskChanger.hh:56
Scheduler * getScheduler() const
Definition: DiskChanger.hh:71
const DiskName & getDiskName() const
Definition: DiskChanger.cc:87
~DiskChanger() override
Definition: DiskChanger.cc:78
int insertDisk(const std::string &filename) override
Definition: DiskChanger.cc:147
const std::string & getDriveName() const
Definition: DiskChanger.hh:54
std::string_view getContainerName() const override
Definition: DiskChanger.cc:107
void serialize(Archive &ar, unsigned version)
Definition: DiskChanger.cc:301
const Disk & getDisk() const
Definition: DiskChanger.hh:59
DiskChanger(MSXMotherBoard &board, std::string driveName, bool createCmd=true, bool doubleSidedDrive=true, std::function< void()> preChangeCallback={})
Definition: DiskChanger.cc:34
bool isDoubleSidedDrive() const
Definition: DiskChanger.hh:72
void changeDisk(std::unique_ptr< Disk > newDisk)
Definition: DiskChanger.cc:177
SectorAccessibleDisk * getSectorAccessibleDisk() override
Definition: DiskChanger.cc:99
bool diskChanged() override
Definition: DiskChanger.cc:92
bool needRecord(span< const TclObject > tokens) const
Definition: DiskChanger.cc:288
void execute(span< const TclObject > tokens, TclObject &result) override
Execute this command.
Definition: DiskChanger.cc:196
std::string help(span< const TclObject > tokens) const override
Print help for this command.
Definition: DiskChanger.cc:264
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: DiskChanger.cc:277
DiskCommand(CommandController &commandController, DiskChanger &diskChanger)
Definition: DiskChanger.cc:189
Contains the main loop of openMSX.
Definition: Reactor.hh:68
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)