openMSX
Rom.hh
Go to the documentation of this file.
1 #ifndef ROM_HH
2 #define ROM_HH
3 
4 #include "File.hh"
5 #include "MemBuffer.hh"
6 #include "sha1.hh"
7 #include "static_string_view.hh"
8 #include "openmsx.hh"
9 #include <string>
10 #include <string_view>
11 #include <memory>
12 #include <cassert>
13 
14 namespace openmsx {
15 
16 class MSXMotherBoard;
17 class XMLElement;
18 class DeviceConfig;
19 class FileContext;
20 class RomDebuggable;
21 
22 class Rom final
23 {
24 public:
25  Rom(std::string name, static_string_view description,
26  const DeviceConfig& config, const std::string& id = {});
27  Rom(Rom&& other) noexcept;
28  ~Rom();
29 
30  [[nodiscard]] const byte& operator[](unsigned address) const {
31  assert(address < size);
32  return rom[address];
33  }
34  [[nodiscard]] unsigned getSize() const { return size; }
35 
36  [[nodiscard]] std::string_view getFilename() const;
37  [[nodiscard]] const std::string& getName() const { return name; }
38  [[nodiscard]] std::string_view getDescription() const { return description; }
39  [[nodiscard]] const Sha1Sum& getOriginalSHA1() const;
40  [[nodiscard]] const Sha1Sum& getSHA1() const;
41 
42  void addPadding(unsigned newSize, byte filler = 0xff);
43 
44 private:
45  void init(MSXMotherBoard& motherBoard, const XMLElement& config,
46  const FileContext& context);
47  [[nodiscard]] bool checkSHA1(const XMLElement& config) const;
48 
49 private:
50  // !! update the move constructor when changing these members !!
51  const byte* rom;
52  MemBuffer<byte> extendedRom;
53 
54  File file; // can be a closed file
55 
56  mutable Sha1Sum originalSha1;
57  mutable Sha1Sum actualSha1;
58  std::string name;
59  /*const*/ static_string_view description; // not const to allow move
60  unsigned size;
61 
62  // This must come after 'name':
63  // the destructor of RomDebuggable calls Rom::getName(), which still
64  // needs the Rom::name member.
65  std::unique_ptr<RomDebuggable> romDebuggable; // can be nullptr
66 };
67 
68 } // namespace openmsx
69 
70 #endif
std::string_view getDescription() const
Definition: Rom.hh:38
unsigned getSize() const
Definition: Rom.hh:34
const Sha1Sum & getSHA1() const
Definition: Rom.cc:365
const byte & operator[](unsigned address) const
Definition: Rom.hh:30
const Sha1Sum & getOriginalSHA1() const
Definition: Rom.cc:357
std::string_view getFilename() const
Definition: Rom.cc:352
Rom(std::string name, static_string_view description, const DeviceConfig &config, const std::string &id={})
Definition: Rom.cc:50
const std::string & getName() const
Definition: Rom.hh:37
void addPadding(unsigned newSize, byte filler=0xff)
Definition: Rom.cc:374
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:22
static_string_view
std::unique_ptr< Context > context
Definition: GLContext.cc:9
This file implemented 3 utility functions:
Definition: Autofire.cc:9