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  int allocateAnyPrimarySlot(const HardwareConfig& hwConfig);
38  int allocateSpecificPrimarySlot(unsigned slot, 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  std::string_view commandName);
52  void execute(span<const 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(span<const TclObject> tokens) const override;
57  private:
58  const HardwareConfig* getExtensionConfig(std::string_view cartname);
59  CartridgeSlotManager& manager;
60  CliComm& cliComm;
61  } cartCmd;
62 
63  struct CartridgeSlotInfo final : InfoTopic {
64  explicit CartridgeSlotInfo(InfoCommand& machineInfoCommand);
65  void execute(span<const TclObject> tokens,
66  TclObject& result) const override;
67  std::string help(const std::vector<std::string>& tokens) const override;
68  } extSlotInfo;
69 
70  struct Slot {
71  ~Slot();
72  bool exists() const;
73  bool used(const HardwareConfig* allowed = nullptr) const;
74 
75  std::unique_ptr<CartCmd> cartCommand;
76  std::unique_ptr<ExtCmd> extCommand;
77  const HardwareConfig* config = nullptr;
78  unsigned useCount = 0;
79  int ps = 0;
80  int ss = 0;
81  };
82  static constexpr unsigned MAX_SLOTS = 16 + 4;
83  Slot slots[MAX_SLOTS];
84 };
85 
86 } // namespace openmsx
87 
88 #endif
void freeSlot(int ps, int ss, const HardwareConfig &hwConfig)
int allocateSpecificPrimarySlot(unsigned slot, const HardwareConfig &hwConfig)
CartridgeSlotManager(MSXMotherBoard &motherBoard)
Definition: span.hh:34
Commands that directly influence the MSX state should send and events so that they can be recorded by...
static int getSlotNum(std::string_view slot)
void freePrimarySlot(int ps, const HardwareConfig &hwConfig)
bool isExternalSlot(int ps, int ss, bool convert) const
void testRemoveExternalSlot(int ps, const HardwareConfig &allowed) const
void convert(const th_ycbcr_buffer &input, RawFrame &output)
Definition: yuv2rgb.cc:341
void allocateSlot(int ps, int ss, const HardwareConfig &hwConfig)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void getSpecificSlot(unsigned slot, int &ps, int &ss) const
bool exists(string_view filename)
void getAnyFreeSlot(int &ps, int &ss) const
int allocateAnyPrimarySlot(const HardwareConfig &hwConfig)