| e8555c89 Andy McCall |
1 |
#ifndef HARDWARECONFIG_HH |
| 2 |
#define HARDWARECONFIG_HH |
| 3 |
|
| 4 |
#include "FileContext.hh" |
| 5 |
#include "XMLElement.hh" |
| 6 |
#include "serialize_constr.hh" |
| 7 |
#include "serialize_meta.hh" |
| 8 |
|
| 9 |
#include <array> |
| 10 |
#include <cstdint> |
| 11 |
#include <memory> |
| 12 |
#include <span> |
| 13 |
#include <string> |
| 14 |
#include <string_view> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace openmsx { |
| 18 |
|
| 19 |
class MSXMotherBoard; |
| 20 |
class MSXDevice; |
| 21 |
class TclObject; |
| 22 |
|
| 23 |
class HardwareConfig |
| 24 |
{ |
| 25 |
public: |
| 26 |
enum class Type : uint8_t { |
| 27 |
MACHINE, |
| 28 |
EXTENSION, |
| 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); |
| 44 |
HardwareConfig(const HardwareConfig&) = delete; |
| 45 |
HardwareConfig(HardwareConfig&&) = delete; |
| 46 |
HardwareConfig& operator=(const HardwareConfig&) = delete; |
| 47 |
HardwareConfig& operator=(HardwareConfig&&) = delete; |
| 48 |
~HardwareConfig(); |
| 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]] XMLElement& getConfig() { return *config.getRoot(); } |
| 58 |
[[nodiscard]] const std::string& getName() const { return name; } |
| 59 |
[[nodiscard]] const std::string& getConfigName() const { return hwName; } |
| 60 |
[[nodiscard]] std::string_view getRomFilename() const; |
| 61 |
[[nodiscard]] const XMLElement& getDevicesElem() const; |
| 62 |
[[nodiscard]] XMLElement& getDevicesElem(); |
| 63 |
[[nodiscard]] Type getType() const { return type; } |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
[[nodiscard]] uint8_t parseSlotMap() const; |
| 70 |
|
| 71 |
void parseSlots(); |
| 72 |
void createDevices(); |
| 73 |
|
| 74 |
[[nodiscard]] const auto& getDevices() const { return devices; }; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void testRemove() const; |
| 80 |
|
| 81 |
template<typename Archive> |
| 82 |
void serialize(Archive& ar, unsigned version); |
| 83 |
|
| 84 |
private: |
| 85 |
void setConfig(XMLElement* root) { config.setRoot(root); } |
| 86 |
void load(std::string_view type); |
| 87 |
|
| 88 |
void createDevices(XMLElement& elem, XMLElement* primary, XMLElement* secondary); |
| 89 |
void createExternalSlot(int ps); |
| 90 |
void createExternalSlot(int ps, int ss); |
| 91 |
void createExpandedSlot(int ps); |
| 92 |
[[nodiscard]] int getAnyFreePrimarySlot(); |
| 93 |
[[nodiscard]] int getSpecificFreePrimarySlot(unsigned slot); |
| 94 |
void addDevice(std::unique_ptr<MSXDevice> device); |
| 95 |
void setName(std::string_view proposedName); |
| 96 |
void setSlot(std::string_view slotName); |
| 97 |
|
| 98 |
private: |
| 99 |
MSXMotherBoard& motherBoard; |
| 100 |
std::string hwName; |
| 101 |
Type type; |
| 102 |
std::string userName; |
| 103 |
XMLDocument config{8192}; |
| 104 |
FileContext context; |
| 105 |
|
| 106 |
std::array<std::array<bool, 4>, 4> externalSlots; |
| 107 |
std::array<bool, 4> externalPrimSlots; |
| 108 |
std::array<bool, 4> expandedSlots; |
| 109 |
std::array<bool, 4> allocatedPrimarySlots; |
| 110 |
|
| 111 |
std::vector<std::unique_ptr<MSXDevice>> devices; |
| 112 |
|
| 113 |
std::string name; |
| 114 |
|
| 115 |
friend struct SerializeConstructorArgs<HardwareConfig>; |
| 116 |
}; |
| 117 |
SERIALIZE_CLASS_VERSION(HardwareConfig, 6); |
| 118 |
|
| 119 |
template<> struct SerializeConstructorArgs<HardwareConfig> |
| 120 |
{ |
| 121 |
using type = std::tuple<std::string>; |
| 122 |
|
| 123 |
template<typename Archive> |
| 124 |
void save(Archive& ar, const HardwareConfig& config) const |
| 125 |
{ |
| 126 |
ar.serialize("hwname", config.hwName); |
| 127 |
} |
| 128 |
|
| 129 |
template<typename Archive> |
| 130 |
[[nodiscard]] type load(Archive& ar, unsigned ) const |
| 131 |
{ |
| 132 |
std::string name; |
| 133 |
ar.serialize("hwname", name); |
| 134 |
return {name}; |
| 135 |
} |
| 136 |
}; |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
#endif |