Skip to content

Commit 324e83f

Browse files
committed
D88: Support multiple sector sizes in a single track.
1 parent ef7fd24 commit 324e83f

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

arch/ibm/encoder.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ class IbmEncoder : public AbstractEncoder
215215
bool first = true;
216216
for (const auto& sectorData : sectors)
217217
{
218+
if (image.getGeometry().variableSectorSize)
219+
{
220+
sectorSize = 0;
221+
int s = sectorData->data.size() >> 7;
222+
while (s > 1)
223+
{
224+
s >>= 1;
225+
sectorSize += 1;
226+
}
227+
}
228+
218229
if (!first)
219230
writeFillerRawBytes(trackdata.gap3(), gapFill);
220231
first = false;
@@ -274,6 +285,10 @@ class IbmEncoder : public AbstractEncoder
274285

275286
Bytes truncatedData =
276287
sectorData->data.slice(0, trackdata.sector_size());
288+
if (image.getGeometry().variableSectorSize) {
289+
truncatedData = sectorData->data;
290+
}
291+
277292
bw += truncatedData;
278293
uint16_t crc = crc16(CCITT_POLY, data);
279294
bw.write_be16(crc);

lib/image.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ std::shared_ptr<Sector> Image::put(unsigned track, unsigned side, unsigned secto
3737
return sector;
3838
}
3939

40-
void Image::calculateSize()
40+
void Image::calculateSize(bool variableSectorSize)
4141
{
4242
_geometry = {};
4343
unsigned maxSector = 0;
@@ -53,6 +53,6 @@ void Image::calculateSize()
5353
_geometry.sectorSize = std::max(_geometry.sectorSize, (unsigned)sector->data.size());
5454
}
5555
}
56+
_geometry.variableSectorSize = variableSectorSize;
5657
_geometry.numSectors = maxSector - _geometry.firstSector + 1;
5758
}
58-

lib/image.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct Geometry
99
unsigned numSectors = 0;
1010
unsigned sectorSize = 0;
1111
bool irregular = false;
12+
bool variableSectorSize = false;
1213
};
1314

1415
class Image
@@ -37,7 +38,7 @@ class Image
3738
};
3839

3940
public:
40-
void calculateSize();
41+
void calculateSize(bool variableSectorSize = false);
4142

4243
std::shared_ptr<const Sector> get(unsigned track, unsigned side, unsigned sectorId) const;
4344
std::shared_ptr<Sector> put(unsigned track, unsigned side, unsigned sectorId);

lib/imagereader/d88imagereader.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ class D88ImageReader : public ImageReader
185185
}
186186
}
187187
}
188-
else if (trackSectorSize != sectorSize)
189-
{
190-
Error() << "D88: multiple sector sizes per track are "
191-
"currently unsupported";
192-
}
193188
Bytes data(sectorSize);
194189
inputFile.read((char*)data.begin(), data.size());
195190
inputFile.seekg(dataLength-sectorSize, std::ios_base::cur);
@@ -212,7 +207,7 @@ class D88ImageReader : public ImageReader
212207
}
213208
}
214209

215-
image->calculateSize();
210+
image->calculateSize(true);
216211
const Geometry& geometry = image->getGeometry();
217212
Logger() << fmt::format("D88: read {} tracks, {} sides",
218213
geometry.numTracks,

0 commit comments

Comments
 (0)