fixed bugs

This commit is contained in:
zanostro 2025-12-06 22:55:01 +01:00
parent d3ab78e76c
commit 098766bb65
5 changed files with 64 additions and 15 deletions

View file

@ -1,8 +1,10 @@
#include "loader.h"
#include "file_reader.h"
#include "string_reader.h"
#include "machine.h"
#include "constants.h"
#include <algorithm>
#include <cstdio>
Loader::~Loader()
{
@ -82,20 +84,24 @@ Loader::TextRecord Loader::readTextRecord()
if(FILE_CONTAINS_WHITE_SPACES) _file_reader->readByte();
// Read length (1 byte, 2 hex digits)
int length = std::stoi(_file_reader->readString(2), nullptr, 16);
if(FILE_CONTAINS_WHITE_SPACES) _file_reader->readByte();
std::string lengthStr = _file_reader->readString(2);
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);
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) {
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));
}
return record;
}