mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-22 09:30:32 +00:00
Add a span compatible ROM loader
This commit is contained in:
parent
4f4d234ed5
commit
af7679505c
16
inc/Rom.h
16
inc/Rom.h
@ -35,6 +35,22 @@ namespace EightBit {
|
||||
int load(std::string path, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
|
||||
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final;
|
||||
|
||||
template <typename Iter>
|
||||
int load(Iter start, Iter end, int writeOffset = 0, int readOffset = 0, int limit = -1) {
|
||||
|
||||
const auto size = end - start;
|
||||
if (limit < 0)
|
||||
limit = size - readOffset;
|
||||
|
||||
const size_t extent = limit + writeOffset;
|
||||
if (m_bytes.size() < extent)
|
||||
m_bytes.resize(extent);
|
||||
|
||||
std::copy(start + readOffset, start + readOffset + limit, m_bytes.begin() + writeOffset);
|
||||
|
||||
return limit;
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8_t peek(uint16_t address) const noexcept final;
|
||||
};
|
||||
}
|
||||
|
12
src/Rom.cpp
12
src/Rom.cpp
@ -68,17 +68,7 @@ int EightBit::Rom::load(const std::string path, const int writeOffset, const int
|
||||
}
|
||||
|
||||
int EightBit::Rom::load(const std::vector<uint8_t>& bytes, const int writeOffset, const int readOffset, int limit) {
|
||||
|
||||
if (limit < 0)
|
||||
limit = bytes.size() - readOffset;
|
||||
|
||||
const size_t extent = limit + writeOffset;
|
||||
if (m_bytes.size() < extent)
|
||||
m_bytes.resize(extent);
|
||||
|
||||
std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + readOffset + limit, m_bytes.begin() + writeOffset);
|
||||
|
||||
return limit;
|
||||
return load(bytes.cbegin(), bytes.cend(), writeOffset, readOffset, limit);
|
||||
}
|
||||
|
||||
uint8_t EightBit::Rom::peek(const uint16_t address) const noexcept {
|
||||
|
Loading…
Reference in New Issue
Block a user