From 0bd31039497db49d7435976c78b0494a314a1955 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 24 Nov 2020 18:19:34 -0500 Subject: [PATCH] Wires in the most common IIgs style of 2MG. --- Storage/Disk/DiskImage/Formats/2MG.cpp | 11 ++++++--- .../Disk/DiskImage/Formats/MacintoshIMG.cpp | 24 ++++++++++++------- .../Disk/DiskImage/Formats/MacintoshIMG.hpp | 8 +++++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/2MG.cpp b/Storage/Disk/DiskImage/Formats/2MG.cpp index 7b85c9e95..a2fd936b0 100644 --- a/Storage/Disk/DiskImage/Formats/2MG.cpp +++ b/Storage/Disk/DiskImage/Formats/2MG.cpp @@ -8,6 +8,8 @@ #include "2MG.hpp" +#include "MacintoshIMG.hpp" + using namespace Storage::Disk; DiskImageHolderBase *Disk2MG::open(const std::string &file_name) { @@ -56,7 +58,12 @@ DiskImageHolderBase *Disk2MG::open(const std::string &file_name) { // TODO: DOS 3.3 sector order. break; case 1: - // TODO: ProDOS sector order. + // ProDOS order, which could still mean Macintosh-style or Apple II-style. Try them both. + try { + return new DiskImageHolder(file_name, MacintoshIMG::FixedType::GCR, data_start, data_size); + } catch(...) {} + + // TODO: Apple II-style. break; case 2: // TODO: NIB data (yuck!). @@ -67,8 +74,6 @@ DiskImageHolderBase *Disk2MG::open(const std::string &file_name) { // a proper holder? Probably more valid than having each actual disk class do // its own range logic? (void)flags; - (void)data_start; - (void)data_size; throw Error::InvalidFormat; return nullptr; diff --git a/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp b/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp index 5fc7f5006..074ac94f5 100644 --- a/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp +++ b/Storage/Disk/DiskImage/Formats/MacintoshIMG.cpp @@ -23,13 +23,15 @@ using namespace Storage::Disk; -MacintoshIMG::MacintoshIMG(const std::string &file_name, FixedType type) : +MacintoshIMG::MacintoshIMG(const std::string &file_name, FixedType type, size_t offset, off_t length) : file_(file_name) { switch(type) { case FixedType::GCR: - construct_raw_gcr(); + construct_raw_gcr(offset, length); break; + default: + throw Error::InvalidFormat; } } @@ -49,7 +51,7 @@ MacintoshIMG::MacintoshIMG(const std::string &file_name) : if(!((name_length == 0x4c && magic_word == 0x4b) || (name_length == 0x00 && magic_word == 0x00))) throw Error::InvalidFormat; - construct_raw_gcr(); + construct_raw_gcr(0, -1); } else { // DiskCopy 4.2 it is then: // @@ -120,13 +122,17 @@ MacintoshIMG::MacintoshIMG(const std::string &file_name) : } } -void MacintoshIMG::construct_raw_gcr() { +void MacintoshIMG::construct_raw_gcr(size_t offset, off_t size) { is_diskCopy_file_ = false; - if(file_.stats().st_size != 819200 && file_.stats().st_size != 409600) + if(size == -1) { + size = file_.stats().st_size; + } + if(size != 819200 && size != 409600) throw Error::InvalidFormat; - file_.seek(0, SEEK_SET); - if(file_.stats().st_size == 819200) { + raw_offset_ = long(offset); + file_.seek(raw_offset_, SEEK_SET); + if(size == 819200) { encoding_ = Encoding::GCR800; format_ = 0x22; data_ = file_.read(819200); @@ -300,8 +306,8 @@ void MacintoshIMG::set_tracks(const std::map &, size_t bytes_to_skip = 0); - void construct_raw_gcr(); + void construct_raw_gcr(size_t offset, off_t length); + long raw_offset_ = 0; }; }