openMSX
DiskChanger.hh
Go to the documentation of this file.
1#ifndef DISKCHANGER_HH
2#define DISKCHANGER_HH
3
4#include "DiskContainer.hh"
6#include "RecordedCommand.hh"
7#include "serialize_meta.hh"
8#include <functional>
9#include <memory>
10#include <optional>
11#include <span>
12#include <string>
13
14namespace openmsx {
15
16class CommandController;
17class StateChangeDistributor;
18class Scheduler;
19class MSXMotherBoard;
20class Reactor;
21class Disk;
22class DiskChanger;
23class TclObject;
24class DiskName;
25
26class DiskCommand final : public Command // TODO RecordedCommand
27{
28public:
29 DiskCommand(CommandController& commandController,
30 DiskChanger& diskChanger);
31 void execute(std::span<const TclObject> tokens,
32 TclObject& result) override;
33 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
34 void tabCompletion(std::vector<std::string>& tokens) const override;
35 [[nodiscard]] bool needRecord(std::span<const TclObject> tokens) const /*override*/;
36private:
37 DiskChanger& diskChanger;
38};
39
40class DiskChanger final : public DiskContainer, private StateChangeListener
41{
42public:
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
77private:
78 void init(std::string_view prefix, bool createCmd);
79 void execute(std::span<const TclObject> tokens);
80 void insertDisk(std::span<const TclObject> args);
81 void ejectDisk();
82 void sendChangeDiskEvent(std::span<const TclObject> args);
83
84 // StateChangeListener
85 void signalStateChange(const StateChange& event) override;
86 void stopReplay(EmuTime::param time) noexcept override;
87
88private:
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
const DiskName & getDiskName() const
Definition: DiskChanger.cc:88
~DiskChanger() override
Definition: DiskChanger.cc:79
int insertDisk(const std::string &filename) override
Definition: DiskChanger.cc:148
std::string_view getContainerName() const override
Definition: DiskChanger.cc:108
void serialize(Archive &ar, unsigned version)
Definition: DiskChanger.cc:300
const Disk & getDisk() const
Definition: DiskChanger.hh:59
const std::string & getDriveName() const
Definition: DiskChanger.hh:54
DiskChanger(MSXMotherBoard &board, std::string driveName, bool createCmd=true, bool doubleSidedDrive=true, std::function< void()> preChangeCallback={})
Definition: DiskChanger.cc:35
bool isDoubleSidedDrive() const
Definition: DiskChanger.hh:72
Scheduler * getScheduler() const
Definition: DiskChanger.hh:71
void changeDisk(std::unique_ptr< Disk > newDisk)
Definition: DiskChanger.cc:178
SectorAccessibleDisk * getSectorAccessibleDisk() override
Definition: DiskChanger.cc:100
bool diskChanged() override
Definition: DiskChanger.cc:93
bool needRecord(std::span< const TclObject > tokens) const
Definition: DiskChanger.cc:287
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
Definition: DiskChanger.cc:263
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
Definition: DiskChanger.cc:197
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: DiskChanger.cc:276
DiskCommand(CommandController &commandController, DiskChanger &diskChanger)
Definition: DiskChanger.cc:190
Contains the main loop of openMSX.
Definition: Reactor.hh:68
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)