1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00
CLK/Storage/Disk/Encodings/MFM/Encoder.hpp

81 lines
2.5 KiB
C++
Raw Normal View History

//
// MFM.hpp
// Clock Signal
//
// Created by Thomas Harte on 18/09/2016.
// Copyright 2016 Thomas Harte. All rights reserved.
//
#pragma once
#include <cstdint>
#include <memory>
2023-12-11 03:17:23 +00:00
#include <optional>
#include <vector>
2023-12-11 03:17:23 +00:00
#include "Constants.hpp"
#include "Sector.hpp"
#include "../../Track/Track.hpp"
2020-01-20 04:14:35 +00:00
#include "../../../../Numeric/CRC.hpp"
2023-05-10 21:02:18 +00:00
namespace Storage::Encodings::MFM {
2017-08-11 18:27:07 +00:00
/*!
2023-12-11 03:17:23 +00:00
Converts a vector of sectors into a properly-encoded FM or MFM track.
2017-08-11 18:27:07 +00:00
@param sectors The sectors to write.
@param sector_gap_length If specified, sets the distance in whole bytes between each ID and its data.
@param sector_gap_filler_byte If specified, sets the value (unencoded) that is used to populate the gap between each ID and its data.
*/
2023-12-11 03:17:23 +00:00
std::shared_ptr<Storage::Disk::Track> TrackWithSectors(
Density density,
const std::vector<Sector> &sectors,
std::optional<std::size_t> sector_gap_length = std::nullopt,
std::optional<uint8_t> sector_gap_filler_byte = std::nullopt);
std::shared_ptr<Storage::Disk::Track> TrackWithSectors(
Density density,
const std::vector<const Sector *> &sectors,
std::optional<std::size_t> sector_gap_length = std::nullopt,
std::optional<uint8_t> sector_gap_filler_byte = std::nullopt);
class Encoder {
public:
Encoder(std::vector<bool> &target, std::vector<bool> *fuzzy_target);
2024-02-17 02:47:23 +00:00
virtual ~Encoder() = default;
virtual void reset_target(std::vector<bool> &target, std::vector<bool> *fuzzy_target = nullptr);
virtual void add_byte(uint8_t input, uint8_t fuzzy_mask = 0) = 0;
virtual void add_index_address_mark() = 0;
virtual void add_ID_address_mark() = 0;
virtual void add_data_address_mark() = 0;
virtual void add_deleted_data_address_mark() = 0;
virtual void output_short(uint16_t value, uint16_t fuzzy_mask = 0);
template <typename IteratorT> void add_bytes(IteratorT begin, IteratorT end) {
while(begin != end) {
add_byte(*begin);
++begin;
}
}
template <typename ContainerT> void add_bytes(const ContainerT &container) {
write(std::begin(container), std::end(container));
}
/// Outputs the CRC for all data since the last address mask; if @c incorrectly is @c true then outputs an incorrect CRC.
void add_crc(bool incorrectly);
protected:
CRC::CCITT crc_generator_;
private:
std::vector<bool> *target_ = nullptr;
std::vector<bool> *fuzzy_target_ = nullptr;
};
std::unique_ptr<Encoder> GetMFMEncoder(std::vector<bool> &target, std::vector<bool> *fuzzy_target = nullptr);
std::unique_ptr<Encoder> GetFMEncoder(std::vector<bool> &target, std::vector<bool> *fuzzy_target = nullptr);
}