Skip to content

Allow new sectors to start in the data region of existing sectors. #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arch/amiga/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class AmigaDecoder : public AbstractDecoder
return sectors;
}

bool recordsSeekable() const override
{
return false;
}

private:
const AmigaDecoderProto& _config;
nanoseconds_t _clock;
Expand Down
37 changes: 23 additions & 14 deletions lib/decoders/decoders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,42 @@ std::shared_ptr<const TrackDataFlux> AbstractDecoder::decodeToSectors(

/* Read the sector record. */

Fluxmap::Position before = fmr.tell();
Fluxmap::Position before_sector = fmr.tell();
decodeSectorRecord();
Fluxmap::Position after = fmr.tell();
pushRecord(before, after);
Fluxmap::Position after_sector = fmr.tell();
pushRecord(before_sector, after_sector);

if (_sector->status != Sector::DATA_MISSING)
{
_sector->position = before.bytes;
_sector->dataStartTime = before.ns();
_sector->dataEndTime = after.ns();
_sector->position = before_sector.bytes;
_sector->dataStartTime = before_sector.ns();
_sector->dataEndTime = after_sector.ns();
}
else
{
/* The data is in a separate record. */
Fluxmap::Position before_data = before_sector;
Fluxmap::Position after_data = after_sector;

for (;;)
{
_sector->headerStartTime = before.ns();
_sector->headerEndTime = after.ns();
_sector->headerStartTime = before_data.ns();
_sector->headerEndTime = after_data.ns();

_sector->clock = advanceToNextRecord();
if (fmr.eof() || !_sector->clock)
break;

before = fmr.tell();
before_data = fmr.tell();
decodeDataRecord();
after = fmr.tell();
after_data = fmr.tell();

if (_sector->status != Sector::DATA_MISSING)
{
_sector->position = before.bytes;
_sector->dataStartTime = before.ns();
_sector->dataEndTime = after.ns();
pushRecord(before, after);
_sector->position = before_data.bytes;
_sector->dataStartTime = before_data.ns();
_sector->dataEndTime = after_data.ns();
pushRecord(before_data, after_data);
break;
}

Expand All @@ -131,6 +133,13 @@ std::shared_ptr<const TrackDataFlux> AbstractDecoder::decodeToSectors(
}
}

/* Allow decode of overlapping records.
* Note that this seeks to after the sector record, but before
* the data record, so it relies on a lone data record being
* ignored. */
if (this->recordsSeekable())
fmr.seek(after_sector);

if (_sector->status != Sector::MISSING)
_trackdata->sectors.push_back(_sector);
}
Expand Down
8 changes: 8 additions & 0 deletions lib/decoders/decoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ class AbstractDecoder

virtual std::set<unsigned> requiredSectors(const Location& location) const;

/* Indicates whether records have a unique start pattern, e.g. whether
* must be read contiguously (Amiga) or can be search for from any
* position (IBM). */
virtual bool recordsSeekable() const
{
return true;
}

protected:
virtual void beginTrack(){};
virtual nanoseconds_t advanceToNextRecord() = 0;
Expand Down