Skip to content

Commit

Permalink
[#80] Support for HxC Floppy Emulator *.HFE images (Part 13: Must pla…
Browse files Browse the repository at this point in the history
…ce fuzzy bits in fuzzy positions to reproduce them on a real disk)
  • Loading branch information
tomas-nestorovic committed Dec 8, 2024
1 parent 96bc878 commit 7e32bb2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Main/src/HFE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT);
CTrackReaderWriter trw( bytes.GetCount()*CHAR_BIT, params.fluxDecoder, params.resetFluxDecoderOnIndex );
PCBYTE p=bytes,const pLast=bytes.end();
TLogTime tCell=GetCellTime( header.dataBitRate*1000 );
TLogTime tCurr=0;
for( BYTE nFollowingDataBitsToSkip=0; p<pLast; )
TLogTime tCurr=0;
for( BYTE nFollowingDataBitsToSkip=0,fuzzyQuot=100; p<pLast; )
switch (BYTE b=*p++){
case TOpCode::SETINDEX:
trw.AddIndexTime( tCurr );
Expand All @@ -354,26 +354,27 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT);
break;
case TOpCode::RANDOM:
b=::rand()&0x54; // constant adopted from HxC2001 emulator
fuzzyQuot=146; // let fluxes be at the very edge of neighboring cells
//fallthrough ('b' is now smaller than 'TOpCode::NOP')
default:
if (b>=TOpCode::NOP){ // invalid OpCode ?
ASSERT( b==TOpCode::NOP ); // 'TOpCode::NOP' is fine here (as it doesn't have its own 'case' in this 'switch')
break; // skip it
}
const BYTE nBits=CHAR_BIT-nFollowingDataBitsToSkip;
const TLogTime tSpan=nBits*tCell;
const TLogTime tSpan=nBits*tCell, tFuzzy=tCell*fuzzyQuot/100;
for( BYTE data=b<<nFollowingDataBitsToSkip,i=0; data; data<<=1,i++ )
if ((char)data<0)
trw.AddTime( tCurr + i*tCell );
trw.AddTime( tCurr + i*tCell+tFuzzy );
tCurr+=tSpan;
nFollowingDataBitsToSkip=0;
nFollowingDataBitsToSkip=0, fuzzyQuot=100;
break;
}
if (trw.GetIndexCount()<1)
trw.AddIndexTime(0);
if (trw.GetIndexCount()<2)
trw.AddIndexTime(tCurr);
return CInternalTrack::CreateFrom( *this, trw, floppyType );
return CInternalTrack::CreateFrom( *this, trw, floppyType );
}else{
CapsTrackInfoT2 cti={};
cti.trackbuf=bytes;
Expand Down

0 comments on commit 7e32bb2

Please sign in to comment.