Fix, hopefully, the rest of the decoders.

This commit is contained in:
David Given
2022-02-12 15:02:42 +01:00
parent 0933dc1afa
commit e8d1c90182
9 changed files with 91 additions and 34 deletions

View File

@@ -78,8 +78,8 @@ public:
void decodeSectorRecord()
{
/* Skip ID (as we know it's a APPLE2_SECTOR_RECORD). */
readRawBits(24);
if (readRaw24() != APPLE2_SECTOR_RECORD)
return;
/* Read header. */
@@ -98,14 +98,13 @@ public:
{
/* Check ID. */
Bytes bytes = toBytes(readRawBits(3*8)).slice(0, 3);
if (bytes.reader().read_be24() != APPLE2_DATA_RECORD)
if (readRaw24() != APPLE2_DATA_RECORD)
return;
/* Read and decode data. */
unsigned recordLength = APPLE2_ENCODED_SECTOR_LENGTH + 2;
bytes = toBytes(readRawBits(recordLength*8)).slice(0, recordLength);
Bytes bytes = toBytes(readRawBits(recordLength*8)).slice(0, recordLength);
_sector->status = Sector::BAD_CHECKSUM;
_sector->data = decode_crazy_data(&bytes[0], _sector->status);

View File

@@ -66,7 +66,9 @@ public:
void decodeSectorRecord()
{
readRawBits(32);
if (readRaw32() != BROTHER_SECTOR_RECORD)
return;
const auto& rawbits = readRawBits(32);
const auto& bytes = toBytes(rawbits).slice(0, 4);
@@ -86,7 +88,8 @@ public:
void decodeDataRecord()
{
readRawBits(32);
if (readRaw32() != BROTHER_DATA_RECORD)
return;
const auto& rawbits = readRawBits(BROTHER_DATA_RECORD_ENCODED_SIZE*8);
const auto& rawbytes = toBytes(rawbits).slice(0, BROTHER_DATA_RECORD_ENCODED_SIZE);

View File

@@ -65,7 +65,8 @@ public:
void decodeSectorRecord()
{
readRawBits(20);
if (readRaw20() != C64_SECTOR_RECORD)
return;
const auto& bits = readRawBits(5*10);
const auto& bytes = decode(bits).slice(0, 5);
@@ -80,7 +81,8 @@ public:
void decodeDataRecord()
{
readRawBits(20);
if (readRaw20() != C64_DATA_RECORD)
return;
const auto& bits = readRawBits(259*10);
const auto& bytes = decode(bits).slice(0, 259);

View File

@@ -67,7 +67,8 @@ public:
{
/* Skip sync bits and ID byte. */
readRawBits(24);
if (readRaw24() != F85_SECTOR_RECORD)
return;
/* Read header. */
@@ -87,7 +88,8 @@ public:
{
/* Skip sync bits ID byte. */
readRawBits(24);
if (readRaw24() != F85_DATA_RECORD)
return;
const auto& bytes = decode(readRawBits((F85_SECTOR_LENGTH+3)*10))
.slice(0, F85_SECTOR_LENGTH+3);

View File

@@ -136,8 +136,8 @@ public:
void decodeSectorRecord()
{
/* Skip ID (as we know it's a MAC_SECTOR_RECORD). */
readRawBits(24);
if (readRaw24() != MAC_SECTOR_RECORD)
return;
/* Read header. */
@@ -165,8 +165,7 @@ public:
void decodeDataRecord()
{
auto id = toBytes(readRawBits(24)).reader().read_be24();
if (id != MAC_DATA_RECORD)
if (readRaw24() != MAC_DATA_RECORD)
return;
/* Read data. */

View File

@@ -23,17 +23,19 @@
* When shifted out of phase, the special 0xa1 byte becomes an illegal
* encoding (you can't do 10 00). So this can't be spoofed by user data.
*/
const uint16_t SECTOR_ID = 0x550a;
const FluxPattern SECTOR_RECORD_PATTERN(32, 0x11112244);
/*
* Data record:
* data: 0 1 0 1 0 1 0 1 .0 0 0 0 1 0 1 1 = 0x550c
* data: 0 1 0 1 0 1 0 1 .0 0 0 0 1 0 1 1 = 0x550b
* mfm: 00 01 00 01 00 01 00 01.00 10 10 10 01 00 01 01 = 0x11112a45
* special: 00 01 00 01 00 01 00 01.00 10 00 10 01 00 01 01 = 0x11112245
* ^^
* When shifted out of phase, the special 0xa1 byte becomes an illegal
* encoding (you can't do 10 00). So this can't be spoofed by user data.
*/
const uint16_t DATA_ID = 0x550b;
const FluxPattern DATA_RECORD_PATTERN(32, 0x11112245);
const FluxMatchers ANY_RECORD_PATTERN({ &SECTOR_RECORD_PATTERN, &DATA_RECORD_PATTERN });
@@ -56,9 +58,11 @@ public:
auto bytes = decodeFmMfm(bits).slice(0, TIDS990_SECTOR_RECORD_SIZE);
ByteReader br(bytes);
if (br.read_be16() != SECTOR_ID)
return;
uint16_t gotChecksum = crc16(CCITT_POLY, bytes.slice(1, TIDS990_SECTOR_RECORD_SIZE-3));
br.seek(2);
_sector->logicalSide = br.read_8() >> 3;
_sector->logicalTrack = br.read_8();
br.read_8(); /* number of sectors per track */
@@ -76,9 +80,11 @@ public:
auto bytes = decodeFmMfm(bits).slice(0, TIDS990_DATA_RECORD_SIZE);
ByteReader br(bytes);
if (br.read_be16() != DATA_ID)
return;
uint16_t gotChecksum = crc16(CCITT_POLY, bytes.slice(1, TIDS990_DATA_RECORD_SIZE-3));
br.seek(2);
_sector->data = br.read(TIDS990_PAYLOAD_SIZE);
uint16_t wantChecksum = br.read_be16();
_sector->status = (wantChecksum == gotChecksum) ? Sector::OK : Sector::BAD_CHECKSUM;

View File

@@ -66,20 +66,22 @@ public:
void decodeSectorRecord()
{
/* Skip the sync marker bit. */
readRawBits(22);
/* Check the ID. */
if (readRaw32() != VICTOR9K_SECTOR_RECORD)
return;
/* Read header. */
auto bytes = decode(readRawBits(4*10)).slice(0, 4);
auto bytes = decode(readRawBits(3*10)).slice(0, 3);
uint8_t rawTrack = bytes[1];
_sector->logicalSector = bytes[2];
uint8_t gotChecksum = bytes[3];
uint8_t rawTrack = bytes[0];
_sector->logicalSector = bytes[1];
uint8_t gotChecksum = bytes[2];
_sector->logicalTrack = rawTrack & 0x7f;
_sector->logicalSide = rawTrack >> 7;
uint8_t wantChecksum = bytes[1] + bytes[2];
uint8_t wantChecksum = bytes[0] + bytes[1];
if ((_sector->logicalSector > 20) || (_sector->logicalTrack > 85) || (_sector->logicalSide > 1))
return;
@@ -89,20 +91,17 @@ public:
void decodeDataRecord()
{
/* Skip the sync marker bit. */
readRawBits(22);
/* Check the ID. */
if (readRaw32() != VICTOR9K_DATA_RECORD)
return;
/* Read data. */
auto bytes = decode(readRawBits((VICTOR9K_SECTOR_LENGTH+5)*10))
.slice(0, VICTOR9K_SECTOR_LENGTH+5);
auto bytes = decode(readRawBits((VICTOR9K_SECTOR_LENGTH+4)*10))
.slice(0, VICTOR9K_SECTOR_LENGTH+4);
ByteReader br(bytes);
/* Check that this is actually a data record. */
if (br.read_8() != 8)
return;
_sector->data = br.read(VICTOR9K_SECTOR_LENGTH);
uint16_t gotChecksum = sumBytes(_sector->data);
uint16_t wantChecksum = br.read_le16();

View File

@@ -156,6 +156,46 @@ std::vector<bool> AbstractDecoder::readRawBits(unsigned count)
return _decoder->readBits(count);
}
uint8_t AbstractDecoder::readRaw8()
{
return toBytes(readRawBits(8)).reader().read_8();
}
uint16_t AbstractDecoder::readRaw16()
{
return toBytes(readRawBits(16)).reader().read_be16();
}
uint32_t AbstractDecoder::readRaw20()
{
std::vector<bool> bits(4);
for (bool b : readRawBits(20))
bits.push_back(b);
return toBytes(bits).reader().read_be24();
}
uint32_t AbstractDecoder::readRaw24()
{
return toBytes(readRawBits(24)).reader().read_be24();
}
uint32_t AbstractDecoder::readRaw32()
{
return toBytes(readRawBits(32)).reader().read_be32();
}
uint64_t AbstractDecoder::readRaw48()
{
return toBytes(readRawBits(48)).reader().read_be48();
}
uint64_t AbstractDecoder::readRaw64()
{
return toBytes(readRawBits(64)).reader().read_be64();
}
std::set<unsigned> AbstractDecoder::requiredSectors(unsigned cylinder, unsigned head) const
{
static std::set<unsigned> set;

View File

@@ -50,6 +50,13 @@ public:
void resetFluxDecoder();
std::vector<bool> readRawBits(unsigned count);
uint8_t readRaw8();
uint16_t readRaw16();
uint32_t readRaw20();
uint32_t readRaw24();
uint32_t readRaw32();
uint64_t readRaw48();
uint64_t readRaw64();
Fluxmap::Position tell()
{ return _fmr->tell(); }