mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Convert all the encoders and imagereaders to the new scheme.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "crc.h"
|
||||
#include "sectorset.h"
|
||||
#include "writer.h"
|
||||
#include "image.h"
|
||||
#include "arch/amiga/amiga.pb.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
|
||||
@@ -105,7 +106,7 @@ public:
|
||||
_config(config.amiga()) {}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
if ((physicalTrack < 0) || (physicalTrack >= AMIGA_TRACKS_PER_DISK))
|
||||
return std::unique_ptr<Fluxmap>();
|
||||
@@ -119,7 +120,7 @@ public:
|
||||
|
||||
for (int sectorId=0; sectorId<AMIGA_SECTORS_PER_TRACK; sectorId++)
|
||||
{
|
||||
const auto& sectorData = allSectors.get(physicalTrack, physicalSide, sectorId);
|
||||
const auto* sectorData = image.get(physicalTrack, physicalSide, sectorId);
|
||||
write_sector(bits, cursor, sectorData);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "crc.h"
|
||||
#include "sectorset.h"
|
||||
#include "writer.h"
|
||||
#include "image.h"
|
||||
#include "arch/brother/brother.pb.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
|
||||
@@ -137,7 +138,7 @@ public:
|
||||
{}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
int logicalTrack;
|
||||
if (physicalSide != 0)
|
||||
@@ -172,7 +173,7 @@ public:
|
||||
double dataMs = headerMs + postHeaderSpacingMs;
|
||||
unsigned dataCursor = dataMs*1e3 / clockRateUs;
|
||||
|
||||
const auto& sectorData = allSectors.get(logicalTrack, 0, sectorId);
|
||||
const auto* sectorData = image.get(logicalTrack, 0, sectorId);
|
||||
|
||||
fillBitmapTo(bits, cursor, headerCursor, { true, false });
|
||||
write_sector_header(bits, cursor, logicalTrack, sectorId);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "sectorset.h"
|
||||
#include "sector.h"
|
||||
#include "writer.h"
|
||||
#include "image.h"
|
||||
#include "fmt/format.h"
|
||||
#include "arch/c64/c64.pb.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
@@ -212,7 +213,7 @@ public:
|
||||
{}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
/* The format ID Character # 1 and # 2 are in the .d64 image only present
|
||||
* in track 18 sector zero which contains the BAM info in byte 162 and 163.
|
||||
@@ -221,7 +222,7 @@ public:
|
||||
* contains the BAM.
|
||||
*/
|
||||
|
||||
const auto& sectorData = allSectors.get(C64_BAM_TRACK*2, 0, 0); //Read de BAM to get the DISK ID bytes
|
||||
const auto* sectorData = image.get(C64_BAM_TRACK*2, 0, 0); //Read de BAM to get the DISK ID bytes
|
||||
if (sectorData)
|
||||
{
|
||||
ByteReader br(sectorData->data);
|
||||
@@ -247,7 +248,7 @@ public:
|
||||
unsigned writtenSectors = 0;
|
||||
for (int sectorId=0; sectorId<numSectors; sectorId++)
|
||||
{
|
||||
const auto& sectorData = allSectors.get(physicalTrack, physicalSide, sectorId);
|
||||
const auto* sectorData = image.get(physicalTrack, physicalSide, sectorId);
|
||||
if (sectorData)
|
||||
{
|
||||
writeSector(bits, cursor, sectorData);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "crc.h"
|
||||
#include "sectorset.h"
|
||||
#include "writer.h"
|
||||
#include "image.h"
|
||||
#include "arch/ibm/ibm.pb.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
#include "fmt/format.h"
|
||||
@@ -110,7 +111,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
IbmEncoderProto::TrackdataProto trackdata;
|
||||
getTrackFormat(trackdata, physicalTrack, physicalSide);
|
||||
@@ -175,7 +176,7 @@ public:
|
||||
writeFillerBytes(trackdata.gap3(), gapFill);
|
||||
first = false;
|
||||
|
||||
const auto& sectorData = allSectors.get(physicalTrack, physicalSide, sectorId);
|
||||
const auto* sectorData = image.get(physicalTrack, physicalSide, sectorId);
|
||||
if (!sectorData)
|
||||
{
|
||||
/* If there are any missing sectors, this is an empty track. */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "crc.h"
|
||||
#include "sectorset.h"
|
||||
#include "writer.h"
|
||||
#include "image.h"
|
||||
#include "fmt/format.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
#include "arch/macintosh/macintosh.pb.h"
|
||||
@@ -209,7 +210,7 @@ public:
|
||||
{}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
if ((physicalTrack < 0) || (physicalTrack >= MAC_TRACKS_PER_DISK))
|
||||
return std::unique_ptr<Fluxmap>();
|
||||
@@ -225,7 +226,7 @@ public:
|
||||
unsigned numSectors = sectorsForTrack(physicalTrack);
|
||||
for (int sectorId=0; sectorId<numSectors; sectorId++)
|
||||
{
|
||||
const auto& sectorData = allSectors.get(physicalTrack, physicalSide, sectorId);
|
||||
const auto* sectorData = image.get(physicalTrack, physicalSide, sectorId);
|
||||
write_sector(bits, cursor, sectorData);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "bytes.h"
|
||||
#include "decoders/decoders.h"
|
||||
#include "encoders/encoders.h"
|
||||
#include "image.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
|
||||
#define GAP_FILL_SIZE_SD 30
|
||||
@@ -108,7 +109,7 @@ public:
|
||||
_config(config.northstar())
|
||||
{}
|
||||
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
int bitsPerRevolution = 100000;
|
||||
double clockRateUs = 4.00;
|
||||
@@ -116,7 +117,7 @@ public:
|
||||
if ((physicalTrack < 0) || (physicalTrack >= 35))
|
||||
return std::unique_ptr<Fluxmap>();
|
||||
|
||||
const auto& sector = allSectors.get(physicalTrack, physicalSide, 0);
|
||||
const auto* sector = image.get(physicalTrack, physicalSide, 0);
|
||||
|
||||
if (sector->data.size() == NORTHSTAR_PAYLOAD_SIZE_SD) {
|
||||
bitsPerRevolution /= 2; // FM
|
||||
@@ -129,7 +130,7 @@ public:
|
||||
|
||||
for (int sectorId = 0; sectorId < 10; sectorId++)
|
||||
{
|
||||
const auto& sectorData = allSectors.get(physicalTrack, physicalSide, sectorId);
|
||||
const auto* sectorData = image.get(physicalTrack, physicalSide, sectorId);
|
||||
write_sector(bits, cursor, sectorData);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "crc.h"
|
||||
#include "sectorset.h"
|
||||
#include "writer.h"
|
||||
#include "image.h"
|
||||
#include "arch/tids990/tids990.pb.h"
|
||||
#include "lib/encoders/encoders.pb.h"
|
||||
#include <fmt/format.h>
|
||||
@@ -60,7 +61,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const SectorSet& allSectors)
|
||||
std::unique_ptr<Fluxmap> encode(int physicalTrack, int physicalSide, const Image& image)
|
||||
{
|
||||
double clockRateUs = 1e3 / _config.clock_rate_khz() / 2.0;
|
||||
int bitsPerRevolution = (_config.track_length_ms() * 1000.0) / clockRateUs;
|
||||
@@ -80,7 +81,7 @@ public:
|
||||
writeBytes(_config.gap3_bytes(), 0x55);
|
||||
first = false;
|
||||
|
||||
const auto& sectorData = allSectors.get(physicalTrack, physicalSide, sectorId);
|
||||
const auto* sectorData = image.get(physicalTrack, physicalSide, sectorId);
|
||||
if (!sectorData)
|
||||
Error() << fmt::format("format tried to find sector {} which wasn't in the input file", sectorId);
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#ifndef ENCODERS_H
|
||||
#define ENCODERS_H
|
||||
|
||||
class FluxSource;
|
||||
class Fluxmap;
|
||||
class SectorSet;
|
||||
class EncoderProto;
|
||||
class Image;
|
||||
|
||||
class AbstractEncoder
|
||||
{
|
||||
@@ -15,7 +14,7 @@ public:
|
||||
|
||||
public:
|
||||
virtual std::unique_ptr<Fluxmap> encode(
|
||||
int physicalTrack, int physicalSide, const SectorSet& allSectors) = 0;
|
||||
int physicalCylinder, int physicalHead, const Image& image) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
11
lib/image.h
11
lib/image.h
@@ -3,10 +3,11 @@
|
||||
|
||||
struct Geometry
|
||||
{
|
||||
unsigned numTracks;
|
||||
unsigned numSides;
|
||||
unsigned numSectors;
|
||||
unsigned sectorSize;
|
||||
unsigned numTracks = 0;
|
||||
unsigned numSides = 0;
|
||||
unsigned numSectors = 0;
|
||||
unsigned sectorSize = 0;
|
||||
bool irregular = false;
|
||||
};
|
||||
|
||||
class Image
|
||||
@@ -43,7 +44,7 @@ public:
|
||||
const_iterator begin() const { return const_iterator(_sectors.cbegin()); }
|
||||
const_iterator end() const { return const_iterator(_sectors.cend()); }
|
||||
|
||||
void setGeometry(Geometry& geometry) { _geometry = geometry; }
|
||||
void setGeometry(Geometry geometry) { _geometry = geometry; }
|
||||
const Geometry& getGeometry() const { return _geometry; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "fmt/format.h"
|
||||
#include "image.h"
|
||||
#include "proto.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@@ -16,7 +17,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
Image readImage()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
return 17;
|
||||
};
|
||||
|
||||
SectorSet sectors;
|
||||
Image image;
|
||||
for (int track = 0; track < 40; track++)
|
||||
{
|
||||
int numSectors = sectorsPerTrack(track);
|
||||
@@ -62,24 +63,22 @@ public:
|
||||
{
|
||||
for (int sectorId = 0; sectorId < numSectors; sectorId++)
|
||||
{
|
||||
if ((offset < inputFileSize))
|
||||
{ //still data available sector OK
|
||||
br.seek(offset);
|
||||
Sector* sector = image.put(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(physicalCylinder, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = track;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
sector->logicalSector = sectorId;
|
||||
sector->data.writer().append(payload);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{ //no more data in input file. Write sectors with status: DATA_MISSING
|
||||
std::unique_ptr<Sector>& sector = sectors.get(physicalCylinder, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
sector->status = Sector::DATA_MISSING;
|
||||
sector->logicalTrack = track;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
@@ -89,7 +88,9 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
return sectors;
|
||||
|
||||
image.calculateSize();
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "image.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
@@ -16,7 +17,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
Image readImage()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -89,7 +90,7 @@ public:
|
||||
uint32_t dataPtr = 0x54;
|
||||
uint32_t tagPtr = dataPtr + dataSize;
|
||||
|
||||
SectorSet sectors;
|
||||
Image image;
|
||||
for (int track = 0; track < numCylinders; track++)
|
||||
{
|
||||
int numSectors = sectorsPerTrack(track);
|
||||
@@ -105,8 +106,7 @@ public:
|
||||
Bytes tag = br.read(12);
|
||||
tagPtr += 12;
|
||||
|
||||
std::unique_ptr<Sector>& sector = sectors.get(track, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
Sector* sector = image.put(track, head, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalCylinder = track;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
@@ -115,7 +115,15 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
return sectors;
|
||||
|
||||
image.setGeometry({
|
||||
.numTracks = numCylinders,
|
||||
.numSides = numHeads,
|
||||
.numSectors = 12,
|
||||
.sectorSize = 512 + 12,
|
||||
.irregular = true
|
||||
});
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "utils.h"
|
||||
#include "fmt/format.h"
|
||||
#include "proto.h"
|
||||
#include "image.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include <algorithm>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
class SectorSet;
|
||||
class ImageSpec;
|
||||
class ImageReaderProto;
|
||||
class Image;
|
||||
|
||||
class ImageReader
|
||||
{
|
||||
@@ -24,7 +25,7 @@ public:
|
||||
static std::unique_ptr<ImageReader> createNsiImageReader(const ImageReaderProto& config);
|
||||
|
||||
public:
|
||||
virtual SectorSet readImage() = 0;
|
||||
virtual Image readImage() = 0;
|
||||
|
||||
protected:
|
||||
const ImageReaderProto& _config;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "image.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
@@ -47,6 +48,7 @@ static unsigned getModulationandSpeed(uint8_t flags, bool *mfm)
|
||||
|
||||
default:
|
||||
Error() << fmt::format("don't understand IMD disks with this modulation and speed {}", flags);
|
||||
throw 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +90,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
Image readImage()
|
||||
/*
|
||||
IMAGE FILE FORMAT
|
||||
The overall layout of an ImageDisk .IMD image file is:
|
||||
@@ -120,7 +122,7 @@ public:
|
||||
Bytes data;
|
||||
data.writer() += inputFile;
|
||||
ByteReader br(data);
|
||||
SectorSet sectors;
|
||||
Image image;
|
||||
TrackHeader header = {0, 0, 0, 0, 0};
|
||||
|
||||
unsigned n = 0;
|
||||
@@ -191,8 +193,7 @@ public:
|
||||
for (int s = 0; s < header.numSectors; s++)
|
||||
{
|
||||
Bytes sectordata;
|
||||
std::unique_ptr<Sector>& sector = sectors.get(header.track, header.Head, sector_map[s]);
|
||||
sector.reset(new Sector);
|
||||
Sector* sector = image.put(header.track, header.Head, sector_map[s]);
|
||||
//read the status of the sector
|
||||
unsigned int Status_Sector = br.read_8();
|
||||
headerPtr++;
|
||||
@@ -259,6 +260,13 @@ public:
|
||||
}
|
||||
//Write format detected in IMD image to screen to help user set the right write parameters
|
||||
|
||||
image.setGeometry({
|
||||
.numTracks = header.track,
|
||||
.numSides = header.Head + 1U,
|
||||
.numSectors = header.numSectors,
|
||||
.sectorSize = sectorSize
|
||||
});
|
||||
|
||||
size_t headSize = header.numSectors * sectorSize;
|
||||
size_t trackSize = headSize * (header.Head + 1);
|
||||
|
||||
@@ -268,7 +276,7 @@ public:
|
||||
mfm ? "MFM" : "FM",
|
||||
Modulation_Speed, header.numSectors, sectorSize, sector_skew, (header.track+1) * trackSize / 1024);
|
||||
|
||||
return sectors;
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "image.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
@@ -16,13 +17,13 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
Image readImage()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
Error() << "cannot open input file";
|
||||
|
||||
SectorSet sectors;
|
||||
Image image;
|
||||
int trackCount = 0;
|
||||
for (int track = 0; track < _config.img().tracks(); track++)
|
||||
{
|
||||
@@ -40,8 +41,7 @@ public:
|
||||
Bytes data(trackdata.sector_size());
|
||||
inputFile.read((char*) data.begin(), data.size());
|
||||
|
||||
std::unique_ptr<Sector>& sector = sectors.get(physicalCylinder, side, sectorId);
|
||||
sector.reset(new Sector);
|
||||
Sector* sector = image.put(physicalCylinder, side, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = track;
|
||||
sector->physicalCylinder = physicalCylinder;
|
||||
@@ -54,10 +54,12 @@ public:
|
||||
trackCount++;
|
||||
}
|
||||
|
||||
image.calculateSize();
|
||||
const Geometry& geometry = image.getGeometry();
|
||||
std::cout << fmt::format("reading {} tracks, {} sides, {} kB total\n",
|
||||
trackCount, _config.img().sides(),
|
||||
geometry.numTracks, geometry.numSides,
|
||||
inputFile.tellg() / 1024);
|
||||
return sectors;
|
||||
return image;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "image.h"
|
||||
#include "fmt/format.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include <algorithm>
|
||||
@@ -81,7 +82,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
Image readImage()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -90,7 +91,7 @@ public:
|
||||
inputFile.seekg( 0, std::ios::end);
|
||||
unsigned inputFileSize = inputFile.tellg();
|
||||
unsigned headerPtr = 0;
|
||||
SectorSet sectors;
|
||||
Image image;
|
||||
for (;;)
|
||||
{
|
||||
unsigned dataPtr = headerPtr + 2901*3 + 1;
|
||||
@@ -110,8 +111,7 @@ public:
|
||||
inputFile.read((char*) data.begin(), sectorSize);
|
||||
|
||||
unsigned head = !!(header.flags & JV3_SIDE);
|
||||
std::unique_ptr<Sector>& sector = sectors.get(header.track, head, header.sector);
|
||||
sector.reset(new Sector);
|
||||
Sector* sector = image.put(header.track, head, header.sector);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalCylinder = header.track;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
@@ -128,7 +128,8 @@ public:
|
||||
headerPtr = dataPtr;
|
||||
}
|
||||
|
||||
return sectors;
|
||||
image.calculateSize();
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "image.h"
|
||||
#include "fmt/format.h"
|
||||
#include "lib/imagereader/imagereader.pb.h"
|
||||
#include <algorithm>
|
||||
@@ -18,7 +19,7 @@ public:
|
||||
ImageReader(config)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
Image readImage()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
@@ -31,10 +32,10 @@ public:
|
||||
|
||||
std::cout << "NSI: Autodetecting geometry based on file size: " << fsize << std::endl;
|
||||
|
||||
int numCylinders = 35;
|
||||
int numSectors = 10;
|
||||
int numHeads = 2;
|
||||
int sectorSize = 512;
|
||||
unsigned numCylinders = 35;
|
||||
unsigned numSectors = 10;
|
||||
unsigned numHeads = 2;
|
||||
unsigned sectorSize = 512;
|
||||
|
||||
switch (fsize) {
|
||||
case 358400:
|
||||
@@ -64,14 +65,14 @@ public:
|
||||
numCylinders * numHeads * trackSize / 1024)
|
||||
<< std::endl;
|
||||
|
||||
SectorSet sectors;
|
||||
Image image;
|
||||
unsigned sectorFileOffset;
|
||||
|
||||
for (int head = 0; head < numHeads; head++)
|
||||
for (unsigned head = 0; head < numHeads; head++)
|
||||
{
|
||||
for (int track = 0; track < numCylinders; track++)
|
||||
for (unsigned track = 0; track < numCylinders; track++)
|
||||
{
|
||||
for (int sectorId = 0; sectorId < numSectors; sectorId++)
|
||||
for (unsigned sectorId = 0; sectorId < numSectors; sectorId++)
|
||||
{
|
||||
if (head == 0) { /* Head 0 is from track 0-34 */
|
||||
sectorFileOffset = track * trackSize + sectorId * sectorSize;
|
||||
@@ -87,8 +88,7 @@ public:
|
||||
Bytes data(sectorSize);
|
||||
inputFile.read((char*) data.begin(), sectorSize);
|
||||
|
||||
std::unique_ptr<Sector>& sector = sectors.get(track, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
Sector* sector = image.put(track, head, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalCylinder = track;
|
||||
sector->logicalSide = sector->physicalHead = head;
|
||||
@@ -97,7 +97,14 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
return sectors;
|
||||
|
||||
image.setGeometry({
|
||||
.numTracks = numCylinders,
|
||||
.numSides = numHeads,
|
||||
.numSectors = numSectors,
|
||||
.sectorSize = sectorSize
|
||||
});
|
||||
return image;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "record.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "image.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include "proto.h"
|
||||
|
||||
@@ -67,11 +68,11 @@ void fillBitmapTo(std::vector<bool>& bitmap,
|
||||
|
||||
void writeDiskCommand(ImageReader& imageReader, AbstractEncoder& encoder, FluxSink& fluxSink)
|
||||
{
|
||||
SectorSet allSectors = imageReader.readImage();
|
||||
Image image = imageReader.readImage();
|
||||
writeTracks(fluxSink,
|
||||
[&](int physicalTrack, int physicalSide) -> std::unique_ptr<Fluxmap>
|
||||
{
|
||||
return encoder.encode(physicalTrack, physicalSide, allSectors);
|
||||
return encoder.encode(physicalTrack, physicalSide, image);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user