2016-09-18 17:35:54 +00:00
|
|
|
//
|
|
|
|
// MFM.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/09/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#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"
|
2017-09-25 00:07:56 +00:00
|
|
|
#include "../../../../NumberTheory/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-08-11 18:24:50 +00:00
|
|
|
extern const 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-08-11 18:24:50 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<Sector> §ors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
|
2017-11-01 01:32:28 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<const Sector *> §ors, 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.
|
|
|
|
*/
|
2017-08-11 18:24:50 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<Sector> §ors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
|
2017-11-01 01:32:28 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<const Sector *> §ors, size_t sector_gap_length = DefaultSectorGapLength, uint8_t sector_gap_filler_byte = 0x4e);
|
2016-09-18 20:53:21 +00:00
|
|
|
|
2016-11-26 05:39:20 +00:00
|
|
|
class Encoder {
|
|
|
|
public:
|
|
|
|
Encoder(std::vector<uint8_t> &target);
|
|
|
|
virtual void add_byte(uint8_t input) = 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;
|
2016-12-28 23:50:28 +00:00
|
|
|
virtual void output_short(uint16_t value);
|
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:
|
2016-12-28 23:29:37 +00:00
|
|
|
NumberTheory::CRC16 crc_generator_;
|
2016-11-26 05:39:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<uint8_t> &target_;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<Encoder> GetMFMEncoder(std::vector<uint8_t> &target);
|
|
|
|
std::unique_ptr<Encoder> GetFMEncoder(std::vector<uint8_t> &target);
|
|
|
|
|
2016-09-18 20:53:21 +00:00
|
|
|
}
|
2016-09-18 17:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MFM_hpp */
|