openMSX
CartridgeSlotManager.hh
Go to the documentation of this file.
1 #ifndef CARTRIDGESLOTMANAGER_HH
2 #define CARTRIDGESLOTMANAGER_HH
3 
4 #include "RecordedCommand.hh"
5 #include "InfoTopic.hh"
6 #include "noncopyable.hh"
7 #include "string_ref.hh"
8 #include <memory>
9 
10 namespace openmsx {
11 
12 class MSXMotherBoard;
13 class ExtCmd;
14 class HardwareConfig;
15 
17 {
18 public:
19  explicit CartridgeSlotManager(MSXMotherBoard& motherBoard);
21 
22  static int getSlotNum(string_ref slot);
23 
24  void createExternalSlot(int ps);
25  void createExternalSlot(int ps, int ss);
26  void removeExternalSlot(int ps);
27  void removeExternalSlot(int ps, int ss);
28  void testRemoveExternalSlot(int ps, const HardwareConfig& allowed) const;
29  void testRemoveExternalSlot(int ps, int ss, const HardwareConfig& allowed) const;
30 
31  // Query/allocate/free external slots
32  void getSpecificSlot(unsigned slot, int& ps, int& ss) const;
33  void getAnyFreeSlot(int& ps, int& ss) const;
34  void allocateSlot(int ps, int ss, const HardwareConfig& hwConfig);
35  void freeSlot(int ps, int ss, const HardwareConfig& hwConfig);
36 
37  // Allocate/free external primary slots
38  void allocatePrimarySlot(int& ps, const HardwareConfig& hwConfig);
39  void freePrimarySlot(int ps, const HardwareConfig& hwConfig);
40 
41  bool isExternalSlot(int ps, int ss, bool convert) const;
42 
43 private:
44  int getSlot(int ps, int ss) const;
45 
46  MSXMotherBoard& motherBoard;
47 
48  class CartCmd final : public RecordedCommand {
49  public:
50  CartCmd(CartridgeSlotManager& manager, MSXMotherBoard& motherBoard,
51  string_ref commandName);
52  void execute(array_ref<TclObject> tokens, TclObject& result,
53  EmuTime::param time) override;
54  std::string help(const std::vector<std::string>& tokens) const override;
55  void tabCompletion(std::vector<std::string>& tokens) const override;
56  bool needRecord(array_ref<TclObject> tokens) const override;
57  private:
58  const HardwareConfig* getExtensionConfig(string_ref cartname);
59  CartridgeSlotManager& manager;
60  CliComm& cliComm;
61  } cartCmd;
62 
63  class CartridgeSlotInfo final : public InfoTopic {
64  public:
65  CartridgeSlotInfo(InfoCommand& machineInfoCommand,
66  CartridgeSlotManager& manger);
67  void execute(array_ref<TclObject> tokens,
68  TclObject& result) const override;
69  std::string help(const std::vector<std::string>& tokens) const override;
70  private:
71  CartridgeSlotManager& manager;
72  } extSlotInfo;
73 
74  struct Slot {
75  Slot();
76  ~Slot();
77  bool exists() const;
78  bool used(const HardwareConfig* allowed = nullptr) const;
79 
80  std::unique_ptr<CartCmd> cartCommand;
81  std::unique_ptr<ExtCmd> extCommand;
82  const HardwareConfig* config;
83  unsigned useCount;
84  int ps;
85  int ss;
86  };
87  static const unsigned MAX_SLOTS = 16 + 4;
88  Slot slots[MAX_SLOTS];
89 };
90 
91 } // namespace openmsx
92 
93 #endif
void getSpecificSlot(unsigned slot, int &ps, int &ss) const
void freeSlot(int ps, int ss, const HardwareConfig &hwConfig)
CartridgeSlotManager(MSXMotherBoard &motherBoard)
void getAnyFreeSlot(int &ps, int &ss) const
Commands that directly influence the MSX state should send and events so that they can be recorded by...
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
void freePrimarySlot(int ps, const HardwareConfig &hwConfig)
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
void convert(const th_ycbcr_buffer &input, RawFrame &output)
Definition: yuv2rgb.cc:341
bool isExternalSlot(int ps, int ss, bool convert) const
void allocateSlot(int ps, int ss, const HardwareConfig &hwConfig)
void allocatePrimarySlot(int &ps, const HardwareConfig &hwConfig)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool exists(string_ref filename)
Does this file (directory) exists?
static int getSlotNum(string_ref slot)
void testRemoveExternalSlot(int ps, const HardwareConfig &allowed) const
Based on boost::noncopyable, see boost documentation: http://www.boost.org/libs/utility.
Definition: noncopyable.hh:12