Migrate to a new global config object.

This commit is contained in:
dg
2023-05-10 23:13:33 +00:00
parent 9ba3f90f1e
commit 42e6c11081
49 changed files with 287 additions and 248 deletions

View File

@@ -1,6 +1,7 @@
LIBFLUXENGINE_SRCS = \
lib/bitmap.cc \
lib/bytes.cc \
lib/config.cc \
lib/crc.cc \
lib/csvreader.cc \
lib/decoders/decoders.cc \

25
lib/config.cc Normal file
View File

@@ -0,0 +1,25 @@
#include "lib/globals.h"
#include "lib/config.h"
#include "lib/proto.h"
static Config config;
Config& globalConfig()
{
return config;
}
ConfigProto* Config::operator->() const
{
return &globalConfigProto();
}
Config::operator ConfigProto*() const
{
return &globalConfigProto();
}
Config::operator ConfigProto&() const
{
return globalConfigProto();
}

14
lib/config.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
class ConfigProto;
class Config
{
public:
ConfigProto* operator -> () const;
operator ConfigProto* () const;
operator ConfigProto& () const;
};
extern Config& globalConfig();

View File

@@ -12,7 +12,7 @@ FluxmapReader::FluxmapReader(const Fluxmap& fluxmap):
_fluxmap(fluxmap),
_bytes(fluxmap.ptr()),
_size(fluxmap.bytes()),
_config(globalConfig().decoder())
_config(globalConfig()->decoder())
{
rewind();
}
@@ -133,7 +133,7 @@ FluxPattern::FluxPattern(unsigned bits, uint64_t pattern): _bits(bits)
bool FluxPattern::matches(const unsigned* end, FluxMatch& match) const
{
const double clockDecodeThreshold =
globalConfig().decoder().bit_error_threshold();
globalConfig()->decoder().bit_error_threshold();
const unsigned* start = end - _intervals.size();
unsigned candidatelength = std::accumulate(start, end - _lowzero, 0);
if (!candidatelength)

View File

@@ -48,7 +48,7 @@ nanoseconds_t Encoder::calculatePhysicalClockPeriod(
nanoseconds_t targetClockPeriod, nanoseconds_t targetRotationalPeriod)
{
nanoseconds_t currentRotationalPeriod =
globalConfig().drive().rotational_period_ms() * 1e6;
globalConfig()->drive().rotational_period_ms() * 1e6;
if (currentRotationalPeriod == 0)
error(
"you must set --drive.rotational_period_ms as it can't be "

View File

@@ -26,12 +26,12 @@ static void upgradeFluxFile(FluxFileProto& proto)
proto.set_version(FluxFileVersion::VERSION_2);
}
if (proto.version() == FluxFileVersion::VERSION_2)
{
proto.mutable_drive()->set_rotational_period_ms(
proto.rotational_period_ms());
if (proto.version() == FluxFileVersion::VERSION_2)
{
proto.mutable_drive()->set_rotational_period_ms(
proto.rotational_period_ms());
proto.set_version(FluxFileVersion::VERSION_3);
}
}
if (proto.version() > FluxFileVersion::VERSION_3)
error(

View File

@@ -52,7 +52,7 @@ void FlagGroup::applyOption(const OptionProto& option)
log("OPTION: {}",
option.has_message() ? option.message() : option.comment());
globalConfig().MergeFrom(option.config());
globalConfig()->MergeFrom(option.config());
}
bool FlagGroup::applyOption(const std::string& optionName)
@@ -70,10 +70,10 @@ bool FlagGroup::applyOption(const std::string& optionName)
return false;
};
if (searchOptionList(globalConfig().option()))
if (searchOptionList(globalConfig()->option()))
return true;
for (const auto& optionGroup : globalConfig().option_group())
for (const auto& optionGroup : globalConfig()->option_group())
{
if (searchOptionList(optionGroup.option()))
return true;
@@ -213,7 +213,7 @@ std::vector<std::string> FlagGroup::parseFlagsWithFilenames(int argc,
/* Apply any default options in groups. */
for (auto& group : globalConfig().option_group())
for (auto& group : globalConfig()->option_group())
{
const OptionProto* defaultOption = &*group.option().begin();
bool isSet = false;
@@ -232,7 +232,7 @@ std::vector<std::string> FlagGroup::parseFlagsWithFilenames(int argc,
/* Next, any standalone options. */
for (auto& option : globalConfig().option())
for (auto& option : globalConfig()->option())
{
if (options.find(option.name()) != options.end())
{
@@ -249,7 +249,7 @@ std::vector<std::string> FlagGroup::parseFlagsWithFilenames(int argc,
for (auto [k, v] : overrides)
{
ProtoField protoField = resolveProtoPath(&globalConfig(), k);
ProtoField protoField = resolveProtoPath(globalConfig(), k);
setProtoFieldFromString(protoField, v);
}
@@ -296,7 +296,7 @@ ConfigProto FlagGroup::parseSingleConfigFile(const std::string& filename,
ConfigProto config;
if (!google::protobuf::TextFormat::MergeFromString(
ss.str(), &globalConfig()))
ss.str(), globalConfig()))
error("couldn't load external config proto");
return config;
}
@@ -305,7 +305,7 @@ ConfigProto FlagGroup::parseSingleConfigFile(const std::string& filename,
void FlagGroup::parseConfigFile(const std::string& filename,
const std::map<std::string, const ConfigProto*>& configFiles)
{
globalConfig().MergeFrom(parseSingleConfigFile(filename, configFiles));
globalConfig()->MergeFrom(parseSingleConfigFile(filename, configFiles));
}
void FlagGroup::checkInitialised() const
@@ -377,7 +377,7 @@ static void doShowConfig()
static void doDoc()
{
const auto fields = findAllProtoFields(&globalConfig());
const auto fields = findAllProtoFields(globalConfig());
for (const auto field : fields)
{
const std::string& path = field.first;

View File

@@ -24,7 +24,7 @@ namespace
bool singlesided(void)
{
return globalConfig().heads().start() == globalConfig().heads().end();
return globalConfig()->heads().start() == globalConfig()->heads().end();
}
class A2RFluxSink : public FluxSink
@@ -38,8 +38,8 @@ namespace
log("A2R: writing A2R {} file containing {} tracks\n",
singlesided() ? "single sided" : "double sided",
globalConfig().tracks().end() -
globalConfig().tracks().start() + 1);
globalConfig()->tracks().end() -
globalConfig()->tracks().start() + 1);
time_t now{std::time(nullptr)};
auto t = gmtime(&now);

View File

@@ -43,7 +43,7 @@ public:
track->add_flux(fluxBytes);
}
proto.mutable_drive()->MergeFrom(globalConfig().drive());
proto.mutable_drive()->MergeFrom(globalConfig()->drive());
saveFl2File(_filename, proto);
}

View File

@@ -74,7 +74,7 @@ void FluxSink::updateConfigForFilename(
[](auto& s, auto* proto)
{
proto->set_type(FluxSinkProto::DRIVE);
globalConfig().mutable_drive()->set_drive(std::stoi(s));
globalConfig()->mutable_drive()->set_drive(std::stoi(s));
}},
};

View File

@@ -22,9 +22,9 @@ public:
public:
void writeFlux(int track, int side, const Fluxmap& fluxmap) override
{
usbSetDrive(globalConfig().drive().drive(),
globalConfig().drive().high_density(),
globalConfig().drive().index_mode());
usbSetDrive(globalConfig()->drive().drive(),
globalConfig()->drive().high_density(),
globalConfig()->drive().index_mode());
#if 0
if (fluxSourceSinkFortyTrack)
{
@@ -41,7 +41,7 @@ public:
operator std::string() const
{
return fmt::format("drive {}", globalConfig().drive().drive());
return fmt::format("drive {}", globalConfig()->drive().drive());
}
private:

View File

@@ -55,7 +55,7 @@ public:
_fileheader.start_track = strackno(minTrack, minSide);
_fileheader.end_track = strackno(maxTrack, maxSide);
_fileheader.flags = SCP_FLAG_INDEXED;
if (globalConfig().drive().tpi() != 48)
if (globalConfig()->drive().tpi() != 48)
_fileheader.flags |= SCP_FLAG_96TPI;
_fileheader.cell_width = 0;
if ((minSide == 0) && (maxSide == 0))

View File

@@ -78,15 +78,15 @@ public:
if (disktype == 1)
{
/* 5.25" with quarter stepping. */
::globalConfig().mutable_drive()->set_tracks(160);
::globalConfig().mutable_drive()->set_heads(1);
::globalConfig().mutable_drive()->set_head_width(4);
::globalConfig().mutable_drive()->set_tpi(48 * 4);
::globalConfig()->mutable_drive()->set_tracks(160);
::globalConfig()->mutable_drive()->set_heads(1);
::globalConfig()->mutable_drive()->set_head_width(4);
::globalConfig()->mutable_drive()->set_tpi(48 * 4);
}
else
{
/* 3.5". */
::globalConfig().mutable_drive()->set_tpi(135);
::globalConfig()->mutable_drive()->set_tpi(135);
}
Bytes stream = findChunk("STRM");

View File

@@ -37,10 +37,10 @@ public:
{
_proto = loadFl2File(_config.filename());
if (::globalConfig().has_drive())
if (::globalConfig()->has_drive())
warning(
"FLUX: overriding drive configuration with flux file contents");
::globalConfig().mutable_drive()->MergeFrom(_proto.drive());
::globalConfig()->mutable_drive()->MergeFrom(_proto.drive());
}
public:

View File

@@ -102,7 +102,7 @@ void FluxSource::updateConfigForFilename(
[](auto& s, auto* proto)
{
proto->set_type(FluxSourceProto::DRIVE);
globalConfig().mutable_drive()->set_drive(std::stoi(s));
globalConfig()->mutable_drive()->set_drive(std::stoi(s));
}},
{std::regex("^flx:(.*)$"),
[](auto& s, auto* proto)

View File

@@ -29,14 +29,14 @@ private:
std::unique_ptr<const Fluxmap> next()
{
usbSetDrive(globalConfig().drive().drive(),
globalConfig().drive().high_density(),
globalConfig().drive().index_mode());
usbSetDrive(globalConfig()->drive().drive(),
globalConfig()->drive().high_density(),
globalConfig()->drive().index_mode());
usbSeek(_track);
Bytes data = usbRead(_head,
globalConfig().drive().sync_with_index(),
globalConfig().drive().revolutions() *
globalConfig()->drive().sync_with_index(),
globalConfig()->drive().revolutions() *
_fluxsource._oneRevolution,
_fluxsource._hardSectorThreshold);
auto fluxmap = std::make_unique<Fluxmap>();

View File

@@ -43,8 +43,8 @@ public:
error("input not a SCP file");
int tpi = (_header.flags & SCP_FLAG_96TPI) ? 96 : 48;
if (!::globalConfig().drive().has_tpi())
::globalConfig().mutable_drive()->set_tpi(tpi);
if (!::globalConfig()->drive().has_tpi())
::globalConfig()->mutable_drive()->set_tpi(tpi);
_resolution = 25 * (_header.resolution + 1);
int startSide = (_header.heads == 2) ? 1 : 0;

View File

@@ -13,7 +13,6 @@ double getCurrentTime(void)
void warning(const std::string msg)
{
log(msg);
fmt::print("Warning: {}\n", msg);
log(msg);
fmt::print("Warning: {}\n", msg);
}

View File

@@ -60,4 +60,6 @@ inline void warning(fmt::string_view fstr, const Args&... args)
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
#include "lib/config.h"
#endif

View File

@@ -56,27 +56,27 @@ public:
inputFile.read((char*)trackTable.begin(), trackTable.size());
ByteReader trackTableReader(trackTable);
if (globalConfig().encoder().format_case() !=
if (globalConfig()->encoder().format_case() !=
EncoderProto::FormatCase::FORMAT_NOT_SET)
log("D88: overriding configured format");
auto ibm = globalConfig().mutable_encoder()->mutable_ibm();
auto ibm = globalConfig()->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);
globalConfig()->mutable_drive()->set_high_density(true);
globalConfig()->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);
globalConfig()->mutable_drive()->set_high_density(false);
globalConfig()->mutable_layout()->set_tpi(48);
}
auto layout = globalConfig().mutable_layout();
auto layout = globalConfig()->mutable_layout();
std::unique_ptr<Image> image(new Image);
for (int track = 0; track < trackTableSize / 4; track++)
{

View File

@@ -91,11 +91,11 @@ public:
trackCount++;
}
auto layout = globalConfig().mutable_layout();
if (globalConfig().encoder().format_case() ==
auto layout = globalConfig()->mutable_layout();
if (globalConfig()->encoder().format_case() ==
EncoderProto::FormatCase::FORMAT_NOT_SET)
{
auto ibm = globalConfig().mutable_encoder()->mutable_ibm();
auto ibm = globalConfig()->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();
globalConfig()->mutable_decoder()->mutable_ibm();
}
image->calculateSize();

View File

@@ -70,11 +70,11 @@ public:
trackCount++;
}
auto layout = globalConfig().mutable_layout();
if (globalConfig().encoder().format_case() ==
auto layout = globalConfig()->mutable_layout();
if (globalConfig()->encoder().format_case() ==
EncoderProto::FormatCase::FORMAT_NOT_SET)
{
auto ibm = globalConfig().mutable_encoder()->mutable_ibm();
auto ibm = globalConfig()->mutable_encoder()->mutable_ibm();
auto trackdata = ibm->add_trackdata();
trackdata->set_target_clock_period_us(2);

View File

@@ -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 = globalConfig()->mutable_layout();
unsigned n = 0;
unsigned headerPtr = 0;
@@ -259,7 +259,7 @@ public:
headerPtr++;
}
auto ibm = globalConfig().mutable_encoder()->mutable_ibm();
auto ibm = globalConfig()->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 (globalConfig()->encoder().format_case() !=
EncoderProto::FormatCase::FORMAT_NOT_SET)
log("IMD: overriding configured format");

View File

@@ -24,7 +24,7 @@ public:
if (!inputFile.is_open())
error("cannot open input file");
auto layout = globalConfig().layout();
auto layout = globalConfig()->layout();
if (!layout.tracks() || !layout.sides())
error(
"IMG: bad configuration; did you remember to set the "

View File

@@ -49,16 +49,16 @@ public:
error("NFD: unsupported number of heads");
}
if (globalConfig().encoder().format_case() !=
if (globalConfig()->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 = globalConfig()->mutable_encoder()->mutable_ibm();
auto layout = globalConfig()->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);
globalConfig()->mutable_drive()->set_high_density(true);
globalConfig()->mutable_layout()->set_tpi(96);
std::unique_ptr<Image> image(new Image);
for (int track = 0; track < 163; track++)

View File

@@ -21,7 +21,7 @@ public:
{
const Geometry geometry = image.getGeometry();
auto& layout = globalConfig().layout();
auto& layout = globalConfig()->layout();
int tracks = layout.has_tracks() ? layout.tracks() : geometry.numTracks;
int sides = layout.has_sides() ? layout.sides() : geometry.numSides;

View File

@@ -10,16 +10,16 @@ bool approximatelyEqual(float a, float b, float epsilon)
static unsigned getTrackStep()
{
if (!globalConfig().layout().tpi())
if (!globalConfig()->layout().tpi())
error("no layout TPI set");
if (!globalConfig().drive().tpi())
if (!globalConfig()->drive().tpi())
error("no drive TPI set");
if (globalConfig().layout().tpi() == 0.0)
if (globalConfig()->layout().tpi() == 0.0)
error("layout TPI is zero; this shouldn't happen?");
float trackStepFactor =
globalConfig().drive().tpi() / globalConfig().layout().tpi();
globalConfig()->drive().tpi() / globalConfig()->layout().tpi();
if (!approximatelyEqual(trackStepFactor, round(trackStepFactor), 0.001))
error(
@@ -34,37 +34,37 @@ static unsigned getTrackStep()
unsigned Layout::remapTrackPhysicalToLogical(unsigned ptrack)
{
return (ptrack - globalConfig().drive().head_bias()) / getTrackStep();
return (ptrack - globalConfig()->drive().head_bias()) / getTrackStep();
}
unsigned Layout::remapTrackLogicalToPhysical(unsigned ltrack)
{
return globalConfig().drive().head_bias() + ltrack * getTrackStep();
return globalConfig()->drive().head_bias() + ltrack * getTrackStep();
}
unsigned Layout::remapSidePhysicalToLogical(unsigned pside)
{
return pside ^ globalConfig().layout().swap_sides();
return pside ^ globalConfig()->layout().swap_sides();
}
unsigned Layout::remapSideLogicalToPhysical(unsigned lside)
{
return lside ^ globalConfig().layout().swap_sides();
return lside ^ globalConfig()->layout().swap_sides();
}
std::vector<std::shared_ptr<const TrackInfo>> Layout::computeLocations()
{
std::set<unsigned> tracks;
if (globalConfig().has_tracks())
tracks = iterate(globalConfig().tracks());
if (globalConfig()->has_tracks())
tracks = iterate(globalConfig()->tracks());
else
tracks = iterate(0, globalConfig().layout().tracks());
tracks = iterate(0, globalConfig()->layout().tracks());
std::set<unsigned> heads;
if (globalConfig().has_heads())
heads = iterate(globalConfig().heads());
if (globalConfig()->has_heads())
heads = iterate(globalConfig()->heads());
else
heads = iterate(0, globalConfig().layout().sides());
heads = iterate(0, globalConfig()->layout().sides());
std::vector<std::shared_ptr<const TrackInfo>> locations;
for (unsigned logicalTrack : tracks)
@@ -97,7 +97,7 @@ void Layout::getBounds(
std::vector<std::pair<int, int>> Layout::getTrackOrdering(
unsigned guessedTracks, unsigned guessedSides)
{
auto layout = globalConfig().layout();
auto layout = globalConfig()->layout();
int tracks = layout.has_tracks() ? layout.tracks() : guessedTracks;
int sides = layout.has_sides() ? layout.sides() : guessedSides;
@@ -179,7 +179,7 @@ std::shared_ptr<const TrackInfo> Layout::getLayoutOfTrack(
auto trackInfo = std::make_shared<TrackInfo>();
LayoutProto::LayoutdataProto layoutdata;
for (const auto& f : globalConfig().layout().layoutdata())
for (const auto& f : globalConfig()->layout().layoutdata())
{
if (f.has_track() && f.has_up_to_track() &&
((logicalTrack < f.track()) || (logicalTrack > f.up_to_track())))
@@ -193,14 +193,14 @@ std::shared_ptr<const TrackInfo> Layout::getLayoutOfTrack(
layoutdata.MergeFrom(f);
}
trackInfo->numTracks = globalConfig().layout().tracks();
trackInfo->numSides = globalConfig().layout().sides();
trackInfo->numTracks = globalConfig()->layout().tracks();
trackInfo->numSides = globalConfig()->layout().sides();
trackInfo->sectorSize = layoutdata.sector_size();
trackInfo->logicalTrack = logicalTrack;
trackInfo->logicalSide = logicalSide;
trackInfo->physicalTrack = remapTrackLogicalToPhysical(logicalTrack);
trackInfo->physicalSide =
logicalSide ^ globalConfig().layout().swap_sides();
logicalSide ^ globalConfig()->layout().swap_sides();
trackInfo->groupSize = getTrackStep();
trackInfo->diskSectorOrder = expandSectorList(layoutdata.physical());
trackInfo->naturalSectorOrder = trackInfo->diskSectorOrder;

View File

@@ -11,7 +11,7 @@ static ConfigProto config = []()
return config;
}();
ConfigProto& globalConfig()
ConfigProto& globalConfigProto()
{
return config;
}

View File

@@ -28,6 +28,6 @@ extern ConfigProto parseConfigBytes(const std::string_view& bytes);
extern const std::map<std::string, const ConfigProto*> formats;
extern ConfigProto& globalConfig();
extern ConfigProto& globalConfigProto();
#endif

View File

@@ -61,13 +61,13 @@ void measureDiskRotation(
log(BeginSpeedOperationLogMessage());
int retries = 5;
usbSetDrive(globalConfig().drive().drive(),
globalConfig().drive().high_density(),
globalConfig().drive().index_mode());
oneRevolution = globalConfig().drive().rotational_period_ms() * 1e6;
if (globalConfig().drive().hard_sector_count() != 0)
usbSetDrive(globalConfig()->drive().drive(),
globalConfig()->drive().high_density(),
globalConfig()->drive().index_mode());
oneRevolution = globalConfig()->drive().rotational_period_ms() * 1e6;
if (globalConfig()->drive().hard_sector_count() != 0)
hardSectorThreshold = oneRevolution * 3 /
(4 * globalConfig().drive().hard_sector_count());
(4 * globalConfig()->drive().hard_sector_count());
else
hardSectorThreshold = 0;
@@ -77,15 +77,15 @@ void measureDiskRotation(
do
{
oneRevolution = usbGetRotationalPeriod(
globalConfig().drive().hard_sector_count());
if (globalConfig().drive().hard_sector_count() != 0)
globalConfig()->drive().hard_sector_count());
if (globalConfig()->drive().hard_sector_count() != 0)
hardSectorThreshold =
oneRevolution * 3 /
(4 * globalConfig().drive().hard_sector_count());
(4 * globalConfig()->drive().hard_sector_count());
retries--;
} while ((oneRevolution == 0) && (retries > 0));
globalConfig().mutable_drive()->set_rotational_period_ms(
globalConfig()->mutable_drive()->set_rotational_period_ms(
oneRevolution / 1e6);
log(EndOperationLogMessage{});
}
@@ -191,7 +191,7 @@ BadSectorsState combineRecordAndSectors(TrackFlux& trackFlux,
static void adjustTrackOnError(FluxSource& fluxSource, int baseTrack)
{
switch (globalConfig().drive().error_behaviour())
switch (globalConfig()->drive().error_behaviour())
{
case DriveProto::NOTHING:
break;
@@ -217,7 +217,7 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder,
ReadResult result = BAD_AND_CAN_NOT_RETRY;
for (unsigned offset = 0; offset < trackInfo->groupSize;
offset += globalConfig().drive().head_width())
offset += globalConfig()->drive().head_width())
{
auto& fluxSourceIterator = fluxSourceIteratorHolder.getIterator(
trackInfo->physicalTrack + offset, trackInfo->physicalSide);
@@ -228,7 +228,7 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder,
trackInfo->physicalTrack + offset, trackInfo->physicalSide});
std::shared_ptr<const Fluxmap> fluxmap = fluxSourceIterator.next();
// ->rescale(
// 1.0 / globalConfig().flux_source().rescale());
// 1.0 / globalConfig()->flux_source().rescale());
log(EndReadOperationLogMessage());
log("{0} ms in {1} bytes",
(int)(fluxmap->duration() / 1e6),
@@ -240,7 +240,7 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder,
HAS_NO_BAD_SECTORS)
{
result = GOOD_READ;
if (globalConfig().decoder().skip_unnecessary_tracks())
if (globalConfig()->decoder().skip_unnecessary_tracks())
return result;
}
else if (fluxSourceIterator.hasNext())
@@ -267,18 +267,18 @@ void writeTracks(FluxSink& fluxSink,
testForEmergencyStop();
int retriesRemaining = globalConfig().decoder().retries();
int retriesRemaining = globalConfig()->decoder().retries();
for (;;)
{
for (int offset = 0; offset < trackInfo->groupSize;
offset += globalConfig().drive().head_width())
offset += globalConfig()->drive().head_width())
{
unsigned physicalTrack = trackInfo->physicalTrack + offset;
log(BeginWriteOperationLogMessage{
physicalTrack, trackInfo->physicalSide});
if (offset == globalConfig().drive().group_offset())
if (offset == globalConfig()->drive().group_offset())
{
auto fluxmap = producer(trackInfo);
if (!fluxmap)
@@ -454,7 +454,7 @@ std::shared_ptr<TrackFlux> readAndDecodeTrack(FluxSource& fluxSource,
trackFlux->trackInfo = trackInfo;
FluxSourceIteratorHolder fluxSourceIteratorHolder(fluxSource);
int retriesRemaining = globalConfig().decoder().retries();
int retriesRemaining = globalConfig()->decoder().retries();
for (;;)
{
auto result =
@@ -488,9 +488,9 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
FluxSource& fluxSource, Decoder& decoder)
{
std::unique_ptr<FluxSink> outputFluxSink;
if (globalConfig().decoder().has_copy_flux_to())
if (globalConfig()->decoder().has_copy_flux_to())
outputFluxSink =
FluxSink::create(globalConfig().decoder().copy_flux_to());
FluxSink::create(globalConfig()->decoder().copy_flux_to());
auto diskflux = std::make_shared<DiskFlux>();
@@ -516,7 +516,7 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
*data->fluxmap);
}
if (globalConfig().decoder().dump_records())
if (globalConfig()->decoder().dump_records())
{
std::vector<std::shared_ptr<const Record>> sorted_records;
@@ -543,7 +543,7 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
}
}
if (globalConfig().decoder().dump_sectors())
if (globalConfig()->decoder().dump_sectors())
{
auto collected_sectors = collectSectors(trackFlux->sectors, false);
std::vector<std::shared_ptr<const Sector>> sorted_sectors(
@@ -595,9 +595,9 @@ void readDiskCommand(
auto diskflux = readDiskCommand(fluxsource, decoder);
writer.printMap(*diskflux->image);
if (globalConfig().decoder().has_write_csv_to())
if (globalConfig()->decoder().has_write_csv_to())
writer.writeCsv(
*diskflux->image, globalConfig().decoder().write_csv_to());
*diskflux->image, globalConfig()->decoder().write_csv_to());
writer.writeMappedImage(*diskflux->image);
}

View File

@@ -23,9 +23,9 @@ static std::shared_ptr<CandidateDevice> selectDevice()
"no devices found (is one plugged in? Do you have the "
"appropriate permissions?");
if (globalConfig().usb().has_serial())
if (globalConfig()->usb().has_serial())
{
auto wantedSerial = globalConfig().usb().serial();
auto wantedSerial = globalConfig()->usb().serial();
for (auto& c : candidates)
{
if (c->serial == wantedSerial)
@@ -63,10 +63,10 @@ USB* get_usb_impl()
{
/* Special case for certain configurations. */
if (globalConfig().usb().has_greaseweazle() &&
globalConfig().usb().greaseweazle().has_port())
if (globalConfig()->usb().has_greaseweazle() &&
globalConfig()->usb().greaseweazle().has_port())
{
const auto& conf = globalConfig().usb().greaseweazle();
const auto& conf = globalConfig()->usb().greaseweazle();
log("Using GreaseWeazle on serial port {}", conf.port());
return createGreaseWeazleUsb(conf.port(), conf);
}
@@ -85,7 +85,7 @@ USB* get_usb_impl()
candidate->serial,
candidate->serialPort);
return createGreaseWeazleUsb(
candidate->serialPort, globalConfig().usb().greaseweazle());
candidate->serialPort, globalConfig()->usb().greaseweazle());
default:
error("internal");

View File

@@ -88,8 +88,8 @@ public:
dev.readOnly = false;
dev.isNativeDev = true;
dev.devType = DEVTYPE_FLOPDD;
dev.cylinders = globalConfig().layout().tracks();
dev.heads = globalConfig().layout().sides();
dev.cylinders = globalConfig()->layout().tracks();
dev.heads = globalConfig()->layout().sides();
dev.sectors = Layout::getLayoutOfTrack(0, 0)->numSectors;
adfInitDevice(&dev, nullptr, false);
int res = adfCreateFlop(&dev, (char*)volumeName.c_str(), 0);

View File

@@ -126,7 +126,7 @@ class CbmfsFilesystem : public Filesystem
bam.resize(fs->getLogicalSectorCount());
usedBlocks = 0;
unsigned block = 0;
for (int track = 0; track < globalConfig().layout().tracks();
for (int track = 0; track < globalConfig()->layout().tracks();
track++)
{
uint8_t blocks = br.read_8();

View File

@@ -151,7 +151,7 @@ void Filesystem::discardChanges()
Filesystem::Filesystem(std::shared_ptr<SectorInterface> sectors):
_sectors(sectors)
{
auto& layout = globalConfig().layout();
auto& layout = globalConfig()->layout();
if (!layout.has_tracks() || !layout.has_sides())
error(
"FS: filesystem support cannot be used without concrete layout "

View File

@@ -7,16 +7,16 @@ extern const std::map<std::string, const ConfigProto*> formats;
static std::string supportStatus(SupportStatus status)
{
switch (status)
{
case SupportStatus::DINOSAUR:
return "🦖";
switch (status)
{
case SupportStatus::DINOSAUR:
return "🦖";
case SupportStatus::UNICORN:
case SupportStatus::UNICORN:
return "🦄";
}
}
return "";
return "";
}
int main(int argc, const char* argv[])
@@ -24,7 +24,7 @@ int main(int argc, const char* argv[])
fmt::print("<!-- FORMATSSTART -->\n");
fmt::print(
"<!-- This section is automatically generated. Do not edit. -->\n");
fmt::print("\n");
fmt::print("\n");
fmt::print("| Profile | Format | Read? | Write? | Filesystem? |\n");
fmt::print("|:--------|:-------|:-----:|:------:|:------------|\n");

View File

@@ -20,7 +20,7 @@ static StringFlag destFlux({"--dest", "-d"},
[](const auto& value)
{
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), value);
globalConfig()->mutable_flux_sink(), value);
});
static IntFlag destTrack({"--cylinder", "-c"}, "track to write to", 0);
@@ -247,15 +247,15 @@ static void draw_x_graticules(Agg2D& painter,
int mainAnalyseDriveResponse(int argc, const char* argv[])
{
globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, {});
if (globalConfig().flux_sink().type() != FluxSinkProto::DRIVE)
if (globalConfig()->flux_sink().type() != FluxSinkProto::DRIVE)
error("this only makes sense with a real disk drive");
usbSetDrive(globalConfig().drive().drive(),
globalConfig().drive().high_density(),
globalConfig().drive().index_mode());
usbSetDrive(globalConfig()->drive().drive(),
globalConfig()->drive().high_density(),
globalConfig()->drive().index_mode());
usbSeek(destTrack);
std::cout << "Measuring rotational speed...\n";

View File

@@ -19,7 +19,7 @@ static StringFlag sourceFlux({"--source", "-s"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
static IntFlag trackFlag({"--cylinder", "-c"}, "Track to read.", 0);
@@ -132,11 +132,11 @@ static nanoseconds_t guessClock(const Fluxmap& fluxmap)
int mainInspect(int argc, const char* argv[])
{
globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, {});
std::unique_ptr<FluxSource> fluxSource(
FluxSource::create(globalConfig().flux_source()));
FluxSource::create(globalConfig()->flux_source()));
const auto fluxmap = fluxSource->readFlux(trackFlag, headFlag)->next();
std::cout << fmt::format("0x{:x} bytes of data in {:.3f}ms\n",
@@ -220,7 +220,7 @@ int mainInspect(int argc, const char* argv[])
"\n\nAligned bitstream from {:.3f}ms follows:\n",
fmr.tell().ns() / 1000000.0);
FluxDecoder decoder(&fmr, clockPeriod, globalConfig().decoder());
FluxDecoder decoder(&fmr, clockPeriod, globalConfig()->decoder());
while (!fmr.eof())
{
std::cout << fmt::format("{:06x} {: 10.3f} : ",
@@ -245,7 +245,7 @@ int mainInspect(int argc, const char* argv[])
dumpRawFlag.get(),
fmr.tell().ns() / 1000000.0);
FluxDecoder decoder(&fmr, clockPeriod, globalConfig().decoder());
FluxDecoder decoder(&fmr, clockPeriod, globalConfig()->decoder());
for (int i = 0; i < dumpRawFlag; i++)
decoder.readBit();

View File

@@ -23,7 +23,7 @@ static StringFlag sourceFlux({"-s", "--source"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
static StringFlag destFlux({"-d", "--dest"},
@@ -32,7 +32,7 @@ static StringFlag destFlux({"-d", "--dest"},
[](const auto& value)
{
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), value);
globalConfig()->mutable_flux_sink(), value);
});
static StringFlag srcTracks({"--cylinders", "-c"},
@@ -40,7 +40,7 @@ static StringFlag srcTracks({"--cylinders", "-c"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_tracks(), value);
setRange(globalConfig()->mutable_tracks(), value);
});
static StringFlag srcHeads({"--heads", "-h"},
@@ -48,26 +48,26 @@ static StringFlag srcHeads({"--heads", "-h"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_heads(), value);
setRange(globalConfig()->mutable_heads(), value);
});
int mainRawRead(int argc, const char* argv[])
{
setRange(globalConfig().mutable_tracks(), "0-79");
setRange(globalConfig().mutable_heads(), "0-1");
setRange(globalConfig()->mutable_tracks(), "0-79");
setRange(globalConfig()->mutable_heads(), "0-1");
if (argc == 1)
showProfiles("rawread", formats);
globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, formats);
if (globalConfig().flux_sink().type() == FluxSinkProto::DRIVE)
if (globalConfig()->flux_sink().type() == FluxSinkProto::DRIVE)
error("you can't use rawread to write to hardware");
std::unique_ptr<FluxSource> fluxSource(
FluxSource::create(globalConfig().flux_source()));
FluxSource::create(globalConfig()->flux_source()));
std::unique_ptr<FluxSink> fluxSink(
FluxSink::create(globalConfig().flux_sink()));
FluxSink::create(globalConfig()->flux_sink()));
rawReadDiskCommand(*fluxSource, *fluxSink);

View File

@@ -18,7 +18,7 @@ static StringFlag sourceFlux({"--source", "-s"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
static StringFlag destFlux({"--dest", "-d"},
@@ -27,7 +27,7 @@ static StringFlag destFlux({"--dest", "-d"},
[](const auto& value)
{
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), value);
globalConfig()->mutable_flux_sink(), value);
});
static StringFlag destTracks({"--cylinders", "-c"},
@@ -35,7 +35,7 @@ static StringFlag destTracks({"--cylinders", "-c"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_tracks(), value);
setRange(globalConfig()->mutable_tracks(), value);
});
static StringFlag destHeads({"--heads", "-h"},
@@ -43,33 +43,33 @@ static StringFlag destHeads({"--heads", "-h"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_heads(), value);
setRange(globalConfig()->mutable_heads(), value);
});
static ActionFlag eraseFlag({"--erase"},
"erases the destination",
[]()
{
globalConfig().mutable_flux_source()->set_type(FluxSourceProto::ERASE);
globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::ERASE);
});
int mainRawWrite(int argc, const char* argv[])
{
setRange(globalConfig().mutable_tracks(), "0-79");
setRange(globalConfig().mutable_heads(), "0-1");
setRange(globalConfig()->mutable_tracks(), "0-79");
setRange(globalConfig()->mutable_heads(), "0-1");
if (argc == 1)
showProfiles("rawwrite", formats);
globalConfig().mutable_flux_sink()->set_type(FluxSinkProto::DRIVE);
globalConfig()->mutable_flux_sink()->set_type(FluxSinkProto::DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, formats);
if (globalConfig().flux_source().type() == FluxSourceProto::DRIVE)
if (globalConfig()->flux_source().type() == FluxSourceProto::DRIVE)
error("you can't use rawwrite to read from hardware");
std::unique_ptr<FluxSource> fluxSource(
FluxSource::create(globalConfig().flux_source()));
FluxSource::create(globalConfig()->flux_source()));
std::unique_ptr<FluxSink> fluxSink(
FluxSink::create(globalConfig().flux_sink()));
FluxSink::create(globalConfig()->flux_sink()));
writeRawDiskCommand(*fluxSource, *fluxSink);
return 0;

View File

@@ -23,7 +23,7 @@ static StringFlag sourceFlux({"-s", "--source"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
static StringFlag destImage({"-o", "--output"},
@@ -32,7 +32,7 @@ static StringFlag destImage({"-o", "--output"},
[](const auto& value)
{
ImageWriter::updateConfigForFilename(
globalConfig().mutable_image_writer(), value);
globalConfig()->mutable_image_writer(), value);
});
static StringFlag copyFluxTo({"--copy-flux-to"},
@@ -41,7 +41,7 @@ static StringFlag copyFluxTo({"--copy-flux-to"},
[](const auto& value)
{
FluxSink::updateConfigForFilename(
globalConfig().mutable_decoder()->mutable_copy_flux_to(), value);
globalConfig()->mutable_decoder()->mutable_copy_flux_to(), value);
});
static StringFlag srcTracks({"--cylinders", "-c"},
@@ -49,7 +49,7 @@ static StringFlag srcTracks({"--cylinders", "-c"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_tracks(), value);
setRange(globalConfig()->mutable_tracks(), value);
});
static StringFlag srcHeads({"--heads", "-h"},
@@ -57,24 +57,25 @@ static StringFlag srcHeads({"--heads", "-h"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_heads(), value);
setRange(globalConfig()->mutable_heads(), value);
});
int mainRead(int argc, const char* argv[])
{
if (argc == 1)
showProfiles("read", formats);
globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, formats);
if (globalConfig().decoder().copy_flux_to().type() == FluxSinkProto::DRIVE)
if (globalConfig()->decoder().copy_flux_to().type() == FluxSinkProto::DRIVE)
error("you cannot copy flux to a hardware device");
std::unique_ptr<FluxSource> fluxSource(
FluxSource::create(globalConfig().flux_source()));
std::unique_ptr<Decoder> decoder(Decoder::create(globalConfig().decoder()));
FluxSource::create(globalConfig()->flux_source()));
std::unique_ptr<Decoder> decoder(
Decoder::create(globalConfig()->decoder()));
std::unique_ptr<ImageWriter> writer(
ImageWriter::create(globalConfig().image_writer()));
ImageWriter::create(globalConfig()->image_writer()));
readDiskCommand(*fluxSource, *decoder, *writer);

View File

@@ -13,21 +13,21 @@ static StringFlag sourceFlux({"-s", "--source"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
int mainRpm(int argc, const char* argv[])
{
flags.parseFlagsWithConfigFiles(argc, argv, {});
if (globalConfig().flux_source().type() != FluxSourceProto::DRIVE)
if (globalConfig()->flux_source().type() != FluxSourceProto::DRIVE)
error("this only makes sense with a real disk drive");
usbSetDrive(globalConfig().drive().drive(),
usbSetDrive(globalConfig()->drive().drive(),
false,
globalConfig().drive().index_mode());
globalConfig()->drive().index_mode());
nanoseconds_t period =
usbGetRotationalPeriod(globalConfig().drive().hard_sector_count());
usbGetRotationalPeriod(globalConfig()->drive().hard_sector_count());
if (period != 0)
std::cout << "Rotational period is " << period / 1000000 << " ms ("
<< 60e9 / period << " rpm)" << std::endl;

View File

@@ -13,7 +13,7 @@ static StringFlag sourceFlux({"-s", "--source"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
static IntFlag track({"--cylinder", "-c"}, "track to seek to", 0);
@@ -24,12 +24,12 @@ int mainSeek(int argc, const char* argv[])
{
flags.parseFlagsWithConfigFiles(argc, argv, {});
if (globalConfig().flux_source().type() != FluxSourceProto::DRIVE)
if (globalConfig()->flux_source().type() != FluxSourceProto::DRIVE)
error("this only makes sense with a real disk drive");
usbSetDrive(globalConfig().drive().drive(),
usbSetDrive(globalConfig()->drive().drive(),
false,
globalConfig().drive().index_mode());
globalConfig()->drive().index_mode());
usbSeek(track);
return 0;
}

View File

@@ -24,7 +24,7 @@ static StringFlag sourceImage({"--input", "-i"},
[](const auto& value)
{
ImageReader::updateConfigForFilename(
globalConfig().mutable_image_reader(), value);
globalConfig()->mutable_image_reader(), value);
});
static StringFlag destFlux({"--dest", "-d"},
@@ -33,9 +33,9 @@ static StringFlag destFlux({"--dest", "-d"},
[](const auto& value)
{
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), value);
globalConfig()->mutable_flux_sink(), value);
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
});
static StringFlag destTracks({"--cylinders", "-c"},
@@ -43,7 +43,7 @@ static StringFlag destTracks({"--cylinders", "-c"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_tracks(), value);
setRange(globalConfig()->mutable_tracks(), value);
});
static StringFlag destHeads({"--heads", "-h"},
@@ -51,7 +51,7 @@ static StringFlag destHeads({"--heads", "-h"},
"",
[](const auto& value)
{
setRange(globalConfig().mutable_heads(), value);
setRange(globalConfig()->mutable_heads(), value);
});
static ActionFlag noVerifyFlag({"--no-verify", "-n"},
@@ -65,27 +65,28 @@ int mainWrite(int argc, const char* argv[])
{
if (argc == 1)
showProfiles("write", formats);
globalConfig().mutable_flux_sink()->set_type(FluxSinkProto::DRIVE);
globalConfig()->mutable_flux_sink()->set_type(FluxSinkProto::DRIVE);
if (verify)
globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
flags.parseFlagsWithConfigFiles(argc, argv, formats);
std::unique_ptr<ImageReader> reader(
ImageReader::create(globalConfig().image_reader()));
ImageReader::create(globalConfig()->image_reader()));
std::shared_ptr<Image> image = reader->readMappedImage();
std::unique_ptr<Encoder> encoder(Encoder::create(globalConfig().encoder()));
std::unique_ptr<Encoder> encoder(
Encoder::create(globalConfig()->encoder()));
std::unique_ptr<FluxSink> fluxSink(
FluxSink::create(globalConfig().flux_sink()));
FluxSink::create(globalConfig()->flux_sink()));
std::unique_ptr<Decoder> decoder;
if (globalConfig().has_decoder() && verify)
decoder = Decoder::create(globalConfig().decoder());
if (globalConfig()->has_decoder() && verify)
decoder = Decoder::create(globalConfig()->decoder());
std::unique_ptr<FluxSource> fluxSource;
if (verify &&
(globalConfig().flux_source().type() == FluxSourceProto::DRIVE))
fluxSource = FluxSource::create(globalConfig().flux_source());
(globalConfig()->flux_source().type() == FluxSourceProto::DRIVE))
fluxSource = FluxSource::create(globalConfig()->flux_source());
writeDiskCommand(
*image, *encoder, *fluxSink, decoder.get(), fluxSource.get());

View File

@@ -22,9 +22,9 @@ static StringFlag image({"-i", "--image"},
[](const auto& value)
{
ImageReader::updateConfigForFilename(
globalConfig().mutable_image_reader(), value);
globalConfig()->mutable_image_reader(), value);
ImageWriter::updateConfigForFilename(
globalConfig().mutable_image_writer(), value);
globalConfig()->mutable_image_writer(), value);
});
static StringFlag flux({"-f", "--flux"},
@@ -33,7 +33,7 @@ static StringFlag flux({"-f", "--flux"},
[](const auto& value)
{
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), value);
globalConfig()->mutable_flux_source(), value);
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), value);
globalConfig()->mutable_flux_sink(), value);
});

View File

@@ -164,7 +164,7 @@ private:
(desiredSide != _explorerSide))
{
auto fluxSource =
FluxSource::create(globalConfig().flux_source());
FluxSource::create(globalConfig()->flux_source());
_explorerFluxmap =
fluxSource->readFlux(desiredTrack, desiredSide)->next();
_explorerTrack = desiredTrack;

View File

@@ -180,7 +180,7 @@ public:
if (formatSelection == wxNOT_FOUND)
error("no format selected");
globalConfig().Clear();
globalConfig()->Clear();
auto formatName = _formatNames[formatChoice->GetSelection()];
FlagGroup::parseConfigFile(formatName, formats);
@@ -196,9 +196,9 @@ public:
auto serial = _selectedDevice;
if (!serial.empty() && (serial[0] == '/'))
setProtoByString(&globalConfig(), "usb.greaseweazle.port", serial);
setProtoByString(globalConfig(), "usb.greaseweazle.port", serial);
else
setProtoByString(&globalConfig(), "usb.serial", serial);
setProtoByString(globalConfig(), "usb.serial", serial);
ClearLog();
@@ -208,15 +208,15 @@ public:
{
case SELECTEDSOURCE_REAL:
{
globalConfig().mutable_drive()->set_high_density(
globalConfig()->mutable_drive()->set_high_density(
_selectedHighDensity);
globalConfig().MergeFrom(*_selectedDriveType);
globalConfig()->MergeFrom(*_selectedDriveType);
std::string filename = _selectedDrive ? "drive:1" : "drive:0";
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), filename);
globalConfig()->mutable_flux_sink(), filename);
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(), filename);
globalConfig()->mutable_flux_source(), filename);
break;
}
@@ -224,9 +224,9 @@ public:
case SELECTEDSOURCE_FLUX:
{
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), _selectedFluxfilename);
globalConfig()->mutable_flux_sink(), _selectedFluxfilename);
FluxSource::updateConfigForFilename(
globalConfig().mutable_flux_source(),
globalConfig()->mutable_flux_source(),
_selectedFluxfilename);
break;
}
@@ -234,10 +234,10 @@ public:
case SELECTEDSOURCE_IMAGE:
{
ImageReader::updateConfigForFilename(
globalConfig().mutable_image_reader(),
globalConfig()->mutable_image_reader(),
_selectedImagefilename);
ImageWriter::updateConfigForFilename(
globalConfig().mutable_image_writer(),
globalConfig()->mutable_image_writer(),
_selectedImagefilename);
break;
}
@@ -258,7 +258,7 @@ public:
{
auto key = setting.substr(0, equals);
auto value = setting.substr(equals + 1);
setProtoByString(&globalConfig(), key, value);
setProtoByString(globalConfig(), key, value);
}
else
FlagGroup::parseConfigFile(setting, formats);
@@ -589,12 +589,12 @@ private:
formatOptionsContainer, wxID_ANY, "(no format selected)"));
else
{
globalConfig().Clear();
globalConfig()->Clear();
std::string formatName =
_formatNames[formatChoice->GetSelection()];
FlagGroup::parseConfigFile(formatName, formats);
for (auto& group : globalConfig().option_group())
for (auto& group : globalConfig()->option_group())
{
sizer->Add(new wxStaticText(formatOptionsContainer,
wxID_ANY,
@@ -646,7 +646,7 @@ private:
/* Anything that's _not_ in a group gets a checkbox. */
for (auto& option : globalConfig().option())
for (auto& option : globalConfig()->option())
{
auto* choice = new wxCheckBox(
formatOptionsContainer, wxID_ANY, option.comment());
@@ -669,8 +669,8 @@ private:
});
}
if (globalConfig().option().empty() &&
globalConfig().option_group().empty())
if (globalConfig()->option().empty() &&
globalConfig()->option_group().empty())
sizer->Add(new wxStaticText(formatOptionsContainer,
wxID_ANY,
"(no options for this format)"));

View File

@@ -99,8 +99,8 @@ public:
Environment::reset();
auto fluxSource =
FluxSource::create(globalConfig().flux_source());
auto decoder = Decoder::create(globalConfig().decoder());
FluxSource::create(globalConfig()->flux_source());
auto decoder = Decoder::create(globalConfig()->decoder());
auto diskflux = readDiskCommand(*fluxSource, *decoder);
runOnUiThread(
@@ -124,15 +124,13 @@ public:
{
SetPage(MainWindow::PAGE_IMAGER);
PrepareConfig();
if (!globalConfig().has_image_reader())
if (!globalConfig()->has_image_reader())
error("This format cannot be read from images.");
auto filename = wxFileSelector("Choose a image file to read",
/* default_path= */ wxEmptyString,
/* default_filename= */
globalConfig()
.image_reader()
.filename(),
globalConfig()->image_reader().filename(),
/* default_extension= */ wxEmptyString,
/* wildcard= */ wxEmptyString,
/* flags= */ wxFD_OPEN | wxFD_FILE_MUST_EXIST);
@@ -140,9 +138,9 @@ public:
return;
ImageReader::updateConfigForFilename(
globalConfig().mutable_image_reader(), filename.ToStdString());
globalConfig()->mutable_image_reader(), filename.ToStdString());
ImageWriter::updateConfigForFilename(
globalConfig().mutable_image_writer(), filename.ToStdString());
globalConfig()->mutable_image_writer(), filename.ToStdString());
visualiser->Clear();
_currentDisk = nullptr;
@@ -151,19 +149,19 @@ public:
[this]()
{
auto image =
ImageReader::create(globalConfig().image_reader())
ImageReader::create(globalConfig()->image_reader())
->readMappedImage();
auto encoder = Encoder::create(globalConfig().encoder());
auto encoder = Encoder::create(globalConfig()->encoder());
auto fluxSink =
FluxSink::create(globalConfig().flux_sink());
FluxSink::create(globalConfig()->flux_sink());
std::unique_ptr<Decoder> decoder;
std::unique_ptr<FluxSource> fluxSource;
if (globalConfig().has_decoder())
if (globalConfig()->has_decoder())
{
decoder = Decoder::create(globalConfig().decoder());
decoder = Decoder::create(globalConfig()->decoder());
fluxSource =
FluxSource::create(globalConfig().flux_source());
FluxSource::create(globalConfig()->flux_source());
}
writeDiskCommand(*image,
@@ -250,16 +248,14 @@ public:
{
try
{
if (!globalConfig().has_image_writer())
if (!globalConfig()->has_image_writer())
error("This format cannot be saved.");
auto filename =
wxFileSelector("Choose the name of the image file to write",
/* default_path= */ wxEmptyString,
/* default_filename= */
globalConfig()
.image_writer()
.filename(),
globalConfig()->image_writer().filename(),
/* default_extension= */ wxEmptyString,
/* wildcard= */ wxEmptyString,
/* flags= */ wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
@@ -267,7 +263,7 @@ public:
return;
ImageWriter::updateConfigForFilename(
globalConfig().mutable_image_writer(), filename.ToStdString());
globalConfig()->mutable_image_writer(), filename.ToStdString());
auto image = _currentDisk->image;
@@ -275,7 +271,7 @@ public:
[image, this]()
{
auto imageWriter =
ImageWriter::create(globalConfig().image_writer());
ImageWriter::create(globalConfig()->image_writer());
imageWriter->writeMappedImage(*image);
});
}
@@ -300,7 +296,7 @@ public:
return;
FluxSink::updateConfigForFilename(
globalConfig().mutable_flux_sink(), filename.ToStdString());
globalConfig()->mutable_flux_sink(), filename.ToStdString());
QueueJob(
[this]()
@@ -308,7 +304,7 @@ public:
auto fluxSource =
FluxSource::createMemoryFluxSource(*_currentDisk);
auto fluxSink =
FluxSink::create(globalConfig().flux_sink());
FluxSink::create(globalConfig()->flux_sink());
writeRawDiskCommand(*fluxSource, *fluxSink);
});
}

View File

@@ -72,8 +72,8 @@ static void setBlock(
static void testPartialExtent()
{
auto sectors = std::make_shared<TestSectorInterface>();
auto fs =
Filesystem::createCpmFsFilesystem(globalConfig().filesystem(), sectors);
auto fs = Filesystem::createCpmFsFilesystem(
globalConfig()->filesystem(), sectors);
setBlock(sectors,
0,
@@ -92,8 +92,8 @@ static void testPartialExtent()
static void testLogicalExtents()
{
auto sectors = std::make_shared<TestSectorInterface>();
auto fs =
Filesystem::createCpmFsFilesystem(globalConfig().filesystem(), sectors);
auto fs = Filesystem::createCpmFsFilesystem(
globalConfig()->filesystem(), sectors);
setBlock(sectors,
0,
@@ -143,7 +143,7 @@ int main(void)
}
}
)M";
google::protobuf::TextFormat::MergeFromString(text, &globalConfig());
google::protobuf::TextFormat::MergeFromString(text, globalConfig());
testPartialExtent();
testLogicalExtents();

View File

@@ -19,9 +19,9 @@ static std::string cleanup(const std::string& s)
static void load_config(const std::string s)
{
globalConfig().Clear();
globalConfig()->Clear();
if (!google::protobuf::TextFormat::MergeFromString(
cleanup(s), &globalConfig()))
cleanup(s), globalConfig()))
error("couldn't load test config");
}