1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Create a specific container for HDV files.

This commit is contained in:
Thomas Harte 2022-11-15 13:18:54 -05:00
parent c8a82933bc
commit 9b235a8f64
3 changed files with 129 additions and 2 deletions

View File

@ -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 */,

View 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;
}

View 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 */