Hopefully get the imagereader/imagewriter and IBM encoder/decoders using sector

IDs.
This commit is contained in:
David Given 2021-07-29 00:02:46 +02:00
parent 8b115f8156
commit 29e8c99b4f
34 changed files with 304 additions and 61 deletions

View file

@ -140,7 +140,7 @@ public:
br.read_8(); /* skip ID byte */
_sector->logicalTrack = br.read_8();
_sector->logicalSide = br.read_8();
_sector->logicalSector = br.read_8() - _config.sector_id_base();
_sector->logicalSector = br.read_8();
_currentSectorSize = 1 << (br.read_8() + 7);
uint16_t wantCrc = br.read_be16();
uint16_t gotCrc = crc16(CCITT_POLY, bytes.slice(0, _currentHeaderLength + 5));

View file

@ -208,7 +208,7 @@ public:
bw.write_8(idamUnencoded);
bw.write_8(sectorData->logicalTrack);
bw.write_8(sectorData->logicalSide);
bw.write_8(sectorData->logicalSector + trackdata.start_sector_id());
bw.write_8(sectorData->logicalSector);
bw.write_8(sectorSize);
uint16_t crc = crc16(CCITT_POLY, header);
bw.write_be16(crc);

View file

@ -8,7 +8,6 @@ message IbmDecoderProto {
repeated int32 sector = 1 [(help) = "require these sectors to exist for a good read"];
}
optional int32 sector_id_base = 1 [default = 1, (help) = "ID of first sector"];
optional bool ignore_side_byte = 2 [default = false, (help) = "ignore side byte in sector header"];
optional bool swap_sides = 4 [default = false, (help) = "swap side bytes when reading"];
optional SectorsProto sectors = 5 [(help) = "require these sectors to exist for a good read"];
@ -27,7 +26,6 @@ message IbmEncoderProto {
optional double track_length_ms = 1 [(help) = "length of track"];
optional int32 sector_size = 2 [default=512, (help) = "number of bytes per sector"];
optional bool emit_iam = 3 [default=true, (help) = "whether to emit an IAM record"];
optional int32 start_sector_id = 4 [default=1, (help) = "ID of first sector"];
optional double clock_rate_khz = 5 [(help) = "data clock rate"];
optional bool use_fm = 6 [default=false, (help) = "whether to use FM encoding rather than MFM"];
optional int32 idam_byte = 7 [default=0x5554, (help) = "16-bit raw bit pattern of IDAM byte"];

View file

@ -11,6 +11,7 @@
#include <vector>
#include <set>
#include <cassert>
#include <climits>
#if defined(_WIN32) || defined(__WIN32__)
#include <direct.h>

View file

@ -36,6 +36,7 @@ const std::shared_ptr<Sector>& Image::put(unsigned track, unsigned side, unsigne
void Image::calculateSize()
{
_geometry = {};
unsigned maxSector = 0;
for (const auto& i : _sectors)
{
const auto& sector = i.second;
@ -43,9 +44,11 @@ void Image::calculateSize()
{
_geometry.numTracks = std::max(_geometry.numTracks, (unsigned)sector->logicalTrack+1);
_geometry.numSides = std::max(_geometry.numSides, (unsigned)sector->logicalSide+1);
_geometry.numSectors = std::max(_geometry.numSectors, (unsigned)sector->logicalSector+1);
_geometry.firstSector = std::min(_geometry.firstSector, (unsigned)sector->logicalSector);
maxSector = std::max(maxSector, (unsigned)sector->logicalSector);
_geometry.sectorSize = std::max(_geometry.sectorSize, (unsigned)sector->data.size());
}
}
_geometry.numSectors = maxSector - _geometry.firstSector + 1;
}

View file

@ -5,6 +5,7 @@ struct Geometry
{
unsigned numTracks = 0;
unsigned numSides = 0;
unsigned firstSector = UINT_MAX;
unsigned numSectors = 0;
unsigned sectorSize = 0;
bool irregular = false;

View file

@ -3,12 +3,25 @@ syntax = "proto2";
import "lib/common.proto";
message ImgInputOutputProto {
message SectorsProto {
repeated int32 sector = 1 [(help) = "sector ID"];
}
message SectorRangeProto {
optional int32 start_sector = 1 [default=0, (help) = "first sector ID"];
optional int32 sector_count = 2 [default=1, (help) = "total number of sectors"];
}
message TrackdataProto {
optional int32 track = 1 [(help) = "if present, this format only applies to this track"];
optional int32 side = 2 [(help) = "if present, this format only applies to this side"];
optional int32 sector_size = 3 [default=512, (help) = "number of bytes per sector"];
optional int32 sectors = 4 [(help) = "number of sectors in this track"];
oneof sectors_oneof {
SectorsProto sectors = 4 [(help) = "use a list of sector IDs"];
SectorRangeProto sector_range = 5 [(help) = "use a range of contiguous IDs"];
}
}
repeated TrackdataProto trackdata = 4 [(help) = "per-track format information (repeatable)"];

View file

@ -35,7 +35,7 @@ public:
ImgInputOutputProto::TrackdataProto trackdata;
getTrackFormat(trackdata, track, side);
for (int sectorId = 0; sectorId < trackdata.sectors(); sectorId++)
for (int sectorId : getSectors(trackdata))
{
Bytes data(trackdata.sector_size());
inputFile.read((char*) data.begin(), data.size());
@ -75,6 +75,32 @@ private:
trackdata.MergeFrom(f);
}
}
std::vector<unsigned> getSectors(const ImgInputOutputProto::TrackdataProto& trackdata)
{
std::vector<unsigned> sectors;
switch (trackdata.sectors_oneof_case())
{
case ImgInputOutputProto::TrackdataProto::SectorsOneofCase::kSectors:
{
for (int sectorId : trackdata.sectors().sector())
sectors.push_back(sectorId);
break;
}
case ImgInputOutputProto::TrackdataProto::SectorsOneofCase::kSectorRange:
{
int sectorId = trackdata.sector_range().start_sector();
for (int i=0; i<trackdata.sector_range().sector_count(); i++)
sectors.push_back(sectorId + i);
break;
}
default:
Error() << "no list of sectors provided in track format";
}
return sectors;
}
};
std::unique_ptr<ImageReader> ImageReader::createImgImageReader(

View file

@ -126,8 +126,12 @@ void ImageWriter::printMap(const Image& image)
for (int side = 0; side < geometry.numSides; side++)
{
for (int sectorId = 0; sectorId < geometry.numSectors; sectorId++)
int maxSector = geometry.firstSector + geometry.numSectors - 1;
for (int sectorId = 0; sectorId <= maxSector; sectorId++)
{
if (sectorId < geometry.firstSector)
continue;
std::cout << fmt::format("{}.{:2} ", side, sectorId);
for (int track = 0; track < geometry.numTracks; track++)
{

View file

@ -34,10 +34,17 @@ public:
ImgInputOutputProto::TrackdataProto trackdata;
getTrackFormat(trackdata, track, side);
int numSectors = trackdata.has_sectors() ? trackdata.sectors() : geometry.numSectors;
auto sectors = getSectors(trackdata);
if (sectors.empty())
{
int maxSector = geometry.firstSector + geometry.numSectors - 1;
for (int i=geometry.firstSector; i<=maxSector; i++)
sectors.push_back(i);
}
int sectorSize = trackdata.has_sector_size() ? trackdata.sector_size() : geometry.sectorSize;
for (int sectorId = 0; sectorId < numSectors; sectorId++)
for (int sectorId : sectors)
{
const auto& sector = image.get(track, side, sectorId);
if (sector)
@ -67,6 +74,29 @@ private:
trackdata.MergeFrom(f);
}
}
std::vector<unsigned> getSectors(const ImgInputOutputProto::TrackdataProto& trackdata)
{
std::vector<unsigned> sectors;
switch (trackdata.sectors_oneof_case())
{
case ImgInputOutputProto::TrackdataProto::SectorsOneofCase::kSectors:
{
for (int sectorId : trackdata.sectors().sector())
sectors.push_back(sectorId);
break;
}
case ImgInputOutputProto::TrackdataProto::SectorsOneofCase::kSectorRange:
{
int sectorId = trackdata.sector_range().start_sector();
for (int i=0; i<trackdata.sector_range().sector_count(); i++)
sectors.push_back(sectorId + i);
break;
}
}
return sectors;
}
};
std::unique_ptr<ImageWriter> ImageWriter::createImgImageWriter(

View file

@ -2,13 +2,17 @@ comment: 'Acorn ADFS L/D/E/F 640kB/800kB/1600kB 3.5" or 5.25" 80-track DS (ro)'
image_writer {
filename: "acornadfs.img"
img {}
img {
trackdata {
sector_range {
start_sector: 0
}
}
}
}
decoder {
ibm {
sector_id_base: 0
}
ibm {}
}
cylinders {

View file

@ -2,13 +2,17 @@ comment: 'Acorn DFS 100kB/200kB 3.5" or 5.25" 40- or 80-track SS (ro)'
image_writer {
filename: "acorndfs.img"
img {}
img {
trackdata {
sector_range {
start_sector: 0
}
}
}
}
decoder {
ibm {
sector_id_base: 0
}
ibm {}
}
cylinders {

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 11
sector_size: 512
sector_range {
start_sector: 1
sector_count: 11
}
}
}
}
@ -19,7 +22,10 @@ image_writer {
sides: 2
trackdata {
sector_size: 512
sectors: 11
sector_range {
start_sector: 1
sector_count: 11
}
}
}
}

View file

@ -2,13 +2,17 @@ comment: 'Ampro 400kB/800kB 5.25" 40/80 track SSDD/DSDD (ro)'
image_writer {
filename: "ampro.img"
img {}
img {
trackdata {
sector_range {
start_sector: 17
}
}
}
}
decoder {
ibm {
sector_id_base: 17
}
ibm {}
}
cylinders {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 80
sides: 1
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
image_writer {
filename: "atarist360.st"
img {}
img {
tracks: 80
sides: 1
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 82
sides: 1
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
image_writer {
filename: "atarist370.st"
img {}
img {
tracks: 82
sides: 1
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 80
sides: 1
trackdata {
sectors: 10
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
image_writer {
filename: "atarist400.st"
img {}
img {
tracks: 80
sides: 1
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 82
sides: 1
trackdata {
sectors: 10
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
image_writer {
filename: "atarist410.st"
img {}
img {
tracks: 82
sides: 1
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
image_writer {
filename: "atarist720.st"
img {}
img {
tracks: 80
sides: 2
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 82
sides: 2
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
image_writer {
filename: "atarist740.st"
img {}
img {
tracks: 82
sides: 2
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 9
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 10
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
image_writer {
filename: "atarist800.st"
img {}
img {
tracks: 80
sides: 2
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
encoder {

View file

@ -6,15 +6,28 @@ image_reader {
tracks: 82
sides: 2
trackdata {
sectors: 10
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
image_writer {
filename: "atarist820.st"
img {}
img {
tracks: 82
sides: 2
trackdata {
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
encoder {

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 39
sides: 1
trackdata {
sectors: 12
sector_size: 256
sector_range {
start_sector: 0
sector_count: 12
}
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 78
sides: 1
trackdata {
sectors: 12
sector_size: 256
sector_range {
start_sector: 0
sector_count: 12
}
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 10
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}
@ -18,8 +21,11 @@ image_writer {
tracks: 80
sides: 2
trackdata {
sectors: 10
sector_size: 512
sector_range {
start_sector: 0
sector_count: 10
}
}
}
}

View file

@ -6,20 +6,29 @@ image_writer {
tracks: 77
sides: 2
trackdata {
sectors: 16
sector_size: 512
sector_range {
start_sector: 1
sector_count: 16
}
}
trackdata {
track: 0
side: 0
sectors: 26
sector_size: 128
sector_range {
start_sector: 1
sector_count: 26
}
}
trackdata {
track: 0
side: 1
sectors: 26
sector_size: 256
sector_range {
start_sector: 1
sector_count: 26
}
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 77
sides: 2
trackdata {
sectors: 5
sector_size: 1024
sector_range {
start_sector: 0
sector_count: 5
}
}
}
}

View file

@ -18,8 +18,11 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 15
sector_size: 512
sector_range {
start_sector: 1
sector_count: 15
}
}
}
}
@ -35,7 +38,6 @@ encoder {
track_length_ms: 167
clock_rate_khz: 500
sectors {
sector: 0
sector: 1
sector: 2
sector: 3
@ -50,6 +52,7 @@ encoder {
sector: 12
sector: 13
sector: 14
sector: 15
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 18
sector_size: 512
sector_range {
start_sector: 1
sector_count: 18
}
}
}
}
@ -23,7 +26,6 @@ encoder {
track_length_ms: 200
clock_rate_khz: 500
sectors {
sector: 0
sector: 1
sector: 2
sector: 3
@ -41,6 +43,7 @@ encoder {
sector: 15
sector: 16
sector: 17
sector: 18
}
}
}

View file

@ -7,8 +7,11 @@ image_reader {
sides: 1
physical_step: 2
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 1
sector_count: 9
}
}
}
}
@ -24,7 +27,6 @@ encoder {
track_length_ms: 167
clock_rate_khz: 300
sectors {
sector: 0
sector: 1
sector: 2
sector: 3
@ -33,6 +35,7 @@ encoder {
sector: 6
sector: 7
sector: 8
sector: 9
}
}
}

View file

@ -7,8 +7,11 @@ image_reader {
sides: 2
physical_step: 2
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 1
sector_count: 9
}
}
}
}
@ -24,7 +27,6 @@ encoder {
track_length_ms: 167
clock_rate_khz: 300
sectors {
sector: 0
sector: 1
sector: 2
sector: 3
@ -33,6 +35,7 @@ encoder {
sector: 6
sector: 7
sector: 8
sector: 9
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 1
sector_count: 9
}
}
}
}
@ -23,7 +26,6 @@ encoder {
track_length_ms: 200
clock_rate_khz: 250
sectors {
sector: 0
sector: 1
sector: 2
sector: 3
@ -32,6 +34,7 @@ encoder {
sector: 6
sector: 7
sector: 8
sector: 9
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 80
sides: 2
trackdata {
sectors: 9
sector_size: 512
sector_range {
start_sector: 1
sector_count: 9
}
}
}
}
@ -23,7 +26,6 @@ encoder {
track_length_ms: 167
clock_rate_khz: 300
sectors {
sector: 0
sector: 1
sector: 2
sector: 3
@ -32,6 +34,7 @@ encoder {
sector: 6
sector: 7
sector: 8
sector: 9
}
}
}

View file

@ -6,8 +6,11 @@ image_reader {
tracks: 77
sides: 2
trackdata {
sectors: 26
sector_size: 288
sector_range {
start_sector: 0
sector_count: 26
}
}
}
}