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_view.hh"
11 #include <string>
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(string_view type, 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(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(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 };
99 SERIALIZE_CLASS_VERSION(HardwareConfig, 4);
100 
101 template<> struct SerializeConstructorArgs<HardwareConfig>
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::make_tuple(name);
114  }
115 };
116 
117 } // namespace openmsx
118 
119 #endif
void serialize(Archive &ar, unsigned version)
static XMLElement loadConfig(string_view type, string_view name)
byte parseSlotMap() const
Parses a slot mapping.
void save(Archive &ar, const HardwareConfig &config)
Definition: span.hh:34
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, std::string romfile, std::string slotname, span< const TclObject > options)
MSXMotherBoard & getMotherBoard() const
void testRemove() const
Checks whether this HardwareConfig can be deleted.
static std::unique_ptr< HardwareConfig > createMachineConfig(MSXMotherBoard &motherBoard, std::string machineName)
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
const std::string & getName() const
const FileContext & getFileContext() const
static std::unique_ptr< HardwareConfig > createExtensionConfig(MSXMotherBoard &motherBoard, std::string extensionName, std::string slotname)
HardwareConfig & operator=(const HardwareConfig &)=delete
HardwareConfig(const HardwareConfig &)=delete
const XMLElement & getConfig() const
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
void setFileContext(FileContext &&ctxt)
Serialize (local) constructor arguments.