mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Victor segmentation and decode works; but clock detection is still terrible.
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
#include "globals.h"
|
||||
#include "bytes.h"
|
||||
|
||||
uint8_t toByte(
|
||||
std::vector<bool>::const_iterator start,
|
||||
std::vector<bool>::const_iterator end)
|
||||
{
|
||||
return toBytes(start, end).at(0);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> toBytes(
|
||||
std::vector<bool>::const_iterator start,
|
||||
std::vector<bool>::const_iterator end)
|
||||
|
||||
@@ -46,6 +46,10 @@ inline void write_le32(T ptr, uint32_t value)
|
||||
ptr[3] = (value>>24) & 0xff;
|
||||
}
|
||||
|
||||
extern uint8_t toByte(
|
||||
std::vector<bool>::const_iterator start,
|
||||
std::vector<bool>::const_iterator end);
|
||||
|
||||
extern std::vector<uint8_t> toBytes(
|
||||
std::vector<bool>::const_iterator start,
|
||||
std::vector<bool>::const_iterator end);
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
#include "globals.h"
|
||||
#include "crc.h"
|
||||
|
||||
uint16_t sumBytes(const uint8_t* start, const uint8_t* end)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
while (start != end)
|
||||
i += *start++;
|
||||
return i;
|
||||
}
|
||||
|
||||
uint8_t xorBytes(const uint8_t* start, const uint8_t* end)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define CCITT_POLY 0x1021
|
||||
#define BROTHER_POLY 0x000201
|
||||
|
||||
extern uint16_t sumBytes(const uint8_t* start, const uint8_t* end);
|
||||
extern uint8_t xorBytes(const uint8_t* start, const uint8_t* end);
|
||||
extern uint16_t crc16(uint16_t poly, const uint8_t* start, const uint8_t* end);
|
||||
extern uint32_t crcbrother(const uint8_t* start, const uint8_t* end);
|
||||
|
||||
@@ -49,6 +49,7 @@ SectorVector VictorDecoder::decodeToSectors(const RawRecordVector& rawRecords, u
|
||||
std::vector<std::unique_ptr<Sector>> sectors;
|
||||
unsigned nextSector;
|
||||
unsigned nextTrack;
|
||||
unsigned nextSide;
|
||||
bool headerIsValid = false;
|
||||
|
||||
for (auto& rawrecord : rawRecords)
|
||||
@@ -61,23 +62,29 @@ SectorVector VictorDecoder::decodeToSectors(const RawRecordVector& rawRecords, u
|
||||
|
||||
switch (bytes[0])
|
||||
{
|
||||
case 8: /* sector record */
|
||||
case 7: /* sector record */
|
||||
{
|
||||
headerIsValid = false;
|
||||
if (bytes.size() < 6)
|
||||
break;
|
||||
|
||||
uint8_t checksum = bytes[1];
|
||||
uint8_t rawTrack = bytes[1];
|
||||
nextSector = bytes[2];
|
||||
nextTrack = bytes[3] - 1;
|
||||
if (checksum != xorBytes(&bytes[2], &bytes[6]))
|
||||
uint8_t gotChecksum = bytes[3];
|
||||
|
||||
nextTrack = rawTrack & 0x7f;
|
||||
nextSide = rawTrack >> 7;
|
||||
uint8_t wantChecksum = sumBytes(&bytes[1], &bytes[3]);
|
||||
if (wantChecksum != gotChecksum)
|
||||
break;
|
||||
if ((nextSector > 20) || (nextTrack > 85) || (nextSide > 1))
|
||||
break;
|
||||
|
||||
headerIsValid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: /* data record */
|
||||
case 8: /* data record */
|
||||
{
|
||||
if (!headerIsValid)
|
||||
break;
|
||||
@@ -85,8 +92,9 @@ SectorVector VictorDecoder::decodeToSectors(const RawRecordVector& rawRecords, u
|
||||
if (bytes.size() < 258)
|
||||
break;
|
||||
|
||||
uint8_t checksum = xorBytes(&bytes[1], &bytes[257]);
|
||||
int status = (checksum == bytes[257]) ? Sector::OK : Sector::BAD_CHECKSUM;
|
||||
uint16_t gotChecksum = sumBytes(&bytes[1], &bytes[257]);
|
||||
uint16_t wantChecksum = read_be16(&bytes[257]);
|
||||
int status = (gotChecksum == wantChecksum) ? Sector::OK : Sector::BAD_CHECKSUM;
|
||||
|
||||
auto sector = std::unique_ptr<Sector>(
|
||||
new Sector(status, nextTrack, 0, nextSector,
|
||||
@@ -102,8 +110,8 @@ SectorVector VictorDecoder::decodeToSectors(const RawRecordVector& rawRecords, u
|
||||
|
||||
int VictorDecoder::recordMatcher(uint64_t fifo) const
|
||||
{
|
||||
uint32_t masked = fifo & 0xffffff;
|
||||
if (masked == VICTOR_RECORD_SEPARATOR)
|
||||
return 8;
|
||||
uint32_t masked = fifo & 0xfffff;
|
||||
if ((masked == VICTOR_SECTOR_RECORD) || (masked == VICTOR_DATA_RECORD))
|
||||
return 9;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef VICTOR_H
|
||||
#define VICTOR_H
|
||||
|
||||
#define VICTOR_RECORD_SEPARATOR 0xffffea
|
||||
#define VICTOR_SECTOR_RECORD 0xffeab
|
||||
#define VICTOR_DATA_RECORD 0xffea4
|
||||
|
||||
class Sector;
|
||||
class Fluxmap;
|
||||
|
||||
Reference in New Issue
Block a user