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) const;
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
openmsx.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
sha1.hh
openmsx::XMLElement
XMLElement
Definition: XMLElement.cc:350
openmsx::Rom::getName
const std::string & getName() const
Definition: Rom.hh:35
openmsx::Rom::getFilename
std::string getFilename() const
Definition: Rom.cc:349
openmsx::Rom::addPadding
void addPadding(unsigned newSize, byte filler=0xff)
Definition: Rom.cc:371
openmsx::FileContext
Definition: FileContext.hh:10
openmsx::Rom::Rom
Rom(std::string name, std::string description, const DeviceConfig &config, const std::string &id={})
Definition: Rom.cc:47
openmsx::XMLElement
Definition: XMLElement.hh:16
File.hh
openmsx::MemBuffer< byte >
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:61
openmsx::FileContext
FileContext
Definition: FileContext.cc:123
openmsx::Rom::~Rom
~Rom()
openmsx::Sha1Sum
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:20
MemBuffer.hh
openmsx::Rom
Definition: Rom.hh:21
gl::context
std::unique_ptr< Context > context
Definition: GLContext.cc:9
openmsx::File
Definition: File.hh:16
openmsx::Rom::operator[]
const byte & operator[](unsigned address) const
Definition: Rom.hh:28
openmsx::Rom::getSHA1
const Sha1Sum & getSHA1() const
Definition: Rom.cc:362
openmsx::Rom::getOriginalSHA1
const Sha1Sum & getOriginalSHA1() const
Definition: Rom.cc:354
openmsx::Rom::getSize
unsigned getSize() const
Definition: Rom.hh:32
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::Rom::getDescription
const std::string & getDescription() const
Definition: Rom.hh:36