openMSX
CartridgeSlotManager.hh
Go to the documentation of this file.
1 #ifndef CARTRIDGESLOTMANAGER_HH
2 #define CARTRIDGESLOTMANAGER_HH
3 
4 #include "noncopyable.hh"
5 #include "string_ref.hh"
6 #include <memory>
7 
8 namespace openmsx {
9 
10 class MSXMotherBoard;
11 class CartCmd;
12 class HardwareConfig;
13 class CartridgeSlotInfo;
14 
16 {
17 public:
18  explicit CartridgeSlotManager(MSXMotherBoard& motherBoard);
20 
21  static int getSlotNum(string_ref slot);
22 
23  void createExternalSlot(int ps);
24  void createExternalSlot(int ps, int ss);
25  void removeExternalSlot(int ps);
26  void removeExternalSlot(int ps, int ss);
27  void testRemoveExternalSlot(int ps, const HardwareConfig& allowed) const;
28  void testRemoveExternalSlot(int ps, int ss, const HardwareConfig& allowed) const;
29 
30  // Query/allocate/free external slots
31  void getSpecificSlot(unsigned slot, int& ps, int& ss) const;
32  void getAnyFreeSlot(int& ps, int& ss) const;
33  void allocateSlot(int ps, int ss, const HardwareConfig& hwConfig);
34  void freeSlot(int ps, int ss, const HardwareConfig& hwConfig);
35 
36  // Allocate/free external primary slots
37  void allocatePrimarySlot(int& ps, const HardwareConfig& hwConfig);
38  void freePrimarySlot(int ps, const HardwareConfig& hwConfig);
39 
40  bool isExternalSlot(int ps, int ss, bool convert) const;
41 
42 private:
43  int getSlot(int ps, int ss) const;
44 
45  struct Slot {
46  Slot();
47  ~Slot();
48  bool exists() const;
49  bool used(const HardwareConfig* allowed = nullptr) const;
50 
51  std::unique_ptr<CartCmd> command;
52  const HardwareConfig* config;
53  unsigned useCount;
54  int ps;
55  int ss;
56  };
57  static const unsigned MAX_SLOTS = 16 + 4;
58  Slot slots[MAX_SLOTS];
59  MSXMotherBoard& motherBoard;
60  const std::unique_ptr<CartCmd> cartCmd;
61  const std::unique_ptr<CartridgeSlotInfo> extSlotInfo;
62  friend class CartCmd;
63  friend class CartridgeSlotInfo;
64 };
65 
66 } // namespace openmsx
67 
68 #endif