fixed bugs
This commit is contained in:
parent
d3ab78e76c
commit
098766bb65
5 changed files with 64 additions and 15 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QScrollBar>
|
||||||
|
|
||||||
class Loader;
|
class Loader;
|
||||||
|
|
||||||
|
|
@ -698,8 +699,19 @@ MainWindow::DisassembledInstruction MainWindow::disassembleAt(int address)
|
||||||
QString reg1Str = (r1 < 10) ? regNames[r1] : "?";
|
QString reg1Str = (r1 < 10) ? regNames[r1] : "?";
|
||||||
QString reg2Str = (r2 < 10) ? regNames[r2] : "?";
|
QString reg2Str = (r2 < 10) ? regNames[r2] : "?";
|
||||||
|
|
||||||
|
// Check if this is a single-operand Format 2 instruction
|
||||||
|
QString mnem = result.mnemonic.toUpper();
|
||||||
|
if (mnem == "CLEAR" || mnem == "TIXR") {
|
||||||
|
result.operand = reg1Str;
|
||||||
|
} else if (mnem == "SVC") {
|
||||||
|
result.operand = QString::number(r1);
|
||||||
|
} else if (mnem == "SHIFTL" || mnem == "SHIFTR") {
|
||||||
|
result.operand = QString("%1, %2").arg(reg1Str).arg(r2);
|
||||||
|
} else {
|
||||||
|
// Two register operands (ADDR, SUBR, COMPR, etc.)
|
||||||
result.operand = QString("%1, %2").arg(reg1Str).arg(reg2Str);
|
result.operand = QString("%1, %2").arg(reg1Str).arg(reg2Str);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -852,7 +864,13 @@ void MainWindow::updateDisassemblyDisplay()
|
||||||
layout->addStretch();
|
layout->addStretch();
|
||||||
container->setLayout(layout);
|
container->setLayout(layout);
|
||||||
|
|
||||||
|
// Save scroll position before updating
|
||||||
|
int scrollPos = ui->DisasemblyScrollArea->verticalScrollBar()->value();
|
||||||
|
|
||||||
ui->DisasemblyScrollArea->setWidget(container);
|
ui->DisasemblyScrollArea->setWidget(container);
|
||||||
|
|
||||||
|
// Restore scroll position after updating
|
||||||
|
ui->DisasemblyScrollArea->verticalScrollBar()->setValue(scrollPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateMemoryDisplay()
|
void MainWindow::updateMemoryDisplay()
|
||||||
|
|
@ -919,7 +937,11 @@ void MainWindow::updateMemoryDisplay()
|
||||||
layout->addStretch();
|
layout->addStretch();
|
||||||
container->setLayout(layout);
|
container->setLayout(layout);
|
||||||
|
|
||||||
|
int scrollPos = ui->MemoryScrollArea->verticalScrollBar()->value();
|
||||||
|
|
||||||
ui->MemoryScrollArea->setWidget(container);
|
ui->MemoryScrollArea->setWidget(container);
|
||||||
|
|
||||||
|
ui->MemoryScrollArea->verticalScrollBar()->setValue(scrollPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadObjectFile()
|
void MainWindow::loadObjectFile()
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ private:
|
||||||
std::fstream fileStream;
|
std::fstream fileStream;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
bool fileCreated;
|
bool fileCreated;
|
||||||
|
std::streampos readPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILE_DEVICE_H
|
#endif // FILE_DEVICE_H
|
||||||
|
|
@ -3,9 +3,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
FileDevice::FileDevice(const std::string &filename)
|
FileDevice::FileDevice(const std::string &filename)
|
||||||
: filename(filename), fileCreated(false)
|
: filename(filename), fileCreated(false), readPosition(0)
|
||||||
{
|
{
|
||||||
// Don't create the file yet - wait until first write
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDevice::~FileDevice()
|
FileDevice::~FileDevice()
|
||||||
|
|
@ -18,9 +17,16 @@ FileDevice::~FileDevice()
|
||||||
void FileDevice::ensureFileOpen()
|
void FileDevice::ensureFileOpen()
|
||||||
{
|
{
|
||||||
if (!fileStream.is_open()) {
|
if (!fileStream.is_open()) {
|
||||||
if (fileCreated) {
|
// Check if file exists
|
||||||
fileStream.open(filename, std::ios::in | std::ios::out);
|
std::ifstream checkFile(filename);
|
||||||
|
bool fileExists = checkFile.good();
|
||||||
|
checkFile.close();
|
||||||
|
|
||||||
|
if (fileExists) {
|
||||||
|
fileStream.open(filename, std::ios::in | std::ios::out | std::ios::ate);
|
||||||
|
fileCreated = true;
|
||||||
} else {
|
} else {
|
||||||
|
// Create new file
|
||||||
std::ofstream create(filename);
|
std::ofstream create(filename);
|
||||||
if (!create) {
|
if (!create) {
|
||||||
throw std::runtime_error("Failed to create file: " + filename);
|
throw std::runtime_error("Failed to create file: " + filename);
|
||||||
|
|
@ -41,9 +47,11 @@ unsigned char FileDevice::read()
|
||||||
unsigned char value = 0;
|
unsigned char value = 0;
|
||||||
ensureFileOpen();
|
ensureFileOpen();
|
||||||
if (fileStream.is_open()) {
|
if (fileStream.is_open()) {
|
||||||
|
fileStream.seekg(readPosition);
|
||||||
char ch;
|
char ch;
|
||||||
if (fileStream.get(ch)) {
|
if (fileStream.get(ch)) {
|
||||||
value = static_cast<unsigned char>(ch);
|
value = static_cast<unsigned char>(ch);
|
||||||
|
readPosition = fileStream.tellg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -53,6 +61,7 @@ void FileDevice::write(unsigned char value)
|
||||||
{
|
{
|
||||||
ensureFileOpen();
|
ensureFileOpen();
|
||||||
if (fileStream.is_open()) {
|
if (fileStream.is_open()) {
|
||||||
|
fileStream.seekp(0, std::ios::end);
|
||||||
fileStream.put(static_cast<char>(value));
|
fileStream.put(static_cast<char>(value));
|
||||||
fileStream.flush();
|
fileStream.flush();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "file_reader.h"
|
#include "file_reader.h"
|
||||||
|
#include "string_reader.h"
|
||||||
#include "machine.h"
|
#include "machine.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
Loader::~Loader()
|
Loader::~Loader()
|
||||||
{
|
{
|
||||||
|
|
@ -82,20 +84,24 @@ Loader::TextRecord Loader::readTextRecord()
|
||||||
if(FILE_CONTAINS_WHITE_SPACES) _file_reader->readByte();
|
if(FILE_CONTAINS_WHITE_SPACES) _file_reader->readByte();
|
||||||
|
|
||||||
// Read length (1 byte, 2 hex digits)
|
// Read length (1 byte, 2 hex digits)
|
||||||
int length = std::stoi(_file_reader->readString(2), nullptr, 16);
|
std::string lengthStr = _file_reader->readString(2);
|
||||||
if(FILE_CONTAINS_WHITE_SPACES) _file_reader->readByte();
|
int length = std::stoi(lengthStr, nullptr, 16);
|
||||||
|
|
||||||
|
// Read the rest of the line (data bytes with spaces)
|
||||||
|
std::string dataLine = _file_reader->readLine();
|
||||||
|
|
||||||
|
// Remove all whitespace from the data line
|
||||||
|
dataLine.erase(std::remove_if(dataLine.begin(), dataLine.end(), ::isspace), dataLine.end());
|
||||||
|
|
||||||
|
// Now use StringReader to parse the hex bytes
|
||||||
|
StringReader stringReader(dataLine);
|
||||||
record.data.resize(length);
|
record.data.resize(length);
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
string byteStr = _file_reader->readLine();
|
|
||||||
// Remove spaces, newlines, and other whitespace characters
|
|
||||||
byteStr.erase(std::remove_if(byteStr.begin(), byteStr.end(), ::isspace), byteStr.end());
|
|
||||||
|
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
std::string byteHex = byteStr.substr(i * 2, 2);
|
std::string byteHex = stringReader.readString(2);
|
||||||
record.data[i] = static_cast<uint8_t>(std::stoi(byteHex, nullptr, 16));
|
record.data[i] = static_cast<uint8_t>(std::stoi(byteHex, nullptr, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,17 @@ string prefix = "Machine error: ";
|
||||||
|
|
||||||
Machine::Machine()
|
Machine::Machine()
|
||||||
{
|
{
|
||||||
|
// Initialize registers and memory to zero
|
||||||
|
A = B = X = L = S = T = PC = SW = 0;
|
||||||
|
F = 0.0;
|
||||||
|
for (int i = 0; i < MEMORY_SIZE; i++) {
|
||||||
|
memory[i] = 0;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < VECTOR_REG_SIZE; i++) {
|
||||||
|
VA[i] = VS[i] = VT[i] = 0;
|
||||||
|
}
|
||||||
|
_stopped = false;
|
||||||
|
|
||||||
devices.resize(NUM_DEVICES);
|
devices.resize(NUM_DEVICES);
|
||||||
// device 0: standard input
|
// device 0: standard input
|
||||||
devices[0] = make_shared<InputDevice>(std::cin);
|
devices[0] = make_shared<InputDevice>(std::cin);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue