From 1d77ba6429ecaf0c758b2aebf76fcbcf2fa1ef1d Mon Sep 17 00:00:00 2001 From: dg Date: Fri, 12 May 2023 22:20:13 +0000 Subject: [PATCH] ImageReaders can now contribute config. --- lib/fluxsource/a2rfluxsource.cc | 10 +++++----- lib/fluxsource/fl2fluxsource.cc | 2 +- lib/fluxsource/fluxsource.h | 22 +++++++++++++--------- lib/fluxsource/scpfluxsource.cc | 2 +- lib/imagereader/d88imagereader.cc | 18 ++++++------------ lib/imagereader/dimimagereader.cc | 6 +++--- lib/imagereader/fdiimagereader.cc | 4 ++-- lib/imagereader/imagereader.h | 9 +++++++++ lib/imagereader/imdimagereader.cc | 6 +++--- lib/imagereader/imgimagereader.cc | 2 +- lib/imagereader/nfdimagereader.cc | 10 +++++----- 11 files changed, 49 insertions(+), 42 deletions(-) diff --git a/lib/fluxsource/a2rfluxsource.cc b/lib/fluxsource/a2rfluxsource.cc index b942fa71..06229bb3 100644 --- a/lib/fluxsource/a2rfluxsource.cc +++ b/lib/fluxsource/a2rfluxsource.cc @@ -78,15 +78,15 @@ public: if (disktype == 1) { /* 5.25" with quarter stepping. */ - _fluxConfig.mutable_drive()->set_tracks(160); - _fluxConfig.mutable_drive()->set_heads(1); - _fluxConfig.mutable_drive()->set_head_width(4); - _fluxConfig.mutable_drive()->set_tpi(48 * 4); + _extraConfig.mutable_drive()->set_tracks(160); + _extraConfig.mutable_drive()->set_heads(1); + _extraConfig.mutable_drive()->set_head_width(4); + _extraConfig.mutable_drive()->set_tpi(48 * 4); } else { /* 3.5". */ - _fluxConfig.mutable_drive()->set_tpi(135); + _extraConfig.mutable_drive()->set_tpi(135); } Bytes stream = findChunk("STRM"); diff --git a/lib/fluxsource/fl2fluxsource.cc b/lib/fluxsource/fl2fluxsource.cc index a7813ff0..26eae5bf 100644 --- a/lib/fluxsource/fl2fluxsource.cc +++ b/lib/fluxsource/fl2fluxsource.cc @@ -37,7 +37,7 @@ public: { _proto = loadFl2File(_config.filename()); - *_fluxConfig.mutable_drive() = _proto.drive(); + *_extraConfig.mutable_drive() = _proto.drive(); } public: diff --git a/lib/fluxsource/fluxsource.h b/lib/fluxsource/fluxsource.h index 3841d9d7..3bcddf77 100644 --- a/lib/fluxsource/fluxsource.h +++ b/lib/fluxsource/fluxsource.h @@ -59,26 +59,30 @@ public: static std::unique_ptr create(const FluxSourceProto& spec); public: - /* Returns any configuration this flux source might be carrying (e.g. tpi - * of the drive which made the capture). */ + /* Returns any configuration this flux source might be carrying (e.g. tpi + * of the drive which made the capture). */ - const ConfigProto& getConfig() const - { return _fluxConfig; } + const ConfigProto& getExtraConfig() const + { + return _extraConfig; + } - /* Read flux from a given track and side. */ + /* Read flux from a given track and side. */ virtual std::unique_ptr readFlux( int track, int side) = 0; - /* Recalibrates; seeks to track 0 and ensures the head is in the right place. */ + /* Recalibrates; seeks to track 0 and ensures the head is in the right + * place. */ virtual void recalibrate() {} - /* Seeks to a given track (without recalibrating). */ + /* Seeks to a given track (without recalibrating). */ virtual void seek(int track) {} - /* Is this real hardware? If so, then flux can be read indefinitely (among other things). */ + /* Is this real hardware? If so, then flux can be read indefinitely (among + * other things). */ virtual bool isHardware() { @@ -86,7 +90,7 @@ public: } protected: - ConfigProto _fluxConfig; + ConfigProto _extraConfig; }; class EmptyFluxSourceIterator : public FluxSourceIterator diff --git a/lib/fluxsource/scpfluxsource.cc b/lib/fluxsource/scpfluxsource.cc index 2e76b631..332d26b6 100644 --- a/lib/fluxsource/scpfluxsource.cc +++ b/lib/fluxsource/scpfluxsource.cc @@ -43,7 +43,7 @@ public: error("input not a SCP file"); int tpi = (_header.flags & SCP_FLAG_96TPI) ? 96 : 48; - _fluxConfig.mutable_drive()->set_tpi(tpi); + _extraConfig.mutable_drive()->set_tpi(tpi); _resolution = 25 * (_header.resolution + 1); int startSide = (_header.heads == 2) ? 1 : 0; diff --git a/lib/imagereader/d88imagereader.cc b/lib/imagereader/d88imagereader.cc index fdd5a6d3..c5ce3783 100644 --- a/lib/imagereader/d88imagereader.cc +++ b/lib/imagereader/d88imagereader.cc @@ -56,27 +56,21 @@ public: inputFile.read((char*)trackTable.begin(), trackTable.size()); ByteReader trackTableReader(trackTable); - if (globalConfig()->encoder().format_case() != - EncoderProto::FormatCase::FORMAT_NOT_SET) - log("D88: overriding configured format"); - - auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); + auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); int clockRate = 500; if (mediaFlag == 0x20) { - log("D88: forcing high density mode"); - globalConfig()->mutable_drive()->set_high_density(true); - globalConfig()->mutable_layout()->set_tpi(96); + _extraConfig.mutable_drive()->set_high_density(true); + _extraConfig.mutable_layout()->set_tpi(96); } else { - log("D88: forcing single/double density mode"); clockRate = 300; - globalConfig()->mutable_drive()->set_high_density(false); - globalConfig()->mutable_layout()->set_tpi(48); + _extraConfig.mutable_drive()->set_high_density(false); + _extraConfig.mutable_layout()->set_tpi(48); } - auto layout = globalConfig()->mutable_layout(); + auto layout = _extraConfig.mutable_layout(); std::unique_ptr image(new Image); for (int track = 0; track < trackTableSize / 4; track++) { diff --git a/lib/imagereader/dimimagereader.cc b/lib/imagereader/dimimagereader.cc index dbb1dd01..d8f5e027 100644 --- a/lib/imagereader/dimimagereader.cc +++ b/lib/imagereader/dimimagereader.cc @@ -91,11 +91,11 @@ public: trackCount++; } - auto layout = globalConfig()->mutable_layout(); + auto layout = _extraConfig.mutable_layout(); if (globalConfig()->encoder().format_case() == EncoderProto::FormatCase::FORMAT_NOT_SET) { - auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); + auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); auto trackdata = ibm->add_trackdata(); trackdata->set_target_clock_period_us(2); @@ -134,7 +134,7 @@ public: break; } - globalConfig()->mutable_decoder()->mutable_ibm(); + _extraConfig.mutable_decoder()->mutable_ibm(); } image->calculateSize(); diff --git a/lib/imagereader/fdiimagereader.cc b/lib/imagereader/fdiimagereader.cc index fcb1c734..8c0813cb 100644 --- a/lib/imagereader/fdiimagereader.cc +++ b/lib/imagereader/fdiimagereader.cc @@ -70,11 +70,11 @@ public: trackCount++; } - auto layout = globalConfig()->mutable_layout(); + auto layout = _extraConfig.mutable_layout(); if (globalConfig()->encoder().format_case() == EncoderProto::FormatCase::FORMAT_NOT_SET) { - auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); + auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); auto trackdata = ibm->add_trackdata(); trackdata->set_target_clock_period_us(2); diff --git a/lib/imagereader/imagereader.h b/lib/imagereader/imagereader.h index adfc761f..c01513db 100644 --- a/lib/imagereader/imagereader.h +++ b/lib/imagereader/imagereader.h @@ -2,9 +2,11 @@ #define IMAGEREADER_H #include "image.h" +#include "lib/config.pb.h" class ImageSpec; class ImageReaderProto; +class ConfigProto; class ImageReader { @@ -40,15 +42,22 @@ public: const ImageReaderProto& config); public: + /* Returns any extra config the image might want to contribute. */ + + const ConfigProto& getContributedConfig() const; + /* Directly reads the image. */ + virtual std::unique_ptr readImage() = 0; /* Reads the image, and then applies any optional mapping to go from * filesystem ordering to disk ordering. */ + std::unique_ptr readMappedImage(); protected: const ImageReaderProto& _config; + ConfigProto _extraConfig; }; #endif diff --git a/lib/imagereader/imdimagereader.cc b/lib/imagereader/imdimagereader.cc index 58636c25..855455b6 100644 --- a/lib/imagereader/imdimagereader.cc +++ b/lib/imagereader/imdimagereader.cc @@ -157,7 +157,7 @@ public: TrackHeader header = {0, 0, 0, 0, 0}; TrackHeader previousheader = {0, 0, 0, 0, 0}; - auto layout = globalConfig()->mutable_layout(); + auto layout = _extraConfig.mutable_layout(); unsigned n = 0; unsigned headerPtr = 0; @@ -259,7 +259,7 @@ public: headerPtr++; } - auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); + auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); auto trackdata = ibm->add_trackdata(); auto layoutdata = layout->add_layoutdata(); @@ -443,7 +443,7 @@ public: } } - if (globalConfig()->encoder().format_case() != + if (_extraConfig.encoder().format_case() != EncoderProto::FormatCase::FORMAT_NOT_SET) log("IMD: overriding configured format"); diff --git a/lib/imagereader/imgimagereader.cc b/lib/imagereader/imgimagereader.cc index 94449731..5644a9a3 100644 --- a/lib/imagereader/imgimagereader.cc +++ b/lib/imagereader/imgimagereader.cc @@ -24,7 +24,7 @@ public: if (!inputFile.is_open()) error("cannot open input file"); - auto layout = globalConfig()->layout(); + const auto& layout = globalConfig()->layout(); if (!layout.tracks() || !layout.sides()) error( "IMG: bad configuration; did you remember to set the " diff --git a/lib/imagereader/nfdimagereader.cc b/lib/imagereader/nfdimagereader.cc index 7347f499..489eb2e0 100644 --- a/lib/imagereader/nfdimagereader.cc +++ b/lib/imagereader/nfdimagereader.cc @@ -49,16 +49,16 @@ public: error("NFD: unsupported number of heads"); } - if (globalConfig()->encoder().format_case() != + if (_extraConfig.encoder().format_case() != EncoderProto::FormatCase::FORMAT_NOT_SET) log("NFD: overriding configured format"); - auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); - auto layout = globalConfig()->mutable_layout(); + auto ibm = _extraConfig.mutable_encoder()->mutable_ibm(); + auto layout = _extraConfig.mutable_layout(); log("NFD: HD 1.2MB mode"); log("NFD: forcing hign density mode"); - globalConfig()->mutable_drive()->set_high_density(true); - globalConfig()->mutable_layout()->set_tpi(96); + _extraConfig.mutable_drive()->set_high_density(true); + _extraConfig.mutable_layout()->set_tpi(96); std::unique_ptr image(new Image); for (int track = 0; track < 163; track++)