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 "MSXMotherBoard.hh"
6#include "InfoTopic.hh"
7#include "TclObject.hh"
8#include <optional>
9#include <string_view>
10
11namespace openmsx {
12
13class HardwareConfig;
14
16{
17public:
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
43private:
44 [[nodiscard]] int getSlot(int ps, int ss) const;
45
46private:
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(std::span<const TclObject> tokens, TclObject& result,
54 EmuTime::param time) override;
55 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
56 void tabCompletion(std::vector<std::string>& tokens) const override;
57 [[nodiscard]] bool needRecord(std::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(std::span<const TclObject> tokens,
67 TclObject& result) const override;
68 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
69 } extSlotInfo;
70
71 struct Slot : public MediaInfoProvider {
72 ~Slot();
73
74 // MediaInfoProvider
75 void getMediaInfo(TclObject& result);
76
77 [[nodiscard]] bool exists() const;
78 [[nodiscard]] bool used(const HardwareConfig* allowed = nullptr) const;
79
80 std::optional<CartCmd> cartCommand;
81 std::optional<ExtCmd> extCommand;
82 const HardwareConfig* config = nullptr;
83 unsigned useCount = 0;
84 int ps = 0;
85 int ss = 0;
86 };
87 static constexpr unsigned MAX_SLOTS = 16 + 4;
88 Slot slots[MAX_SLOTS];
89};
90
91} // namespace openmsx
92
93#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...
bool exists(zstring_view filename)
Does this file (directory) exists?
This file implemented 3 utility functions:
Definition: Autofire.cc:9