mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-27 10:29:30 +00:00
Tidy the Bus reference definition a little
This commit is contained in:
parent
61b7359505
commit
927938560a
@ -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;
|
||||
|
10
src/Bus.cpp
10
src/Bus.cpp
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user