diff --git a/arch/smaky/decoder.cc b/arch/smaky/decoder.cc index 1005993d..5a125b44 100644 --- a/arch/smaky/decoder.cc +++ b/arch/smaky/decoder.cc @@ -12,141 +12,144 @@ #include #include -static const FluxPattern SECTOR_PATTERN(20, 0x92aaa); +static const FluxPattern SECTOR_PATTERN(28, 0x4892aaa); class SmakyDecoder : public Decoder { public: - SmakyDecoder(const DecoderProto& config): - Decoder(config), - _config(config.smaky()) - {} + SmakyDecoder(const DecoderProto& config): + Decoder(config), + _config(config.smaky()) + { + } private: - void adjustForIndex(const Fluxmap::Position& previous, const Fluxmap::Position& now) - { - if ((now.ns() - previous.ns()) < 8e6) - { - seekToIndexMark(); - auto next = tell(); - if ((next.ns() - now.ns()) < 8e6) - { - /* We have seen two short gaps in a row, so sector 0 - * starts here. */ - } - else - { - /* We have seen one short gap and one long gap. This - * means the index mark must be at the beginning of - * the long gap. */ + void adjustForIndex( + const Fluxmap::Position& previous, const Fluxmap::Position& now) + { + if ((now.ns() - previous.ns()) < 8e6) + { + seekToIndexMark(); + auto next = tell(); + if ((next.ns() - now.ns()) < 8e6) + { + /* We have seen two short gaps in a row, so sector 0 + * starts here. */ + } + else + { + /* We have seen one short gap and one long gap. This + * means the index mark must be at the beginning of + * the long gap. */ - seek(now); - } + seek(now); + } - _sectorId = 0; - } - } + _sectorId = 0; + } + } public: - void beginTrack() override - { - /* Find the start-of-track index marks, which will be an interval - * of about 6ms. */ + void beginTrack() override + { + /* Find the start-of-track index marks, which will be an interval + * of about 6ms. */ - seekToIndexMark(); - _sectorId = -1; - while (_sectorId == -1) - { - auto previous = tell(); - seekToIndexMark(); - auto now = tell(); - if (eof()) - return; + seekToIndexMark(); + _sectorId = -1; + while (_sectorId == -1) + { + auto previous = tell(); + seekToIndexMark(); + auto now = tell(); + if (eof()) + return; - adjustForIndex(previous, now); - } + adjustForIndex(previous, now); + } - /* Now we know where to start counting, start finding sectors. */ + /* Now we know where to start counting, start finding sectors. */ - _sectorId = 0; - _sectorStarts.clear(); - for (;;) - { - auto now = tell(); - if (eof()) - break; + _sectorId = 0; + _sectorStarts.clear(); + for (;;) + { + auto now = tell(); + if (eof()) + break; - if (_sectorId < 16) - _sectorStarts.push_back(std::make_pair(_sectorId, now)); - _sectorId++; + if (_sectorId < 16) + _sectorStarts.push_back(std::make_pair(_sectorId, now)); + _sectorId++; - seekToIndexMark(); - auto next = tell(); + seekToIndexMark(); + auto next = tell(); - adjustForIndex(now, next); - } + adjustForIndex(now, next); + } - _sectorIndex = 0; - } + _sectorIndex = 0; + } nanoseconds_t advanceToNextRecord() override - { - if (_sectorIndex == _sectorStarts.size()) - { - seekToIndexMark(); - return 0; - } + { + if (_sectorIndex == _sectorStarts.size()) + { + seekToIndexMark(); + return 0; + } - const auto& p = _sectorStarts[_sectorIndex++]; - _sectorId = p.first; - seek(p.second); + const auto& p = _sectorStarts[_sectorIndex++]; + _sectorId = p.first; + seek(p.second); - nanoseconds_t clock = seekToPattern(SECTOR_PATTERN); - _sector->headerStartTime = tell().ns(); + nanoseconds_t clock = seekToPattern(SECTOR_PATTERN); + _sector->headerStartTime = tell().ns(); - return clock; - } + return clock; + } void decodeSectorRecord() override - { - readRawBits(21); - const auto& rawbits = readRawBits(SMAKY_RECORD_SIZE*16); - if (rawbits.size() < SMAKY_SECTOR_SIZE) - return; - const auto& rawbytes = toBytes(rawbits).slice(0, SMAKY_RECORD_SIZE*16); + { + readRawBits(29); + const auto& rawbits = readRawBits(SMAKY_RECORD_SIZE * 16); + if (rawbits.size() < SMAKY_SECTOR_SIZE) + return; + const auto& rawbytes = + toBytes(rawbits).slice(0, SMAKY_RECORD_SIZE * 16); - /* The Smaky bytes are stored backwards! Backwards! */ + /* The Smaky bytes are stored backwards! Backwards! */ - const auto& bytes = decodeFmMfm(rawbits).slice(0, SMAKY_RECORD_SIZE).reverseBits(); - ByteReader br(bytes); + const auto& bytes = + decodeFmMfm(rawbits).slice(0, SMAKY_RECORD_SIZE).reverseBits(); + ByteReader br(bytes); - uint8_t track = br.read_8(); - Bytes data = br.read(SMAKY_SECTOR_SIZE); - uint8_t wantedChecksum = br.read_8(); - uint8_t gotChecksum = sumBytes(data) & 0xff; + uint8_t track = br.read_8(); + Bytes data = br.read(SMAKY_SECTOR_SIZE); + uint8_t wantedChecksum = br.read_8(); + uint8_t gotChecksum = sumBytes(data) & 0xff; - if (track != _sector->physicalTrack) - return; + if (track != _sector->physicalTrack) + return; - _sector->logicalTrack = _sector->physicalTrack; - _sector->logicalSide = _sector->physicalSide; - _sector->logicalSector = _sectorId; + _sector->logicalTrack = _sector->physicalTrack; + _sector->logicalSide = _sector->physicalSide; + _sector->logicalSector = _sectorId; - _sector->data = data; - _sector->status = (wantedChecksum == gotChecksum) ? Sector::OK : Sector::BAD_CHECKSUM; - } + _sector->data = data; + _sector->status = + (wantedChecksum == gotChecksum) ? Sector::OK : Sector::BAD_CHECKSUM; + } private: - const SmakyDecoderProto& _config; - nanoseconds_t _startOfTrack; - std::vector> _sectorStarts; - int _sectorId; - int _sectorIndex; + const SmakyDecoderProto& _config; + nanoseconds_t _startOfTrack; + std::vector> _sectorStarts; + int _sectorId; + int _sectorIndex; }; std::unique_ptr createSmakyDecoder(const DecoderProto& config) { - return std::unique_ptr(new SmakyDecoder(config)); + return std::unique_ptr(new SmakyDecoder(config)); } - - diff --git a/lib/decoders/decoders.cc b/lib/decoders/decoders.cc index 808759b7..d0932b2b 100644 --- a/lib/decoders/decoders.cc +++ b/lib/decoders/decoders.cc @@ -152,6 +152,7 @@ void Decoder::pushRecord( _trackdata->records.push_back(record); _sector->records.push_back(record); + record->position = start.bytes; record->startTime = start.ns(); record->endTime = end.ns(); record->clock = _sector->clock; diff --git a/lib/flux.h b/lib/flux.h index ad355154..f958c71e 100644 --- a/lib/flux.h +++ b/lib/flux.h @@ -10,32 +10,32 @@ class TrackInfo; struct Record { - nanoseconds_t clock = 0; - nanoseconds_t startTime = 0; - nanoseconds_t endTime = 0; - Bytes rawData; + nanoseconds_t clock = 0; + nanoseconds_t startTime = 0; + nanoseconds_t endTime = 0; + uint32_t position = 0; + Bytes rawData; }; struct TrackDataFlux { - std::shared_ptr trackInfo; - std::shared_ptr fluxmap; - std::vector> records; - std::vector> sectors; + std::shared_ptr trackInfo; + std::shared_ptr fluxmap; + std::vector> records; + std::vector> sectors; }; struct TrackFlux { - std::shared_ptr trackInfo; - std::vector> trackDatas; - std::set> sectors; + std::shared_ptr trackInfo; + std::vector> trackDatas; + std::set> sectors; }; struct DiskFlux { - std::vector> tracks; - std::shared_ptr image; + std::vector> tracks; + std::shared_ptr image; }; #endif -