From b3b2e18c4bc2c8b12eca0c42ae00e96a492d1dc9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 12 Jan 2020 22:23:34 -0500 Subject: [PATCH] Ensures head and track counts are reported accurately. --- Storage/Disk/DiskImage/Formats/STX.cpp | 14 ++++++++++---- Storage/Disk/DiskImage/Formats/STX.hpp | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/STX.cpp b/Storage/Disk/DiskImage/Formats/STX.cpp index 5a6cc10bc..38c499076 100644 --- a/Storage/Disk/DiskImage/Formats/STX.cpp +++ b/Storage/Disk/DiskImage/Formats/STX.cpp @@ -280,8 +280,8 @@ STX::STX(const std::string &file_name) : file_(file_name) { // Skip: tool used, 2 reserved bytes. file_.seek(4, SEEK_CUR); - // Grab the track count and test for a new-style encoding, and skip a reserved area. - track_count_ = file_.get8(); + // Skip the track count, test for a new-style encoding, skip a reserved area. + file_.seek(1, SEEK_CUR); is_new_format_ = file_.get8() == 2; file_.seek(4, SEEK_CUR); @@ -301,6 +301,8 @@ STX::STX(const std::string &file_name) : file_(file_name) { // 12 2 Total number of bytes on track. // 14 1 Track number (b7 = side, b0-b6 = track). // 15 1 Track type. + track_count_ = 0; + head_count_ = 1; while(true) { const long offset = file_.tell(); const uint32_t size = file_.get32le(); @@ -312,17 +314,21 @@ STX::STX(const std::string &file_name) : file_(file_name) { const uint8_t track_position = file_.get8(); offset_by_track_[track_position] = offset; + // Update the maximum surface dimensions. + track_count_ = std::max(track_count_, track_position & 0x7f); + head_count_ = std::max(head_count_, ((track_position & 0x80) >> 6)); + // Seek next track start. file_.seek(offset + size, SEEK_SET); } } HeadPosition STX::get_maximum_head_position() { - return HeadPosition(80); + return HeadPosition(track_count_ + 1); // Same issue as MSA; must fix! } int STX::get_head_count() { - return 2; + return head_count_; } std::shared_ptr<::Storage::Disk::Track> STX::get_track_at_position(::Storage::Disk::Track::Address address) { diff --git a/Storage/Disk/DiskImage/Formats/STX.hpp b/Storage/Disk/DiskImage/Formats/STX.hpp index dc21028dc..c7aba86d8 100644 --- a/Storage/Disk/DiskImage/Formats/STX.hpp +++ b/Storage/Disk/DiskImage/Formats/STX.hpp @@ -38,6 +38,8 @@ class STX: public DiskImage { FileHolder file_; int track_count_; + int head_count_; + bool is_new_format_; long offset_by_track_[256]; };