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