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