Display loaded assembly and binary files as text
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
#include "programfiletab.h"
#include "registerwidget.h"
+#include "defines.h"
+
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), m_ui(new Ui::MainWindow) {
m_ui->setupUi(this);
@@ -68,9 +70,31 @@ void MainWindow::on_actionLoadAssemblyFile_triggered() {
void MainWindow::loadBinaryFile(QString fileName) {
// ... load file
- auto a = fileName;
+ QString output = "";
+ QFile file(fileName);
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ QByteArray read = file.readAll();
+ auto length = read.length();
+ QDataStream in(&read, QIODevice::ReadOnly);
+ char buffer[4];
+ for (int i = 0; i < length; i += 4) {
+ in.readRawData(buffer, 4);
+ for (int j = 0; j < 4; j++) {
+ output.append(
+ QString().setNum((uint8_t)buffer[j], 2).rightJustified(8, '0'));
+ }
+ output.append("\n");
+ }
+
+ m_ui->programfiletab->setBinaryText(output);
+ file.close();
+ }
}
void MainWindow::loadAssemblyFile(QString fileName) {
// ... load file
- auto a = fileName;
+ QFile file(fileName);
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ m_ui->programfiletab->setAssemblyText(file.readAll());
+ file.close();
+ }
}

MODIFY
src/programfiletab.cpp
src/programfiletab.cpp
@@ -16,3 +16,11 @@ void ProgramfileTab::on_pushButton_clicked() {
loadAssemblyFile();
}
}
+
+void ProgramfileTab::setAssemblyText(const QString &text) {
+ m_ui->assemblyedit->setPlainText(text);
+}
+
+void ProgramfileTab::setBinaryText(const QString &text) {
+ m_ui->binaryedit->setPlainText(text);
+}

MODIFY
src/programfiletab.h
src/programfiletab.h
#ifndef PROGRAMFILETAB_H
#define PROGRAMFILETAB_H
+#include <QFile>
#include <QWidget>
namespace Ui {
@@ -14,6 +15,9 @@ public:
explicit ProgramfileTab(QWidget *parent = 0);
~ProgramfileTab();
+ void setAssemblyText(const QString &text);
+ void setBinaryText(const QString &text);
+
signals:
void loadBinaryFile();
void loadAssemblyFile();

MODIFY
src/programfiletab.ui
src/programfiletab.ui
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <widget class="QPlainTextEdit" name="plainTextEdit"/>
- <widget class="QPlainTextEdit" name="plainTextEdit_2">
+ <widget class="QPlainTextEdit" name="assemblyedit">
+ <property name="tabStopWidth">
+ <number>20</number>
+ </property>
+ </widget>
+ <widget class="QPlainTextEdit" name="binaryedit">
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="tabStopWidth">
+ <number>20</number>
</property>
</widget>
</widget>

Display loaded assembly and binary files as text