Merge pull request #335 from ejona86/scp-revs-crash

scpfluxsource: Support more than 5 revolutions
This commit is contained in:
David Given
2021-10-30 20:39:45 +02:00
committed by GitHub
4 changed files with 35 additions and 15 deletions

View File

@@ -88,10 +88,10 @@ public:
int strack = strackno(cylinder, head);
ScpTrack trackheader = {0};
trackheader.track_id[0] = 'T';
trackheader.track_id[1] = 'R';
trackheader.track_id[2] = 'K';
trackheader.strack = strack;
trackheader.header.track_id[0] = 'T';
trackheader.header.track_id[1] = 'R';
trackheader.header.track_id[2] = 'K';
trackheader.header.strack = strack;
FluxmapReader fmr(fluxmap);
Bytes fluxdata;

View File

@@ -2,6 +2,7 @@
#include "fluxmap.h"
#include "kryoflux.h"
#include "lib/fluxsource/fluxsource.pb.h"
#include "lib/utils.h"
#include "fluxsource/fluxsource.h"
#include "scp.h"
#include "proto.h"
@@ -57,11 +58,13 @@ public:
std::unique_ptr<Fluxmap> readFlux(int track, int side)
{
int strack = strackno(track, side);
if (strack >= ARRAY_SIZE(_header.track))
return std::unique_ptr<Fluxmap>();
uint32_t offset = Bytes(_header.track[strack], 4).reader().read_le32();
if (offset == 0)
return std::unique_ptr<Fluxmap>();
ScpTrack trackheader;
ScpTrackHeader trackheader;
_if.seekg(offset, std::ios::beg);
_if.read((char*) &trackheader, sizeof(trackheader));
check_for_error();
@@ -71,6 +74,15 @@ public:
|| (trackheader.track_id[2] != 'K'))
Error() << "corrupt SCP file";
std::vector<ScpTrackRevolution> revs(_header.revolutions);
for (int revolution = 0; revolution < _header.revolutions; revolution++)
{
ScpTrackRevolution trackrev;
_if.read((char*) &trackrev, sizeof(trackrev));
check_for_error();
revs[revolution] = trackrev;
}
std::unique_ptr<Fluxmap> fluxmap(new Fluxmap);
nanoseconds_t pending = 0;
unsigned inputBytes = 0;
@@ -79,8 +91,8 @@ public:
if (revolution != 0)
fluxmap->appendIndex();
uint32_t datalength = Bytes(trackheader.revolution[revolution].length, 4).reader().read_le32();
uint32_t dataoffset = Bytes(trackheader.revolution[revolution].offset, 4).reader().read_le32();
uint32_t datalength = Bytes(revs[revolution].length, 4).reader().read_le32();
uint32_t dataoffset = Bytes(revs[revolution].offset, 4).reader().read_le32();
Bytes data(datalength*2);
_if.seekg(dataoffset + offset, std::ios::beg);

View File

@@ -27,17 +27,23 @@ enum
SCP_FLAG_FOOTER = (1<<5)
};
struct ScpTrack
struct ScpTrackHeader
{
char track_id[3]; // 'TRK'
uint8_t strack; // SCP track number
struct
{
uint8_t index[4]; // time for one revolution
uint8_t length[4]; // number of bitcells
uint8_t offset[4]; // offset to bitcell data, relative to track header
}
revolution[5];
};
struct ScpTrackRevolution
{
uint8_t index[4]; // time for one revolution
uint8_t length[4]; // number of bitcells
uint8_t offset[4]; // offset to bitcell data, relative to track header
};
struct ScpTrack
{
ScpTrackHeader header;
ScpTrackRevolution revolution[5];
};
#endif

View File

@@ -1,6 +1,8 @@
#ifndef UTILS_H
#define UTILS_H
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
extern bool beginsWith(const std::string& value, const std::string& beginning);
extern bool endsWith(const std::string& value, const std::string& ending);