From be9d1c329711c96a943fab418002721cf50b0335 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Mon, 9 Dec 2024 18:53:41 +0100 Subject: [PATCH] Fix counting objects --- cpp/devices/tape.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cpp/devices/tape.cpp b/cpp/devices/tape.cpp index 121225c8..193f6b0e 100644 --- a/cpp/devices/tape.cpp +++ b/cpp/devices/tape.cpp @@ -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(scsi_type), length, actual_count)); @@ -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); } } @@ -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; } } @@ -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(meta_data.cls), meta_data.value, reverse ? tape_position : tape_position - META_DATA_SIZE)); @@ -886,6 +882,12 @@ pair 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};