Skip to content

Commit

Permalink
[#80] Support for HxC Floppy Emulator *.HFE images (Part 12: Adopted …
Browse files Browse the repository at this point in the history
…way of generating random bits from HxC2001 emulator)
  • Loading branch information
tomas-nestorovic committed Nov 14, 2024
1 parent 14cdfc9 commit d216fff
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions Main/src/HFE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT);
TLogTime tCell=GetCellTime( header.dataBitRate*1000 );
TLogTime tCurr=0;
for( BYTE nFollowingDataBitsToSkip=0; p<pLast; )
switch (const BYTE b=*p++){
switch (BYTE b=*p++){
case TOpCode::SETINDEX:
trw.AddIndexTime( tCurr );
break;
Expand All @@ -352,22 +352,14 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT);
ASSERT(nFollowingDataBitsToSkip>0);
}
break;
case TOpCode::RANDOM:{
BYTE nBits=CHAR_BIT-nFollowingDataBitsToSkip;
const TLogTime tSpan=nBits*tCell;
for( TLogTime t=0,const tLimit=tSpan-tCell/2; nBits>0; nBits-- ) // "tLimit" = make sure two Times don't overlap (e.g. end of this Random region and beginning of common data region)
if (( t+=::rand()%tSpan )<tLimit)
trw.AddTime( tCurr+t );
else
break;
tCurr+=tSpan;
nFollowingDataBitsToSkip=0;
break;
}
case TOpCode::RANDOM:
b=::rand()&0x54; // constant adopted from HxC2001 emulator
//fallthrough ('b' is now smaller than 'TOpCode::NOP')
default:
ASSERT( b<=TOpCode::NOP ); // 'TOpCode::NOP' is fine here (as it doesn't have its own 'case' in this 'switch')
if (b>=TOpCode::NOP) // invalid OpCode ?
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;
for( BYTE data=b<<nFollowingDataBitsToSkip,i=0; data; data<<=1,i++ )
Expand Down

0 comments on commit d216fff

Please sign in to comment.