halt j halt

This commit is contained in:
aljazbrodar. 2025-12-07 14:45:47 +01:00
parent bfa4a8cd72
commit 12421d0e5d
23 changed files with 270 additions and 173 deletions

View file

@ -11,13 +11,12 @@ int Loader::readByte(std::istream &in) {
std::string byte;
byte += c1;
byte += c2;
cout << "test: " << byte << " c1: " << c1 << " c2: " << c2 << endl;
return std::stoi(byte, nullptr, 16);
}
int Loader::readWord(std::istream &in) {
int result = 0;
for (int i = 0; i < 6; i++) {
for (int i = 0; i < 3; i++) {
int byte = readByte(in);
if (byte < 0) return -1;
result = (result << 8) | byte;
@ -35,12 +34,22 @@ std::string Loader::readString(std::istream &in, int len) {
return result;
}
void skipNewline(std::istream& stream) {
if (stream.peek() == '\r') {
stream.get(); // odstrani \r
}
if (stream.peek() == '\n') {
stream.get(); // odstrani \n
}
}
bool Loader::loadSection(Machine& machine, std::istream& stream) {
if (stream.get() != 'H') return false;
cout << readString(stream, 6)<< endl; // ime programa ignoriramo
readString(stream, 6); // ime programa ignoriramo
int start = readWord(stream);
int length = readWord(stream);
if (stream.peek() == '\r' || stream.peek() == '\n') stream.get();
skipNewline(stream);
// Preberi text zapise
int ch = stream.get();
while (ch == 'T') {
@ -51,14 +60,13 @@ bool Loader::loadSection(Machine& machine, std::istream& stream) {
int val = readByte(stream);
machine.writeByte(loc++, static_cast<unsigned char>(val));
}
if (stream.peek() == '\r' ||stream.peek() == '\n') stream.get();
skipNewline(stream);
ch = stream.get();
}
// End zapis
if (ch != 'E') return false;
machine.setPC(readWord(stream));
return true;
}