Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 8, 2024
1 parent 8e964f0 commit 87a5c14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions cpp/devices/tape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ void Tape::ResetPosition()
object_location = 0;
}

void Tape::ReadNextMetaData(SimhMetaData &meta_data, int64_t count, bool reverse)
bool Tape::ReadNextMetaData(SimhMetaData &meta_data, bool reverse)
{
if (reverse) {
// Position before trailing length or marker
tape_position -= META_DATA_SIZE;

if (tape_position < 0) {
RaiseBeginningOfPartition(count);
return false;
}

file.seekg(tape_position);
Expand All @@ -757,6 +757,8 @@ void Tape::ReadNextMetaData(SimhMetaData &meta_data, int64_t count, bool reverse

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));

return true;
}

uint32_t Tape::GetByteCount()
Expand Down Expand Up @@ -833,7 +835,9 @@ vector<PbStatistics> Tape::GetStatistics() const
pair<Tape::object_type, int> Tape::ReadSimhMetaData(SimhMetaData &meta_data, int64_t count, bool reverse)
{
while (true) {
ReadNextMetaData(meta_data, count, reverse);
if (!ReadNextMetaData(meta_data, reverse)) {
RaiseBeginningOfPartition(reverse ? -count : count);
}

switch (meta_data.cls) {
case simh_class::tape_mark_good_data_record:
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/tape.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Tape : public StorageDevice, public ScsiStreamCommands

void WriteMetaData(Tape::object_type, uint32_t = 0);
SimhMetaData FindNextObject(Tape::object_type, int64_t, bool);
void ReadNextMetaData(SimhMetaData&, int64_t, bool);
bool ReadNextMetaData(SimhMetaData&, bool);

[[noreturn]] void RaiseBeginningOfPartition(int64_t);
[[noreturn]] void RaiseEndOfPartition(int64_t);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/tape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ TEST(TapeTest, Space6_simh)
Dispatch(*tape, scsi_command::request_sense);
EXPECT_EQ(0b01000000, controller->GetBuffer()[2]) << "EOM must be set";
EXPECT_EQ(0x80, controller->GetBuffer()[0] & 0x80) << "VALID must be set";
EXPECT_EQ(1U, GetInt32(controller->GetBuffer(), 3));
EXPECT_EQ(0xffffffffU, GetInt32(controller->GetBuffer(), 3));


// Write 6 data records (bad and good) and different markers, 1 filemark
Expand Down

0 comments on commit 87a5c14

Please sign in to comment.