2016-09-18 13:35:54 -04:00
|
|
|
//
|
|
|
|
// MFM.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/09/2016.
|
2018-05-13 15:19:52 -04:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-18 13:35:54 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Storage_Disk_Encodings_MFM_hpp
|
|
|
|
#define Storage_Disk_Encodings_MFM_hpp
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-11-09 22:04:49 -05:00
|
|
|
#include <memory>
|
2016-09-18 16:53:21 -04:00
|
|
|
#include <vector>
|
2017-11-09 22:04:49 -05:00
|
|
|
|
2017-09-24 20:31:19 -04:00
|
|
|
#include "Sector.hpp"
|
2017-09-24 21:40:43 -04:00
|
|
|
#include "../../Track/Track.hpp"
|
2017-09-24 20:07:56 -04:00
|
|
|
#include "../../../../NumberTheory/CRC.hpp"
|
2016-09-18 13:35:54 -04:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Encodings {
|
2016-09-18 16:53:21 -04:00
|
|
|
namespace MFM {
|
2016-09-18 13:35:54 -04:00
|
|
|
|
2017-11-11 15:28:40 -05:00
|
|
|
extern const std::size_t DefaultSectorGapLength;
|
2017-08-11 14:27:07 -04: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 15:28:40 -05: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 14:27:07 -04: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-11-11 15:28:40 -05: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 = 0x4e);
|
|
|
|
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 = 0x4e);
|
2016-09-18 16:53:21 -04:00
|
|
|
|
2016-11-26 13:39:20 +08:00
|
|
|
class Encoder {
|
|
|
|
public:
|
2018-07-01 12:05:41 -04:00
|
|
|
Encoder(std::vector<bool> &target);
|
2019-01-13 20:37:50 -05:00
|
|
|
virtual ~Encoder() {}
|
2016-11-26 13:39:20 +08:00
|
|
|
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 18:50:28 -05:00
|
|
|
virtual void output_short(uint16_t value);
|
2017-08-11 14:24:50 -04: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 13:39:20 +08:00
|
|
|
|
|
|
|
protected:
|
2018-05-23 22:21:57 -04:00
|
|
|
CRC::CCITT crc_generator_;
|
2016-11-26 13:39:20 +08:00
|
|
|
|
|
|
|
private:
|
2018-07-01 12:05:41 -04:00
|
|
|
std::vector<bool> &target_;
|
2016-11-26 13:39:20 +08:00
|
|
|
};
|
|
|
|
|
2018-07-01 12:05:41 -04:00
|
|
|
std::unique_ptr<Encoder> GetMFMEncoder(std::vector<bool> &target);
|
|
|
|
std::unique_ptr<Encoder> GetFMEncoder(std::vector<bool> &target);
|
2016-11-26 13:39:20 +08:00
|
|
|
|
2016-09-18 16:53:21 -04:00
|
|
|
}
|
2016-09-18 13:35:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MFM_hpp */
|