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  [[nodiscard]] static XMLElement loadConfig(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]] const XMLElement& getConfig() const { return config; }
53  [[nodiscard]] const std::string& getName() const { return name; }
54  [[nodiscard]] const std::string& getConfigName() const { return hwName; }
55  [[nodiscard]] Type getType() const { return type; }
56 
61  [[nodiscard]] byte parseSlotMap() const;
62 
63  void parseSlots();
64  void createDevices();
65 
66  [[nodiscard]] const std::vector<std::unique_ptr<MSXDevice>>& getDevices() const { return devices; };
67 
71  void testRemove() const;
72 
73  template<typename Archive>
74  void serialize(Archive& ar, unsigned version);
75 
76 private:
77  void setConfig(XMLElement config_) { config = std::move(config_); }
78  void load(std::string_view type);
79 
80  [[nodiscard]] const XMLElement& getDevicesElem() const;
81  void createDevices(const XMLElement& elem,
82  const XMLElement* primary, const XMLElement* secondary);
83  void createExternalSlot(int ps);
84  void createExternalSlot(int ps, int ss);
85  void createExpandedSlot(int ps);
86  [[nodiscard]] int getAnyFreePrimarySlot();
87  [[nodiscard]] int getSpecificFreePrimarySlot(unsigned slot);
88  void addDevice(std::unique_ptr<MSXDevice> device);
89  void setName(std::string_view proposedName);
90  void setSlot(std::string_view slotname);
91 
92 private:
93  MSXMotherBoard& motherBoard;
94  std::string hwName;
95  Type type;
96  std::string userName;
97  XMLElement config;
98  FileContext context;
99 
100  bool externalSlots[4][4];
101  bool externalPrimSlots[4];
102  bool expandedSlots[4];
103  bool allocatedPrimarySlots[4];
104 
105  std::vector<std::unique_ptr<MSXDevice>> devices;
106 
107  std::string name;
108 
110 };
112 
114 {
115  using type = std::tuple<std::string>;
116 
117  template<typename Archive>
118  void save(Archive& ar, const HardwareConfig& config)
119  {
120  ar.serialize("hwname", config.hwName);
121  }
122 
123  template<typename Archive>
124  [[nodiscard]] type load(Archive& ar, unsigned /*version*/)
125  {
126  std::string name;
127  ar.serialize("hwname", name);
128  return std::tuple(name);
129  }
130 };
131 
132 } // namespace openmsx
133 
134 #endif
const XMLElement & getConfig() const
static XMLElement loadConfig(std::string_view type, std::string_view name)
HardwareConfig(const HardwareConfig &)=delete
const std::vector< std::unique_ptr< MSXDevice > > & getDevices() const
const std::string & getConfigName() const
MSXMotherBoard & getMotherBoard() const
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 > createExtensionConfig(MSXMotherBoard &motherBoard, std::string extensionName, std::string_view slotname)
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, std::string romfile, std::string slotname, span< const TclObject > options)
const FileContext & getFileContext() const
byte parseSlotMap() const
Parses a slot mapping.
static std::unique_ptr< HardwareConfig > createMachineConfig(MSXMotherBoard &motherBoard, std::string machineName)
void testRemove() const
Checks whether this HardwareConfig can be deleted.
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:5
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
void save(Archive &ar, const HardwareConfig &config)
Serialize (local) constructor arguments.