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
32 static void loadConfig(XMLDocument& doc, std::string_view type, std::string_view name);
33
34 [[nodiscard]] static std::unique_ptr<HardwareConfig> createMachineConfig(
35 MSXMotherBoard& motherBoard, std::string machineName);
36 [[nodiscard]] static std::unique_ptr<HardwareConfig> createExtensionConfig(
37 MSXMotherBoard& motherBoard, std::string extensionName,
38 std::string_view slotName);
39 [[nodiscard]] static std::unique_ptr<HardwareConfig> createRomConfig(
40 MSXMotherBoard& motherBoard, std::string_view romFile,
41 std::string_view slotName, std::span<const TclObject> options);
42
43 HardwareConfig(MSXMotherBoard& motherBoard, std::string hwName);
49
50 [[nodiscard]] MSXMotherBoard& getMotherBoard() const { return motherBoard; }
51
52 [[nodiscard]] const FileContext& getFileContext() const { return context; }
53 void setFileContext(FileContext&& ctxt) { context = std::move(ctxt); }
54
55 [[nodiscard]] XMLDocument& getXMLDocument() { return config; }
56 [[nodiscard]] const XMLElement& getConfig() const { return *config.getRoot(); }
57 [[nodiscard]] const std::string& getName() const { return name; }
58 [[nodiscard]] const std::string& getConfigName() const { return hwName; }
59 [[nodiscard]] std::string_view getRomFilename() const;
60 [[nodiscard]] const XMLElement& getDevicesElem() const;
61 [[nodiscard]] Type getType() const { return type; }
62
67 [[nodiscard]] byte parseSlotMap() const;
68
69 void parseSlots();
70 void createDevices();
71
72 [[nodiscard]] const auto& getDevices() const { return devices; };
73
77 void testRemove() const;
78
79 template<typename Archive>
80 void serialize(Archive& ar, unsigned version);
81
82private:
83 void setConfig(XMLElement* root) { config.setRoot(root); }
84 void load(std::string_view type);
85
86 void createDevices(const XMLElement& elem,
87 const XMLElement* primary, const XMLElement* secondary);
88 void createExternalSlot(int ps);
89 void createExternalSlot(int ps, int ss);
90 void createExpandedSlot(int ps);
91 [[nodiscard]] int getAnyFreePrimarySlot();
92 [[nodiscard]] int getSpecificFreePrimarySlot(unsigned slot);
93 void addDevice(std::unique_ptr<MSXDevice> device);
94 void setName(std::string_view proposedName);
95 void setSlot(std::string_view slotName);
96
97private:
98 MSXMotherBoard& motherBoard;
99 std::string hwName;
100 Type type;
101 std::string userName;
102 XMLDocument config{8192}; // tweak: initial allocator buffer size
103 FileContext context;
104
105 std::array<std::array<bool, 4>, 4> externalSlots;
106 std::array<bool, 4> externalPrimSlots;
107 std::array<bool, 4> expandedSlots;
108 std::array<bool, 4> allocatedPrimarySlots;
109
110 std::vector<std::unique_ptr<MSXDevice>> devices;
111
112 std::string name;
113
115};
117
119{
120 using type = std::tuple<std::string>;
121
122 template<typename Archive>
123 void save(Archive& ar, const HardwareConfig& config) const
124 {
125 ar.serialize("hwname", config.hwName);
126 }
127
128 template<typename Archive>
129 [[nodiscard]] type load(Archive& ar, unsigned /*version*/) const
130 {
131 std::string name;
132 ar.serialize("hwname", name);
133 return {name};
134 }
135};
136
137} // namespace openmsx
138
139#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
HardwareConfig & operator=(HardwareConfig &&)=delete
const std::string & getName() const
const FileContext & getFileContext() const
const XMLElement & getConfig() const
byte parseSlotMap() const
Parses a slot mapping.
MSXMotherBoard & getMotherBoard() const
HardwareConfig(HardwareConfig &&)=delete
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.