mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Attach the underlying raw records to Sector structures; add a .raw exporter for
getting the MFM/FM/GCR stream.
This commit is contained in:
73
lib/imagewriter/rawimagewriter.cc
Normal file
73
lib/imagewriter/rawimagewriter.cc
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "sector.h"
|
||||
#include "imagewriter/imagewriter.h"
|
||||
#include "fmt/format.h"
|
||||
#include "decoders/decoders.h"
|
||||
#include "image.h"
|
||||
#include "arch/northstar/northstar.h"
|
||||
#include "lib/imagewriter/imagewriter.pb.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
class RawImageWriter : public ImageWriter
|
||||
{
|
||||
public:
|
||||
RawImageWriter(const ImageWriterProto& config):
|
||||
ImageWriter(config)
|
||||
{}
|
||||
|
||||
void writeImage(const Image& image)
|
||||
{
|
||||
const Geometry& geometry = image.getGeometry();
|
||||
|
||||
size_t trackSize = geometry.numSectors * geometry.sectorSize;
|
||||
|
||||
if (geometry.numTracks * trackSize == 0) {
|
||||
std::cout << "RAW: no sectors in output; skipping image file generation." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << fmt::format("RAW: writing {} cylinders, {} sides\n",
|
||||
geometry.numTracks, geometry.numSides);
|
||||
|
||||
std::ofstream outputFile(_config.filename(), std::ios::out | std::ios::binary);
|
||||
if (!outputFile.is_open())
|
||||
Error() << "RAW: cannot open output file";
|
||||
|
||||
unsigned sectorFileOffset;
|
||||
for (int track = 0; track < geometry.numTracks * geometry.numSides; track++)
|
||||
{
|
||||
int side = (track < geometry.numTracks) ? 0 : 1;
|
||||
|
||||
std::vector<std::shared_ptr<Record>> records;
|
||||
for (int sectorId = 0; sectorId < geometry.numSectors; sectorId++)
|
||||
{
|
||||
const auto& sector = image.get(track % geometry.numTracks, side, sectorId);
|
||||
if (sector)
|
||||
records.insert(records.end(), sector->records.begin(), sector->records.end());
|
||||
}
|
||||
|
||||
std::sort(records.begin(), records.end(),
|
||||
[&](std::shared_ptr<Record> left, std::shared_ptr<Record> right) {
|
||||
return left->startTime < right->startTime;
|
||||
});
|
||||
|
||||
for (const auto& record : records)
|
||||
{
|
||||
record->rawData.writeTo(outputFile);
|
||||
Bytes(3).writeTo(outputFile);
|
||||
}
|
||||
Bytes(1).writeTo(outputFile);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
std::unique_ptr<ImageWriter> ImageWriter::createRawImageWriter(
|
||||
const ImageWriterProto& config)
|
||||
{
|
||||
return std::unique_ptr<ImageWriter>(new RawImageWriter(config));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user