Skip to content

Commit

Permalink
Merge pull request #127 from davidgiven/fixing
Browse files Browse the repository at this point in the history
Fix an issue where HD IBM disks can't be read
  • Loading branch information
davidgiven authored Jan 26, 2020
2 parents 60e5e35 + efa4c93 commit 9e75dc3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
7 changes: 5 additions & 2 deletions arch/ibm/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ const FluxPattern FM_TRS80DAM2_PATTERN(16, 0xf56c);
* encoding (you can't do 10 00). So this can't be spoofed by user data.
*
* shifted: 10 00 10 01 00 01 00 1
*
* It's repeated three times.
*/
const FluxPattern MFM_PATTERN(16, 0x4489);
const FluxPattern MFM_PATTERN(48, 0x448944894489LL);

const FluxMatchers ANY_RECORD_PATTERN(
{
Expand All @@ -100,7 +102,8 @@ AbstractDecoder::RecordType IbmDecoder::advanceToNextRecord()
if (_currentHeaderLength > 0)
readRawBits(_currentHeaderLength*16);
auto idbits = readRawBits(16);
uint8_t id = decodeFmMfm(idbits).slice(0, 1)[0];
const Bytes idbytes = decodeFmMfm(idbits);
uint8_t id = idbytes.slice(0, 1)[0];
seek(here);

switch (id)
Expand Down
8 changes: 3 additions & 5 deletions lib/decoders/decoders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ void AbstractDecoder::decodeToSectors(Track& track)
sector.headerStartTime = recordStart.ns();
sector.headerEndTime = recordEnd.ns();
r = advanceToNextRecord();
recordStart = fmr.tell();
if (r == DATA_RECORD)
{
recordStart = fmr.tell();
decodeDataRecord();
recordEnd = fmr.tell();
pushRecord(recordStart, recordEnd);
}
recordEnd = fmr.tell();
pushRecord(recordStart, recordEnd);
}
sector.dataStartTime = recordStart.ns();
sector.dataEndTime = recordEnd.ns();
Expand Down
9 changes: 8 additions & 1 deletion lib/decoders/fluxmapreader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ static DoubleFlag clockIntervalBias(
"Adjust intervals between pulses by this many clocks before decoding.",
-0.02);

static DoubleFlag minimumClockUs(
{ "--minimum-clock-us" },
"Refuse to detect clocks shorter than this, to avoid false positives.",
0.75);

int FluxmapReader::readOpcode(unsigned& ticks)
{
ticks = 0;
Expand Down Expand Up @@ -222,7 +227,9 @@ nanoseconds_t FluxmapReader::seekToPattern(const FluxMatcher& pattern, const Flu
seek(positions[intervalCount-match.intervals]);
_pos.zeroes = match.zeroes;
matching = match.matcher;
return match.clock * NS_PER_TICK;
nanoseconds_t detectedClock = match.clock * NS_PER_TICK;
if (detectedClock > (minimumClockUs*1000))
return match.clock * NS_PER_TICK;
}

for (unsigned i=0; i<intervalCount; i++)
Expand Down
4 changes: 2 additions & 2 deletions lib/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ void readDiskCommand(AbstractDecoder& decoder)
std::cout << "\nRaw (undecoded) records follow:\n\n";
for (auto& record : track->rawrecords)
{
std::cout << fmt::format("I+{:.2f}us", record.position.ns() / 1000.0)
<< std::endl;
std::cout << fmt::format("I+{:.2f}us with {:.2f}us clock\n",
record.position.ns() / 1000.0, record.clock / 1000.0);
hexdump(std::cout, record.data);
std::cout << std::endl;
}
Expand Down

0 comments on commit 9e75dc3

Please sign in to comment.