2018-11-04 16:38:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "Memory.h"
|
|
|
|
|
|
|
|
namespace EightBit {
|
|
|
|
// ROM is a basic implementation of the Memory interface.
|
|
|
|
// Nothing over and above the interface is exposed to users
|
|
|
|
// of the ROM class.
|
|
|
|
class Rom : public Memory {
|
|
|
|
private:
|
|
|
|
std::vector<uint8_t> m_bytes;
|
|
|
|
|
|
|
|
protected:
|
2021-08-23 08:44:48 +00:00
|
|
|
[[nodiscard]] constexpr const auto& BYTES() const noexcept { return m_bytes; }
|
|
|
|
[[nodiscard]] constexpr auto& BYTES() noexcept { return m_bytes; }
|
2018-11-04 16:38:57 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
void poke(uint16_t address, uint8_t value) noexcept override;
|
2018-11-04 16:38:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static int load(std::ifstream& file, std::vector<uint8_t>& output, int writeOffset = 0, int readOffset = 0, int limit = -1, int maximumSize = -1);
|
2020-11-07 09:41:12 +00:00
|
|
|
static int load(std::string path, std::vector<uint8_t>& output, int writeOffset = 0, int readOffset = 0, int limit = -1, int maximumSize = -1);
|
2018-11-04 16:38:57 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
Rom(size_t size = 0) noexcept;
|
2021-08-23 08:45:40 +00:00
|
|
|
Rom(const Rom& rhs);
|
|
|
|
Rom& operator=(const Rom& rhs);
|
2018-11-04 16:38:57 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] size_t size() const noexcept final;
|
2018-11-04 16:38:57 +00:00
|
|
|
|
2018-11-27 22:36:54 +00:00
|
|
|
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
|
2020-11-07 09:41:12 +00:00
|
|
|
int load(std::string path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
|
2018-11-27 22:36:54 +00:00
|
|
|
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
|
2018-11-04 16:38:57 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
[[nodiscard]] uint8_t peek(uint16_t address) const noexcept final;
|
2018-11-04 16:38:57 +00:00
|
|
|
};
|
|
|
|
}
|