mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
The C64 decoder now works with the new architecture, although it looks like I'm
going to have to do some rearchitecting...
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "globals.h"
|
||||
#include "fluxmap.h"
|
||||
#include "fluxmapreader.h"
|
||||
#include "protocol.h"
|
||||
#include "record.h"
|
||||
#include "decoders.h"
|
||||
@@ -11,6 +12,8 @@
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
const FluxPattern RECORD_SEPARATOR_PATTERN(16, C64_RECORD_SEPARATOR);
|
||||
|
||||
static int decode_data_gcr(uint8_t gcr)
|
||||
{
|
||||
switch (gcr)
|
||||
@@ -47,67 +50,49 @@ static Bytes decode(const std::vector<bool>& bits)
|
||||
return output;
|
||||
}
|
||||
|
||||
SectorVector Commodore64Decoder::decodeToSectors(const RawRecordVector& rawRecords, unsigned, unsigned)
|
||||
nanoseconds_t Commodore64Decoder::findSector(FluxmapReader& fmr, Track& track)
|
||||
{
|
||||
std::vector<std::unique_ptr<Sector>> sectors;
|
||||
unsigned nextSector;
|
||||
unsigned nextTrack;
|
||||
bool headerIsValid = false;
|
||||
|
||||
for (auto& rawrecord : rawRecords)
|
||||
{
|
||||
const auto& rawdata = rawrecord->data;
|
||||
const auto& bytes = decode(rawdata);
|
||||
|
||||
if (bytes.size() == 0)
|
||||
continue;
|
||||
|
||||
switch (bytes[0])
|
||||
{
|
||||
case 8: /* sector record */
|
||||
{
|
||||
headerIsValid = false;
|
||||
if (bytes.size() < 6)
|
||||
break;
|
||||
|
||||
uint8_t checksum = bytes[1];
|
||||
nextSector = bytes[2];
|
||||
nextTrack = bytes[3] - 1;
|
||||
if (checksum != xorBytes(bytes.slice(2, 4)))
|
||||
break;
|
||||
|
||||
headerIsValid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: /* data record */
|
||||
{
|
||||
if (!headerIsValid)
|
||||
break;
|
||||
headerIsValid = false;
|
||||
if (bytes.size() < 258)
|
||||
break;
|
||||
|
||||
Bytes payload = bytes.slice(1, C64_SECTOR_LENGTH);
|
||||
uint8_t gotChecksum = xorBytes(payload);
|
||||
uint8_t wantChecksum = bytes[257];
|
||||
int status = (wantChecksum == gotChecksum) ? Sector::OK : Sector::BAD_CHECKSUM;
|
||||
|
||||
auto sector = std::unique_ptr<Sector>(
|
||||
new Sector(status, nextTrack, 0, nextSector, payload));
|
||||
sectors.push_back(std::move(sector));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sectors;
|
||||
nanoseconds_t clock = fmr.seekToPattern(RECORD_SEPARATOR_PATTERN);
|
||||
if (clock)
|
||||
fmr.readRawBits(12, clock);
|
||||
return clock;
|
||||
}
|
||||
|
||||
int Commodore64Decoder::recordMatcher(uint64_t fifo) const
|
||||
nanoseconds_t Commodore64Decoder::findData(FluxmapReader& fmr, Track& track)
|
||||
{
|
||||
uint16_t masked = fifo & 0xffff;
|
||||
if (masked == C64_RECORD_SEPARATOR)
|
||||
return 4;
|
||||
return 0;
|
||||
return findSector(fmr, track);
|
||||
}
|
||||
|
||||
void Commodore64Decoder::decodeHeader(FluxmapReader& fmr, Track& track, Sector& sector)
|
||||
{
|
||||
const auto& idbits = fmr.readRawBits(1*10, sector.clock);
|
||||
const auto& idbytes = decode(idbits).slice(0, 1);
|
||||
if (idbytes[0] != 8)
|
||||
return; /* Not a sector record */
|
||||
|
||||
const auto& bits = fmr.readRawBits(5*10, sector.clock);
|
||||
const auto& bytes = decode(bits).slice(0, 5);
|
||||
|
||||
uint8_t checksum = bytes[0];
|
||||
sector.logicalSector = bytes[1];
|
||||
sector.logicalSide = 0;
|
||||
sector.logicalTrack = bytes[2] - 1;
|
||||
if (checksum == xorBytes(bytes.slice(1, 4)))
|
||||
sector.status = Sector::DATA_MISSING; /* unintuitive but correct */
|
||||
}
|
||||
|
||||
void Commodore64Decoder::decodeData(FluxmapReader& fmr, Track& track, Sector& sector)
|
||||
{
|
||||
const auto& idbits = fmr.readRawBits(1*10, sector.clock);
|
||||
const auto& idbytes = decode(idbits).slice(0, 1);
|
||||
if (idbytes[0] != 7)
|
||||
return; /* Not a data record */
|
||||
|
||||
const auto& bits = fmr.readRawBits(259*10, sector.clock);
|
||||
const auto& bytes = decode(bits).slice(0, 259);
|
||||
|
||||
sector.data = bytes.slice(0, C64_SECTOR_LENGTH);
|
||||
uint8_t gotChecksum = xorBytes(sector.data);
|
||||
uint8_t wantChecksum = bytes[256];
|
||||
sector.status = (wantChecksum == gotChecksum) ? Sector::OK : Sector::BAD_CHECKSUM;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user