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 <array>
10#include <memory>
11#include <span>
12#include <string>
13#include <string_view>
14#include <vector>
15
16namespace openmsx {
17
18class MSXMotherBoard;
19class MSXDevice;
20class TclObject;
21
23{
24public:
25 enum class Type {
26 MACHINE,
27 EXTENSION,
28 ROM
29 };
30
33
34 static void loadConfig(XMLDocument& doc, std::string_view type, std::string_view name);
35
36 [[nodiscard]] static std::unique_ptr<HardwareConfig> createMachineConfig(
37 MSXMotherBoard& motherBoard, std::string machineName);
38 [[nodiscard]] static std::unique_ptr<HardwareConfig> createExtensionConfig(
39 MSXMotherBoard& motherBoard, std::string extensionName,
40 std::string_view slotName);
41 [[nodiscard]] static std::unique_ptr<HardwareConfig> createRomConfig(
42 MSXMotherBoard& motherBoard, std::string_view romFile,
43 std::string_view slotName, std::span<const TclObject> options);
44
45 HardwareConfig(MSXMotherBoard& motherBoard, std::string hwName);
47
48 [[nodiscard]] MSXMotherBoard& getMotherBoard() const { return motherBoard; }
49
50 [[nodiscard]] const FileContext& getFileContext() const { return context; }
51 void setFileContext(FileContext&& ctxt) { context = std::move(ctxt); }
52
53 [[nodiscard]] XMLDocument& getXMLDocument() { return config; }
54 [[nodiscard]] const XMLElement& getConfig() const { return *config.getRoot(); }
55 [[nodiscard]] const std::string& getName() const { return name; }
56 [[nodiscard]] const std::string& getConfigName() const { return hwName; }
57 [[nodiscard]] const XMLElement& getDevicesElem() const;
58 [[nodiscard]] Type getType() const { return type; }
59
64 [[nodiscard]] byte parseSlotMap() const;
65
66 void parseSlots();
67 void createDevices();
68
69 [[nodiscard]] const auto& getDevices() const { return devices; };
70
74 void testRemove() const;
75
76 template<typename Archive>
77 void serialize(Archive& ar, unsigned version);
78
79private:
80 void setConfig(XMLElement* root) { config.setRoot(root); }
81 void load(std::string_view type);
82
83 void createDevices(const XMLElement& elem,
84 const XMLElement* primary, const XMLElement* secondary);
85 void createExternalSlot(int ps);
86 void createExternalSlot(int ps, int ss);
87 void createExpandedSlot(int ps);
88 [[nodiscard]] int getAnyFreePrimarySlot();
89 [[nodiscard]] int getSpecificFreePrimarySlot(unsigned slot);
90 void addDevice(std::unique_ptr<MSXDevice> device);
91 void setName(std::string_view proposedName);
92 void setSlot(std::string_view slotName);
93
94private:
95 MSXMotherBoard& motherBoard;
96 std::string hwName;
97 Type type;
98 std::string userName;
99 XMLDocument config;
100 FileContext context;
101
102 std::array<std::array<bool, 4>, 4> externalSlots;
103 std::array<bool, 4> externalPrimSlots;
104 std::array<bool, 4> expandedSlots;
105 std::array<bool, 4> allocatedPrimarySlots;
106
107 std::vector<std::unique_ptr<MSXDevice>> devices;
108
109 std::string name;
110
112};
114
116{
117 using type = std::tuple<std::string>;
118
119 template<typename Archive>
120 void save(Archive& ar, const HardwareConfig& config)
121 {
122 ar.serialize("hwname", config.hwName);
123 }
124
125 template<typename Archive>
126 [[nodiscard]] type load(Archive& ar, unsigned /*version*/)
127 {
128 std::string name;
129 ar.serialize("hwname", name);
130 return {name};
131 }
132};
133
134} // namespace openmsx
135
136#endif
HardwareConfig(const HardwareConfig &)=delete
const std::string & getConfigName() 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_)
Definition: XMLElement.hh:270
const XMLElement * getRoot() const
Definition: XMLElement.hh:269
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.