mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
The protoified reader now builds and runs, although doesn't work properly.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "bytes.h"
|
||||
#include "fmt/format.h"
|
||||
#include "lib/decoders/decoders.pb.h"
|
||||
#include "lib/data.pb.h"
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -32,8 +33,8 @@ public:
|
||||
|
||||
RecordType advanceToNextRecord()
|
||||
{
|
||||
_sector->clock = _fmr->seekToPattern(SECTOR_PATTERN);
|
||||
if (_fmr->eof() || !_sector->clock)
|
||||
_sector->set_clock(_fmr->seekToPattern(SECTOR_PATTERN));
|
||||
if (_fmr->eof() || !_sector->clock())
|
||||
return UNKNOWN_RECORD;
|
||||
return SECTOR_RECORD;
|
||||
}
|
||||
@@ -51,9 +52,9 @@ public:
|
||||
Bytes header = amigaDeinterleave(ptr, 4);
|
||||
Bytes recoveryinfo = amigaDeinterleave(ptr, 16);
|
||||
|
||||
_sector->logicalTrack = header[1] >> 1;
|
||||
_sector->logicalSide = header[1] & 1;
|
||||
_sector->logicalSector = header[2];
|
||||
_sector->set_logical_track(header[1] >> 1);
|
||||
_sector->set_logical_side(header[1] & 1);
|
||||
_sector->set_logical_sector(header[2]);
|
||||
|
||||
uint32_t wantedheaderchecksum = amigaDeinterleave(ptr, 4).reader().read_be32();
|
||||
uint32_t gotheaderchecksum = amigaChecksum(rawbytes.slice(6, 40));
|
||||
@@ -63,9 +64,10 @@ public:
|
||||
uint32_t wanteddatachecksum = amigaDeinterleave(ptr, 4).reader().read_be32();
|
||||
uint32_t gotdatachecksum = amigaChecksum(rawbytes.slice(62, 1024));
|
||||
|
||||
_sector->data.clear();
|
||||
_sector->data.writer().append(amigaDeinterleave(ptr, 512)).append(recoveryinfo);
|
||||
_sector->status = (gotdatachecksum == wanteddatachecksum) ? Sector::OK : Sector::BAD_CHECKSUM;
|
||||
Bytes data;
|
||||
data.writer().append(amigaDeinterleave(ptr, 512)).append(recoveryinfo);
|
||||
_sector->set_data(data);
|
||||
_sector->set_status((gotdatachecksum == wanteddatachecksum) ? SectorStatus::OK : SectorStatus::BAD_CHECKSUM);
|
||||
}
|
||||
|
||||
std::set<unsigned> requiredSectors(Track& track) const
|
||||
|
||||
@@ -14,7 +14,7 @@ message FluxRecordProto {
|
||||
message FluxTrackProto {
|
||||
optional int32 physical_cylinder = 1;
|
||||
optional int32 physical_head = 2;
|
||||
optional bytes data = 3;
|
||||
optional bytes flux = 3;
|
||||
|
||||
// Used to accumulate data during decoding.
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@ std::unique_ptr<AbstractDecoder> AbstractDecoder::create(const DecoderProto& con
|
||||
static const std::map<int,
|
||||
std::function<std::unique_ptr<AbstractDecoder>(const DecoderProto&)>> decoders =
|
||||
{
|
||||
{ DecoderProto::kAeslanier, createAesLanierDecoder },
|
||||
//{ DecoderProto::kAeslanier, createAesLanierDecoder },
|
||||
{ DecoderProto::kAmiga, createAmigaDecoder },
|
||||
#if 0
|
||||
{ DecoderProto::kApple2, createApple2Decoder },
|
||||
{ DecoderProto::kBrother, createBrotherDecoder },
|
||||
{ DecoderProto::kC64, createCommodore64Decoder },
|
||||
@@ -49,6 +50,7 @@ std::unique_ptr<AbstractDecoder> AbstractDecoder::create(const DecoderProto& con
|
||||
{ DecoderProto::kTids990, createTids990Decoder },
|
||||
{ DecoderProto::kVictor9K, createVictor9kDecoder },
|
||||
{ DecoderProto::kZilogmcz, createZilogMczDecoder },
|
||||
#endif
|
||||
};
|
||||
|
||||
auto decoder = decoders.find(config.format_case());
|
||||
@@ -65,7 +67,7 @@ void AbstractDecoder::decodeToSectors(FluxTrackProto& track)
|
||||
|
||||
_sector->set_physical_head(track.physical_head());
|
||||
_sector->set_physical_cylinder(track.physical_cylinder());
|
||||
Fluxmap fm(track.data());
|
||||
Fluxmap fm(track.flux());
|
||||
FluxmapReader fmr(fm);
|
||||
|
||||
_track = &track;
|
||||
@@ -141,3 +143,9 @@ std::vector<bool> AbstractDecoder::readRawBits(unsigned count)
|
||||
return _fmr->readRawBits(count, _sector->clock());
|
||||
}
|
||||
|
||||
std::set<unsigned> AbstractDecoder::requiredSectors(FluxTrackProto& track) const
|
||||
{
|
||||
static std::set<unsigned> set;
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
void seek(const Fluxmap::Position& pos)
|
||||
{ return _fmr->seek(pos); }
|
||||
|
||||
virtual std::set<unsigned> requiredSectors(FluxTrackProto& track) const;
|
||||
|
||||
protected:
|
||||
virtual void beginTrack() {};
|
||||
virtual RecordType advanceToNextRecord() = 0;
|
||||
|
||||
@@ -17,12 +17,14 @@ std::unique_ptr<AbstractEncoder> AbstractEncoder::create(const EncoderProto& con
|
||||
static const std::map<int,
|
||||
std::function<std::unique_ptr<AbstractEncoder>(const EncoderProto&)>> encoders =
|
||||
{
|
||||
#if 0
|
||||
{ EncoderProto::kAmiga, createAmigaEncoder },
|
||||
{ EncoderProto::kBrother, createBrotherEncoder },
|
||||
{ EncoderProto::kC64, createCommodore64Encoder },
|
||||
{ EncoderProto::kIbm, createIbmEncoder },
|
||||
{ EncoderProto::kMacintosh, createMacintoshEncoder },
|
||||
{ EncoderProto::kNorthstar, createNorthstarEncoder },
|
||||
#endif
|
||||
};
|
||||
|
||||
auto encoder = encoders.find(config.format_case());
|
||||
|
||||
@@ -29,7 +29,7 @@ static void readFluxmap(FluxSource& fluxsource, FluxTrackProto& track)
|
||||
int h = track.physical_head();
|
||||
std::cout << fmt::format("{0:>3}.{1}: ", c, h) << std::flush;
|
||||
std::unique_ptr<Fluxmap> fluxmap = fluxsource.readFlux(c, h);
|
||||
track.set_data(fluxmap->rawBytes());
|
||||
track.set_flux(fluxmap->rawBytes());
|
||||
std::cout << fmt::format(
|
||||
"{0} ms in {1} bytes\n",
|
||||
fluxmap->duration()/1e6,
|
||||
@@ -155,8 +155,9 @@ void readDiskCommand(FluxSource& fluxsource, AbstractDecoder& decoder, ImageWrit
|
||||
for (const auto& record : track_records)
|
||||
{
|
||||
std::cout << fmt::format("I+{:.2f}us with {:.2f}us clock\n",
|
||||
record.record_starttime_ns() / 1000.0, record.clock() / 1000.0);
|
||||
hexdump(std::cout, record.data());
|
||||
record->record_starttime_ns() / 1000.0,
|
||||
record->clock() / 1000.0);
|
||||
hexdump(std::cout, record->data());
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -164,38 +165,31 @@ void readDiskCommand(FluxSource& fluxsource, AbstractDecoder& decoder, ImageWrit
|
||||
if (config.decoder().dump_sectors())
|
||||
{
|
||||
std::cout << "\nDecoded sectors follow:\n\n";
|
||||
for (const auto& sector : track->sectors())
|
||||
for (const auto& sector : track_sectors)
|
||||
{
|
||||
std::cout << fmt::format("{}.{:02}.{:02}: I+{:.2f}us with {:.2f}us clock: status {}\n",
|
||||
sector.logical_track(),
|
||||
sector.logical_side(),
|
||||
sector.logical_sector(),
|
||||
sector.position_ns() / 1000.0,
|
||||
sector.clock() / 1000.0,
|
||||
SectorStatus_Name(sector.status()));
|
||||
hexdump(std::cout, sector.data());
|
||||
sector->logical_track(),
|
||||
sector->logical_side(),
|
||||
sector->logical_sector(),
|
||||
sector->header_starttime_ns() / 1000.0,
|
||||
sector->clock() / 1000.0,
|
||||
SectorStatus_Name(sector->status()));
|
||||
hexdump(std::cout, sector->data());
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
bool printedTrack = false;
|
||||
for (auto& i : readSectors)
|
||||
for (auto& sector : track_sectors)
|
||||
{
|
||||
auto& sector = i.second;
|
||||
if (sector)
|
||||
if (!printedTrack)
|
||||
{
|
||||
if (!printedTrack)
|
||||
{
|
||||
std::cout << fmt::format("logical track {}.{}; ", sector->logicalTrack, sector->logicalSide);
|
||||
printedTrack = true;
|
||||
}
|
||||
|
||||
size += sector->data.size();
|
||||
|
||||
std::unique_ptr<Sector>& replacing = allSectors.get(sector->logicalTrack, sector->logicalSide, sector->logicalSector);
|
||||
replace_sector(replacing, *sector);
|
||||
std::cout << fmt::format("logical track {}.{}; ", sector->logical_track(), sector->logical_side());
|
||||
printedTrack = true;
|
||||
}
|
||||
|
||||
size += sector->data().size();
|
||||
}
|
||||
std::cout << size << " bytes decoded." << std::endl;
|
||||
}
|
||||
@@ -216,11 +210,13 @@ void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink)
|
||||
{
|
||||
for (int head : iterate(config.heads()))
|
||||
{
|
||||
Track track(cylinder, head);
|
||||
track.fluxsource = &fluxsource;
|
||||
track.readFluxmap();
|
||||
FluxTrackProto track;
|
||||
track.set_physical_cylinder(cylinder);
|
||||
track.set_physical_head(head);
|
||||
|
||||
fluxsink.writeFlux(cylinder, head, *(track.fluxmap));
|
||||
readFluxmap(fluxsource, track);
|
||||
Fluxmap fluxmap(track.flux());
|
||||
fluxsink.writeFlux(cylinder, head, fluxmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user