1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-05 08:26:28 +00:00

This is probably how Acorn hard disk images look (?)

This commit is contained in:
Thomas Harte
2021-01-31 16:00:52 -05:00
parent 8db289e229
commit f1ba040dd8
3 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
//
// AcornADF.cpp
// Clock Signal
//
// Created by Thomas Harte on 31/01/2021.
// Copyright © 2021 Thomas Harte. All rights reserved.
//
#include "AcornADF.hpp"
using namespace Storage::MassStorage;
AcornADF::AcornADF(const std::string &file_name) : file_(file_name) {
// Only one sanity check: is the file a multiple of 256 bytes in size?
// [TODO: and larger than a floppy disk?]
const auto file_size = file_.stats().st_size;
if(file_size & 255) throw std::exception();
}
size_t AcornADF::get_block_size() {
return 256;
}
size_t AcornADF::get_number_of_blocks() {
return size_t(file_.stats().st_size) / 256;
}
std::vector<uint8_t> AcornADF::get_block(size_t address) {
file_.seek(long(address * 256), SEEK_SET);
return file_.read(256);
}
void AcornADF::set_block(size_t address, const std::vector<uint8_t> &contents) {
file_.seek(long(address * 256), SEEK_SET);
file_.write(contents);
}

View File

@@ -0,0 +1,39 @@
//
// AcornADF.hpp
// Clock Signal
//
// Created by Thomas Harte on 31/01/2021.
// Copyright © 2021 Thomas Harte. All rights reserved.
//
#ifndef AcornADF_hpp
#define AcornADF_hpp
#include "../MassStorageDevice.hpp"
#include "../../FileHolder.hpp"
namespace Storage {
namespace MassStorage {
/*!
Provides a @c MassStorageDevice containing an Acorn ADFS image, which is just a
sector dump of an ADFS volume.
*/
class AcornADF: public MassStorageDevice {
public:
AcornADF(const std::string &file_name);
private:
FileHolder file_;
/* 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 /* AcornADF_hpp */