Skip to content

Commit

Permalink
add dict impl to libalee section
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsullivan committed Nov 16, 2023
1 parent ebbde43 commit 9ac70bf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions splitmemdict.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SplitMemDict : public Dictionary
uint8_t rwdict[MemDictSize - Dictionary::Begin] = {0};
uint8_t extra[Dictionary::Begin];

LIBALEE_SECTION
Addr convertAddress(Addr addr) const noexcept {
return addr < RON ? addr : static_cast<Addr>(addr - RON);
}
Expand All @@ -53,6 +54,7 @@ class SplitMemDict : public Dictionary
return *this;
}

LIBALEE_SECTION
virtual Cell read(Addr addr) const noexcept final {
const uint8_t *dict;
if (addr < RON)
Expand All @@ -63,13 +65,15 @@ class SplitMemDict : public Dictionary
return *reinterpret_cast<const Cell *>(dict + convertAddress(addr));
}

LIBALEE_SECTION
virtual void write(Addr addr, Cell value) noexcept final {
if (addr >= RON)
*reinterpret_cast<Cell *>(rwdict + addr - RON) = value;
else if (addr < Dictionary::Begin)
*reinterpret_cast<Cell *>(extra + addr) = value;
}

LIBALEE_SECTION
virtual uint8_t readbyte(Addr addr) const noexcept final {
const uint8_t *dict;
if (addr < RON)
Expand All @@ -80,13 +84,15 @@ class SplitMemDict : public Dictionary
return dict[convertAddress(addr)];
}

LIBALEE_SECTION
virtual void writebyte(Addr addr, uint8_t value) noexcept final {
if (addr >= RON)
rwdict[addr - RON] = value;
else if (addr < Dictionary::Begin)
extra[addr] = value;
}

LIBALEE_SECTION
virtual unsigned long int capacity() const noexcept final {
return RON + sizeof(extra) + sizeof(rwdict);
}
Expand Down

0 comments on commit 9ac70bf

Please sign in to comment.