| 10 | #include "lib/encoders/encoders.pb.h" |
| 11 | |
| 12 | class AgatEncoder : public Encoder |
| 13 | { |
| 14 | public: |
| 15 | AgatEncoder(const EncoderProto& config): |
| 16 | Encoder(config), |
| 17 | _config(config.agat()) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | private: |
| 22 | void writeRawBits(uint64_t data, int width) |
| 23 | { |
| 24 | _cursor += width; |
| 25 | _lastBit = data & 1; |
| 26 | for (int i = 0; i < width; i++) |
| 27 | { |
| 28 | unsigned pos = _cursor - i - 1; |
| 29 | if (pos < _bits.size()) |
| 30 | _bits[pos] = data & 1; |
| 31 | data >>= 1; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void writeBytes(const Bytes& bytes) |
| 36 | { |
| 37 | encodeMfm(_bits, _cursor, bytes, _lastBit); |
| 38 | } |
| 39 | |
| 40 | void writeByte(uint8_t byte) |
| 41 | { |
| 42 | Bytes b; |
| 43 | b.writer().write_8(byte); |
| 44 | writeBytes(b); |
| 45 | } |
| 46 | |
| 47 | void writeFillerRawBytes(int count, uint16_t byte) |
| 48 | { |
| 49 | for (int i = 0; i < count; i++) |
| 50 | writeRawBits(byte, 16); |
| 51 | }; |
| 52 | |
| 53 | void writeFillerBytes(int count, uint8_t byte) |
| 54 | { |
| 55 | Bytes b{byte}; |
| 56 | for (int i = 0; i < count; i++) |
| 57 | writeBytes(b); |
| 58 | }; |
| 59 | |
| 60 | public: |
| 61 | std::unique_ptr<Fluxmap> encode(const LogicalTrackLayout& ltl, |
| 62 | const std::vector<std::shared_ptr<const Sector>>& sectors, |
| 63 | const Image& image) override |
| 64 | { |
| 65 | double clockRateUs = _config.target_clock_period_us() / 2.0; |
| 66 | int bitsPerRevolution = |
| 67 | (_config.target_rotational_period_ms() * 1000.0) / clockRateUs; |
| 68 | _bits.resize(bitsPerRevolution); |
| 69 | _cursor = 0; |
nothing calls this directly
no outgoing calls
no test coverage detected