summaryrefslogtreecommitdiff
path: root/src/storage/dram.cc
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-11 20:34:40 -0400
committerGitHub <noreply@github.com>2025-03-11 20:34:40 -0400
commit1b01b557e76f8643964e5c367c072ab7778036f6 (patch)
tree30947c7018653ca18d4a69de20936b3615768f9e /src/storage/dram.cc
parent92e8c2583695a3bf652e0e8dedb79e7a99922f5f (diff)
parentc55104f8e99ea6ccb0c66a5e0d3cfc81dbbc19ab (diff)
Merge pull request #26 from bdunahu/bdunahu
clarify macro names, implement load in CLI, fix many display issues
Diffstat (limited to 'src/storage/dram.cc')
-rw-r--r--src/storage/dram.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/storage/dram.cc b/src/storage/dram.cc
index f375a76..56eec47 100644
--- a/src/storage/dram.cc
+++ b/src/storage/dram.cc
@@ -6,6 +6,7 @@
#include <bitset>
#include <iostream>
#include <iterator>
+#include <utils.h>
Dram::Dram(int lines, int delay)
{
@@ -22,6 +23,7 @@ Dram::~Dram() { delete this->data; }
void Dram::do_write(signed int data, int address)
{
+ address = wrap_address(address);
int line = address / LINE_SIZE;
int word = address % LINE_SIZE;
@@ -31,18 +33,21 @@ void Dram::do_write(signed int data, int address)
void Dram::do_write_line(
std::array<signed int, LINE_SIZE> data_line, int address)
{
+ address = wrap_address(address);
int line = address / LINE_SIZE;
this->data->at(line) = data_line;
}
void Dram::do_read(std::array<signed int, LINE_SIZE> &data_line, int address)
{
+ address = wrap_address(address);
int line = address / LINE_SIZE;
data_line = this->data->at(line);
}
void Dram::do_read_word(signed int &data, int address)
{
+ address = wrap_address(address);
int line = address / LINE_SIZE;
int word = address % LINE_SIZE;
data = this->data->at(line).at(word);
@@ -136,13 +141,15 @@ std::ostream &operator<<(std::ostream &os, const Dram &d)
const auto default_flags = std::cout.flags();
const auto default_fill = std::cout.fill();
- std::vector<std::array<signed int, LINE_SIZE>> data = d.view(0, MEM_SIZE);
+ std::vector<std::array<signed int, LINE_SIZE>> data = d.view(0, MEM_LINES);
- os << " " << std::setfill(' ') << std::setw(MEM_SPEC + 2) << "INDEX"
+ os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2 + LINE_SPEC)
+ << "ADDRESS"
<< " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA"
<< std::endl;
- for (int i = 0; i < MEM_SIZE; ++i) {
- os << " 0b" << std::setw(MEM_SPEC) << std::bitset<MEM_SPEC>(i) << " | ";
+ for (int i = 0; i < MEM_LINES; ++i) {
+ os << " 0b" << std::setw(MEM_LINE_SPEC + LINE_SPEC) << left
+ << std::bitset<MEM_LINE_SPEC>(i) << " | ";
for (int j = 0; j < LINE_SIZE; ++j) {
os << "0x" << std::setfill('0') << std::setw(8) << std::hex
<< data.at(i).at(j) << ' ';