Skip to content

Commit

Permalink
D88: Support multiple sector sizes in a single track.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdaede committed Aug 18, 2022
1 parent ef7fd24 commit 324e83f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
15 changes: 15 additions & 0 deletions arch/ibm/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ class IbmEncoder : public AbstractEncoder
bool first = true;
for (const auto& sectorData : sectors)
{
if (image.getGeometry().variableSectorSize)
{
sectorSize = 0;
int s = sectorData->data.size() >> 7;
while (s > 1)
{
s >>= 1;
sectorSize += 1;
}
}

if (!first)
writeFillerRawBytes(trackdata.gap3(), gapFill);
first = false;
Expand Down Expand Up @@ -274,6 +285,10 @@ class IbmEncoder : public AbstractEncoder

Bytes truncatedData =
sectorData->data.slice(0, trackdata.sector_size());
if (image.getGeometry().variableSectorSize) {
truncatedData = sectorData->data;
}

bw += truncatedData;
uint16_t crc = crc16(CCITT_POLY, data);
bw.write_be16(crc);
Expand Down
4 changes: 2 additions & 2 deletions lib/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::shared_ptr<Sector> Image::put(unsigned track, unsigned side, unsigned secto
return sector;
}

void Image::calculateSize()
void Image::calculateSize(bool variableSectorSize)
{
_geometry = {};
unsigned maxSector = 0;
Expand All @@ -53,6 +53,6 @@ void Image::calculateSize()
_geometry.sectorSize = std::max(_geometry.sectorSize, (unsigned)sector->data.size());
}
}
_geometry.variableSectorSize = variableSectorSize;
_geometry.numSectors = maxSector - _geometry.firstSector + 1;
}

3 changes: 2 additions & 1 deletion lib/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct Geometry
unsigned numSectors = 0;
unsigned sectorSize = 0;
bool irregular = false;
bool variableSectorSize = false;
};

class Image
Expand Down Expand Up @@ -37,7 +38,7 @@ class Image
};

public:
void calculateSize();
void calculateSize(bool variableSectorSize = false);

std::shared_ptr<const Sector> get(unsigned track, unsigned side, unsigned sectorId) const;
std::shared_ptr<Sector> put(unsigned track, unsigned side, unsigned sectorId);
Expand Down
7 changes: 1 addition & 6 deletions lib/imagereader/d88imagereader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ class D88ImageReader : public ImageReader
}
}
}
else if (trackSectorSize != sectorSize)
{
Error() << "D88: multiple sector sizes per track are "
"currently unsupported";
}
Bytes data(sectorSize);
inputFile.read((char*)data.begin(), data.size());
inputFile.seekg(dataLength-sectorSize, std::ios_base::cur);
Expand All @@ -212,7 +207,7 @@ class D88ImageReader : public ImageReader
}
}

image->calculateSize();
image->calculateSize(true);
const Geometry& geometry = image->getGeometry();
Logger() << fmt::format("D88: read {} tracks, {} sides",
geometry.numTracks,
Expand Down

0 comments on commit 324e83f

Please sign in to comment.