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