mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Add pluggable image readers, plus some documentation.
This commit is contained in:
38
lib/image.cc
38
lib/image.cc
@@ -4,48 +4,16 @@
|
||||
#include "dataspec.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "imagewriter/imagewriter.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void readSectorsFromFile(SectorSet& sectors, const ImageSpec& spec)
|
||||
SectorSet readSectorsFromFile(const ImageSpec& spec)
|
||||
{
|
||||
std::ifstream inputFile(spec.filename, std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
Error() << "cannot open input file";
|
||||
|
||||
size_t headSize = spec.sectors * spec.bytes;
|
||||
size_t trackSize = headSize * spec.heads;
|
||||
|
||||
std::cout << fmt::format("{} tracks, {} heads, {} sectors, {} bytes per sector, {} kB total",
|
||||
spec.cylinders, spec.heads,
|
||||
spec.sectors, spec.bytes,
|
||||
spec.cylinders * trackSize / 1024)
|
||||
<< std::endl;
|
||||
|
||||
for (int track = 0; track < spec.cylinders; track++)
|
||||
{
|
||||
for (int head = 0; head < spec.heads; head++)
|
||||
{
|
||||
for (int sectorId = 0; sectorId < spec.sectors; sectorId++)
|
||||
{
|
||||
inputFile.seekg(track*trackSize + head*headSize + sectorId*spec.bytes, std::ios::beg);
|
||||
|
||||
Bytes data(spec.bytes);
|
||||
inputFile.read((char*) data.begin(), spec.bytes);
|
||||
|
||||
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 = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ImageReader::create(spec)->readImage();
|
||||
}
|
||||
|
||||
void writeSectorsToFile(const SectorSet& sectors, const ImageSpec& spec)
|
||||
|
||||
Reference in New Issue
Block a user