mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
We can now decode IBM MFM disks all the way to an image, although with no CRC
checking as yet.
This commit is contained in:
40
lib/image.cc
Normal file
40
lib/image.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "globals.h"
|
||||
#include "image.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void writeSectorsToFile(const std::vector<std::unique_ptr<Sector>>& sectors, const std::string& filename)
|
||||
{
|
||||
/* Count the tracks, sides and sectors. */
|
||||
|
||||
int trackCount = 0;
|
||||
int sideCount = 0;
|
||||
int sectorCount = 0;
|
||||
size_t sectorSize = 0;
|
||||
for (auto& sector : sectors)
|
||||
{
|
||||
trackCount = std::max(sector->track()+1, trackCount);
|
||||
sideCount = std::max(sector->side()+1, sideCount);
|
||||
sectorCount = std::max(sector->sector()+1, sectorCount);
|
||||
sectorSize = std::max(sector->data().size(), sectorSize);
|
||||
}
|
||||
|
||||
size_t sideSize = sectorCount * sectorSize;
|
||||
size_t trackSize = sideSize * sideCount;
|
||||
|
||||
std::cout << fmt::format("{} tracks, {} sides, {} sectors, {} bytes per sector, {} kB total",
|
||||
trackCount, sideCount, sectorCount, sectorSize,
|
||||
trackCount * sideCount * sectorCount * sectorSize / 1024);
|
||||
|
||||
std::ofstream outputFile(filename, std::ios::out | std::ios::binary);
|
||||
if (!outputFile.is_open())
|
||||
Error() << "cannot open output file";
|
||||
|
||||
for (auto& sector : sectors)
|
||||
{
|
||||
outputFile.seekp(sector->track()*trackSize + sector->side()*sideSize + sector->sector()*sectorSize, std::ios::beg);
|
||||
outputFile.write((const char*) §or->data().at(0), sector->data().size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user