diff options
| -rw-r--r-- | gui/gui.cc | 56 | ||||
| -rw-r--r-- | gui/gui.h | 1 | ||||
| -rw-r--r-- | gui/gui.ui | 2 | ||||
| -rw-r--r-- | gui/worker.cc | 14 | ||||
| -rw-r--r-- | gui/worker.h | 1 | 
5 files changed, 36 insertions, 38 deletions
@@ -41,6 +41,9 @@ GUI::GUI(QWidget *parent)      // Refresh DRAM from worker thread      connect(this, &GUI::sendRefreshDram, worker, &Worker::refreshDram, Qt::QueuedConnection); +    // Load program from worker thread +    connect(this, &GUI::sendLoadProgram, worker, &Worker::loadProgram, Qt::QueuedConnection); +      // Refresh Cache from worker thread      connect(this, &GUI::sendRefreshCache, worker, &Worker::refreshCache, Qt::QueuedConnection); @@ -113,45 +116,28 @@ void displayTableHTML(QTextEdit *textEdit, const std::vector<std::array<signed i      textEdit->setReadOnly(true);  } -void browseAndUploadFile(QWidget* parent) { -    QString filePath = QFileDialog::getOpenFileName(nullptr, "Open File", QDir::homePath(), "Text Files (*.txt);;All Files (*.*)"); +std::vector<signed int> browseAndRetrieveFile(QWidget* parent) { +    QString filePath = QFileDialog::getOpenFileName(parent, "Open Binary File", QDir::homePath(), "Binary Files (*.bin *.rv);;All Files (*.*)"); +    std::vector<signed int> program; -    if (filePath.isEmpty()) { -        return; -    } +    if (filePath.isEmpty()) return program;      QFile file(filePath); -    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { -       // textEdit->setPlainText("Error: Unable to open file!"); -       QMessageBox::critical(parent, "File Upload", "Unable to open file!"); -        return; +    if (!file.open(QIODevice::ReadOnly)) { +        QMessageBox::critical(parent, "File Upload", "Unable to open file!"); +        return program;      } -    QTextStream in(&file); -    QString content; -    int lineNumber = 0; - -    while (!in.atEnd()) { -        QString line = in.readLine(); -         -        content += QString("<div id='line_%1' style='display: flex; justify-content: space-between; align-items: center;'>" -                           "<span style='font-size: 10px; font-weight: bold; color: gray;'>%1.</span>" -                           "<span>%2</span>" -                           "</div><hr>") -                   .arg(lineNumber)   -                   .arg(line);        -         -        lineNumber++; +    while (!file.atEnd()) { +        int32_t word = 0; +        if (file.read(reinterpret_cast<char*>(&word), sizeof(int32_t)) == sizeof(int32_t)) { +            program.push_back(static_cast<signed int>(word)); +        }      }      file.close(); - -    QMessageBox::information(parent, "File Upload", "Instructions loaded successfully!"); - -    // textEdit->setReadOnly(false);   -    // textEdit->setHtml(content); -    // textEdit->setReadOnly(true); +    return program;  }  void GUI::onWorkerClockCycles(int cycles, int pc) { @@ -257,8 +243,14 @@ void GUI::onWorkerFinished() {  void GUI::on_upload_intructions_btn_clicked()  {      qDebug() << "Upload intructions button clicked."; -    browseAndUploadFile(ui->register_table); - +    std::vector<signed int> program; +    program = browseAndRetrieveFile(ui->register_table); +    if(program.empty()){ +        QMessageBox::critical(ui->register_table, "File Upload", "Invalid Program File!"); +    } +    emit sendLoadProgram(program); +    emit sendRefreshDram(); +    QMessageBox::information(ui->register_table, "File Upload", "Instructions loaded successfully!");  } @@ -30,6 +30,7 @@ signals:      void sendRefreshRegisters();      void sendRunSteps(int steps);      void sendRunStep(); +    void sendLoadProgram(std::vector<signed int> program);  private slots:      void onWorkerClockCycles(int value, int pc); @@ -18,7 +18,7 @@      <item>       <layout class="QGridLayout" name="gridLayout_2" rowstretch="0,0,0" columnstretch="0,3,0,1,0">        <item row="0" column="1"> -       <layout class="QVBoxLayout" name="verticalLayout_19"> +       <layout class="QVBoxLayout" name="verticalLayout_19" stretch="1,0,3">          <item>           <layout class="QVBoxLayout" name="verticalLayout_20">            <item> diff --git a/gui/worker.cc b/gui/worker.cc index a912e06..df6ebd2 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -6,7 +6,7 @@ void Worker::doWork()  {  	qDebug() << "Initializing...";  	this->d = new Dram(0); -	this->c = new Cache(this->d, 5, 0, 0); +	this->c = new Cache(this->d, 8, 0, 0);  	this->if_stage = new IF(nullptr);  	this->id_stage = new ID(if_stage);  	this->ex_stage = new EX(id_stage); @@ -16,7 +16,7 @@ void Worker::doWork()  	emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());  	emit dram_storage(this->d->view(0, 32)); -	emit cache_storage(this->c->view(0, 7)); +	emit cache_storage(this->c->view(0, 256));  	emit register_storage(this->ct->get_gprs());  	std::vector<signed int> p; @@ -84,6 +84,10 @@ Worker::~Worker()  	delete this->c;  } +void Worker::loadProgram(std::vector<signed int> p) { +	this->d->load(p); +} +  void Worker::refreshDram()  {  	qDebug() << "Refreshing Dram"; @@ -93,7 +97,7 @@ void Worker::refreshDram()  void Worker::refreshCache()  {  	qDebug() << "Refreshing Dram"; -	emit cache_storage(this->c->view(24, 31)); +	emit cache_storage(this->c->view(0, 256));  }  void Worker::refreshRegisters() @@ -107,7 +111,7 @@ void Worker::runSteps(int steps)  	qDebug() << "Running for steps: " << steps;  	this->ct->run_for(steps);  	emit dram_storage(this->d->view(0, 256)); -	emit cache_storage(this->c->view(0, 7)); +	emit cache_storage(this->c->view(0, 256));  	emit register_storage(this->ct->get_gprs());  	emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());  	emit if_info(this->if_stage->stage_info()); @@ -122,7 +126,7 @@ void Worker::runStep()  	qDebug() << "Running for 1 step ";  	this->ct->run_for(1);  	emit dram_storage(this->d->view(0, 256)); -	emit cache_storage(this->c->view(24, 8)); +	emit cache_storage(this->c->view(0, 256));  	emit register_storage(this->ct->get_gprs());  	emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());  	emit if_info(this->if_stage->stage_info()); diff --git a/gui/worker.h b/gui/worker.h index ee8926b..8fde554 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -34,6 +34,7 @@ public:  public slots:      void doWork();      void refreshDram(); +    void loadProgram(std::vector<signed int> p);      void refreshCache();       void refreshRegisters();       void runSteps(int steps);  | 
