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 <array>
9#include <optional>
10#include <string_view>
11
12namespace openmsx {
13
14class HardwareConfig;
15
17{
18public:
19 explicit CartridgeSlotManager(MSXMotherBoard& motherBoard);
21
22 static int getSlotNum(std::string_view slot);
23
24 void createExternalSlot(int ps);
25 void createExternalSlot(int ps, int ss);
26 void removeExternalSlot(int ps);
27 void removeExternalSlot(int ps, int ss);
28 void testRemoveExternalSlot(int ps, const HardwareConfig& allowed) const;
29 void testRemoveExternalSlot(int ps, int ss, const HardwareConfig& allowed) const;
30
31 // Query/allocate/free external slots
32 void getSpecificSlot(unsigned slot, int& ps, int& ss) const;
33 void getAnyFreeSlot(int& ps, int& ss) const;
34 void allocateSlot(int ps, int ss, const HardwareConfig& hwConfig);
35 void freeSlot(int ps, int ss, const HardwareConfig& hwConfig);
36
37 // Allocate/free external primary slots
38 [[nodiscard]] int allocateAnyPrimarySlot(const HardwareConfig& hwConfig);
39 [[nodiscard]] int allocateSpecificPrimarySlot(unsigned slot, const HardwareConfig& hwConfig);
40 void freePrimarySlot(int ps, const HardwareConfig& hwConfig);
41
42 [[nodiscard]] bool isExternalSlot(int ps, int ss, bool convert) const;
43
44private:
45 [[nodiscard]] unsigned getSlot(int ps, int ss) const;
46
47private:
48 MSXMotherBoard& motherBoard;
49
50 class CartCmd final : public RecordedCommand {
51 public:
52 CartCmd(CartridgeSlotManager& manager, MSXMotherBoard& motherBoard,
53 std::string_view commandName);
54 void execute(std::span<const TclObject> tokens, TclObject& result,
55 EmuTime::param time) override;
56 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
57 void tabCompletion(std::vector<std::string>& tokens) const override;
58 [[nodiscard]] bool needRecord(std::span<const TclObject> tokens) const override;
59 private:
60 const HardwareConfig* getExtensionConfig(std::string_view cartName);
61 CartridgeSlotManager& manager;
62 CliComm& cliComm;
63 } cartCmd;
64
65 struct CartridgeSlotInfo final : InfoTopic {
66 explicit CartridgeSlotInfo(InfoCommand& machineInfoCommand);
67 void execute(std::span<const TclObject> tokens,
68 TclObject& result) const override;
69 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
70 } extSlotInfo;
71
72 struct Slot : public MediaInfoProvider {
73 ~Slot();
74
75 // MediaInfoProvider
76 void getMediaInfo(TclObject& result) override;
77
78 [[nodiscard]] bool exists() const;
79 [[nodiscard]] bool used(const HardwareConfig* allowed = nullptr) const;
80
81 std::optional<CartCmd> cartCommand;
82 std::optional<ExtCmd> extCommand;
83 const HardwareConfig* config = nullptr;
84 unsigned useCount = 0;
85 int ps = 0;
86 int ss = 0;
87 MSXCPUInterface* cpuInterface;
88 };
89 static constexpr unsigned MAX_SLOTS = 16 + 4;
90 std::array<Slot, MAX_SLOTS> slots;
91};
92
93} // namespace openmsx
94
95#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