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 <memory>
7 #include <string_view>
8 
9 namespace openmsx {
10 
11 class MSXMotherBoard;
12 class ExtCmd;
13 class HardwareConfig;
14 
16 {
17 public:
18  explicit CartridgeSlotManager(MSXMotherBoard& motherBoard);
20 
21  static int getSlotNum(std::string_view 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  [[nodiscard]] int allocateAnyPrimarySlot(const HardwareConfig& hwConfig);
38  [[nodiscard]] int allocateSpecificPrimarySlot(unsigned slot, const HardwareConfig& hwConfig);
39  void freePrimarySlot(int ps, const HardwareConfig& hwConfig);
40 
41  [[nodiscard]] bool isExternalSlot(int ps, int ss, bool convert) const;
42 
43 private:
44  [[nodiscard]] int getSlot(int ps, int ss) const;
45 
46 private:
47  MSXMotherBoard& motherBoard;
48 
49  class CartCmd final : public RecordedCommand {
50  public:
51  CartCmd(CartridgeSlotManager& manager, MSXMotherBoard& motherBoard,
52  std::string_view commandName);
53  void execute(span<const TclObject> tokens, TclObject& result,
54  EmuTime::param time) override;
55  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
56  void tabCompletion(std::vector<std::string>& tokens) const override;
57  [[nodiscard]] bool needRecord(span<const TclObject> tokens) const override;
58  private:
59  const HardwareConfig* getExtensionConfig(std::string_view cartname);
60  CartridgeSlotManager& manager;
61  CliComm& cliComm;
62  } cartCmd;
63 
64  struct CartridgeSlotInfo final : InfoTopic {
65  explicit CartridgeSlotInfo(InfoCommand& machineInfoCommand);
66  void execute(span<const TclObject> tokens,
67  TclObject& result) const override;
68  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
69  } extSlotInfo;
70 
71  struct Slot {
72  ~Slot();
73  [[nodiscard]] bool exists() const;
74  [[nodiscard]] bool used(const HardwareConfig* allowed = nullptr) const;
75 
76  std::unique_ptr<CartCmd> cartCommand;
77  std::unique_ptr<ExtCmd> extCommand;
78  const HardwareConfig* config = nullptr;
79  unsigned useCount = 0;
80  int ps = 0;
81  int ss = 0;
82  };
83  static constexpr unsigned MAX_SLOTS = 16 + 4;
84  Slot slots[MAX_SLOTS];
85 };
86 
87 } // namespace openmsx
88 
89 #endif
CartridgeSlotManager(MSXMotherBoard &motherBoard)
void getAnyFreeSlot(int &ps, int &ss) const
static int getSlotNum(std::string_view slot)
void testRemoveExternalSlot(int ps, const HardwareConfig &allowed) const
void getSpecificSlot(unsigned slot, int &ps, int &ss) const
bool isExternalSlot(int ps, int ss, bool convert) const
void freeSlot(int ps, int ss, const HardwareConfig &hwConfig)
int allocateAnyPrimarySlot(const HardwareConfig &hwConfig)
int allocateSpecificPrimarySlot(unsigned slot, const HardwareConfig &hwConfig)
void allocateSlot(int ps, int ss, const HardwareConfig &hwConfig)
void freePrimarySlot(int ps, const HardwareConfig &hwConfig)
Commands that directly influence the MSX state should send and events so that they can be recorded by...
Definition: span.hh:126
bool exists(zstring_view filename)
Does this file (directory) exists?
void convert(const th_ycbcr_buffer &input, RawFrame &output)
Definition: yuv2rgb.cc:342
This file implemented 3 utility functions:
Definition: Autofire.cc:5