mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
#include "lib/core/globals.h"
|
|
#include "lib/config/config.h"
|
|
#include "lib/config/flags.h"
|
|
#include "lib/data/sector.h"
|
|
#include "lib/imagewriter/imagewriter.h"
|
|
#include "lib/data/image.h"
|
|
#include "lib/config/proto.h"
|
|
#include "lib/config/config.pb.h"
|
|
#include "lib/data/layout.h"
|
|
#include "lib/config/layout.pb.h"
|
|
#include "lib/core/logger.h"
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
class ImgImageWriter : public ImageWriter
|
|
{
|
|
public:
|
|
ImgImageWriter(const ImageWriterProto& config): ImageWriter(config) {}
|
|
|
|
void writeImage(const Image& image) override
|
|
{
|
|
const Geometry geometry = image.getGeometry();
|
|
|
|
auto& layout = globalConfig()->layout();
|
|
int tracks =
|
|
layout.has_tracks() ? layout.tracks() : geometry.numCylinders;
|
|
int sides = layout.has_sides() ? layout.sides() : geometry.numHeads;
|
|
|
|
std::ofstream outputFile(
|
|
_config.filename(), std::ios::out | std::ios::binary);
|
|
if (!outputFile.is_open())
|
|
error("cannot open output file");
|
|
|
|
const auto diskLayout = createDiskLayout();
|
|
bool in_filesystem_order = _config.img().filesystem_sector_order();
|
|
|
|
for (auto& logicalLocation :
|
|
in_filesystem_order ? diskLayout->logicalLocationsInFilesystemOrder
|
|
: diskLayout->logicalLocations)
|
|
{
|
|
auto& ltl = diskLayout->layoutByLogicalLocation.at(logicalLocation);
|
|
|
|
for (unsigned sectorId : in_filesystem_order
|
|
? ltl->filesystemSectorOrder
|
|
: ltl->naturalSectorOrder)
|
|
{
|
|
const auto& sector = image.get(
|
|
logicalLocation.cylinder, logicalLocation.head, sectorId);
|
|
if (sector)
|
|
sector->data.slice(0, ltl->sectorSize).writeTo(outputFile);
|
|
else
|
|
outputFile.seekp(ltl->sectorSize, std::ios::cur);
|
|
}
|
|
}
|
|
|
|
log("IMG: wrote {} tracks, {} sides, {} kB total to {}",
|
|
tracks,
|
|
sides,
|
|
outputFile.tellp() / 1024,
|
|
_config.filename());
|
|
}
|
|
};
|
|
|
|
std::unique_ptr<ImageWriter> ImageWriter::createImgImageWriter(
|
|
const ImageWriterProto& config)
|
|
{
|
|
return std::unique_ptr<ImageWriter>(new ImgImageWriter(config));
|
|
}
|