2019-02-02 21:08:32 +00:00
|
|
|
#include "memorystrapping.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
2022-12-10 16:26:39 +00:00
|
|
|
MemoryStrapping::MemoryStrapping(MemoryRow &row): row{row}, strapped{false} {
|
2019-02-02 21:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryStrapping::strap_to(std::uint16_t addr_base, std::uint16_t addr_size) {
|
|
|
|
this->addr_base = addr_base;
|
|
|
|
this->addr_size = addr_size;
|
2022-12-10 16:26:39 +00:00
|
|
|
this->strapped = true;
|
2019-02-02 21:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryStrapping::contains(std::uint16_t address) const {
|
2022-12-10 16:26:39 +00:00
|
|
|
if (!this->strapped) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-07 05:45:54 +00:00
|
|
|
return this->addr_base <= address && address < this->addr_base + size();
|
2019-02-02 21:08:32 +00:00
|
|
|
}
|
|
|
|
|
2019-06-24 03:25:09 +00:00
|
|
|
std::uint8_t MemoryStrapping::read(const std::uint16_t address, const std::uint8_t data) const {
|
2022-12-10 16:26:39 +00:00
|
|
|
if (!this->strapped) {
|
|
|
|
return 0xFFu;
|
|
|
|
}
|
2019-06-24 03:25:09 +00:00
|
|
|
return this->row.read(address - this->addr_base, data);
|
2019-02-02 21:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryStrapping::write(const std::uint16_t address, const std::uint8_t data) {
|
2022-12-10 16:26:39 +00:00
|
|
|
if (!this->strapped) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-02 21:08:32 +00:00
|
|
|
this->row.write(address - this->addr_base, data);
|
|
|
|
}
|
2019-02-07 05:45:54 +00:00
|
|
|
|
|
|
|
std::uint16_t MemoryStrapping::size() const {
|
2022-12-10 16:26:39 +00:00
|
|
|
if (!this->strapped) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-07 05:45:54 +00:00
|
|
|
return std::min(this->row.size(), this->addr_size);
|
|
|
|
}
|