2016-09-18 17:35:54 +00:00
|
|
|
//
|
|
|
|
// MFM.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-18 17:35:54 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Storage_Disk_Encodings_MFM_hpp
|
|
|
|
#define Storage_Disk_Encodings_MFM_hpp
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-11-10 03:04:49 +00:00
|
|
|
#include <memory>
|
2016-09-18 20:53:21 +00:00
|
|
|
#include <vector>
|
2017-11-10 03:04:49 +00:00
|
|
|
|
2017-09-25 00:31:19 +00:00
|
|
|
#include "Sector.hpp"
|
2017-09-25 01:40:43 +00:00
|
|
|
#include "../../Track/Track.hpp"
|
2020-01-20 04:14:35 +00:00
|
|
|
#include "../../../../Numeric/CRC.hpp"
|
2016-09-18 17:35:54 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Encodings {
|
2016-09-18 20:53:21 +00:00
|
|
|
namespace MFM {
|
2016-09-18 17:35:54 +00:00
|
|
|
|
2017-11-11 20:28:40 +00:00
|
|
|
extern const std::size_t DefaultSectorGapLength;
|
2017-08-11 18:27:07 +00:00
|
|
|
/*!
|
|
|
|
Converts a vector of sectors into a properly-encoded MFM track.
|
|
|
|
|
|
|
|
@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.
|
|
|
|
*/
|
2017-11-11 20:28:40 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<Sector> §ors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
|
|
|
|
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<const Sector *> §ors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
|
2017-08-11 18:27:07 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Converts a vector of sectors into a properly-encoded FM track.
|
|
|
|
|
|
|
|
@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.
|
|
|
|
*/
|
2020-05-30 23:31:17 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<Sector> §ors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0xff);
|
|
|
|
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<const Sector *> §ors, std::size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0xff);
|
2016-09-18 20:53:21 +00:00
|
|
|
|
2016-11-26 05:39:20 +00:00
|
|
|
class Encoder {
|
|
|
|
public:
|
2020-01-20 02:08:15 +00:00
|
|
|
Encoder(std::vector<bool> &target, std::vector<bool> *fuzzy_target);
|
2019-01-14 01:37:50 +00:00
|
|
|
virtual ~Encoder() {}
|
2020-01-20 02:08:15 +00:00
|
|
|
virtual void reset_target(std::vector<bool> &target, std::vector<bool> *fuzzy_target = nullptr);
|
2020-01-19 17:11:56 +00:00
|
|
|
|
2020-01-20 02:08:15 +00:00
|
|
|
virtual void add_byte(uint8_t input, uint8_t fuzzy_mask = 0) = 0;
|
2016-11-26 05:39:20 +00:00
|
|
|
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;
|
2020-01-20 02:20:21 +00:00
|
|
|
virtual void output_short(uint16_t value, uint16_t fuzzy_mask = 0);
|
2017-08-11 18:24:50 +00:00
|
|
|
|
|
|
|
/// 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);
|
2016-11-26 05:39:20 +00:00
|
|
|
|
|
|
|
protected:
|
2018-05-24 02:21:57 +00:00
|
|
|
CRC::CCITT crc_generator_;
|
2016-11-26 05:39:20 +00:00
|
|
|
|
|
|
|
private:
|
2020-01-19 17:11:56 +00:00
|
|
|
std::vector<bool> *target_ = nullptr;
|
2020-01-20 02:08:15 +00:00
|
|
|
std::vector<bool> *fuzzy_target_ = nullptr;
|
2016-11-26 05:39:20 +00:00
|
|
|
};
|
|
|
|
|
2020-01-20 02:08:15 +00:00
|
|
|
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);
|
2016-11-26 05:39:20 +00:00
|
|
|
|
2016-09-18 20:53:21 +00:00
|
|
|
}
|
2016-09-18 17:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MFM_hpp */
|