| 1 |
#ifndef ROM_HH |
| 2 |
#define ROM_HH |
| 3 |
|
| 4 |
#include "MappedFile.hh" |
| 5 |
|
| 6 |
#include "MemBuffer.hh" |
| 7 |
#include "sha1.hh" |
| 8 |
#include "static_string_view.hh" |
| 9 |
|
| 10 |
#include <cassert> |
| 11 |
#include <cstdint> |
| 12 |
#include <memory> |
| 13 |
#include <optional> |
| 14 |
#include <span> |
| 15 |
#include <string> |
| 16 |
#include <string_view> |
| 17 |
|
| 18 |
namespace openmsx { |
| 19 |
|
| 20 |
class MSXMotherBoard; |
| 21 |
class XMLElement; |
| 22 |
class DeviceConfig; |
| 23 |
class FileContext; |
| 24 |
class RomDebuggable; |
| 25 |
class TclObject; |
| 26 |
|
| 27 |
class Rom final |
| 28 |
{ |
| 29 |
public: |
| 30 |
Rom(std::string name, static_string_view description, |
| 31 |
DeviceConfig& config, std::string_view id = {}); |
| 32 |
Rom(Rom&& other) noexcept; |
| 33 |
~Rom(); |
| 34 |
|
| 35 |
[[nodiscard]] const uint8_t& operator[](size_t address) const { |
| 36 |
assert(address < rom.size()); |
| 37 |
return rom[address]; |
| 38 |
} |
| 39 |
[[nodiscard]] auto size() const { return rom.size(); } |
| 40 |
[[nodiscard]] auto begin() const { return rom.begin(); } |
| 41 |
[[nodiscard]] auto end() const { return rom.end(); } |
| 42 |
|
| 43 |
[[nodiscard]] const std::string& getFilename() const { return filename; } |
| 44 |
[[nodiscard]] const std::string& getName() const { return name; } |
| 45 |
[[nodiscard]] std::string_view getDescription() const { return description; } |
| 46 |
[[nodiscard]] const Sha1Sum& getOriginalSHA1() const; |
| 47 |
[[nodiscard]] const Sha1Sum& getSHA1() const; |
| 48 |
|
| 49 |
void addPadding(size_t newSize, uint8_t filler = 0xff); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
void getInfo(TclObject& result) const; |
| 55 |
|
| 56 |
private: |
| 57 |
void init(MSXMotherBoard& motherBoard, XMLElement& config, |
| 58 |
const FileContext& context); |
| 59 |
[[nodiscard]] bool checkSHA1(const XMLElement& config) const; |
| 60 |
|
| 61 |
private: |
| 62 |
|
| 63 |
std::span<const uint8_t> rom; |
| 64 |
MemBuffer<uint8_t> extendedRom; |
| 65 |
|
| 66 |
std::string filename; |
| 67 |
std::optional<MappedFile<uint8_t>> mmap; |
| 68 |
|
| 69 |
mutable Sha1Sum originalSha1; |
| 70 |
mutable Sha1Sum actualSha1; |
| 71 |
std::string name; |
| 72 |
static_string_view description; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
std::unique_ptr<RomDebuggable> romDebuggable; |
| 78 |
}; |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
#endif |