mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-19 02:22:39 +00:00
52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
//
|
|
// MOOF.cpp
|
|
// Clock Signal
|
|
//
|
|
// Created by Thomas Harte on 15/02/2026.
|
|
// Copyright © 2026 Thomas Harte. All rights reserved.
|
|
//
|
|
|
|
#include "MOOF.hpp"
|
|
|
|
#include "Numeric/CRC.hpp"
|
|
|
|
using namespace Storage::Disk;
|
|
|
|
namespace {
|
|
constexpr uint32_t chunk(const char *str) {
|
|
return uint32_t(str[0] | (str[1] << 8) | (str[2] << 16) | (str[3] << 24));
|
|
}
|
|
}
|
|
|
|
MOOF::MOOF(const std::string &file_name) :
|
|
file_(file_name) {
|
|
|
|
static constexpr char signature[] = {
|
|
'M', 'O', 'O', 'F',
|
|
char(0xff), 0x0a, 0x0d, 0x0a
|
|
};
|
|
if(!file_.check_signature<SignatureType::Binary>(signature)) {
|
|
throw Error::InvalidFormat;
|
|
}
|
|
|
|
// Test the file's CRC32.
|
|
const auto crc = file_.get_le<uint32_t>();
|
|
post_crc_contents_ = file_.read(size_t(file_.stats().st_size - 12));
|
|
const uint32_t computed_crc = CRC::CRC32::crc_of(post_crc_contents_);
|
|
if(crc != computed_crc) {
|
|
throw Error::InvalidFormat;
|
|
}
|
|
}
|
|
|
|
HeadPosition MOOF::maximum_head_position() const {
|
|
return HeadPosition(1);
|
|
}
|
|
|
|
std::unique_ptr<Track> MOOF::track_at_position(Track::Address) const {
|
|
return nullptr;
|
|
}
|
|
|
|
bool MOOF::represents(const std::string &name) const {
|
|
return name == file_.name();
|
|
}
|