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.hh"
10 #include <string>
11 #include <string_view>
12 #include <vector>
13 #include <memory>
14 
15 namespace openmsx {
16 
17 class MSXMotherBoard;
18 class MSXDevice;
19 class TclObject;
20 
22 {
23 public:
24  HardwareConfig(const HardwareConfig&) = delete;
25  HardwareConfig& operator=(const HardwareConfig&) = delete;
26 
27  static XMLElement loadConfig(std::string_view type, std::string_view name);
28 
29  static std::unique_ptr<HardwareConfig> createMachineConfig(
30  MSXMotherBoard& motherBoard, std::string machineName);
31  static std::unique_ptr<HardwareConfig> createExtensionConfig(
32  MSXMotherBoard& motherBoard, std::string extensionName,
33  std::string slotname);
34  static std::unique_ptr<HardwareConfig> createRomConfig(
35  MSXMotherBoard& motherBoard, std::string romfile,
36  std::string slotname, span<const TclObject> options);
37 
38  HardwareConfig(MSXMotherBoard& motherBoard, std::string hwName);
40 
41  MSXMotherBoard& getMotherBoard() const { return motherBoard; }
42 
43  const FileContext& getFileContext() const { return context; }
44  void setFileContext(FileContext&& ctxt) { context = std::move(ctxt); }
45 
46  const XMLElement& getConfig() const { return config; }
47  const std::string& getName() const { return name; }
48 
53  byte parseSlotMap() const;
54 
55  void parseSlots();
56  void createDevices();
57 
61  void testRemove() const;
62 
63  template<typename Archive>
64  void serialize(Archive& ar, unsigned version);
65 
66 private:
67  void setConfig(XMLElement config_) { config = std::move(config_); }
68  void load(std::string_view type);
69 
70  const XMLElement& getDevices() const;
71  void createDevices(const XMLElement& elem,
72  const XMLElement* primary, const XMLElement* secondary);
73  void createExternalSlot(int ps);
74  void createExternalSlot(int ps, int ss);
75  void createExpandedSlot(int ps);
76  int getAnyFreePrimarySlot();
77  int getSpecificFreePrimarySlot(unsigned slot);
78  void addDevice(std::unique_ptr<MSXDevice> device);
79  void setName(std::string_view proposedName);
80  void setSlot(std::string slotname);
81 
82  MSXMotherBoard& motherBoard;
83  std::string hwName;
84  std::string userName;
85  XMLElement config;
86  FileContext context;
87 
88  bool externalSlots[4][4];
89  bool externalPrimSlots[4];
90  bool expandedSlots[4];
91  bool allocatedPrimarySlots[4];
92 
93  std::vector<std::unique_ptr<MSXDevice>> devices;
94 
95  std::string name;
96 
98 };
100 
102 {
103  using type = std::tuple<std::string>;
104  template<typename Archive> void save(
105  Archive& ar, const HardwareConfig& config)
106  {
107  ar.serialize("hwname", config.hwName);
108  }
109  template<typename Archive> type load(Archive& ar, unsigned /*version*/)
110  {
111  std::string name;
112  ar.serialize("hwname", name);
113  return std::tuple(name);
114  }
115 };
116 
117 } // namespace openmsx
118 
119 #endif
openmsx::HardwareConfig::createMachineConfig
static std::unique_ptr< HardwareConfig > createMachineConfig(MSXMotherBoard &motherBoard, std::string machineName)
Definition: HardwareConfig.cc:30
openmsx::SerializeConstructorArgs< HardwareConfig >::load
type load(Archive &ar, unsigned)
Definition: HardwareConfig.hh:109
openmsx::HardwareConfig::~HardwareConfig
~HardwareConfig()
Definition: HardwareConfig.cc:127
openmsx.hh
openmsx::SerializeConstructorArgs< HardwareConfig >::save
void save(Archive &ar, const HardwareConfig &config)
Definition: HardwareConfig.hh:104
openmsx::HardwareConfig::createDevices
void createDevices()
Definition: HardwareConfig.cc:321
serialize_meta.hh
openmsx::XMLElement
XMLElement
Definition: XMLElement.cc:348
openmsx::HardwareConfig::parseSlotMap
byte parseSlotMap() const
Parses a slot mapping.
Definition: HardwareConfig.cc:300
XMLElement.hh
openmsx::HardwareConfig::operator=
HardwareConfig & operator=(const HardwareConfig &)=delete
openmsx::HardwareConfig::HardwareConfig
HardwareConfig(const HardwareConfig &)=delete
openmsx::FileContext
Definition: FileContext.hh:9
openmsx::HardwareConfig::getConfig
const XMLElement & getConfig() const
Definition: HardwareConfig.hh:46
span
Definition: span.hh:34
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::XMLElement
Definition: XMLElement.hh:15
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
openmsx::HardwareConfig::createRomConfig
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, std::string romfile, std::string slotname, span< const TclObject > options)
Definition: HardwareConfig.cc:50
openmsx::FileContext
FileContext
Definition: FileContext.cc:120
openmsx::HardwareConfig::createExtensionConfig
static std::unique_ptr< HardwareConfig > createExtensionConfig(MSXMotherBoard &motherBoard, std::string extensionName, std::string slotname)
Definition: HardwareConfig.cc:39
span.hh
FileContext.hh
openmsx::HardwareConfig::setFileContext
void setFileContext(FileContext &&ctxt)
Definition: HardwareConfig.hh:44
openmsx::HardwareConfig::getName
const std::string & getName() const
Definition: HardwareConfig.hh:47
openmsx::MSXDevice
MSXDevice
Definition: MSXDevice.cc:533
openmsx::SerializeConstructorArgs< HardwareConfig >::type
std::tuple< std::string > type
Definition: HardwareConfig.hh:103
openmsx::HardwareConfig
Definition: HardwareConfig.hh:21
openmsx::HardwareConfig::serialize
void serialize(Archive &ar, unsigned version)
Definition: HardwareConfig.cc:419
openmsx::HardwareConfig::testRemove
void testRemove() const
Checks whether this HardwareConfig can be deleted.
Definition: HardwareConfig.cc:161
openmsx::SerializeConstructorArgs
Serialize (local) constructor arguments.
Definition: serialize_constr.hh:31
openmsx::HardwareConfig::getFileContext
const FileContext & getFileContext() const
Definition: HardwareConfig.hh:43
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
serialize_constr.hh
openmsx::HardwareConfig::loadConfig
static XMLElement loadConfig(std::string_view type, std::string_view name)
Definition: HardwareConfig.cc:220
openmsx::HardwareConfig::parseSlots
void parseSlots()
Definition: HardwareConfig.cc:235
openmsx::HardwareConfig::getMotherBoard
MSXMotherBoard & getMotherBoard() const
Definition: HardwareConfig.hh:41