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 "noncopyable.hh"
9 #include <string>
10 #include <memory>
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  , private noncopyable
26 {
27 public:
29  const std::string& driveName,
30  bool createCommand = true,
31  bool isDoubleSidedDrive = true);
32  DiskChanger(Reactor& reactor,
33  const 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 
75  const std::string driveName;
76  std::unique_ptr<Disk> disk;
77 
78  friend class DiskCommand;
79  std::unique_ptr<DiskCommand> diskCommand; // must come after driveName
80  const bool doubleSidedDrive; // for DirAsDSK
81 
82  bool diskChangedFlag;
83 };
85 
86 } // namespace openmsx
87 
88 #endif
Contains the main loop of openMSX.
Definition: Reactor.hh:62
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:38
const DiskName & getDiskName() const
Definition: DiskChanger.cc:98
DiskChanger(MSXMotherBoard &board, const std::string &driveName, bool createCommand=true, bool isDoubleSidedDrive=true)
Definition: DiskChanger.cc:47
void serialize(Archive &ar, unsigned version)
Definition: DiskChanger.cc:307
void changeDisk(std::unique_ptr< Disk > newDisk)
Definition: DiskChanger.cc:186
Scheduler * getScheduler() const
Definition: DiskChanger.hh:54
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
int insertDisk(string_ref filename) override
Definition: DiskChanger.cc:156
bool isDoubleSidedDrive() const
Definition: DiskChanger.hh:55
SectorAccessibleDisk * getSectorAccessibleDisk() override
Definition: DiskChanger.cc:110
Based on boost::noncopyable, see boost documentation: http://www.boost.org/libs/utility.
Definition: noncopyable.hh:12
bool peekDiskChanged() const
Definition: DiskChanger.hh:40