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"
8#include "openmsx.hh"
9
10#include <cassert>
11#include <memory>
12#include <span>
13#include <string>
14#include <string_view>
15
16namespace openmsx {
17
18class MSXMotherBoard;
19class XMLElement;
20class DeviceConfig;
21class FileContext;
22class RomDebuggable;
23class TclObject;
24
25class Rom final
26{
27public:
28 Rom(std::string name, static_string_view description,
29 const DeviceConfig& config, std::string_view id = {});
30 Rom(Rom&& other) noexcept;
32
33 [[nodiscard]] const byte& operator[](size_t address) const {
34 assert(address < rom.size());
35 return rom[address];
36 }
37 [[nodiscard]] auto size() const { return rom.size(); }
38 [[nodiscard]] auto begin() const { return rom.begin(); }
39 [[nodiscard]] auto end() const { return rom.end(); }
40
41 [[nodiscard]] std::string_view getFilename() const;
42 [[nodiscard]] const std::string& getName() const { return name; }
43 [[nodiscard]] std::string_view getDescription() const { return description; }
44 [[nodiscard]] const Sha1Sum& getOriginalSHA1() const;
45 [[nodiscard]] const Sha1Sum& getSHA1() const;
46
47 void addPadding(size_t newSize, byte filler = 0xff);
48
52 void getInfo(TclObject& result) const;
53
54private:
55 void init(MSXMotherBoard& motherBoard, const XMLElement& config,
56 const FileContext& context);
57 [[nodiscard]] bool checkSHA1(const XMLElement& config) const;
58
59private:
60 // !! update the move constructor when changing these members !!
61 std::span<const byte> rom;
62 MemBuffer<byte> extendedRom;
63
64 File file; // can be a closed file
65
66 mutable Sha1Sum originalSha1;
67 mutable Sha1Sum actualSha1;
68 std::string name;
69 /*const*/ static_string_view description; // not const to allow move
70
71 // This must come after 'name':
72 // the destructor of RomDebuggable calls Rom::getName(), which still
73 // needs the Rom::name member.
74 std::unique_ptr<RomDebuggable> romDebuggable; // can be nullptr
75};
76
77} // namespace openmsx
78
79#endif
This class manages the lifetime of a block of memory.
Definition MemBuffer.hh:32
auto end() const
Definition Rom.hh:39
std::string_view getDescription() const
Definition Rom.hh:43
const Sha1Sum & getSHA1() const
Definition Rom.cc:358
auto begin() const
Definition Rom.hh:38
const Sha1Sum & getOriginalSHA1() const
Definition Rom.cc:350
std::string_view getFilename() const
Definition Rom.cc:345
void getInfo(TclObject &result) const
Add dict values with info to result.
Definition Rom.cc:380
auto size() const
Definition Rom.hh:37
const std::string & getName() const
Definition Rom.hh:42
const byte & operator[](size_t address) const
Definition Rom.hh:33
void addPadding(size_t newSize, byte filler=0xff)
Definition Rom.cc:367
This class represents the result of a sha1 calculation (a 160-bit value).
Definition sha1.hh:24
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:11