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 "serialize_meta.hh"
7 #include "array_ref.hh"
8 #include <functional>
9 #include <memory>
10 #include <string>
11 
12 namespace openmsx {
13 
14 class CommandController;
15 class StateChangeDistributor;
16 class Scheduler;
17 class MSXMotherBoard;
18 class Reactor;
19 class Disk;
20 class DiskCommand;
21 class TclObject;
22 class DiskName;
23 
24 class DiskChanger final : public DiskContainer, private StateChangeListener
25 {
26 public:
28  std::string driveName,
29  bool createCommand = true,
30  bool doubleSidedDrive = true,
31  std::function<void()> preChangeCallback = {});
32  DiskChanger(Reactor& reactor,
33  std::string driveName); // for virtual_drive
34  ~DiskChanger();
35 
36  void createCommand();
37 
38  const std::string& getDriveName() const { return driveName; }
39  const DiskName& getDiskName() const;
40  bool peekDiskChanged() const { return diskChangedFlag; }
41  void forceDiskChange() { diskChangedFlag = true; }
42  Disk& getDisk() { return *disk; }
43 
44  // DiskContainer
46  const std::string& getContainerName() const override;
47  bool diskChanged() override;
48  int insertDisk(string_ref filename) override;
49 
50  // for NowindCommand
51  void changeDisk(std::unique_ptr<Disk> newDisk);
52 
53  // for DirAsDSK
54  Scheduler* getScheduler() const { return scheduler; }
55  bool isDoubleSidedDrive() const { return doubleSidedDrive; }
56 
57  template<typename Archive>
58  void serialize(Archive& ar, unsigned version);
59 
60 private:
61  void init(const std::string& prefix, bool createCmd);
63  void ejectDisk();
64  void sendChangeDiskEvent(array_ref<std::string> args);
65 
66  // StateChangeListener
67  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
68  void stopReplay(EmuTime::param time) override;
69 
70  Reactor& reactor;
71  CommandController& controller;
72  StateChangeDistributor* stateChangeDistributor;
73  Scheduler* scheduler;
74  std::function<void()> preChangeCallback;
75 
76  const std::string driveName;
77  std::unique_ptr<Disk> disk;
78 
79  friend class DiskCommand;
80  std::unique_ptr<DiskCommand> diskCommand; // must come after driveName
81  const bool doubleSidedDrive; // for DirAsDSK
82 
83  bool diskChangedFlag;
84 };
86 
87 } // namespace openmsx
88 
89 #endif
Contains the main loop of openMSX.
Definition: Reactor.hh:61
const std::string & getContainerName() const override
Definition: DiskChanger.cc:120
DiskChanger(MSXMotherBoard &board, std::string driveName, bool createCommand=true, bool doubleSidedDrive=true, std::function< void()> preChangeCallback={})
Definition: DiskChanger.cc:47
const DiskName & getDiskName() const
Definition: DiskChanger.cc:100
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
bool isDoubleSidedDrive() const
Definition: DiskChanger.hh:55
Scheduler * getScheduler() const
Definition: DiskChanger.hh:54
void serialize(Archive &ar, unsigned version)
Definition: DiskChanger.cc:312
void changeDisk(std::unique_ptr< Disk > newDisk)
Definition: DiskChanger.cc:188
bool diskChanged() override
Definition: DiskChanger.cc:105
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
int insertDisk(string_ref filename) override
Definition: DiskChanger.cc:158
bool peekDiskChanged() const
Definition: DiskChanger.hh:40
SectorAccessibleDisk * getSectorAccessibleDisk() override
Definition: DiskChanger.cc:112
const std::string & getDriveName() const
Definition: DiskChanger.hh:38