mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-18 16:30:29 +00:00
Adds support for raw sector dumps.
This commit is contained in:
parent
506276a2bd
commit
9730800b6a
@ -22,6 +22,14 @@ using namespace Storage::Disk;
|
||||
DiskCopy42::DiskCopy42(const std::string &file_name) :
|
||||
file_(file_name) {
|
||||
|
||||
// Test 1: is this a raw secctor dump? If so it'll start with
|
||||
// the magic word 0x4C4B6000 (big endian) and be exactly
|
||||
// 819,200 bytes long if double sided, or 409,600 bytes if
|
||||
// single sided.
|
||||
//
|
||||
// Luckily, 0x4c is an invalid string length for the proper
|
||||
// DiskCopy 4.2 format, so there's no ambiguity here.
|
||||
|
||||
// File format starts with 64 bytes dedicated to the disk name;
|
||||
// this is a Pascal-style string though there is apparently a
|
||||
// bug in one version of Disk Copy that can cause the length to
|
||||
@ -29,6 +37,25 @@ DiskCopy42::DiskCopy42(const std::string &file_name) :
|
||||
//
|
||||
// Validate the length, then skip the rest of the string.
|
||||
const auto name_length = file_.get8();
|
||||
if(name_length == 0x4c) {
|
||||
if(file_.stats().st_size != 819200 && file_.stats().st_size != 409600)
|
||||
throw Error::InvalidFormat;
|
||||
|
||||
uint32_t magic_word = file_.get24be();
|
||||
if(magic_word != 0x4b6000)
|
||||
throw Error::InvalidFormat;
|
||||
|
||||
file_.seek(0, SEEK_SET);
|
||||
if(file_.stats().st_size == 819200) {
|
||||
encoding_ = Encoding::GCR800;
|
||||
format_ = 0x22;
|
||||
data_ = file_.read(819200);
|
||||
} else {
|
||||
encoding_ = Encoding::GCR400;
|
||||
format_ = 0x2;
|
||||
data_ = file_.read(409600);
|
||||
}
|
||||
} else {
|
||||
if(name_length > 64)
|
||||
throw Error::InvalidFormat;
|
||||
|
||||
@ -74,6 +101,7 @@ DiskCopy42::DiskCopy42(const std::string &file_name) :
|
||||
|
||||
if(computed_tag_checksum != tag_checksum || computed_data_checksum != data_checksum)
|
||||
throw Error::InvalidFormat;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DiskCopy42::checksum(const std::vector<uint8_t> &data, size_t bytes_to_skip) {
|
||||
@ -130,7 +158,7 @@ std::shared_ptr<::Storage::Disk::Track> DiskCopy42::get_track_at_position(::Stor
|
||||
if(start_sector*512 >= data_.size()) return nullptr;
|
||||
|
||||
uint8_t *sector = &data_[512 * start_sector];
|
||||
uint8_t *tags = tags_.size() ? nullptr : &tags_[12 * start_sector];
|
||||
uint8_t *tags = tags_.size() ? &tags_[12 * start_sector] : nullptr;
|
||||
|
||||
Storage::Disk::PCMSegment segment;
|
||||
segment += Encodings::AppleGCR::six_and_two_sync(24);
|
||||
|
Loading…
x
Reference in New Issue
Block a user