Fix the Amiga decoder, which got broken with the decoder change. Also fix the

encoder which was always broken (but Amigas apparently didn't care).
This commit is contained in:
David Given
2022-02-12 22:42:15 +01:00
parent 830f4cec0f
commit c539debc84
3 changed files with 9 additions and 29 deletions

View File

@@ -7,7 +7,7 @@
#define AMIGA_TRACKS_PER_DISK 80 #define AMIGA_TRACKS_PER_DISK 80
#define AMIGA_SECTORS_PER_TRACK 11 #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<AbstractDecoder> createAmigaDecoder(const DecoderProto& config);
extern std::unique_ptr<AbstractEncoder> createAmigaEncoder(const EncoderProto& config); extern std::unique_ptr<AbstractEncoder> createAmigaEncoder(const EncoderProto& config);

View File

@@ -29,43 +29,23 @@ public:
_config(config.amiga()) _config(config.amiga())
{} {}
void beginTrack() override
{
/* Force a seek for the first sector. */
_bad = true;
}
nanoseconds_t advanceToNextRecord() override nanoseconds_t advanceToNextRecord() override
{ {
/* seekToPattern always advances one pulse, but Amiga sectors are return seekToPattern(SECTOR_PATTERN);
* 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;
} }
void decodeSectorRecord() override void decodeSectorRecord() override
{ {
if (readRaw48() != AMIGA_SECTOR_RECORD)
return;
const auto& rawbits = readRawBits(AMIGA_RECORD_SIZE*16); const auto& rawbits = readRawBits(AMIGA_RECORD_SIZE*16);
if (rawbits.size() < (AMIGA_RECORD_SIZE*16)) if (rawbits.size() < (AMIGA_RECORD_SIZE*16))
{
_bad = true;
return; return;
}
const auto& rawbytes = toBytes(rawbits).slice(0, AMIGA_RECORD_SIZE*2); 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 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 header = amigaDeinterleave(ptr, 4);
Bytes recoveryinfo = amigaDeinterleave(ptr, 16); Bytes recoveryinfo = amigaDeinterleave(ptr, 16);
@@ -75,12 +55,12 @@ public:
_sector->logicalSector = header[2]; _sector->logicalSector = header[2];
uint32_t wantedheaderchecksum = amigaDeinterleave(ptr, 4).reader().read_be32(); 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) if (gotheaderchecksum != wantedheaderchecksum)
return; return;
uint32_t wanteddatachecksum = amigaDeinterleave(ptr, 4).reader().read_be32(); 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; Bytes data;
data.writer().append(amigaDeinterleave(ptr, 512)).append(recoveryinfo); data.writer().append(amigaDeinterleave(ptr, 512)).append(recoveryinfo);
@@ -97,7 +77,6 @@ public:
private: private:
const AmigaDecoderProto& _config; const AmigaDecoderProto& _config;
nanoseconds_t _clock; nanoseconds_t _clock;
bool _bad;
}; };
std::unique_ptr<AbstractDecoder> createAmigaDecoder(const DecoderProto& config) 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_interleaved_bytes(b);
}; };
write_bits(bits, cursor, 0xaaaa, 2*8);
write_bits(bits, cursor, AMIGA_SECTOR_RECORD, 6*8); write_bits(bits, cursor, AMIGA_SECTOR_RECORD, 6*8);
checksum = 0; checksum = 0;