mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-04 14:30:19 +00:00
Wires in the most common IIgs style of 2MG.
This commit is contained in:
parent
9a819d6ca0
commit
0bd3103949
@ -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<Storage::Disk::MacintoshIMG>(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;
|
||||
|
@ -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<Track::Address, std::shared_ptr<Tra
|
||||
std::lock_guard lock_guard(file_.get_file_access_mutex());
|
||||
|
||||
if(!is_diskCopy_file_) {
|
||||
// Just dump out the new sectors. Grossly lazy, possibly worth improving.
|
||||
file_.seek(0, SEEK_SET);
|
||||
// Just dump out the entire disk. Grossly lazy, possibly worth improving.
|
||||
file_.seek(raw_offset_, SEEK_SET);
|
||||
file_.write(data_);
|
||||
} else {
|
||||
// Write out the sectors, and possibly the tags, and update checksums.
|
||||
|
@ -38,8 +38,11 @@ class MacintoshIMG: public DiskImage {
|
||||
Constructs a @c MacintoshIMG without attempting to autodetect whether this is a raw
|
||||
image or a Disk Copy 4.2 image; if GCR is specified and the file size checks out then
|
||||
it is accepted as a GCR image.
|
||||
|
||||
If @c offset and @c length are specified and non-zero, only that portion of the file
|
||||
will be modified.
|
||||
*/
|
||||
MacintoshIMG(const std::string &file_name, FixedType type);
|
||||
MacintoshIMG(const std::string &file_name, FixedType type, size_t offset = 0, off_t length = -1);
|
||||
|
||||
// implemented to satisfy @c Disk
|
||||
HeadPosition get_maximum_head_position() final;
|
||||
@ -66,7 +69,8 @@ class MacintoshIMG: public DiskImage {
|
||||
std::mutex buffer_mutex_;
|
||||
|
||||
uint32_t checksum(const std::vector<uint8_t> &, size_t bytes_to_skip = 0);
|
||||
void construct_raw_gcr();
|
||||
void construct_raw_gcr(size_t offset, off_t length);
|
||||
long raw_offset_ = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user