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, const std::string& machineName);
31  static std::unique_ptr<HardwareConfig> createExtensionConfig(
32  MSXMotherBoard& motherBoard, string_view extensionName, string_view slotname);
33  static std::unique_ptr<HardwareConfig> createRomConfig(
34  MSXMotherBoard& motherBoard, string_view romfile,
35  string_view slotname, span<const TclObject> options);
36 
37  HardwareConfig(MSXMotherBoard& motherBoard, std::string hwName);
39 
40  MSXMotherBoard& getMotherBoard() const { return motherBoard; }
41 
42  const FileContext& getFileContext() const { return context; }
43  void setFileContext(FileContext&& ctxt) { context = std::move(ctxt); }
44 
45  const XMLElement& getConfig() const { return config; }
46  const std::string& getName() const { return name; }
47 
52  byte parseSlotMap() const;
53 
54  void parseSlots();
55  void createDevices();
56 
60  void testRemove() const;
61 
62  template<typename Archive>
63  void serialize(Archive& ar, unsigned version);
64 
65 private:
66  static std::string getFilename(string_view type, string_view name);
67  static XMLElement loadConfig(const std::string& filename);
68  void setConfig(XMLElement config_) { config = std::move(config_); }
69  void load(string_view type);
70 
71  const XMLElement& getDevices() const;
72  void createDevices(const XMLElement& elem,
73  const XMLElement* primary, const XMLElement* secondary);
74  void createExternalSlot(int ps);
75  void createExternalSlot(int ps, int ss);
76  void createExpandedSlot(int ps);
77  int getAnyFreePrimarySlot();
78  int getSpecificFreePrimarySlot(unsigned slot);
79  void addDevice(std::unique_ptr<MSXDevice> device);
80  void setName(string_view proposedName);
81  void setSlot(string_view slotname);
82 
83  MSXMotherBoard& motherBoard;
84  std::string hwName;
85  std::string userName;
86  XMLElement config;
87  FileContext context;
88 
89  bool externalSlots[4][4];
90  bool externalPrimSlots[4];
91  bool expandedSlots[4];
92  bool allocatedPrimarySlots[4];
93 
94  std::vector<std::unique_ptr<MSXDevice>> devices;
95 
96  std::string name;
97 
99 };
100 SERIALIZE_CLASS_VERSION(HardwareConfig, 4);
101 
102 template<> struct SerializeConstructorArgs<HardwareConfig>
103 {
104  using type = std::tuple<std::string>;
105  template<typename Archive> void save(
106  Archive& ar, const HardwareConfig& config)
107  {
108  ar.serialize("hwname", config.hwName);
109  }
110  template<typename Archive> type load(Archive& ar, unsigned /*version*/)
111  {
112  std::string name;
113  ar.serialize("hwname", name);
114  return std::make_tuple(name);
115  }
116 };
117 
118 } // namespace openmsx
119 
120 #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
static std::unique_ptr< HardwareConfig > createExtensionConfig(MSXMotherBoard &motherBoard, string_view extensionName, string_view slotname)
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
MSXMotherBoard & getMotherBoard() const
static std::unique_ptr< HardwareConfig > createMachineConfig(MSXMotherBoard &motherBoard, const std::string &machineName)
static std::unique_ptr< HardwareConfig > createRomConfig(MSXMotherBoard &motherBoard, string_view romfile, string_view slotname, span< const TclObject > options)
void testRemove() const
Checks whether this HardwareConfig can be deleted.
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
const std::string & getName() const
const FileContext & getFileContext() const
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.