Tidy the Bus reference definition a little

This commit is contained in:
Adrian Conlon 2021-12-08 19:45:07 +00:00
parent 61b7359505
commit 927938560a
2 changed files with 6 additions and 6 deletions

View File

@ -11,6 +11,8 @@ namespace EightBit {
enum class AccessLevel { Unknown, ReadOnly, WriteOnly, ReadWrite };
constexpr auto offset(uint16_t address) const noexcept { return (address - begin) & mask; }
Memory& memory;
uint16_t begin = Chip::Mask16;
uint16_t mask = 0U;

View File

@ -40,10 +40,8 @@ void EightBit::Bus::loadHexFile(const std::string path) {
uint8_t& EightBit::Bus::reference(const uint16_t address) noexcept {
const auto mapped = mapping(address);
const uint16_t offset = (address - mapped.begin) & mapped.mask;
if (mapped.access == MemoryMapping::AccessLevel::ReadOnly) {
DATA() = mapped.memory.peek(offset);
return DATA();
}
return mapped.memory.reference(offset);
const auto offset = mapped.offset(address);
if (mapped.access != MemoryMapping::AccessLevel::ReadOnly)
return mapped.memory.reference(offset);
return DATA() = mapped.memory.peek(offset);
}