Skip to content

Commit

Permalink
Fix counting objects
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 9, 2024
1 parent f9d8fe9 commit be9d1c3
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions cpp/devices/tape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,6 @@ SimhMetaData Tape::FindNextObject(object_type type, int32_t requested_count, boo
return meta_data;
}

--requested_count;
++actual_count;

LogTrace(
fmt::format("Found object type {0}, length {1}, spaced over {2} object(s)", static_cast<int>(scsi_type),
length, actual_count));
Expand All @@ -665,7 +662,7 @@ SimhMetaData Tape::FindNextObject(object_type type, int32_t requested_count, boo
}
else {
// End-of-data while spacing over something else
RaiseEndOfData(type, requested_count + 1);
RaiseEndOfData(type, requested_count);
}
}

Expand All @@ -676,10 +673,15 @@ SimhMetaData Tape::FindNextObject(object_type type, int32_t requested_count, boo

if (scsi_type == object_type::filemark && type == object_type::block) {
// Terminate while spacing over blocks and a filemark is found
RaiseFilemark(requested_count + 1, read);
RaiseFilemark(requested_count, read);
}

if (scsi_type == type) {
--requested_count;
++actual_count;
}

if (scsi_type == type && requested_count <= 0) {
if (requested_count <= 0) {
return meta_data;
}
}
Expand Down Expand Up @@ -778,12 +780,6 @@ bool Tape::ReadNextMetaData(SimhMetaData &meta_data, bool reverse)
tape_position += META_DATA_SIZE;
}

// Update object location for valid data records and tape marks
if (IsRecord(meta_data) || (meta_data.cls == simh_class::bad_data_record && !meta_data.value)
|| (meta_data.cls == simh_class::tape_mark_good_data_record && !meta_data.value)) {
object_location += reverse ? -1 : 1;
}

LogTrace(fmt::format("Read SIMH meta data with class {0:1X}, value ${1:07x} at position {2}",
static_cast<int>(meta_data.cls), meta_data.value, reverse ? tape_position : tape_position - META_DATA_SIZE));

Expand Down Expand Up @@ -886,6 +882,12 @@ pair<Tape::object_type, int> Tape::ReadSimhMetaData(SimhMetaData &meta_data, int
RaiseBeginningOfPartition(count);
}

// Update object location for data records and tape marks
if (IsRecord(meta_data) || (meta_data.cls == simh_class::bad_data_record && !meta_data.value)
|| (meta_data.cls == simh_class::tape_mark_good_data_record && !meta_data.value)) {
object_location += reverse ? -1 : 1;
}

switch (meta_data.cls) {
case simh_class::tape_mark_good_data_record:
return {meta_data.value ? object_type::block : object_type::filemark, meta_data.value};
Expand Down

0 comments on commit be9d1c3

Please sign in to comment.