mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Merge pull request #1104 from TomHarte/HDV
Add support for Apple II .HDV files.
This commit is contained in:
commit
2fe6253ca8
@ -59,6 +59,7 @@
|
||||
// Mass Storage Devices (i.e. usually, hard disks)
|
||||
#include "../../Storage/MassStorage/Formats/DAT.hpp"
|
||||
#include "../../Storage/MassStorage/Formats/DSK.hpp"
|
||||
#include "../../Storage/MassStorage/Formats/HDV.hpp"
|
||||
#include "../../Storage/MassStorage/Formats/HFV.hpp"
|
||||
|
||||
// State Snapshots
|
||||
@ -170,6 +171,7 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::FAT12>, TargetPlatform::MSX) // DSK (MSX)
|
||||
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::OricMFMDSK>, TargetPlatform::Oric) // DSK (Oric)
|
||||
Format("g64", result.disks, Disk::DiskImageHolder<Storage::Disk::G64>, TargetPlatform::Commodore) // G64
|
||||
Format("hdv", result.mass_storage_devices, MassStorage::HDV, TargetPlatform::AppleII) // HDV (Apple II, hard disk, single volume image)
|
||||
Format( "hfe",
|
||||
result.disks,
|
||||
Disk::DiskImageHolder<Storage::Disk::HFE>,
|
||||
|
@ -310,6 +310,8 @@
|
||||
4B6AAEAE230E40250078E864 /* Target.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6AAEA8230E40250078E864 /* Target.cpp */; };
|
||||
4B6ED2F0208E2F8A0047B343 /* WOZ.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6ED2EE208E2F8A0047B343 /* WOZ.cpp */; };
|
||||
4B6ED2F1208E2F8A0047B343 /* WOZ.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6ED2EE208E2F8A0047B343 /* WOZ.cpp */; };
|
||||
4B6FD0362923B88F00EC4760 /* HDV.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FD0342923061300EC4760 /* HDV.cpp */; };
|
||||
4B6FD0372923B89000EC4760 /* HDV.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FD0342923061300EC4760 /* HDV.cpp */; };
|
||||
4B7136861F78724F008B8ED9 /* Encoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B7136841F78724F008B8ED9 /* Encoder.cpp */; };
|
||||
4B7136891F78725F008B8ED9 /* Shifter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B7136871F78725F008B8ED9 /* Shifter.cpp */; };
|
||||
4B71368E1F788112008B8ED9 /* Parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B71368C1F788112008B8ED9 /* Parser.cpp */; };
|
||||
@ -1446,6 +1448,8 @@
|
||||
4B6AAEAA230E40250078E864 /* TargetImplementation.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TargetImplementation.hpp; sourceTree = "<group>"; };
|
||||
4B6ED2EE208E2F8A0047B343 /* WOZ.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WOZ.cpp; sourceTree = "<group>"; };
|
||||
4B6ED2EF208E2F8A0047B343 /* WOZ.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = WOZ.hpp; sourceTree = "<group>"; };
|
||||
4B6FD0342923061300EC4760 /* HDV.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HDV.cpp; sourceTree = "<group>"; };
|
||||
4B6FD0352923061300EC4760 /* HDV.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = HDV.hpp; sourceTree = "<group>"; };
|
||||
4B7041271F92C26900735E45 /* JoystickMachine.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = JoystickMachine.hpp; sourceTree = "<group>"; };
|
||||
4B70412A1F92C2A700735E45 /* Joystick.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Joystick.hpp; sourceTree = "<group>"; };
|
||||
4B70EF6A1FFDCDF400A3494E /* ROMSlotHandler.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ROMSlotHandler.hpp; sourceTree = "<group>"; };
|
||||
@ -3207,10 +3211,12 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4BE8EB6425C750B50040BC40 /* DAT.cpp */,
|
||||
4BE8EB6525C750B50040BC40 /* DAT.hpp */,
|
||||
4B96F7CC263E33B10092AEE1 /* DSK.cpp */,
|
||||
4B96F7CD263E33B10092AEE1 /* DSK.hpp */,
|
||||
4B6FD0342923061300EC4760 /* HDV.cpp */,
|
||||
4B74CF802312FA9C00500CE8 /* HFV.cpp */,
|
||||
4BE8EB6525C750B50040BC40 /* DAT.hpp */,
|
||||
4B96F7CD263E33B10092AEE1 /* DSK.hpp */,
|
||||
4B6FD0352923061300EC4760 /* HDV.hpp */,
|
||||
4B74CF7F2312FA9C00500CE8 /* HFV.hpp */,
|
||||
4B96F7CB263E30B00092AEE1 /* RawSectorDump.hpp */,
|
||||
);
|
||||
@ -5723,6 +5729,7 @@
|
||||
4B055A7E1FAE84AA0060FFFF /* main.cpp in Sources */,
|
||||
4B894537201967B4007DE474 /* Z80.cpp in Sources */,
|
||||
4B055A9F1FAE85DA0060FFFF /* HFE.cpp in Sources */,
|
||||
4B6FD0372923B89000EC4760 /* HDV.cpp in Sources */,
|
||||
4BD191F52191180E0042E144 /* ScanTarget.cpp in Sources */,
|
||||
4B055AEC1FAE9BA20060FFFF /* Z80Base.cpp in Sources */,
|
||||
4B0F94FF208C1A1600FE41D9 /* NIB.cpp in Sources */,
|
||||
@ -5907,6 +5914,7 @@
|
||||
4B5FADBA1DE3151600AEC565 /* FileHolder.cpp in Sources */,
|
||||
4B643F3A1D77AD1900D431D6 /* CSStaticAnalyser.mm in Sources */,
|
||||
4B622AE5222E0AD5008B59F2 /* DisplayMetrics.cpp in Sources */,
|
||||
4B6FD0362923B88F00EC4760 /* HDV.cpp in Sources */,
|
||||
4B051CB0267C1CA200CA44E8 /* Keyboard.cpp in Sources */,
|
||||
4B1497881EE4A1DA00CE2596 /* ZX80O81P.cpp in Sources */,
|
||||
4B894520201967B4007DE474 /* StaticAnalyser.cpp in Sources */,
|
||||
|
@ -672,6 +672,28 @@
|
||||
<key>NSDocumentClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).MachineDocument</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>hdv</string>
|
||||
</array>
|
||||
<key>CFBundleTypeIconFile</key>
|
||||
<string>floppy35</string>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>Apple II Hard Disk Image</string>
|
||||
<key>CFBundleTypeOSTypes</key>
|
||||
<array>
|
||||
<string>????</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Default</string>
|
||||
<key>LSTypeIsPackage</key>
|
||||
<false/>
|
||||
<key>NSDocumentClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).MachineDocument</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
|
@ -9,15 +9,13 @@
|
||||
#include "2MG.hpp"
|
||||
|
||||
#include "MacintoshIMG.hpp"
|
||||
#include "../../../MassStorage/Encodings/AppleIIVolume.hpp"
|
||||
#include "../../../MassStorage/Formats/HDV.hpp"
|
||||
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace Storage::Disk;
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO: I've boxed myself into a corner on this stuff by not using factories more generally;
|
||||
// volume to device mappers are not themselves mass storage devices because then their use
|
||||
// can't currently be private to file types and relevant knowledge would need to be pushed up into
|
||||
@ -25,65 +23,6 @@ namespace {
|
||||
//
|
||||
// So, I guess: go factory, pervasively. And probably stop the strict disk/mass storage/tape
|
||||
// distinction, given that clearly some platforms just capture volumes abstractly from media.
|
||||
class MassStorage2MG: public Storage::MassStorage::MassStorageDevice {
|
||||
public:
|
||||
MassStorage2MG(const std::string &file_name, long start, long size):
|
||||
file_(file_name),
|
||||
file_start_(start),
|
||||
image_size_(size)
|
||||
{
|
||||
mapper_.set_drive_type(
|
||||
Storage::MassStorage::Encodings::Apple::DriveType::SCSI,
|
||||
size_t(size / 512)
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
Storage::FileHolder file_;
|
||||
long file_start_, image_size_;
|
||||
Storage::MassStorage::Encodings::AppleII::Mapper mapper_;
|
||||
|
||||
/* MassStorageDevices overrides. */
|
||||
size_t get_block_size() final {
|
||||
return 512;
|
||||
}
|
||||
size_t get_number_of_blocks() final {
|
||||
return mapper_.get_number_of_blocks();
|
||||
}
|
||||
std::vector<uint8_t> get_block(size_t address) final {
|
||||
const auto source_address = mapper_.to_source_address(address);
|
||||
const auto file_offset = offset_for_block(source_address);
|
||||
|
||||
if(source_address >= 0) {
|
||||
file_.seek(file_offset, SEEK_SET);
|
||||
return mapper_.convert_source_block(source_address, file_.read(get_block_size()));
|
||||
} else {
|
||||
return mapper_.convert_source_block(source_address);
|
||||
}
|
||||
}
|
||||
void set_block(size_t address, const std::vector<uint8_t> &data) final {
|
||||
const auto source_address = mapper_.to_source_address(address);
|
||||
const auto file_offset = offset_for_block(source_address);
|
||||
|
||||
if(source_address >= 0 && file_offset >= 0) {
|
||||
file_.seek(file_offset, SEEK_SET);
|
||||
file_.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// @returns -1 if @c address is out of range; the offset into the file at which
|
||||
/// the block for @c address resides otherwise.
|
||||
long offset_for_block(ssize_t address) {
|
||||
if(address < 0) return -1;
|
||||
|
||||
const long offset = 512 * address;
|
||||
if(offset > image_size_ - 512) return -1;
|
||||
|
||||
return file_start_ + offset;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Disk2MG::DiskOrMassStorageDevice Disk2MG::open(const std::string &file_name) {
|
||||
FileHolder file(file_name);
|
||||
@ -145,7 +84,7 @@ Disk2MG::DiskOrMassStorageDevice Disk2MG::open(const std::string &file_name) {
|
||||
// TODO: Apple II-style.
|
||||
|
||||
// Try a hard-disk image. For now this assumes: for an Apple IIe or GS.
|
||||
return new MassStorage2MG(file_name, data_start, data_size);
|
||||
return new MassStorage::HDV(file_name, data_start, data_size);
|
||||
break;
|
||||
case 2:
|
||||
// TODO: NIB data (yuck!).
|
||||
|
63
Storage/MassStorage/Formats/HDV.cpp
Normal file
63
Storage/MassStorage/Formats/HDV.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// HDV.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 14/11/2022.
|
||||
// Copyright © 2022 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "HDV.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Storage::MassStorage;
|
||||
|
||||
HDV::HDV(const std::string &file_name, long start, long size):
|
||||
file_(file_name),
|
||||
file_start_(start),
|
||||
image_size_(std::min(size, long(file_.stats().st_size)))
|
||||
{
|
||||
mapper_.set_drive_type(
|
||||
Storage::MassStorage::Encodings::Apple::DriveType::SCSI,
|
||||
size_t(size / 512)
|
||||
);
|
||||
}
|
||||
|
||||
size_t HDV::get_block_size() {
|
||||
return 512;
|
||||
}
|
||||
|
||||
size_t HDV::get_number_of_blocks() {
|
||||
return mapper_.get_number_of_blocks();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> HDV::get_block(size_t address) {
|
||||
const auto source_address = mapper_.to_source_address(address);
|
||||
const auto file_offset = offset_for_block(source_address);
|
||||
|
||||
if(source_address >= 0) {
|
||||
file_.seek(file_offset, SEEK_SET);
|
||||
return mapper_.convert_source_block(source_address, file_.read(get_block_size()));
|
||||
} else {
|
||||
return mapper_.convert_source_block(source_address);
|
||||
}
|
||||
}
|
||||
|
||||
void HDV::set_block(size_t address, const std::vector<uint8_t> &data) {
|
||||
const auto source_address = mapper_.to_source_address(address);
|
||||
const auto file_offset = offset_for_block(source_address);
|
||||
|
||||
if(source_address >= 0 && file_offset >= 0) {
|
||||
file_.seek(file_offset, SEEK_SET);
|
||||
file_.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
long HDV::offset_for_block(ssize_t address) {
|
||||
if(address < 0) return -1;
|
||||
|
||||
const long offset = 512 * address;
|
||||
if(offset > image_size_ - 512) return -1;
|
||||
|
||||
return file_start_ + offset;
|
||||
}
|
56
Storage/MassStorage/Formats/HDV.hpp
Normal file
56
Storage/MassStorage/Formats/HDV.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// HDV.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 14/11/2022.
|
||||
// Copyright © 2022 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef HDV_hpp
|
||||
#define HDV_hpp
|
||||
|
||||
#include "../MassStorageDevice.hpp"
|
||||
#include "../../FileHolder.hpp"
|
||||
#include "../Encodings/AppleIIVolume.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
namespace Storage {
|
||||
namespace MassStorage {
|
||||
|
||||
/*!
|
||||
Provides a @c MassStorageDevice containing an HDV image, which is a sector dump of
|
||||
the ProDOS volume of an Apple II drive.
|
||||
*/
|
||||
class HDV: public MassStorageDevice {
|
||||
public:
|
||||
/*!
|
||||
Constructs an HDV with the contents of the file named @c file_name within
|
||||
the range given.
|
||||
|
||||
Raises an exception if the file name doesn't appear to identify a valid
|
||||
Apple II mass storage image.
|
||||
*/
|
||||
HDV(const std::string &file_name, long start = 0, long size = std::numeric_limits<long>::max());
|
||||
|
||||
private:
|
||||
FileHolder file_;
|
||||
long file_start_, image_size_;
|
||||
Storage::MassStorage::Encodings::AppleII::Mapper mapper_;
|
||||
|
||||
/// @returns -1 if @c address is out of range; the offset into the file at which
|
||||
/// the block for @c address resides otherwise.
|
||||
long offset_for_block(ssize_t address);
|
||||
|
||||
/* MassStorageDevices overrides. */
|
||||
size_t get_block_size() final;
|
||||
size_t get_number_of_blocks() final;
|
||||
std::vector<uint8_t> get_block(size_t address) final;
|
||||
void set_block(size_t address, const std::vector<uint8_t> &) final;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HDV_hpp */
|
Loading…
Reference in New Issue
Block a user