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  const Sha1Sum& getSHA1() const;
39 
40  void addPadding(unsigned newSize, byte filler = 0xff);
41 
42 private:
43  void init(MSXMotherBoard& motherBoard, const XMLElement& config,
44  const FileContext& context);
45  bool checkSHA1(const XMLElement& config);
46 
47 private:
48  // !! update the move constructor when changing these members !!
49  const byte* rom;
50  MemBuffer<byte> extendedRom;
51 
52  File file; // can be a closed file
53 
54  mutable Sha1Sum originalSha1;
55  mutable Sha1Sum actualSha1;
56  std::string name;
57  /*const*/ std::string description; // not const to allow move
58  unsigned size;
59 
60  // This must come after 'name':
61  // the destructor of RomDebuggable calls Rom::getName(), which still
62  // needs the Rom::name member.
63  std::unique_ptr<RomDebuggable> romDebuggable; // can be nullptr
64 };
65 
66 } // namespace openmsx
67 
68 #endif
const Sha1Sum & getSHA1() const
Definition: Rom.cc:362
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:354
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
std::string getFilename() const
Definition: Rom.cc:349
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:371
Rom(std::string name, std::string description, const DeviceConfig &config, const std::string &id={})
Definition: Rom.cc:47