mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Added some checks on sector status
This commit is contained in:
@@ -22,9 +22,16 @@ public:
|
||||
if (!inputFile.is_open())
|
||||
Error() << "cannot open input file";
|
||||
|
||||
inputFile.seekg(0, inputFile.beg);
|
||||
uint32_t begin = inputFile.tellg();
|
||||
inputFile.seekg(0, inputFile.end);
|
||||
uint32_t end = inputFile.tellg();
|
||||
uint32_t inputFileSize = (end-begin);
|
||||
inputFile.seekg(0, inputFile.beg);
|
||||
Bytes data;
|
||||
data.writer() += inputFile;
|
||||
ByteReader br(data);
|
||||
|
||||
unsigned numCylinders = 39;
|
||||
unsigned numHeads = 1;
|
||||
unsigned numSectors = 0;
|
||||
@@ -54,17 +61,31 @@ public:
|
||||
{
|
||||
for (int sectorId = 0; sectorId < numSectors; sectorId++)
|
||||
{
|
||||
br.seek(offset);
|
||||
Bytes payload = br.read(256);
|
||||
offset += 256;
|
||||
std::cout << "reading D64 image\n"
|
||||
<< fmt::format("{} cylinders, {} heads, {} sectors\n",
|
||||
track, head, sectorId);
|
||||
if ((offset < inputFileSize))
|
||||
{ //still data available sector OK
|
||||
br.seek(offset);
|
||||
Bytes payload = br.read(256);
|
||||
offset += 256;
|
||||
|
||||
std::unique_ptr<Sector>& sector = sectors.get(track, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalTrack = track;
|
||||
sector->logicalSide = sector->physicalSide = head;
|
||||
sector->logicalSector = sectorId;
|
||||
sector->data.writer().append(payload);
|
||||
std::unique_ptr<Sector>& sector = sectors.get(track, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalTrack = track;
|
||||
sector->logicalSide = sector->physicalSide = head;
|
||||
sector->logicalSector = sectorId;
|
||||
sector->data.writer().append(payload);
|
||||
} else
|
||||
{ //no more data in input file. Write sectors with status: DATA_MISSING
|
||||
std::unique_ptr<Sector>& sector = sectors.get(track, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
sector->status = Sector::DATA_MISSING;
|
||||
sector->logicalTrack = sector->physicalTrack = track;
|
||||
sector->logicalSide = sector->physicalSide = head;
|
||||
sector->logicalSector = sectorId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user