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