Writes now work.

This commit is contained in:
David Given
2025-10-13 22:24:00 +02:00
parent b1d64f3683
commit f67ddc1f77
5 changed files with 73 additions and 17 deletions

View File

@@ -285,6 +285,8 @@ DiskLayout::DiskLayout(const ConfigProto& config)
blockId++;
}
}
totalBytes = sectorOffset;
}
static ConfigProto createTestConfig(unsigned numCylinders,

View File

@@ -87,10 +87,11 @@ public:
unsigned minPhysicalCylinder, maxPhysicalCylinder;
unsigned minPhysicalHead, maxPhysicalHead;
unsigned groupSize; /* Number of physical cylinders per logical cylinder */
unsigned headBias; /* Physical cylinder offset */
unsigned headWidth; /* Width of the physical head */
bool swapSides; /* Whether sides need to be swapped */
unsigned groupSize; /* Number of physical cylinders per logical cylinder */
unsigned headBias; /* Physical cylinder offset */
unsigned headWidth; /* Width of the physical head */
bool swapSides; /* Whether sides need to be swapped */
unsigned totalBytes; /* Total number of bytes on the disk. */
/* Physical and logical layouts by location. */

View File

@@ -100,7 +100,7 @@ void ControlPanelView::drawContent()
ImGui::TableNextColumn();
button(ICON_VS_SAVE_AS,
"fluxengine.view.controlpanel.writeDevice"_lang,
nullptr,
Datastore::beginWrite,
busy || !hasImage);
ImGui::TableNextRow();

View File

@@ -89,11 +89,12 @@ static void workerThread_cb()
catch (const std::exception& e)
{
const std::lock_guard<std::mutex> lock(pendingTasksMutex);
std::string message = e.what();
hex::TaskManager::doLater(
[=]
{
hex::ui::ToastError::open(
fmt::format("FluxEngine error: {}", e.what()));
fmt::format("FluxEngine error: {}", message));
});
stopWorkerThread();
return;
@@ -311,6 +312,16 @@ void Datastore::probeDevices()
});
}
static void wtClearDiskData()
{
hex::TaskManager::doLater(
[]
{
::wtImage = nullptr;
::diskFlux = nullptr;
});
}
void wtRebuildConfiguration()
{
/* Reset and apply the format configuration. */
@@ -395,10 +406,6 @@ void wtRebuildConfiguration()
/* Update the UI-thread copy of the bits of configuration we
* need. */
auto diskFlux = std::make_shared<DecodedDisk>();
wtImage = std::make_shared<Image>();
wtImage->addMissingSectors(*diskLayout);
diskFlux->image = wtImage;
bool formattingSupported = false;
try
{
@@ -417,7 +424,6 @@ void wtRebuildConfiguration()
{
::formattingSupported = formattingSupported;
::diskLayout = diskLayout;
::diskFlux = diskFlux;
});
}
@@ -506,7 +512,26 @@ void Datastore::onLogMessage(const AnyLogMessage& message)
message);
}
void Datastore::beginRead(void)
void Datastore::beginRead()
{
Datastore::runOnWorkerThread(
[]
{
busy = true;
DEFER(busy = false);
wtRebuildConfiguration();
wtClearDiskData();
wtWaitForUiThreadToCatchUp();
auto fluxSource = FluxSource::create(globalConfig());
auto decoder = Arch::createDecoder(globalConfig());
auto diskflux = std::make_shared<DecodedDisk>();
readDiskCommand(*diskLayout, *fluxSource, *decoder, *diskflux);
});
}
void Datastore::beginWrite()
{
Datastore::runOnWorkerThread(
[]
@@ -516,11 +541,25 @@ void Datastore::beginRead(void)
wtRebuildConfiguration();
wtWaitForUiThreadToCatchUp();
auto fluxSource = FluxSource::create(globalConfig());
auto decoder = Arch::createDecoder(globalConfig());
auto diskflux = std::make_shared<DecodedDisk>();
readDiskCommand(*diskLayout, *fluxSource, *decoder, *diskflux);
auto fluxSink = FluxSink::create(globalConfig());
auto encoder = Arch::createEncoder(globalConfig());
std::shared_ptr<Decoder> decoder;
std::shared_ptr<FluxSource> verificationFluxSource;
if (globalConfig().hasDecoder() && fluxSink->isHardware())
{
decoder = Arch::createDecoder(globalConfig());
verificationFluxSource = FluxSource::create(
globalConfig().getVerificationFluxSourceProto());
}
auto image = diskFlux->image;
writeDiskCommand(*diskLayout,
*image,
*encoder,
*fluxSink,
decoder.get(),
verificationFluxSource.get());
});
}
@@ -533,11 +572,12 @@ void Datastore::reset()
DEFER(busy = false);
wtRebuildConfiguration();
wtClearDiskData();
wtWaitForUiThreadToCatchUp();
});
}
void Datastore::stop(void)
void Datastore::stop()
{
emergencyStop = true;
}
@@ -554,6 +594,7 @@ void Datastore::writeImage(const std::fs::path& path)
};
wtRebuildConfiguration();
wtWaitForUiThreadToCatchUp();
globalConfig().setImageWriter(path.string());
ImageWriter::create(globalConfig())
->writeImage(*Datastore::getDecodedDisk()->image);
@@ -572,6 +613,14 @@ void Datastore::writeFluxFile(const std::fs::path& path)
};
wtRebuildConfiguration();
wtWaitForUiThreadToCatchUp();
if (!diskFlux || !diskFlux->image)
error("no loaded image");
if (diskFlux->image->getGeometry().totalBytes !=
diskLayout->totalBytes)
error("loaded image is not the right size for this format");
globalConfig().setFluxSink(path.string());
auto fluxSource = FluxSource::createMemoryFluxSource(*diskFlux);
auto fluxSink = FluxSink::create(globalConfig());
@@ -591,6 +640,9 @@ void Datastore::createBlankImage()
};
wtRebuildConfiguration();
wtClearDiskData();
wtWaitForUiThreadToCatchUp();
auto diskflux = std::make_shared<DecodedDisk>();
auto image = std::make_shared<Image>();
std::shared_ptr<SectorInterface> sectorInterface =

View File

@@ -36,6 +36,7 @@ public:
/* Begins a transation. Rebuilds the configuration. */
static void reset();
static void beginRead();
static void beginWrite();
static void writeImage(const std::fs::path& path);
static void writeFluxFile(const std::fs::path& path);
static void createBlankImage();