-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #752 from davidgiven/tartu
Add encoder support for the Tartu format.
- Loading branch information
Showing
13 changed files
with
752 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "lib/globals.h" | ||
#include "lib/decoders/decoders.h" | ||
#include "lib/encoders/encoders.h" | ||
#include "arch/tartu/tartu.h" | ||
#include "lib/crc.h" | ||
#include "lib/fluxmap.h" | ||
#include "lib/sector.h" | ||
#include <string.h> | ||
|
||
class TartuEncoder : public Encoder | ||
{ | ||
public: | ||
TartuEncoder(const EncoderProto& config): | ||
Encoder(config), | ||
_config(config.tartu()) | ||
{ | ||
} | ||
|
||
std::unique_ptr<Fluxmap> encode(std::shared_ptr<const TrackInfo>& trackInfo, | ||
const std::vector<std::shared_ptr<const Sector>>& sectors, | ||
const Image& image) override | ||
{ | ||
_clockRateUs = _config.clock_period_us(); | ||
int bitsPerRevolution = | ||
(_config.target_rotational_period_ms() * 1000.0) / _clockRateUs; | ||
|
||
const auto& sector = *sectors.begin(); | ||
_bits.resize(bitsPerRevolution); | ||
_cursor = 0; | ||
|
||
writeFillerRawBitsUs(_config.gap1_us()); | ||
bool first = true; | ||
for (const auto& sectorData : sectors) | ||
{ | ||
if (!first) | ||
writeFillerRawBitsUs(_config.gap4_us()); | ||
first = false; | ||
writeSector(sectorData); | ||
} | ||
|
||
if (_cursor > _bits.size()) | ||
error("track data overrun"); | ||
writeFillerRawBitsUs(_config.target_rotational_period_ms() * 1000.0); | ||
|
||
std::unique_ptr<Fluxmap> fluxmap(new Fluxmap); | ||
fluxmap->appendBits(_bits, | ||
calculatePhysicalClockPeriod(_clockRateUs * 1e3, | ||
_config.target_rotational_period_ms() * 1e6)); | ||
return fluxmap; | ||
} | ||
|
||
private: | ||
void writeBytes(const Bytes& bytes) | ||
{ | ||
encodeMfm(_bits, _cursor, bytes, _lastBit); | ||
} | ||
|
||
void writeRawBits(uint64_t data, int width) | ||
{ | ||
_cursor += width; | ||
_lastBit = data & 1; | ||
for (int i = 0; i < width; i++) | ||
{ | ||
unsigned pos = _cursor - i - 1; | ||
if (pos < _bits.size()) | ||
_bits[pos] = data & 1; | ||
data >>= 1; | ||
} | ||
} | ||
|
||
void writeFillerRawBitsUs(double us) | ||
{ | ||
unsigned count = (us / _clockRateUs) / 2; | ||
for (int i = 0; i < count; i++) | ||
writeRawBits(0b10, 2); | ||
}; | ||
|
||
void writeSector(const std::shared_ptr<const Sector>& sectorData) | ||
{ | ||
writeRawBits(_config.header_marker(), 64); | ||
{ | ||
Bytes bytes; | ||
ByteWriter bw(bytes); | ||
bw.write_8( | ||
(sectorData->logicalTrack << 1) | sectorData->logicalSide); | ||
bw.write_8(1); | ||
bw.write_8(sectorData->logicalSector); | ||
bw.write_8(~sumBytes(bytes.slice(0, 3))); | ||
writeBytes(bytes); | ||
} | ||
|
||
writeFillerRawBitsUs(_config.gap3_us()); | ||
writeRawBits(_config.data_marker(), 64); | ||
{ | ||
Bytes bytes; | ||
ByteWriter bw(bytes); | ||
bw.append(sectorData->data); | ||
bw.write_8(~sumBytes(bytes.slice(0, sectorData->data.size()))); | ||
writeBytes(bytes); | ||
} | ||
} | ||
|
||
private: | ||
const TartuEncoderProto& _config; | ||
double _clockRateUs; | ||
std::vector<bool> _bits; | ||
unsigned _cursor; | ||
bool _lastBit; | ||
}; | ||
|
||
std::unique_ptr<Encoder> createTartuEncoder(const EncoderProto& config) | ||
{ | ||
return std::unique_ptr<Encoder>(new TartuEncoder(config)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
syntax = "proto2"; | ||
|
||
import "lib/common.proto"; | ||
|
||
message TartuDecoderProto {} | ||
|
||
message TartuEncoderProto { | ||
optional double clock_period_us = 1 | ||
[ default = 2.0, (help) = "clock rate on the real device (for MFM)" ]; | ||
optional double target_rotational_period_ms = 2 | ||
[ default=200, (help) = "rotational period of target disk" ]; | ||
optional double gap1_us = 3 | ||
[ default = 1200, | ||
(help) = "size of gap 1 (the post-index gap)" ]; | ||
optional double gap3_us = 4 | ||
[ default = 150, | ||
(help) = "size of gap 3 (the pre-data gap)" ]; | ||
optional double gap4_us = 5 | ||
[ default = 180, | ||
(help) = "size of gap 4 (the post-data or format gap)" ]; | ||
optional uint64 header_marker = 6 | ||
[ default = 0xaaaaaaaa44895554, | ||
(help) = "64-bit raw bit pattern of header record marker" ]; | ||
optional uint64 data_marker = 7 | ||
[ default = 0xaaaaaaaa44895545, | ||
(help) = "64-bit raw bit pattern of data record marker" ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.