Skip to content

Commit

Permalink
Rework the A2R writer to be a bit less broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Jul 30, 2024
1 parent e4f1a5a commit 7a3d104
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/fluxsink/a2rfluxsink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "lib/logger.h"
#include "lib/proto.h"
#include "lib/fluxmap.h"
#include "lib/layout.h"
#include "lib/a2r.h"
#include <fstream>
#include <sys/stat.h>
Expand All @@ -22,11 +23,6 @@ namespace
return ticks * NS_PER_TICK / A2R_NS_PER_TICK;
}

bool singlesided(void)
{
return globalConfig()->heads().start() == globalConfig()->heads().end();
}

class A2RFluxSink : public FluxSink
{
public:
Expand All @@ -35,11 +31,7 @@ namespace
_bytes{},
_writer{_bytes.writer()}
{

log("A2R: writing A2R {} file containing {} tracks\n",
singlesided() ? "single sided" : "double sided",
globalConfig()->tracks().end() -
globalConfig()->tracks().start() + 1);
log("A2R: collecting data");

time_t now{std::time(nullptr)};
auto t = gmtime(&now);
Expand All @@ -48,12 +40,19 @@ namespace

~A2RFluxSink()
{
auto locations = Layout::computeLocations();
Layout::getBounds(
locations, _minTrack, _maxTrack, _minSide, _maxSide);

log("A2R: writing A2R {} file containing {} tracks...",
(_minSide == _maxSide) ? "single sided" : "double sided",
_maxTrack - _minTrack + 1);

writeHeader();
writeInfo();
writeStream();
writeMeta();

log("A2R: writing output file...\n");
std::ofstream of(
_config.filename(), std::ios::out | std::ios::binary);
if (!of.is_open())
Expand Down Expand Up @@ -85,7 +84,7 @@ namespace
auto version_str_padded = fmt::format("{: <32}", "Fluxengine");
assert(version_str_padded.size() == 32);
writer.append(version_str_padded);
writer.write_8(singlesided() ? A2R_DISK_525 : A2R_DISK_35);
writer.write_8(A2R_DISK_35);
writer.write_8(1); // write protected
writer.write_8(1); // synchronized
writeChunkAndData(A2R_CHUNK_INFO, info);
Expand Down Expand Up @@ -192,15 +191,15 @@ namespace
}
else
{
// We have an index, so this is real from a floppy and should be
// "one revolution plus a bit"
// We have an index, so this is a real read from a floppy and
// should be "one revolution plus a bit"
fmr.skipToEvent(F_BIT_INDEX);
write_flux();
}

uint32_t chunk_size = 10 + trackBytes.size();

_strmWriter.write_8(cylinder);
_strmWriter.write_8((cylinder << 1) | head);
_strmWriter.write_8(A2R_TIMING);
_strmWriter.write_le32(trackBytes.size());
_strmWriter.write_le32(ticks_to_a2r(loopPoint));
Expand All @@ -219,6 +218,10 @@ namespace
Bytes _strmBytes;
ByteWriter _strmWriter{_strmBytes.writer()};
std::map<std::string, std::string> _metadata;
int _minSide;
int _maxSide;
int _minTrack;
int _maxTrack;
};
} // namespace

Expand Down

0 comments on commit 7a3d104

Please sign in to comment.