Add the experimental FL2 encoder.

This commit is contained in:
dg
2021-12-04 12:39:36 +00:00
parent 70b2f7efb4
commit d36a18c17a
7 changed files with 95 additions and 48 deletions

View File

@@ -1,40 +0,0 @@
syntax = "proto2";
// Images
enum SectorStatus {
UNKNOWN = 0;
OK = 1;
BAD_CHECKSUM = 2;
MISSING = 3;
DATA_MISSING = 4;
CONFLICT = 5;
INTERNAL_ERROR = 6;
}
message SectorProto {
optional int32 logical_sector = 1;
optional bytes data = 2;
optional SectorStatus status = 3;
optional uint64 clock = 4;
optional uint64 header_starttime_ns = 5;
optional uint64 header_endtime_ns = 6;
optional uint64 data_starttime_ns = 7;
optional uint64 data_endtime_ns = 8;
optional int32 physical_cylinder = 9;
optional int32 physical_head = 10;
optional int32 logical_track = 11;
optional int32 logical_side = 12;
}
message TrackProto {
map<int32, SectorProto> sectors = 1;
optional int32 logical_track = 2;
optional int32 logical_side = 3;
}
message ImageProto {
map<int32, TrackProto> tracks = 1;
}

17
lib/fl2.proto Normal file
View File

@@ -0,0 +1,17 @@
syntax = "proto2";
enum FluxFileVersion {
VERSION_1 = 1;
}
message TrackFluxProto {
optional int32 cylinder = 1;
optional int32 head = 2;
optional bytes flux = 3;
}
message FluxFileProto {
optional FluxFileVersion version = 1;
repeated TrackFluxProto track = 2;
}

View File

@@ -0,0 +1,62 @@
#include "globals.h"
#include "flags.h"
#include "fluxmap.h"
#include "sql.h"
#include "bytes.h"
#include "protocol.h"
#include "fluxsink/fluxsink.h"
#include "decoders/fluxmapreader.h"
#include "lib/fluxsink/fluxsink.pb.h"
#include "proto.h"
#include "fmt/format.h"
#include "lib/fl2.pb.h"
#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
class Fl2FluxSink : public FluxSink
{
public:
Fl2FluxSink(const Fl2FluxSinkProto& lconfig):
_config(lconfig),
_of(lconfig.filename())
{
if (!_of.is_open())
Error() << "cannot open output file";
_proto.set_version(FluxFileVersion::VERSION_1);
}
~Fl2FluxSink()
{
std::cerr << "FL2: writing output file\n";
if (!_proto.SerializeToOstream(&_of))
Error() << "unable to write output file";
_of.close();
}
public:
void writeFlux(int cylinder, int head, Fluxmap& fluxmap)
{
auto track = _proto.add_track();
track->set_cylinder(cylinder);
track->set_head(head);
track->set_flux(fluxmap.rawBytes());
}
operator std::string () const
{
return fmt::format("fl2({})", _config.filename());
}
private:
const Fl2FluxSinkProto& _config;
std::ofstream _of;
FluxFileProto _proto;
};
std::unique_ptr<FluxSink> FluxSink::createFl2FluxSink(const Fl2FluxSinkProto& config)
{
return std::unique_ptr<FluxSink>(new Fl2FluxSink(config));
}

View File

@@ -26,6 +26,9 @@ std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
case FluxSinkProto::kScp:
return createScpFluxSink(config.scp());
case FluxSinkProto::kFl2:
return createFl2FluxSink(config.fl2());
default:
Error() << "bad output disk config";
return std::unique_ptr<FluxSink>();
@@ -38,6 +41,7 @@ void FluxSink::updateConfigForFilename(FluxSinkProto* proto, const std::string&
{
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->set_fluxfile(s); }},
{ std::regex("^(.*\\.scp)$"), [&](const auto& s) { proto->mutable_scp()->set_filename(s); }},
{ std::regex("^(.*\\.fl2)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
{ std::regex("^vcd:(.*)$"), [&](const auto& s) { proto->mutable_vcd()->set_directory(s); }},
{ std::regex("^au:(.*)$"), [&](const auto& s) { proto->mutable_au()->set_directory(s); }},
{ std::regex("^drive:(.*)"), [&](const auto& s) { proto->mutable_drive()->set_drive(std::stoi(s)); }},

View File

@@ -10,6 +10,7 @@ class HardwareFluxSinkProto;
class AuFluxSinkProto;
class VcdFluxSinkProto;
class ScpFluxSinkProto;
class Fl2FluxSinkProto;
class FluxSink
{
@@ -21,6 +22,7 @@ public:
static std::unique_ptr<FluxSink> createAuFluxSink(const AuFluxSinkProto& config);
static std::unique_ptr<FluxSink> createVcdFluxSink(const VcdFluxSinkProto& config);
static std::unique_ptr<FluxSink> createScpFluxSink(const ScpFluxSinkProto& config);
static std::unique_ptr<FluxSink> createFl2FluxSink(const Fl2FluxSinkProto& config);
static std::unique_ptr<FluxSink> create(const FluxSinkProto& config);
static void updateConfigForFilename(FluxSinkProto* proto, const std::string& filename);

View File

@@ -24,6 +24,10 @@ message ScpFluxSinkProto {
optional int32 type_byte = 4 [default = 0xff, (help) = "set the SCP disk type byte"];
}
message Fl2FluxSinkProto {
optional string filename = 1 [default = "flux.fl2", (help) = ".fl2 file to write to"];
}
message FluxSinkProto {
oneof dest {
string fluxfile = 1 [(help) = "name of destination flux file"];
@@ -31,6 +35,7 @@ message FluxSinkProto {
AuFluxSinkProto au = 3;
VcdFluxSinkProto vcd = 4;
ScpFluxSinkProto scp = 5;
Fl2FluxSinkProto fl2 = 6;
}
}

View File

@@ -244,14 +244,12 @@ runtest() {
buildlibrary lib$prog.a \
-Idep/snowhouse/include \
-d $OBJDIR/proto/libconfig.def \
-d $OBJDIR/proto/libdata.def \
"$@"
buildprogram $OBJDIR/$prog \
lib$prog.a \
libbackend.a \
libconfig.a \
libdata.a \
libtestproto.a \
libagg.a \
libfmt.a
@@ -309,13 +307,13 @@ buildproto libconfig.a \
lib/imagewriter/imagewriter.proto \
lib/usb/usb.proto \
buildproto libdata.a \
lib/data.proto
buildproto libfl2.a \
lib/fl2.proto
buildlibrary libbackend.a \
-I$OBJDIR/proto \
-d $OBJDIR/proto/libconfig.def \
-d $OBJDIR/proto/libdata.def \
-d $OBJDIR/proto/libfl2.def \
arch/aeslanier/decoder.cc \
arch/amiga/amiga.cc \
arch/amiga/decoder.cc \
@@ -353,6 +351,7 @@ buildlibrary libbackend.a \
lib/flags.cc \
lib/fluxmap.cc \
lib/fluxsink/aufluxsink.cc \
lib/fluxsink/fl2fluxsink.cc \
lib/fluxsink/fluxsink.cc \
lib/fluxsink/hardwarefluxsink.cc \
lib/fluxsink/scpfluxsink.cc \
@@ -454,7 +453,6 @@ buildmktable formats $OBJDIR/formats.cc $FORMATS
buildlibrary libfrontend.a \
-I$OBJDIR/proto \
-d $OBJDIR/proto/libconfig.def \
-d $OBJDIR/proto/libdata.def \
$(for a in $FORMATS; do echo $OBJDIR/proto/src/formats/$a.cc; done) \
$OBJDIR/formats.cc \
src/fe-analysedriveresponse.cc \
@@ -475,7 +473,7 @@ buildprogram fluxengine \
libfrontend.a \
libbackend.a \
libconfig.a \
libdata.a \
libfl2.a \
libfmt.a \
libagg.a \
@@ -515,7 +513,6 @@ runtest kryoflux-test tests/kryoflux.cc
runtest ldbs-test tests/ldbs.cc
runtest proto-test -I$OBJDIR/proto \
-d $OBJDIR/proto/libconfig.def \
-d $OBJDIR/proto/libdata.def \
-d $OBJDIR/proto/libtestproto.def \
tests/proto.cc \
$OBJDIR/proto/tests/testproto.cc