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,
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]] std::string_view getRomFilename() const;
58 [[nodiscard]] const XMLElement& getDevicesElem() const;
59 [[nodiscard]] Type getType() const { return type; }
60
65 [[nodiscard]] byte parseSlotMap() const;
66
67 void parseSlots();
68 void createDevices();
69
70 [[nodiscard]] const auto& getDevices() const { return devices; };
71
75 void testRemove() const;
76
77 template<typename Archive>
78 void serialize(Archive& ar, unsigned version);
79
80private:
81 void setConfig(XMLElement* root) { config.setRoot(root); }
82 void load(std::string_view type);
83
84 void createDevices(const XMLElement& elem,
85 const XMLElement* primary, const XMLElement* secondary);
86 void createExternalSlot(int ps);
87 void createExternalSlot(int ps, int ss);
88 void createExpandedSlot(int ps);
89 [[nodiscard]] int getAnyFreePrimarySlot();
90 [[nodiscard]] int getSpecificFreePrimarySlot(unsigned slot);
91 void addDevice(std::unique_ptr<MSXDevice> device);
92 void setName(std::string_view proposedName);
93 void setSlot(std::string_view slotName);
94
95private:
96 MSXMotherBoard& motherBoard;
97 std::string hwName;
98 Type type;
99 std::string userName;
100 XMLDocument config;
101 FileContext context;
102
103 std::array<std::array<bool, 4>, 4> externalSlots;
104 std::array<bool, 4> externalPrimSlots;
105 std::array<bool, 4> expandedSlots;
106 std::array<bool, 4> allocatedPrimarySlots;
107
108 std::vector<std::unique_ptr<MSXDevice>> devices;
109
110 std::string name;
111
113};
115
117{
118 using type = std::tuple<std::string>;
119
120 template<typename Archive>
121 void save(Archive& ar, const HardwareConfig& config)
122 {
123 ar.serialize("hwname", config.hwName);
124 }
125
126 template<typename Archive>
127 [[nodiscard]] type load(Archive& ar, unsigned /*version*/)
128 {
129 std::string name;
130 ar.serialize("hwname", name);
131 return {name};
132 }
133};
134
135} // namespace openmsx
136
137#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:9
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)
void save(Archive &ar, const HardwareConfig &config)
Serialize (local) constructor arguments.