Skip to content

Commit

Permalink
[#57] Support for KryoFlux and associated images (Part 205: Removed r…
Browse files Browse the repository at this point in the history
…edundant info on count of sectors)
  • Loading branch information
tomas-nestorovic committed Sep 16, 2024
1 parent 8a258c1 commit 1b55dfe
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
28 changes: 14 additions & 14 deletions Main/src/CapsBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@
: CTrackReaderWriter(trw)
// - initialization
, modified(false)
, nSectors(nSectors) , sectors( nSectors, sectors ) {
, sectors( nSectors, sectors ) {
RewindToIndex(0);
}

CCapsBase::CInternalTrack::~CInternalTrack(){
// dtor
for( TSector i=0; i<nSectors; i++ )
for( TSector i=0; i<sectors.length; i++ )
for( BYTE r=0; r<Revolution::MAX; r++ )
if (const PVOID data=sectors[i].revolutions[r].data)
::free(data);
Expand Down Expand Up @@ -419,7 +419,7 @@

void CCapsBase::CInternalTrack::FlushSectorBuffers(){
// spreads referential "dirty" data (if Sector modified) across each Revolution
for( TSector s=0; s<nSectors; s++ ){
for( TSector s=0; s<sectors.length; s++ ){
const TInternalSector &ris=sectors[s];
if (ris.dirtyRevolution<Revolution::MAX){
// Sector has been modified
Expand Down Expand Up @@ -571,14 +571,14 @@
// . attempting to return good data
EXCLUSIVELY_LOCK_THIS_IMAGE(); // !!! see also below this->{Lock,Unlock}
if (rit){ // may be Null if, e.g., device manually reset, disconnected, etc.
if (GetCountOfHealthySectors(cyl,head)>0 || !rit->nSectors // Track at least partly healthy or without known Sectors
if (GetCountOfHealthySectors(cyl,head)>0 || !rit->sectors.length // Track at least partly healthy or without known Sectors
||
params.calibrationAfterError==TParams::TCalibrationAfterError::NONE // calibration disabled
)
break;
if (params.calibrationAfterErrorOnlyForKnownSectors && dos->IsKnown()){
bool knownSectorBad=false; // assumption (the Track is unhealthy due to an irrelevant Unknown Sector, e.g. out of geometry)
for( TSector s=0; s<rit->nSectors; s++ ){
for( TSector s=0; s<rit->sectors.length; s++ ){
const TInternalSector &is=rit->sectors[s];
const TPhysicalAddress chs={ cyl, head, is.id };
if (!dos->IsStdSector(chs))
Expand Down Expand Up @@ -609,7 +609,7 @@
}
// - scanning the Track
if (const PCInternalTrack pit=rit){
for( TSector s=0; s<pit->nSectors; s++ ){
for( TSector s=0; s<pit->sectors.length; s++ ){
const TInternalSector &ris=pit->sectors[s];
if (bufferId)
*bufferId++=ris.id;
Expand All @@ -628,7 +628,7 @@
*pCodec=pit->GetCodec();
if (pAvgGap3)
*pAvgGap3=FDD_350_SECTOR_GAP3*2/3; // TODO
return pit->nSectors;
return pit->sectors.length;
}else
return 0;
}
Expand Down Expand Up @@ -665,7 +665,7 @@
// . searching for the Sector on the Track
const TSectorId sectorId=*bufferId++;
TInternalSector *pis=pit->sectors;
TSector n=pit->nSectors;
TSector n=pit->sectors.length;
for( BYTE nSectorsToSkip=*bufferNumbersOfSectorsToSkip++; n>0; n--,pis++ )
if (nSectorsToSkip)
nSectorsToSkip--;
Expand Down Expand Up @@ -736,7 +736,7 @@
ASSERT( rev<Revolution::MAX );
EXCLUSIVELY_LOCK_THIS_IMAGE();
if (const PCInternalTrack pit=GetInternalTrackSafe(cyl,head)) // is Track scanned?
while (nSectorsToSkip<pit->nSectors){
while (nSectorsToSkip<pit->sectors.length){
const auto &ris=pit->sectors[nSectorsToSkip++];
if (ris.id==id)
if (rev>=ris.nRevolutions)
Expand All @@ -754,7 +754,7 @@
Revolution::TType CCapsBase::GetDirtyRevolution(RCPhysicalAddress chs,BYTE nSectorsToSkip) const{
// returns the Revolution that has been marked as "dirty"
if (const PCInternalTrack pit=GetInternalTrackSafe(chs.cylinder,chs.head))
while (nSectorsToSkip<pit->nSectors){
while (nSectorsToSkip<pit->sectors.length){
const auto &ris=pit->sectors[nSectorsToSkip++];
if (ris.id==chs.sectorId)
return ris.dirtyRevolution;
Expand Down Expand Up @@ -790,7 +790,7 @@
CInternalTrack::CreateFrom( *this, trw, rOutMediumType=(Medium::TType)type )
)
){
const TSector nRecognizedSectors=rit->nSectors;
const TSector nRecognizedSectors=rit->sectors.length;
if (WORD score= nRecognizedSectors + 32*GetCountOfHealthySectors(cyl,0)){
if (Medium::GetProperties( (Medium::TType)type )->IsAcceptableRevolutionTime( trw.GetAvgIndexDistance() ))
score|=0x8000;
Expand Down Expand Up @@ -1013,12 +1013,12 @@
const Utils::CVarTempReset<PInternalTrack> pit0( internalTracks[cyl][head], nullptr ); // forcing rescan
ScanTrack( cyl, head );
if (const PInternalTrack pitVerif=internalTracks[cyl][head]){
if (pitVerif->nSectors>0 || !cancelled){
if (pitVerif->sectors.length>0 || !cancelled){
const PInternalTrack pitWritten=CInternalTrack::CreateFrom( *this, trwWritten, floppyType );
// . comparing common cells between first two Indices
const auto &revWrittenFirstSector=pitWritten->sectors[0].revolutions[0];
const auto &revWrittenFirstSector=pitWritten->sectors[(TSector)0].revolutions[0];
pitWritten->SetCurrentTimeAndProfile( revWrittenFirstSector.idEndTime, revWrittenFirstSector.idEndProfile );
const auto &revVerifFirstSector=pitVerif->sectors[0].revolutions[0];
const auto &revVerifFirstSector=pitVerif->sectors[(TSector)0].revolutions[0];
pitVerif->SetCurrentTimeAndProfile( revVerifFirstSector.idEndTime, revVerifFirstSector.idEndProfile );
while (
*pitWritten && pitWritten->GetCurrentTime()<pitWritten->GetIndexTime(1)
Expand Down
3 changes: 1 addition & 2 deletions Main/src/CapsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
static CInternalTrack *CreateFrom(const CCapsBase &cb,const CapsTrackInfoT2 *ctiRevs,BYTE nRevs,UDWORD lockFlags);
static CInternalTrack *CreateFrom(const CCapsBase &cb,CTrackReaderWriter trw,Medium::TType floppyType=Medium::UNKNOWN);

const TSector nSectors;
const Utils::CCallocPtr<TInternalSector> sectors;
const Utils::CCallocPtr<TInternalSector,TSector> sectors;
bool modified;

~CInternalTrack();
Expand Down
2 changes: 1 addition & 1 deletion Main/src/CapsBase_Mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
TARGET_ALL_STD_SECTORS_PRESENT
);
}
if (pit && pit->nSectors){
if (pit && pit->sectors.length){
cbx.SetItemData(
cbx.AddString(_T("All current sectors healthy")),
TARGET_ALL_CURRENT_SECTORS_HEALTHY
Expand Down
2 changes: 1 addition & 1 deletion Main/src/KryoFluxBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
if (chs.cylinder>capsImageInfo.maxcylinder || chs.head>capsImageInfo.maxhead)
return ERROR_INVALID_PARAMETER;
if (const PInternalTrack pit=internalTracks[chs.cylinder][chs.head]){
while (nSectorsToSkip<pit->nSectors){
while (nSectorsToSkip<pit->sectors.length){
auto &ris=pit->sectors[nSectorsToSkip++];
if (ris.id==chs.sectorId){
ASSERT( ris.dirtyRevolution>=Revolution::MAX||ris.dirtyRevolution==ris.currentRevolution ); // no Revolution yet marked as "dirty" or marking "dirty" the same Revolution
Expand Down
8 changes: 4 additions & 4 deletions Main/src/KryoFluxDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@
for( BYTE i=1; i<pit->GetIndexCount(); i++ ){
const BYTE r=i-1;
TSector nHealthySectors=0; bool hasDataOverIndex=false; // assumptions
for( TSector s=0; s<pit->nSectors; s++ ){
for( TSector s=0; s<pit->sectors.length; s++ ){
pit->ReadSector( pit->sectors[s], r );
const auto &rev=pit->sectors[s].revolutions[r];
if (pit->GetIndexTime(i)<rev.dataEndTime){ // data over index?
Expand All @@ -711,14 +711,14 @@
}
if (bestRev.nHealthySectors<nHealthySectors) // better Revolution found?
bestRev.i=r, bestRev.nHealthySectors=nHealthySectors, bestRev.hasDataOverIndex=hasDataOverIndex;
if (bestRev.nHealthySectors==pit->nSectors) // best possible Revolution found?
if (bestRev.nHealthySectors==pit->sectors.length) // best possible Revolution found?
break;
}
// . extracting the minimum number of fluxes into the temporary Track
const TLogTime tIndex0=pit->RewindToIndex(bestRev.i), tIndex1=pit->GetIndexTime(bestRev.i+1);
TLogTime tWritingEnd=tIndex1;
if (bestRev.hasDataOverIndex){
const auto &firstSector=pit->sectors[0];
const auto &firstSector=pit->sectors[(TSector)0];
TLogTime tOverhang=INT_MAX;
for( BYTE r=0; r<firstSector.nRevolutions; r++ ){
TLogTime tIdEnd=firstSector.revolutions[r].idEndTime;
Expand Down Expand Up @@ -776,7 +776,7 @@
continue;
}
// . writing verification
if (!err && params.verifyWrittenTracks && pit->nSectors>0){ // can verify the Track only if A&B&C, A = writing successfull, B&C = at least one Sector is recognized in it
if (!err && params.verifyWrittenTracks && pit->sectors.length>0){ // can verify the Track only if A&B&C, A = writing successfull, B&C = at least one Sector is recognized in it
const Utils::CVarTempReset<TParams::TCalibrationAfterError> cae0( params.calibrationAfterError, TParams::TCalibrationAfterError::NONE ); // already calibrated before writing
const Utils::CVarTempReset<TParams::TPrecision> p0( params.precision, TParams::TPrecision::SINGLE );
std::unique_ptr<CTrackReaderWriter> pVerifiedTrack;
Expand Down

0 comments on commit 1b55dfe

Please sign in to comment.