diff --git a/Makefile b/Makefile index f0001076..841c7dca 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ CFLAGS += -Ilib -Idep/fmt -Iarch export OBJDIR = .obj all: .obj/build.ninja - @ninja -f .obj/build.ninja + @ninja -f .obj/build.ninja -k 0 @if command -v cscope > /dev/null; then cscope -bRq; fi clean: diff --git a/arch/ibm/decoder.cc b/arch/ibm/decoder.cc index 5791d017..4156a4d6 100644 --- a/arch/ibm/decoder.cc +++ b/arch/ibm/decoder.cc @@ -108,6 +108,7 @@ public: _currentHeaderLength = (matcher == &MFM_PATTERN) ? 3 : 0; Fluxmap::Position here = tell(); + resetFluxDecoder(); if (_currentHeaderLength > 0) readRawBits(_currentHeaderLength*16); auto idbits = readRawBits(16); diff --git a/lib/decoders/decoders.cc b/lib/decoders/decoders.cc index 6de123e6..b1f1b21b 100644 --- a/lib/decoders/decoders.cc +++ b/lib/decoders/decoders.cc @@ -91,7 +91,7 @@ std::unique_ptr AbstractDecoder::decodeToSectors( /* Read the sector record. */ recordStart = fmr.tell(); - _decoder.reset(new FluxDecoder(&fmr, _sector->clock, _config)); + resetFluxDecoder(); decodeSectorRecord(); Fluxmap::Position recordEnd = fmr.tell(); pushRecord(recordStart, recordEnd); @@ -112,7 +112,7 @@ std::unique_ptr AbstractDecoder::decodeToSectors( recordStart = fmr.tell(); if (r == DATA_RECORD) { - _decoder.reset(new FluxDecoder(&fmr, _sector->clock, _config)); + resetFluxDecoder(); decodeDataRecord(); } recordEnd = fmr.tell(); @@ -143,6 +143,11 @@ void AbstractDecoder::pushRecord(const Fluxmap::Position& start, const Fluxmap:: _fmr->seek(here); } +void AbstractDecoder::resetFluxDecoder() +{ + _decoder.reset(new FluxDecoder(_fmr, _sector->clock, _config)); +} + std::vector AbstractDecoder::readRawBits(unsigned count) { return _decoder->readBits(count); diff --git a/lib/decoders/decoders.h b/lib/decoders/decoders.h index 2700093b..44ff3e54 100644 --- a/lib/decoders/decoders.h +++ b/lib/decoders/decoders.h @@ -48,8 +48,8 @@ public: std::unique_ptr decodeToSectors(std::shared_ptr fluxmap, unsigned cylinder, unsigned head); void pushRecord(const Fluxmap::Position& start, const Fluxmap::Position& end); + void resetFluxDecoder(); std::vector readRawBits(unsigned count); - //{ return _fmr->readRawBits(count, _sector->clock); } Fluxmap::Position tell() { return _fmr->tell(); } diff --git a/lib/decoders/fluxdecoder.cc b/lib/decoders/fluxdecoder.cc index 63f47d2d..c5e89603 100644 --- a/lib/decoders/fluxdecoder.cc +++ b/lib/decoders/fluxdecoder.cc @@ -14,15 +14,21 @@ FluxDecoder::FluxDecoder(FluxmapReader* fmr, nanoseconds_t bitcell, _clock_centre(bitcell), _clock_min(bitcell * (1.0 - _pll_adjust)), _clock_max(bitcell * (1.0 + _pll_adjust)), - _flux(0) + _flux(0), + _leading_zeroes(fmr->tell().zeroes) {} bool FluxDecoder::readBit() { - if (_first_bit) + if (_leading_zeroes > 0) { - _first_bit = false; + _leading_zeroes--; + return false; + } + else if (_leading_zeroes == 0) + { + _leading_zeroes--; return true; }