Skip to content

Commit 2470c5e

Browse files
committed
WIP: Add solved/reconstructed fluxmap support.
This proof of concept adds an optional encoder and fluxsink that runs after the image is written. This currently exposes the config of the solvedEncoder, though I think I ultimately don't want it to be exposed as part of the config proto. Another way to do this would be by extending the decoders and/or directly reading their records. That is actually closer to what I want in many ways, however those records would need to be deduplicated from multiple reads, etc. The ultimate goal is to exactly replicate the timing of the original sectors, but with a stable clock, sectors reread if a bad read happens, and garbage between sectors removed. This requires extending the sector struct to have more information than it currently holds.
1 parent e733dc9 commit 2470c5e

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

lib/config.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import "lib/drive.proto";
1111
import "lib/mapper.proto";
1212
import "lib/common.proto";
1313

14-
// NEXT_TAG: 17
14+
// NEXT_TAG: 19
1515
message ConfigProto {
1616
optional string comment = 8;
1717
optional bool is_extension = 13;
@@ -21,9 +21,11 @@ message ConfigProto {
2121

2222
optional FluxSourceProto flux_source = 10;
2323
optional FluxSinkProto flux_sink = 11;
24+
optional FluxSinkProto solved_flux = 17;
2425
optional DriveProto drive = 15;
2526

2627
optional EncoderProto encoder = 3;
28+
optional EncoderProto solved_encoder = 18;
2729
optional DecoderProto decoder = 4;
2830
optional UsbProto usb = 5;
2931

lib/encoders/encoders.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include "arch/tids990/tids990.h"
1414
#include "arch/victor9k/victor9k.h"
1515
#include "lib/encoders/encoders.pb.h"
16+
#include "lib/decoders/decoders.pb.h"
17+
#include "arch/ibm/ibm.pb.h"
18+
#include "lib/image.h"
1619
#include "protocol.h"
1720

1821
std::unique_ptr<AbstractEncoder> AbstractEncoder::create(
@@ -40,6 +43,37 @@ std::unique_ptr<AbstractEncoder> AbstractEncoder::create(
4043
return (encoder->second)(config);
4144
}
4245

46+
std::unique_ptr<AbstractEncoder> AbstractEncoder::createFromImage(EncoderProto& encoderConfig,
47+
const DecoderProto& decoderConfig, const Image& image)
48+
{
49+
IbmEncoderProto* ibm;
50+
Geometry geometry;
51+
IbmEncoderProto::TrackdataProto* trackdata;
52+
IbmEncoderProto::TrackdataProto::SectorRangeProto* sector_range;
53+
switch (decoderConfig.format_case()) {
54+
case DecoderProto::kIbm:
55+
ibm = encoderConfig.mutable_ibm();
56+
geometry = image.getGeometry();
57+
trackdata = ibm->mutable_trackdata()->Add();
58+
sector_range = trackdata->mutable_sector_range();
59+
sector_range->set_min_sector(geometry.firstSector);
60+
sector_range->set_max_sector(geometry.firstSector + geometry.numSectors);
61+
trackdata->set_gap0(0x1b);
62+
trackdata->set_gap2(0x09);
63+
trackdata->set_gap3(0x1b);
64+
trackdata->set_target_clock_period_us(1e3/250);
65+
trackdata->set_target_rotational_period_ms(200);
66+
trackdata->set_sector_size(256);
67+
return createIbmEncoder(encoderConfig);
68+
break;
69+
default:
70+
Error() << "Solved fluxmap not supported for this decoder";
71+
break;
72+
}
73+
74+
return NULL;
75+
}
76+
4377
Fluxmap& Fluxmap::appendBits(const std::vector<bool>& bits, nanoseconds_t clock)
4478
{
4579
nanoseconds_t now = duration();

lib/encoders/encoders.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define ENCODERS_H
33

44
class EncoderProto;
5+
class DecoderProto;
56
class Fluxmap;
67
class Image;
78
class Location;
@@ -14,6 +15,8 @@ class AbstractEncoder
1415
virtual ~AbstractEncoder() {}
1516

1617
static std::unique_ptr<AbstractEncoder> create(const EncoderProto& config);
18+
static std::unique_ptr<AbstractEncoder> createFromImage(EncoderProto& encoderConfig,
19+
const DecoderProto& decoderConfig, const Image& image);
1720

1821
public:
1922
virtual std::vector<std::shared_ptr<const Sector>> collectSectors(

lib/readerwriter.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,19 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
470470
}
471471

472472
void readDiskCommand(
473-
FluxSource& fluxsource, AbstractDecoder& decoder, ImageWriter& writer)
473+
FluxSource& fluxsource, AbstractDecoder& decoder, ImageWriter& writer,FluxSink* solvedFlux)
474474
{
475475
auto diskflux = readDiskCommand(fluxsource, decoder);
476476

477477
writer.printMap(*diskflux->image);
478478
if (config.decoder().has_write_csv_to())
479479
writer.writeCsv(*diskflux->image, config.decoder().write_csv_to());
480480
writer.writeImage(*diskflux->image);
481+
if (config.has_solved_flux()) {
482+
std::unique_ptr<AbstractEncoder> solvedEncoder = AbstractEncoder::createFromImage(*config.mutable_encoder(),
483+
config.decoder(), *diskflux->image);
484+
writeTracks(*solvedFlux, *solvedEncoder, *diskflux->image);
485+
}
481486
}
482487

483488
void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink)

lib/readerwriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern std::unique_ptr<TrackDataFlux> readAndDecodeTrack(
3434
FluxSource& source, AbstractDecoder& decoder, unsigned track, unsigned head);
3535

3636
extern std::shared_ptr<const DiskFlux> readDiskCommand(FluxSource& fluxsource, AbstractDecoder& decoder);
37-
extern void readDiskCommand(FluxSource& source, AbstractDecoder& decoder, ImageWriter& writer);
37+
extern void readDiskCommand(FluxSource& source, AbstractDecoder& decoder, ImageWriter& writer, FluxSink* solvedFlux);
3838
extern void rawReadDiskCommand(FluxSource& source, FluxSink& sink);
3939

4040
#endif

src/fe-read.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "readerwriter.h"
44
#include "fluxmap.h"
55
#include "decoders/decoders.h"
6+
#include "encoders/encoders.h"
67
#include "macintosh/macintosh.h"
78
#include "sector.h"
89
#include "proto.h"
@@ -45,6 +46,15 @@ static StringFlag copyFluxTo(
4546
FluxSink::updateConfigForFilename(config.mutable_decoder()->mutable_copy_flux_to(), value);
4647
});
4748

49+
static StringFlag solvedFlux(
50+
{ "-r", "--solved" },
51+
"after reading, write a reconstructed/solved fluxmap to this file",
52+
"",
53+
[](const auto& value)
54+
{
55+
FluxSink::updateConfigForFilename(config.mutable_solved_flux(), value);
56+
});
57+
4858
static StringFlag srcTracks(
4959
{ "--cylinders", "-c" },
5060
"tracks to read from",
@@ -76,8 +86,12 @@ int mainRead(int argc, const char* argv[])
7686
std::unique_ptr<FluxSource> fluxSource(FluxSource::create(config.flux_source()));
7787
std::unique_ptr<AbstractDecoder> decoder(AbstractDecoder::create(config.decoder()));
7888
std::unique_ptr<ImageWriter> writer(ImageWriter::create(config.image_writer()));
89+
std::unique_ptr<FluxSink> solvedFlux;
90+
std::unique_ptr<AbstractEncoder> solvedEncoder;
91+
if (config.has_solved_flux()) {
92+
solvedFlux = FluxSink::create(config.solved_flux()); }
7993

80-
readDiskCommand(*fluxSource, *decoder, *writer);
94+
readDiskCommand(*fluxSource, *decoder, *writer, solvedFlux.get());
8195

8296
return 0;
8397
}

0 commit comments

Comments
 (0)