Skip to content

Commit

Permalink
[#64] Internal FDD improvements and bugfixes (Part 16.1: Fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-nestorovic committed Mar 28, 2022
1 parent 8216975 commit 09258b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
47 changes: 26 additions & 21 deletions Main/src/FDD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ terminateWithError: fdd->UnformatInternalTrack(cyl,head); // disposing any new
TInternalTrack::TSectorInfo *psi=sectors;
for( TSector s=0; s<nSectors; psi++->seqNum=s++ ){
psi->length=fdd->GetUsableSectorLength(( psi->id=*bufferId++ ).lengthCode );
for( BYTE r=0; r<Revolution::MAX; r++ )
psi->revolutions[r].fdcStatus=TFdcStatus::Unknown; // not yet attempted for reading
psi->dirtyRevolution=Revolution::NONE;
if (sectorStartsNanoseconds>(PCLogTime)0x100) // if start times provided (that is, if no Gap3 information from <0;255> Bytes provided) ...
psi->startNanoseconds=*sectorStartsNanoseconds++; // ... they are used
Expand Down Expand Up @@ -891,7 +893,6 @@ error: switch (const TStdWinError err=::GetLastError()){
}
}
// . executing the above composed Plan
const bool silentlyRecoverFromErrors=rev>=Revolution::ANY_GOOD;
for( const TPlanStep *pPlanStep=plan; pPlanStep<planEnd; pPlanStep++ ){
TInternalTrack::TSectorInfo &rsi=*pPlanStep->psi;
const BYTE index=pPlanStep->indexIntoOutputBuffers;
Expand All @@ -902,22 +903,24 @@ error: switch (const TStdWinError err=::GetLastError()){
rsi.currentRevolution=rsi.dirtyRevolution;
else
switch (rev){
case Revolution::CURRENT:
// getting Current Revolution
break;
default:
if (rev<rsi.nRevolutions)
if (rev<rsi.nRevolutions){
// getting particular existing Revolution
rsi.currentRevolution=rev;
else if (rev<Revolution::MAX)
break;
}else if (rev<Revolution::MAX){
// getting particular non-existing Revolution by subsequently requesting Next Revolutions
for( WORD w; rsi.nRevolutions<rev; )
GetSectorData( cyl, head, Revolution::NEXT, &rsi.id, rsi.seqNum, &w, &TFdcStatus() );
else{
rsi.nRevolutions = rsi.currentRevolution = rev;
//fallthrough
}else{
ASSERT(FALSE); // we shouldn't end up here!
::SetLastError( ERROR_BAD_COMMAND );
return;
}
break;
case Revolution::CURRENT:
// getting Current Revolution
break;
//fallthrough
case Revolution::NEXT:{
// getting Next Revolution
// > if the Next Revolution maps to an existing Revolution, return it
Expand All @@ -932,18 +935,10 @@ error: switch (const TStdWinError err=::GetLastError()){
);
rsi.nRevolutions--;
}
// > attempt for the Data
auto &rev=rsi.revolutions[ rsi.currentRevolution=rsi.nRevolutions ]; // the last Revolution, below set empty
rev.data=nullptr; // Sector with given ID physically not found or has no DAM)
rev.fdcStatus=TFdcStatus::NoDataField;
// > seek Head over the given Cylinder
if (!fddHead.__seekTo__(cyl))
return; // Sectors cannot be found as Head cannot be seeked
// > attempt for the Data
if (__bufferSectorData__( cyl, head, &rsi.id, length, pit, bufferNumbersOfSectorsToSkip[index], &rev.fdcStatus ) // yes, Sector found ...
&&
!rev.fdcStatus.DescribesMissingDam() // ... and has a DAM
)
rev.data=(PSectorData)::memcpy( ALLOCATE_SECTOR_DATA(length), dataBuffer, length );
rev.fdcStatus=TFdcStatus::Unknown; // attempt for the data below
rsi.nRevolutions++;
break;
}
Expand Down Expand Up @@ -987,8 +982,18 @@ error: switch (const TStdWinError err=::GetLastError()){
break;
}
}
// : if not yet attempted for the data, doing so now
auto &rev=rsi.revolutions[rsi.currentRevolution];
if (rev.fdcStatus.ToWord()==TFdcStatus::Unknown.ToWord()){
if (!fddHead.__seekTo__(cyl))
return; // Sectors cannot be found as Head cannot be seeked
if (__bufferSectorData__( cyl, head, &rsi.id, length, pit, bufferNumbersOfSectorsToSkip[index], &rev.fdcStatus ) // yes, Sector found ...
&&
!rev.fdcStatus.DescribesMissingDam() // ... and has a DAM
)
rev.data=(PSectorData)::memcpy( ALLOCATE_SECTOR_DATA(length), dataBuffer, length );
}
// : returning (any) Data
const auto &rev=rsi.revolutions[rsi.currentRevolution];
outFdcStatuses[index]=rev.fdcStatus;
outBufferData[index]=rev.data;
}
Expand Down
1 change: 1 addition & 0 deletions Main/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@



const TFdcStatus TFdcStatus::Unknown(-1,-1);
const TFdcStatus TFdcStatus::WithoutError;
const TFdcStatus TFdcStatus::SectorNotFound( FDC_ST1_NO_ADDRESS_MARK, 0 );
const TFdcStatus TFdcStatus::IdFieldCrcError( FDC_ST1_DATA_ERROR|FDC_ST1_NO_DATA, 0 );
Expand Down
1 change: 1 addition & 0 deletions Main/src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@

#pragma pack(1)
typedef const struct TFdcStatus sealed{
static const TFdcStatus Unknown; // e.g. when Sector not yet attempted for reading
static const TFdcStatus WithoutError;
static const TFdcStatus SectorNotFound;
static const TFdcStatus IdFieldCrcError;
Expand Down

0 comments on commit 09258b7

Please sign in to comment.