Merge pull request #453 from davidgiven/mx

Fix regressions caused by the decoder change.
This commit is contained in:
David Given
2022-02-12 22:56:57 +01:00
committed by GitHub
6 changed files with 28 additions and 35 deletions

View File

@@ -7,7 +7,7 @@
#define AMIGA_TRACKS_PER_DISK 80
#define AMIGA_SECTORS_PER_TRACK 11
#define AMIGA_RECORD_SIZE 0x21f
#define AMIGA_RECORD_SIZE 0x21c
extern std::unique_ptr<AbstractDecoder> createAmigaDecoder(const DecoderProto& config);
extern std::unique_ptr<AbstractEncoder> createAmigaEncoder(const EncoderProto& config);

View File

@@ -29,43 +29,23 @@ public:
_config(config.amiga())
{}
void beginTrack() override
{
/* Force a seek for the first sector. */
_bad = true;
}
nanoseconds_t advanceToNextRecord() override
{
/* seekToPattern always advances one pulse, but Amiga sectors are
* usually right next each other (they're written out with no gaps).
* So, only actually do a seek if we haven't just read a reasonably
* good sector. */
if (_bad)
_clock = seekToPattern(SECTOR_PATTERN);
_bad = false;
return _clock;
return seekToPattern(SECTOR_PATTERN);
}
void decodeSectorRecord() override
{
if (readRaw48() != AMIGA_SECTOR_RECORD)
return;
const auto& rawbits = readRawBits(AMIGA_RECORD_SIZE*16);
if (rawbits.size() < (AMIGA_RECORD_SIZE*16))
{
_bad = true;
return;
}
const auto& rawbytes = toBytes(rawbits).slice(0, AMIGA_RECORD_SIZE*2);
if (rawbytes.reader().read_be48() != AMIGA_SECTOR_RECORD)
{
_bad = true;
return;
}
const auto& bytes = decodeFmMfm(rawbits).slice(0, AMIGA_RECORD_SIZE);
const uint8_t* ptr = bytes.begin() + 3;
const uint8_t* ptr = bytes.begin();
Bytes header = amigaDeinterleave(ptr, 4);
Bytes recoveryinfo = amigaDeinterleave(ptr, 16);
@@ -75,12 +55,12 @@ public:
_sector->logicalSector = header[2];
uint32_t wantedheaderchecksum = amigaDeinterleave(ptr, 4).reader().read_be32();
uint32_t gotheaderchecksum = amigaChecksum(rawbytes.slice(6, 40));
uint32_t gotheaderchecksum = amigaChecksum(rawbytes.slice(0, 40));
if (gotheaderchecksum != wantedheaderchecksum)
return;
uint32_t wanteddatachecksum = amigaDeinterleave(ptr, 4).reader().read_be32();
uint32_t gotdatachecksum = amigaChecksum(rawbytes.slice(62, 1024));
uint32_t gotdatachecksum = amigaChecksum(rawbytes.slice(56, 1024));
Bytes data;
data.writer().append(amigaDeinterleave(ptr, 512)).append(recoveryinfo);
@@ -97,7 +77,6 @@ public:
private:
const AmigaDecoderProto& _config;
nanoseconds_t _clock;
bool _bad;
};
std::unique_ptr<AbstractDecoder> createAmigaDecoder(const DecoderProto& config)

View File

@@ -74,6 +74,7 @@ static void write_sector(std::vector<bool>& bits, unsigned& cursor, const std::s
write_interleaved_bytes(b);
};
write_bits(bits, cursor, 0xaaaa, 2*8);
write_bits(bits, cursor, AMIGA_SECTOR_RECORD, 6*8);
checksum = 0;

View File

@@ -90,24 +90,38 @@ std::unique_ptr<TrackDataFlux> AbstractDecoder::decodeToSectors(
Fluxmap::Position before = fmr.tell();
decodeSectorRecord();
pushRecord(before, fmr.tell());
Fluxmap::Position after = fmr.tell();
pushRecord(before, after);
if (_sector->status == Sector::DATA_MISSING)
if (_sector->status != Sector::DATA_MISSING)
{
_sector->position = before.bytes;
_sector->dataStartTime = before.ns();
_sector->dataEndTime = after.ns();
}
else
{
/* The data is in a separate record. */
for (;;)
{
_sector->headerStartTime = before.ns();
_sector->headerEndTime = after.ns();
_sector->clock = advanceToNextRecord();
if (fmr.eof() || !_sector->clock)
break;
before = fmr.tell();
decodeDataRecord();
after = fmr.tell();
if (_sector->status != Sector::DATA_MISSING)
{
pushRecord(before, fmr.tell());
_sector->position = before.bytes;
_sector->dataStartTime = before.ns();
_sector->dataEndTime = after.ns();
pushRecord(before, after);
break;
}
@@ -144,7 +158,6 @@ void AbstractDecoder::resetFluxDecoder()
nanoseconds_t AbstractDecoder::seekToPattern(const FluxMatcher& pattern)
{
_fmr->skipToEvent(F_BIT_PULSE);
nanoseconds_t clock = _fmr->seekToPattern(pattern);
_decoder.reset(new FluxDecoder(_fmr, clock, _config));
return clock;

View File

@@ -107,7 +107,7 @@ void ImageWriter::writeCsv(const Image& image, const std::string& filename)
sector->headerEndTime,
sector->dataStartTime,
sector->dataEndTime,
sector->position.bytes,
sector->position,
sector->data.size(),
Sector::statusToString(sector->status)
);

View File

@@ -28,7 +28,7 @@ public:
static Status stringToStatus(const std::string& value);
Status status = Status::INTERNAL_ERROR;
Fluxmap::Position position;
uint32_t position;
nanoseconds_t clock = 0;
nanoseconds_t headerStartTime = 0;
nanoseconds_t headerEndTime = 0;