From 3cb098f9ba7b2b29ff0f7ff22c014c93e1c7c24e Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 11 Sep 2022 17:05:40 +0200 Subject: [PATCH] Rip out the old approach to soft sector remapping as it wasn't working. --- arch/aeslanier/decoder.cc | 2 +- arch/agat/decoder.cc | 2 +- arch/amiga/decoder.cc | 2 +- arch/amiga/encoder.cc | 4 +-- arch/apple2/decoder.cc | 4 +-- arch/apple2/encoder.cc | 6 ++--- arch/brother/decoder.cc | 4 +-- arch/brother/encoder.cc | 2 +- arch/c64/decoder.cc | 2 +- arch/c64/encoder.cc | 2 +- arch/f85/decoder.cc | 2 +- arch/fb100/decoder.cc | 2 +- arch/ibm/decoder.cc | 6 ++--- arch/ibm/encoder.cc | 7 +++-- arch/macintosh/decoder.cc | 2 +- arch/macintosh/encoder.cc | 4 +-- arch/micropolis/decoder.cc | 4 +-- arch/micropolis/encoder.cc | 4 +-- arch/mx/decoder.cc | 2 +- arch/northstar/decoder.cc | 2 +- arch/northstar/encoder.cc | 2 +- arch/tids990/decoder.cc | 2 +- arch/tids990/encoder.cc | 2 +- arch/victor9k/decoder.cc | 4 +-- arch/victor9k/encoder.cc | 2 +- arch/zilogmcz/decoder.cc | 4 +-- lib/decoders/decoders.cc | 1 - lib/image.cc | 3 +-- lib/imagereader/imagereader.proto | 5 ++++ lib/imagereader/imgimagereader.cc | 2 +- lib/imagewriter/imagewriter.cc | 8 +++--- lib/imagewriter/imgimagewriter.cc | 2 +- lib/layout.cc | 43 ++++++++++-------------------- lib/layout.h | 17 ++++++------ lib/layout.proto | 28 ++++++++++---------- lib/sector.h | 1 - lib/vfs/amigaffs.cc | 2 +- lib/vfs/fluxsectorinterface.cc | 4 +-- lib/vfs/vfs.cc | 4 +-- lib/vfs/vfs.proto | 4 +++ src/fe-analyselayout.cc | 15 +++++------ src/formats/appledos.textpb | 38 +++++++++++++------------- src/formats/prodos.textpb | 44 ++++++++++++++----------------- 43 files changed, 141 insertions(+), 161 deletions(-) diff --git a/arch/aeslanier/decoder.cc b/arch/aeslanier/decoder.cc index 4069d1c9..f2fcc41e 100644 --- a/arch/aeslanier/decoder.cc +++ b/arch/aeslanier/decoder.cc @@ -47,7 +47,7 @@ public: _sector->logicalTrack = reversed[1]; _sector->logicalSide = 0; - _sector->physicalSector = reversed[2]; + _sector->logicalSector = reversed[2]; /* Check header 'checksum' (which seems far too simple to mean much). */ diff --git a/arch/agat/decoder.cc b/arch/agat/decoder.cc index 03e9db1a..efb14011 100644 --- a/arch/agat/decoder.cc +++ b/arch/agat/decoder.cc @@ -66,7 +66,7 @@ public: return; _sector->logicalTrack = bytes[1] >> 1; - _sector->physicalSector = bytes[2]; + _sector->logicalSector = bytes[2]; _sector->logicalSide = bytes[1] & 1; _sector->status = Sector::DATA_MISSING; /* unintuitive but correct */ } diff --git a/arch/amiga/decoder.cc b/arch/amiga/decoder.cc index 6cb6427a..6af128d7 100644 --- a/arch/amiga/decoder.cc +++ b/arch/amiga/decoder.cc @@ -52,7 +52,7 @@ public: _sector->logicalTrack = header[1] >> 1; _sector->logicalSide = header[1] & 1; - _sector->physicalSector = header[2]; + _sector->logicalSector = header[2]; uint32_t wantedheaderchecksum = amigaDeinterleave(ptr, 4).reader().read_be32(); uint32_t gotheaderchecksum = amigaChecksum(rawbytes.slice(0, 40)); diff --git a/arch/amiga/encoder.cc b/arch/amiga/encoder.cc index 3dad3894..2f81baed 100644 --- a/arch/amiga/encoder.cc +++ b/arch/amiga/encoder.cc @@ -85,8 +85,8 @@ static void write_sector(std::vector& bits, checksum = 0; Bytes header = {0xff, /* Amiga 1.0 format byte */ (uint8_t)((sector->logicalTrack << 1) | sector->logicalSide), - (uint8_t)sector->physicalSector, - (uint8_t)(AMIGA_SECTORS_PER_TRACK - sector->physicalSector)}; + (uint8_t)sector->logicalSector, + (uint8_t)(AMIGA_SECTORS_PER_TRACK - sector->logicalSector)}; write_interleaved_bytes(header); Bytes recoveryInfo(16); if (sector->data.size() == 528) diff --git a/arch/apple2/decoder.cc b/arch/apple2/decoder.cc index 23d9e876..8ad4ca52 100644 --- a/arch/apple2/decoder.cc +++ b/arch/apple2/decoder.cc @@ -88,12 +88,12 @@ public: uint8_t volume = combine(br.read_be16()); _sector->logicalTrack = combine(br.read_be16()); - _sector->physicalSector = combine(br.read_be16()); + _sector->logicalSector = combine(br.read_be16()); uint8_t checksum = combine(br.read_be16()); // If the checksum is correct, upgrade the sector from MISSING // to DATA_MISSING in anticipation of its data record - if (checksum == (volume ^ _sector->logicalTrack ^ _sector->physicalSector)) + if (checksum == (volume ^ _sector->logicalTrack ^ _sector->logicalSector)) _sector->status = Sector::DATA_MISSING; /* unintuitive but correct */ } diff --git a/arch/apple2/encoder.cc b/arch/apple2/encoder.cc index 2ad0e7df..7e5fdb9a 100644 --- a/arch/apple2/encoder.cc +++ b/arch/apple2/encoder.cc @@ -148,15 +148,15 @@ private: // // In standard formatting, the first logical sector apparently gets // extra padding. - write_ff40(sector.physicalSector == 0 ? 32 : 8); + write_ff40(sector.logicalSector == 0 ? 32 : 8); // Write address field: APPLE2_SECTOR_RECORD + sector identifier + // DE AA EB write_bits(APPLE2_SECTOR_RECORD, 24); write_gcr44(volume_id); write_gcr44(sector.logicalTrack); - write_gcr44(sector.physicalSector); - write_gcr44(volume_id ^ sector.logicalTrack ^ sector.physicalSector); + write_gcr44(sector.logicalSector); + write_gcr44(volume_id ^ sector.logicalTrack ^ sector.logicalSector); write_bits(0xDEAAEB, 24); // Write data syncing leader: FF40 + APPLE2_DATA_RECORD + sector diff --git a/arch/brother/decoder.cc b/arch/brother/decoder.cc index c1a926e7..9fbc4072 100644 --- a/arch/brother/decoder.cc +++ b/arch/brother/decoder.cc @@ -74,11 +74,11 @@ public: ByteReader br(bytes); _sector->logicalTrack = decode_header_gcr(br.read_be16()); - _sector->physicalSector = decode_header_gcr(br.read_be16()); + _sector->logicalSector = decode_header_gcr(br.read_be16()); /* Sanity check the values read; there's no header checksum and * occasionally we get garbage due to bit errors. */ - if (_sector->physicalSector > 11) + if (_sector->logicalSector > 11) return; if (_sector->logicalTrack > 79) return; diff --git a/arch/brother/encoder.cc b/arch/brother/encoder.cc index c53b8b93..3e961cd7 100644 --- a/arch/brother/encoder.cc +++ b/arch/brother/encoder.cc @@ -169,7 +169,7 @@ public: fillBitmapTo(bits, cursor, headerCursor, {true, false}); write_sector_header( - bits, cursor, sectorData->logicalTrack, sectorData->physicalSector); + bits, cursor, sectorData->logicalTrack, sectorData->logicalSector); fillBitmapTo(bits, cursor, dataCursor, {true, false}); write_sector_data(bits, cursor, sectorData->data); diff --git a/arch/c64/decoder.cc b/arch/c64/decoder.cc index 6a60a066..2792fa12 100644 --- a/arch/c64/decoder.cc +++ b/arch/c64/decoder.cc @@ -72,7 +72,7 @@ public: const auto& bytes = decode(bits).slice(0, 5); uint8_t checksum = bytes[0]; - _sector->physicalSector = bytes[1]; + _sector->logicalSector = bytes[1]; _sector->logicalSide = 0; _sector->logicalTrack = bytes[2] - 1; if (checksum == xorBytes(bytes.slice(1, 4))) diff --git a/arch/c64/encoder.cc b/arch/c64/encoder.cc index e444de4e..3ca6447a 100644 --- a/arch/c64/encoder.cc +++ b/arch/c64/encoder.cc @@ -269,7 +269,7 @@ private: * 06-07 - $0F ("off" bytes) */ uint8_t encodedTrack = ((sector->logicalTrack) + 1); // C64 track numbering starts with 1. Fluxengine with 0. - uint8_t encodedSector = sector->physicalSector; + uint8_t encodedSector = sector->logicalSector; // uint8_t formatByte1 = C64_FORMAT_ID_BYTE1; // uint8_t formatByte2 = C64_FORMAT_ID_BYTE2; uint8_t headerChecksum = (encodedTrack ^ encodedSector ^ _formatByte1 ^ _formatByte2); diff --git a/arch/f85/decoder.cc b/arch/f85/decoder.cc index ba5288e2..96f24815 100644 --- a/arch/f85/decoder.cc +++ b/arch/f85/decoder.cc @@ -74,7 +74,7 @@ public: const auto& bytes = decode(readRawBits(6*10)); - _sector->physicalSector = bytes[2]; + _sector->logicalSector = bytes[2]; _sector->logicalSide = 0; _sector->logicalTrack = bytes[0]; diff --git a/arch/fb100/decoder.cc b/arch/fb100/decoder.cc index 7c5d99f2..fd5891f9 100644 --- a/arch/fb100/decoder.cc +++ b/arch/fb100/decoder.cc @@ -129,7 +129,7 @@ public: uint8_t abssector = id[2]; _sector->logicalTrack = abssector >> 1; _sector->logicalSide = 0; - _sector->physicalSector = abssector & 1; + _sector->logicalSector = abssector & 1; _sector->data.writer().append(id.slice(5, 12)).append(payload); _sector->status = (wantPayloadCrc == gotPayloadCrc) ? Sector::OK : Sector::BAD_CHECKSUM; diff --git a/arch/ibm/decoder.cc b/arch/ibm/decoder.cc index db0e8179..c916bc0e 100644 --- a/arch/ibm/decoder.cc +++ b/arch/ibm/decoder.cc @@ -144,7 +144,7 @@ public: _sector->logicalTrack = br.read_8(); _sector->logicalSide = br.read_8(); - _sector->physicalSector = br.read_8(); + _sector->logicalSector = br.read_8(); _currentSectorSize = 1 << (br.read_8() + 7); uint16_t gotCrc = crc16(CCITT_POLY, bytes.slice(0, br.pos)); uint16_t wantCrc = br.read_be16(); @@ -159,7 +159,7 @@ public: _sector->logicalTrack = _sector->physicalTrack; for (int sector : trackdata.ignore_sector()) - if (_sector->physicalSector == sector) + if (_sector->logicalSector == sector) { _sector->status = Sector::MISSING; break; @@ -207,7 +207,7 @@ public: std::set requiredSectors(const Location& location) const override { auto& trackLayout = Layout::getLayoutOfTrack(location.logicalTrack, location.head); - return std::set(trackLayout.logicalSectors.begin(), trackLayout.logicalSectors.end()); + return std::set(trackLayout.logicalSectorOrder.begin(), trackLayout.logicalSectorOrder.end()); } private: diff --git a/arch/ibm/encoder.cc b/arch/ibm/encoder.cc index 78588514..847fdfab 100644 --- a/arch/ibm/encoder.cc +++ b/arch/ibm/encoder.cc @@ -118,11 +118,10 @@ public: Layout::getLayoutOfTrack(location.logicalTrack, location.head); int logicalSide = location.head ^ trackdata.swap_sides(); - for (unsigned physicalSectorId : trackLayout.physicalSectors) + for (unsigned sectorId : trackLayout.diskSectorOrder) { - unsigned logicalSectorId = trackLayout.physicalSectorToLogical(physicalSectorId); const auto& sector = - image.get(location.logicalTrack, logicalSide, logicalSectorId); + image.get(location.logicalTrack, logicalSide, sectorId); if (sector) sectors.push_back(sector); } @@ -226,7 +225,7 @@ public: bw.write_8(idamUnencoded); bw.write_8(sectorData->logicalTrack); bw.write_8(sectorData->logicalSide); - bw.write_8(sectorData->physicalSector); + bw.write_8(sectorData->logicalSector); bw.write_8(sectorSize); uint16_t crc = crc16(CCITT_POLY, header); bw.write_be16(crc); diff --git a/arch/macintosh/decoder.cc b/arch/macintosh/decoder.cc index c4e0cdf7..255105e5 100644 --- a/arch/macintosh/decoder.cc +++ b/arch/macintosh/decoder.cc @@ -157,7 +157,7 @@ public: _sector->logicalTrack = _sector->physicalTrack; _sector->logicalSide = decode_side(encodedSide); - _sector->physicalSector = encodedSector; + _sector->logicalSector = encodedSector; uint8_t gotsum = (encodedTrack ^ encodedSector ^ encodedSide ^ formatByte) & 0x3f; if (wantedsum == gotsum) _sector->status = Sector::DATA_MISSING; /* unintuitive but correct */ diff --git a/arch/macintosh/encoder.cc b/arch/macintosh/encoder.cc index 784ca290..c5c2bb1c 100644 --- a/arch/macintosh/encoder.cc +++ b/arch/macintosh/encoder.cc @@ -181,7 +181,7 @@ static void write_sector(std::vector& bits, write_bits(bits, cursor, MAC_SECTOR_RECORD, 3 * 8); uint8_t encodedTrack = sector->logicalTrack & 0x3f; - uint8_t encodedSector = sector->physicalSector; + uint8_t encodedSector = sector->logicalSector; uint8_t encodedSide = encode_side(sector->logicalTrack, sector->logicalSide); uint8_t formatByte = MAC_FORMAT_BYTE; @@ -197,7 +197,7 @@ static void write_sector(std::vector& bits, write_bits(bits, cursor, 0xdeaaff, 3 * 8); write_bits(bits, cursor, 0xff3fcff3fcffLL, 6 * 8); /* sync */ write_bits(bits, cursor, MAC_DATA_RECORD, 3 * 8); - write_bits(bits, cursor, encode_data_gcr(sector->physicalSector), 1 * 8); + write_bits(bits, cursor, encode_data_gcr(sector->logicalSector), 1 * 8); Bytes wireData; wireData.writer() diff --git a/arch/micropolis/decoder.cc b/arch/micropolis/decoder.cc index b8dc9555..409c11bd 100644 --- a/arch/micropolis/decoder.cc +++ b/arch/micropolis/decoder.cc @@ -128,8 +128,8 @@ public: _sector->logicalTrack = br.read_8(); _sector->logicalSide = _sector->physicalHead; - _sector->physicalSector = br.read_8(); - if (_sector->physicalSector > 15) + _sector->logicalSector = br.read_8(); + if (_sector->logicalSector > 15) return; if (_sector->logicalTrack > 76) return; diff --git a/arch/micropolis/encoder.cc b/arch/micropolis/encoder.cc index d2883682..1ad1b5d3 100644 --- a/arch/micropolis/encoder.cc +++ b/arch/micropolis/encoder.cc @@ -31,7 +31,7 @@ static void write_sector(std::vector& bits, micropolisChecksum(sector->data.slice(1, 2 + 266)); if (wantChecksum != gotChecksum) std::cerr << "Warning: checksum incorrect. Sector: " - << sector->physicalSector << std::endl; + << sector->logicalSector << std::endl; sectorData = sector->data; } else @@ -39,7 +39,7 @@ static void write_sector(std::vector& bits, ByteWriter writer(sectorData); writer.write_8(0xff); /* Sync */ writer.write_8(sector->logicalTrack); - writer.write_8(sector->physicalSector); + writer.write_8(sector->logicalSector); for (int i = 0; i < 10; i++) writer.write_8(0); /* Padding */ writer += sector->data; diff --git a/arch/mx/decoder.cc b/arch/mx/decoder.cc index b1409536..3d04d2ab 100644 --- a/arch/mx/decoder.cc +++ b/arch/mx/decoder.cc @@ -67,7 +67,7 @@ public: _sector->logicalTrack = _sector->physicalTrack; _sector->logicalSide = _sector->physicalHead; - _sector->physicalSector = _currentSector; + _sector->logicalSector = _currentSector; _sector->data = bytes.slice(0, SECTOR_SIZE).swab(); _sector->status = (gotChecksum == wantChecksum) ? Sector::OK : Sector::BAD_CHECKSUM; _currentSector++; diff --git a/arch/northstar/decoder.cc b/arch/northstar/decoder.cc index dbbdb640..a79979d1 100644 --- a/arch/northstar/decoder.cc +++ b/arch/northstar/decoder.cc @@ -151,7 +151,7 @@ public: ByteReader br(bytes); _sector->logicalSide = _sector->physicalHead; - _sector->physicalSector = _hardSectorId; + _sector->logicalSector = _hardSectorId; _sector->logicalTrack = _sector->physicalTrack; if (headerSize == NORTHSTAR_HEADER_SIZE_DD) { diff --git a/arch/northstar/encoder.cc b/arch/northstar/encoder.cc index cb1dd59b..455437b9 100644 --- a/arch/northstar/encoder.cc +++ b/arch/northstar/encoder.cc @@ -89,7 +89,7 @@ static void write_sector(std::vector& bits, for (uint8_t b : sectorData) fullSector->push_back(b); - if (sector->physicalSector != 9) + if (sector->logicalSector != 9) { /* sector postamble */ for (int i = 0; i < gapFillSize; i++) diff --git a/arch/tids990/decoder.cc b/arch/tids990/decoder.cc index 8219513c..ebb2d2cb 100644 --- a/arch/tids990/decoder.cc +++ b/arch/tids990/decoder.cc @@ -66,7 +66,7 @@ public: _sector->logicalSide = br.read_8() >> 3; _sector->logicalTrack = br.read_8(); br.read_8(); /* number of sectors per track */ - _sector->physicalSector = br.read_8(); + _sector->logicalSector = br.read_8(); br.read_be16(); /* sector size */ uint16_t wantChecksum = br.read_be16(); diff --git a/arch/tids990/encoder.cc b/arch/tids990/encoder.cc index 5effd1c7..111a08a1 100644 --- a/arch/tids990/encoder.cc +++ b/arch/tids990/encoder.cc @@ -116,7 +116,7 @@ public: bw.write_8(sectorData->logicalSide << 3); bw.write_8(sectorData->logicalTrack); bw.write_8(_config.sector_count()); - bw.write_8(sectorData->physicalSector); + bw.write_8(sectorData->logicalSector); bw.write_be16(sectorData->data.size()); uint16_t crc = crc16(CCITT_POLY, header); bw.write_be16(crc); diff --git a/arch/victor9k/decoder.cc b/arch/victor9k/decoder.cc index 25749735..50a349ea 100644 --- a/arch/victor9k/decoder.cc +++ b/arch/victor9k/decoder.cc @@ -76,13 +76,13 @@ public: auto bytes = decode(readRawBits(3*10)).slice(0, 3); uint8_t rawTrack = bytes[0]; - _sector->physicalSector = bytes[1]; + _sector->logicalSector = bytes[1]; uint8_t gotChecksum = bytes[2]; _sector->logicalTrack = rawTrack & 0x7f; _sector->logicalSide = rawTrack >> 7; uint8_t wantChecksum = bytes[0] + bytes[1]; - if ((_sector->physicalSector > 20) || (_sector->logicalTrack > 85) || (_sector->logicalSide > 1)) + if ((_sector->logicalSector > 20) || (_sector->logicalTrack > 85) || (_sector->logicalSide > 1)) return; if (wantChecksum == gotChecksum) diff --git a/arch/victor9k/encoder.cc b/arch/victor9k/encoder.cc index 5420fa5c..e3bfd602 100644 --- a/arch/victor9k/encoder.cc +++ b/arch/victor9k/encoder.cc @@ -112,7 +112,7 @@ static void write_sector(std::vector& bits, write_bits(bits, cursor, VICTOR9K_SECTOR_RECORD, 10); uint8_t encodedTrack = sector.logicalTrack | (sector.logicalSide << 7); - uint8_t encodedSector = sector.physicalSector; + uint8_t encodedSector = sector.logicalSector; write_bytes(bits, cursor, Bytes{ diff --git a/arch/zilogmcz/decoder.cc b/arch/zilogmcz/decoder.cc index 721b166d..c39f0f6e 100644 --- a/arch/zilogmcz/decoder.cc +++ b/arch/zilogmcz/decoder.cc @@ -34,10 +34,10 @@ public: auto bytes = decodeFmMfm(rawbits).slice(0, 140); ByteReader br(bytes); - _sector->physicalSector = br.read_8() & 0x1f; + _sector->logicalSector = br.read_8() & 0x1f; _sector->logicalSide = 0; _sector->logicalTrack = br.read_8() & 0x7f; - if (_sector->physicalSector > 31) + if (_sector->logicalSector > 31) return; if (_sector->logicalTrack > 80) return; diff --git a/lib/decoders/decoders.cc b/lib/decoders/decoders.cc index 33a574c3..4482d938 100644 --- a/lib/decoders/decoders.cc +++ b/lib/decoders/decoders.cc @@ -137,7 +137,6 @@ std::shared_ptr AbstractDecoder::decodeToSectors( if (_sector->status != Sector::MISSING) { auto& trackLayout = Layout::getLayoutOfTrack(_sector->logicalTrack, _sector->logicalSide); - _sector->logicalSector = trackLayout.physicalSectorToLogical(_sector->physicalSector); _trackdata->sectors.push_back(_sector); } } diff --git a/lib/image.cc b/lib/image.cc index d1cad01f..5811cf16 100644 --- a/lib/image.cc +++ b/lib/image.cc @@ -31,7 +31,7 @@ void Image::createBlankImage() unsigned side = trackAndHead.second; auto& trackLayout = Layout::getLayoutOfTrack(track, side); Bytes blank(trackLayout.sectorSize); - for (unsigned sectorId : trackLayout.logicalSectors) + for (unsigned sectorId : trackLayout.logicalSectorOrder) put(track, side, sectorId)->data = blank; } } @@ -70,7 +70,6 @@ std::shared_ptr Image::put( sector->logicalSector = sectorid; sector->physicalTrack = Layout::remapTrackLogicalToPhysical(track); sector->physicalHead = side; - sector->physicalSector = trackLayout.logicalSectorToPhysical(sectorid); _sectors[key] = sector; return sector; } diff --git a/lib/imagereader/imagereader.proto b/lib/imagereader/imagereader.proto index 4be287e6..510bf225 100644 --- a/lib/imagereader/imagereader.proto +++ b/lib/imagereader/imagereader.proto @@ -16,8 +16,13 @@ message FdiInputProto {} message D88InputProto {} message NFDInputProto {} +// NEXT_TAG: 14 message ImageReaderProto { optional string filename = 1 [(help) = "filename of input sector image"]; + optional bool filesystem_sector_order = 13 [ + (help) = "read/write sector image in filesystem order", + default = false ]; + oneof format { ImgInputOutputProto img = 2; DiskCopyInputProto diskcopy = 3; diff --git a/lib/imagereader/imgimagereader.cc b/lib/imagereader/imgimagereader.cc index 57226a79..ff6cdd49 100644 --- a/lib/imagereader/imgimagereader.cc +++ b/lib/imagereader/imgimagereader.cc @@ -40,7 +40,7 @@ public: break; auto& trackLayout = Layout::getLayoutOfTrack(track, side); - for (int sectorId : trackLayout.logicalSectors) + for (int sectorId : trackLayout.logicalSectorOrder) { Bytes data(trackLayout.sectorSize); inputFile.read((char*)data.begin(), data.size()); diff --git a/lib/imagewriter/imagewriter.cc b/lib/imagewriter/imagewriter.cc index 2493ebe2..0d5aba0a 100644 --- a/lib/imagewriter/imagewriter.cc +++ b/lib/imagewriter/imagewriter.cc @@ -89,10 +89,9 @@ void ImageWriter::writeCsv(const Image& image, const std::string& filename) f << "\"Physical track\"," "\"Physical side\"," - "\"Physical sector\"," + "\"Logical sector\"," "\"Logical track\"," "\"Logical side\"," - "\"Logical sector\"," "\"Clock (ns)\"," "\"Header start (ns)\"," "\"Header end (ns)\"," @@ -105,13 +104,12 @@ void ImageWriter::writeCsv(const Image& image, const std::string& filename) for (const auto& sector : image) { - f << fmt::format("{},{},{},{},{},{},{},{},{},{},{},{},{},{}\n", + f << fmt::format("{},{},{},{},{},{},{},{},{},{},{},{},{}\n", sector->physicalTrack, sector->physicalHead, - sector->physicalSector, + sector->logicalSector, sector->logicalTrack, sector->logicalSide, - sector->logicalSector, sector->clock, sector->headerStartTime, sector->headerEndTime, diff --git a/lib/imagewriter/imgimagewriter.cc b/lib/imagewriter/imgimagewriter.cc index e4f273cb..748027a8 100644 --- a/lib/imagewriter/imgimagewriter.cc +++ b/lib/imagewriter/imgimagewriter.cc @@ -37,7 +37,7 @@ public: int side = p.second; auto& trackLayout = Layout::getLayoutOfTrack(track, side); - for (int sectorId : trackLayout.logicalSectors) + for (int sectorId : trackLayout.logicalSectorOrder) { const auto& sector = image.get(track, side, sectorId); if (sector) diff --git a/lib/layout.cc b/lib/layout.cc index 84ad038d..73789ce6 100644 --- a/lib/layout.cc +++ b/lib/layout.cc @@ -109,9 +109,10 @@ std::vector> Layout::getTrackOrdering( return ordering; } -static void expandSectors(const LayoutProto::SectorsProto& sectorsProto, - std::vector& sectors) +std::vector Layout::expandSectorList(const SectorListProto& sectorsProto) { + std::vector sectors; + if (sectorsProto.has_count()) { if (sectorsProto.sector_size() != 0) @@ -129,6 +130,8 @@ static void expandSectors(const LayoutProto::SectorsProto& sectorsProto, } else Error() << "LAYOUT: no sectors in track!"; + + return sectors; } const Layout& Layout::getLayoutOfTrack(unsigned track, unsigned side) @@ -155,39 +158,20 @@ const Layout& Layout::getLayoutOfTrack(unsigned track, unsigned side) layout->numTracks = config.layout().tracks(); layout->numSides = config.layout().sides(); layout->sectorSize = layoutdata.sector_size(); - expandSectors(layoutdata.physical(), layout->physicalSectors); - if (layoutdata.has_logical()) - expandSectors(layoutdata.logical(), layout->logicalSectorsOnDisk); - else - layout->logicalSectorsOnDisk = layout->physicalSectors; - - if (layout->logicalSectorsOnDisk.size() != - layout->physicalSectors.size()) - Error() << fmt::format( - "LAYOUT: physical and logical sectors lists are different " - "sizes in {}.{}", - track, - side); - - layout->logicalSectors = layout->logicalSectorsOnDisk; - std::sort(layout->logicalSectors.begin(), layout->logicalSectors.end()); - layout->numSectors = layout->logicalSectors.size(); - - if ((layout->numSectors != layout->logicalSectorsOnDisk.size()) || - (layout->numSectors != layout->physicalSectors.size())) - Error() << fmt::format( - "LAYOUT: duplicate sector ID in specification for {}.{}", - track, - side); + layout->diskSectorOrder = expandSectorList(layoutdata.physical()); + layout->logicalSectorOrder = layout->diskSectorOrder; + std::sort(layout->diskSectorOrder.begin(), layout->diskSectorOrder.end()); + layout->numSectors = layout->logicalSectorOrder.size(); } return *layout; } +#if 0 unsigned Layout::physicalSectorToLogical(unsigned physicalSectorId) const { - for (int i = 0; i < physicalSectors.size(); i++) - if (physicalSectors[i] == physicalSectorId) + for (int i = 0; i < diskSectorOrder.size(); i++) + if (diskSectorOrder[i] == physicalSectorId) return logicalSectorsOnDisk[i]; Error() << fmt::format( "LAYOUT: physical sector {} not recognised", physicalSectorId); @@ -198,8 +182,9 @@ unsigned Layout::logicalSectorToPhysical(unsigned logicalSectorId) const { for (int i = 0; i < logicalSectorsOnDisk.size(); i++) if (logicalSectorsOnDisk[i] == logicalSectorId) - return physicalSectors[i]; + return diskSectorOrder[i]; Error() << fmt::format( "LAYOUT: logical sector {} not recognised", logicalSectorId); throw nullptr; } +#endif diff --git a/lib/layout.h b/lib/layout.h index 59d2eeb6..60cfd68e 100644 --- a/lib/layout.h +++ b/lib/layout.h @@ -3,6 +3,8 @@ #include "lib/flux.h" +class SectorListProto; + class Layout { public: @@ -40,6 +42,9 @@ public: static const Layout& getLayoutOfTrack( unsigned logicalTrack, unsigned logicalHead); + /* Expand a SectorList into the actual sector IDs. */ + static std::vector expandSectorList(const SectorListProto& sectorsProto); + public: unsigned numTracks; unsigned numSides; @@ -47,16 +52,10 @@ public: unsigned sectorSize; /* Physical sector IDs in disk order. */ - std::vector physicalSectors; + std::vector diskSectorOrder; - /* Logical sector IDs in disk order. */ - std::vector logicalSectorsOnDisk; - - /* Logical sector IDs in filesystem order. */ - std::vector logicalSectors; - - unsigned physicalSectorToLogical(unsigned sectorId) const; - unsigned logicalSectorToPhysical(unsigned sectorId) const; + /* Physical sector IDs in dlogical order. */ + std::vector logicalSectorOrder; }; #endif diff --git a/lib/layout.proto b/lib/layout.proto index 29a75765..261656f3 100644 --- a/lib/layout.proto +++ b/lib/layout.proto @@ -2,6 +2,18 @@ syntax = "proto2"; import "lib/common.proto"; +message SectorListProto +{ + /* either */ + repeated int32 sector = 1 [ (help) = "sector ID" ]; + + /* or */ + optional int32 start_sector = 2 + [ (help) = "first sector of a continuous run" ]; + optional int32 count = 3 + [ (help) = "number of sectors in a continuous run" ]; +} + message LayoutProto { enum Order @@ -11,18 +23,6 @@ message LayoutProto HCS = 2; } - message SectorsProto - { - /* either */ - repeated int32 sector = 1 [ (help) = "sector ID" ]; - - /* or */ - optional int32 start_sector = 2 - [ (help) = "first sector of a continuous run" ]; - optional int32 count = 3 - [ (help) = "number of sectors in a continuous run" ]; - } - message LayoutdataProto { optional int32 track = 1 @@ -35,9 +35,9 @@ message LayoutProto optional int32 sector_size = 3 [ default = 512, (help) = "number of bytes per sector" ]; - optional SectorsProto physical = 4 + optional SectorListProto physical = 4 [ (help) = "physical order of sectors on disk" ]; - optional SectorsProto logical = 6 + optional SectorListProto logical = 6 [ (help) = "logical order of sectors in filesystem" ]; } diff --git a/lib/sector.h b/lib/sector.h index 4d2b2e88..eaaf2946 100644 --- a/lib/sector.h +++ b/lib/sector.h @@ -38,7 +38,6 @@ public: nanoseconds_t dataEndTime = 0; unsigned physicalTrack = 0; unsigned physicalHead = 0; - unsigned physicalSector = 0; unsigned logicalTrack = 0; unsigned logicalSide = 0; unsigned logicalSector = 0; diff --git a/lib/vfs/amigaffs.cc b/lib/vfs/amigaffs.cc index bcd85984..aabcdc4c 100644 --- a/lib/vfs/amigaffs.cc +++ b/lib/vfs/amigaffs.cc @@ -91,7 +91,7 @@ public: dev.devType = DEVTYPE_FLOPDD; dev.cylinders = config.layout().tracks(); dev.heads = config.layout().sides(); - dev.sectors = Layout::getLayoutOfTrack(0, 0).logicalSectors.size(); + dev.sectors = Layout::getLayoutOfTrack(0, 0).numSectors; adfInitDevice(&dev, nullptr, false); int res = adfCreateFlop(&dev, (char*)volumeName.c_str(), 0); if (res != RC_OK) diff --git a/lib/vfs/fluxsectorinterface.cc b/lib/vfs/fluxsectorinterface.cc index 27eb4b6c..41def3fe 100644 --- a/lib/vfs/fluxsectorinterface.cc +++ b/lib/vfs/fluxsectorinterface.cc @@ -70,7 +70,7 @@ public: * a time. */ if (!imageContainsAllSectorsOf( - _changedSectors, track, side, trackLayout.logicalSectors)) + _changedSectors, track, side, trackLayout.logicalSectorOrder)) { /* If we don't have any loaded sectors for this track, pre-read * it. */ @@ -81,7 +81,7 @@ public: /* Now merge the loaded track with the changed one, and write * the result back. */ - for (unsigned sectorId : trackLayout.logicalSectors) + for (unsigned sectorId : trackLayout.logicalSectorOrder) { if (!_changedSectors.contains(track, side, sectorId)) _changedSectors.put(track, side, sectorId)->data = diff --git a/lib/vfs/vfs.cc b/lib/vfs/vfs.cc index e5d30ac8..695c0041 100644 --- a/lib/vfs/vfs.cc +++ b/lib/vfs/vfs.cc @@ -165,11 +165,11 @@ Filesystem::Filesystem(std::shared_ptr sectors): int side = p.second; auto& trackLayout = Layout::getLayoutOfTrack(track, side); - if (trackLayout.logicalSectors.empty()) + if (trackLayout.numSectors == 0) Error() << "FS: filesystem support cannot be used without concrete " "layout information"; - for (int sectorId : trackLayout.logicalSectors) + for (int sectorId : trackLayout.logicalSectorOrder) _locations.push_back(std::make_tuple(track, side, sectorId)); } } diff --git a/lib/vfs/vfs.proto b/lib/vfs/vfs.proto index 6f4be8fe..cc7a0b1f 100644 --- a/lib/vfs/vfs.proto +++ b/lib/vfs/vfs.proto @@ -1,6 +1,7 @@ syntax = "proto2"; import "lib/common.proto"; +import "lib/layout.proto"; message AcornDfsProto { @@ -58,6 +59,7 @@ message CbmfsProto message ProdosProto {} +// NEXT_TAG: 10 message FilesystemProto { oneof filesystem @@ -71,4 +73,6 @@ message FilesystemProto CbmfsProto cbmfs = 7; ProdosProto prodos = 8; } + + optional SectorListProto sector_order = 9 [(help) = "specify the filesystem order of sectors"]; } diff --git a/src/fe-analyselayout.cc b/src/fe-analyselayout.cc index e8992c5d..c6e6c434 100644 --- a/src/fe-analyselayout.cc +++ b/src/fe-analyselayout.cc @@ -97,7 +97,7 @@ void visualiseSectorsToFile(const Image& image, const std::string& filename) for (const auto& sector : image) { if ((sector->physicalHead == side) && (sector->physicalTrack == physicalTrack) - && (sector->physicalSector == alignWithSector)) + && (sector->logicalSector == alignWithSector)) { offset = sector->headerStartTime; if (!offset) @@ -189,20 +189,19 @@ static void readRow(const std::vector& row, Image& image) int logicalTrack = std::stoi(row[3]); int logicalSide = std::stoi(row[4]); - int logicalSector = std::stoi(row[5]); + int logicalSector = std::stoi(row[2]); const auto& sector = image.put(logicalTrack, logicalSide, logicalSector); sector->physicalTrack = std::stoi(row[0]); sector->physicalHead = std::stoi(row[1]); - sector->physicalSector = std::stoi(row[2]); sector->logicalTrack = logicalTrack; sector->logicalSide = logicalSide; sector->logicalSector = logicalSector; - sector->clock = std::stod(row[6]); - sector->headerStartTime = std::stod(row[7]); - sector->headerEndTime = std::stod(row[8]); - sector->dataStartTime = std::stod(row[9]); - sector->dataEndTime = std::stod(row[10]); + sector->clock = std::stod(row[5]); + sector->headerStartTime = std::stod(row[6]); + sector->headerEndTime = std::stod(row[7]); + sector->dataStartTime = std::stod(row[8]); + sector->dataEndTime = std::stod(row[9]); sector->status = status; } catch (const std::invalid_argument& e) diff --git a/src/formats/appledos.textpb b/src/formats/appledos.textpb index 9b87d3c5..e3c8aa8e 100644 --- a/src/formats/appledos.textpb +++ b/src/formats/appledos.textpb @@ -1,25 +1,23 @@ comment: 'Applies standard AppleDOS soft sector skew to the Apple II format' is_extension: true -layout { - layoutdata { - logical { - sector: 0 - sector: 7 - sector: 14 - sector: 6 - sector: 13 - sector: 5 - sector: 12 - sector: 4 - sector: 11 - sector: 3 - sector: 10 - sector: 2 - sector: 9 - sector: 1 - sector: 8 - sector: 15 - } +filesystem { + sector_order { + sector: 0 + sector: 7 + sector: 14 + sector: 6 + sector: 13 + sector: 5 + sector: 12 + sector: 4 + sector: 11 + sector: 3 + sector: 10 + sector: 2 + sector: 9 + sector: 1 + sector: 8 + sector: 15 } } diff --git a/src/formats/prodos.textpb b/src/formats/prodos.textpb index b11bc6d8..517b34de 100644 --- a/src/formats/prodos.textpb +++ b/src/formats/prodos.textpb @@ -2,30 +2,26 @@ comment: 'Applies standard ProDOS soft sector skew to the Apple II format' is_extension: true -layout { - layoutdata { - logical { - sector: 0 - sector: 8 - sector: 1 - sector: 9 - sector: 2 - sector: 10 - sector: 3 - sector: 11 - sector: 4 - sector: 12 - sector: 5 - sector: 13 - sector: 6 - sector: 14 - sector: 7 - sector: 15 - } +filesystem { + prodos {} + + sector_order { + sector: 0 + sector: 8 + sector: 1 + sector: 9 + sector: 2 + sector: 10 + sector: 3 + sector: 11 + sector: 4 + sector: 12 + sector: 5 + sector: 13 + sector: 6 + sector: 14 + sector: 7 + sector: 15 } } -filesystem { - prodos {} -} -