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 "string_ref.hh"
7 #include <memory>
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(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  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  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  struct CartridgeSlotInfo final : InfoTopic {
64  explicit CartridgeSlotInfo(InfoCommand& machineInfoCommand);
65  void execute(array_ref<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  ~Slot();
73  bool exists() const;
74  bool used(const HardwareConfig* allowed = nullptr) const;
75 
76  std::unique_ptr<CartCmd> cartCommand;
77  std::unique_ptr<ExtCmd> extCommand;
78  const HardwareConfig* config;
79  unsigned useCount;
80  int ps;
81  int ss;
82  };
83  static const unsigned MAX_SLOTS = 16 + 4;
84  Slot slots[MAX_SLOTS];
85 };
86 
87 } // namespace openmsx
88 
89 #endif
void freeSlot(int ps, int ss, const HardwareConfig &hwConfig)
int allocateSpecificPrimarySlot(unsigned slot, const HardwareConfig &hwConfig)
CartridgeSlotManager(MSXMotherBoard &motherBoard)
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)
bool isExternalSlot(int ps, int ss, bool convert) const
void testRemoveExternalSlot(int ps, const HardwareConfig &allowed) const
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
void allocateSlot(int ps, int ss, 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?
void getSpecificSlot(unsigned slot, int &ps, int &ss) const
static int getSlotNum(string_ref slot)
void getAnyFreeSlot(int &ps, int &ss) const
int allocateAnyPrimarySlot(const HardwareConfig &hwConfig)