summaryrefslogtreecommitdiff
path: root/src/storage/dram.cc
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-21 16:42:16 -0400
committerbd <bdunahu@operationnull.com>2025-03-21 16:42:16 -0400
commita29cd5297d2d66f05ea91d05175fdc9fd4b2fef3 (patch)
tree9386aa3ccd2302fceb9750858d74ab56f156b4e2 /src/storage/dram.cc
parent431cba9a4bcef0e0ae047d45a7f3d98e601e30ed (diff)
add 'process' function to handle boilerplate on every request
Diffstat (limited to 'src/storage/dram.cc')
-rw-r--r--src/storage/dram.cc38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/storage/dram.cc b/src/storage/dram.cc
index 779e392..2c24b4b 100644
--- a/src/storage/dram.cc
+++ b/src/storage/dram.cc
@@ -24,24 +24,17 @@ Dram::~Dram() { delete this->data; }
Response Dram::write_line(
Accessor accessor, std::array<signed int, LINE_SIZE> data_line, int address)
{
- Response r = this->is_access_cleared(accessor);
- if (r == OK) {
- int line, word;
- get_memory_index(address, line, word);
+ return process(accessor, address, [&](int line, int word) {
+ (void)word;
this->data->at(line) = data_line;
- }
- return r;
+ });
}
Response Dram::write_word(Accessor accessor, signed int data, int address)
{
- Response r = this->is_access_cleared(accessor);
- if (r == OK) {
- int line, word;
- get_memory_index(address, line, word);
+ return process(accessor, address, [&](int line, int word) {
this->data->at(line).at(word) = data;
- }
- return r;
+ });
}
// TODO requires testing
@@ -50,22 +43,29 @@ Response Dram::read_line(
int address,
std::array<signed int, LINE_SIZE> &data_line)
{
- Response r = this->is_access_cleared(accessor);
- if (r == OK) {
- int line, word;
- get_memory_index(address, line, word);
+ return process(accessor, address, [&](int line, int word) {
+ (void)word;
data_line = this->data->at(line);
- }
- return r;
+ });
}
Response Dram::read_word(Accessor accessor, int address, signed int &data)
{
+ return process(accessor, address, [&](int line, int word) {
+ data = this->data->at(line).at(word);
+ });
+}
+
+Response Dram::process(
+ Accessor accessor,
+ int address,
+ std::function<void(int line, int word)> request_handler)
+{
Response r = this->is_access_cleared(accessor);
if (r == OK) {
int line, word;
get_memory_index(address, line, word);
- data = this->data->at(line).at(word);
+ request_handler(line, word);
}
return r;
}