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