openMSX
HardwareConfig.hh
Go to the documentation of this file.
1 #ifndef HARDWARECONFIG_HH
2 #define HARDWARECONFIG_HH
3 
4 #include "XMLElement.hh"
5 #include "FileContext.hh"
6 #include "openmsx.hh"
7 #include "serialize_meta.hh"
8 #include "serialize_constr.hh"
9 #include "span.hh"
10 #include <string>
11 #include <string_view>
12 #include <vector>
13 #include <memory>
14 
15 namespace openmsx {
16 
17 class MSXMotherBoard;
18 class MSXDevice;
19 class TclObject;
20 
22 {
23 public:
24  enum class Type {
25  MACHINE,
26  EXTENSION,
27  ROM
28  };
29 
30  HardwareConfig(const HardwareConfig&) = delete;
32 
33  static void loadConfig(XMLDocument& doc, std::string_view type, std::string_view name);
34 
35  [[nodiscard]] static std::unique_ptr<HardwareConfig> createMachineConfig(
36  MSXMotherBoard& motherBoard, std::string machineName);
37  [[nodiscard]] static std::unique_ptr<HardwareConfig> createExtensionConfig(
38  MSXMotherBoard& motherBoard, std::string extensionName,
39  std::string_view slotname);
40  [[nodiscard]] static std::unique_ptr<HardwareConfig> createRomConfig(
41  MSXMotherBoard& motherBoard, std::string romfile,
42  std::string slotname, span<const TclObject> options);
43 
44  HardwareConfig(MSXMotherBoard& motherBoard, std::string hwName);
46 
47  [[nodiscard]] MSXMotherBoard& getMotherBoard() const { return motherBoard; }
48 
49  [[nodiscard]] const FileContext& getFileContext() const { return context; }
50  void setFileContext(FileContext&& ctxt) { context = std::move(ctxt); }
51 
52  [[nodiscard]] XMLDocument& getXMLDocument() { return config; }
53  [[nodiscard]] const XMLElement& getConfig() const { return *config.getRoot(); }
54  [[nodiscard]] const std::string& getName() const { return name; }
55  [[nodiscard]] const std::string& getConfigName() const { return hwName; }
56  [[nodiscard]] Type getType() const { return type; }
57 
62  [[nodiscard]] byte parseSlotMap() const;
63 
64  void parseSlots();
65  void createDevices();
66 
67  [[nodiscard]] const auto& getDevices() const { return devices; };
68 
72  void testRemove() const;
73 
74  template<typename Archive>
75  void serialize(Archive& ar, unsigned version);
76 
77 private:
78  void setConfig(XMLElement* root) { config.setRoot(root); }
79  void load(std::string_view type);
80 
81  [[nodiscard]] const XMLElement& getDevicesElem() const;
82  void createDevices(const XMLElement& elem,
83  const XMLElement* primary, const XMLElement* secondary);
84  void createExternalSlot(int ps);
85  void createExternalSlot(int ps, int ss);
86  void createExpandedSlot(int ps);
87  [[nodiscard]] int getAnyFreePrimarySlot();
88  [[nodiscard]] int getSpecificFreePrimarySlot(unsigned slot);
89  void addDevice(std::unique_ptr<MSXDevice> device);
90  void setName(std::string_view proposedName);
91  void setSlot(std::string_view slotname);
92 
93 private:
94  MSXMotherBoard& motherBoard;
95  std::string hwName;
96  Type type;
97  std::string userName;
98  XMLDocument config;
99  FileContext context;
100 
101  bool externalSlots[4][4];
102  bool externalPrimSlots[4];
103  bool expandedSlots[4];
104  bool allocatedPrimarySlots[4];
105 
106  std::vector<std::unique_ptr<MSXDevice>> devices;
107 
108  std::string name;
109 
111 };
113 
115 {
116  using type = std::tuple<std::string>;
117 
118  template<typename Archive>
119  void save(Archive& ar, const HardwareConfig& config)
120  {
121  ar.serialize("hwname", config.hwName);
122  }
123 
124  template<typename Archive>
125  [[nodiscard]] type load(Archive& ar, unsigned /*version*/)
126  {
127  std::string name;
128  ar.serialize("hwname", name);
129  return std::tuple(name);
130  }
131 };
132 
133 } // namespace openmsx
134 
135 #endif
const XMLElement & getConfig() const
const auto & getDevices() const
HardwareConfig(const HardwareConfig &)=delete
XMLDocument & getXMLDocument()
const std::string & getConfigName() const
MSXMotherBoard & getMotherBoard() const
static std::unique_ptr< HardwareConfig > createMachineConfig(MSXMotherBoard &motherBoard, std::string machineName)
const std::string & getName() const
void serialize(Archive &ar, unsigned version)
void setFileContext(FileContext &&ctxt)
HardwareConfig & operator=(const HardwareConfig &)=delete
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, std::string romfile, std::string slotname, span< const TclObject > options)
static std::unique_ptr< HardwareConfig > createExtensionConfig(MSXMotherBoard &motherBoard, std::string extensionName, std::string_view slotname)
const FileContext & getFileContext() const
byte parseSlotMap() const
Parses a slot mapping.
static void loadConfig(XMLDocument &doc, std::string_view type, std::string_view name)
void testRemove() const
Checks whether this HardwareConfig can be deleted.
const XMLElement * getRoot() const
Definition: XMLElement.hh:272
void setRoot(XMLElement *root_)
Definition: XMLElement.hh:273
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
void save(Archive &ar, const HardwareConfig &config)
Serialize (local) constructor arguments.