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
const DiskName & getDiskName() const
~DiskChanger() override
int insertDisk(const std::string &filename) override
std::string_view getContainerName() const override
void serialize(Archive &ar, unsigned version)
const Disk & getDisk() const
const std::string & getDriveName() const
bool isDoubleSidedDrive() const
Scheduler * getScheduler() const
void changeDisk(std::unique_ptr< Disk > newDisk)
SectorAccessibleDisk * getSectorAccessibleDisk() override
bool diskChanged() override
bool needRecord(std::span< const TclObject > tokens) const
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Contains the main loop of openMSX.
Definition Reactor.hh:72
Base class for all external MSX state changing events.
This file implemented 3 utility functions:
Definition Autofire.cc:9
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)