diff --git a/inc/Rom.h b/inc/Rom.h index 38baef6..f0af1ab 100644 --- a/inc/Rom.h +++ b/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& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) final; + template + 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; }; } diff --git a/src/Rom.cpp b/src/Rom.cpp index 7deaaa7..a87ffef 100644 --- a/src/Rom.cpp +++ b/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& 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 {