Skip to content

Commit 5098bf5

Browse files
committedNov 9, 2023
[#57] Support for KryoFlux and associated images (Part 187: Fixed cooperation with legacy MFC)
1 parent 1201f05 commit 5098bf5

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed
 

‎Main/src/Greaseweazle.cpp

+50-49
Original file line numberDiff line numberDiff line change
@@ -419,53 +419,53 @@
419419
params.GetGlobalFluxDecoder(), params.resetFluxDecoderOnIndex
420420
);
421421
const PCBYTE pEnd=p+length;
422-
for( int sampleCounter=0,sampleCounterSinceIndex=0; p<pEnd; p++ ){
423-
const BYTE i=*p;
424-
if (i<TFluxOp::Special){
425-
// flux information
426-
if (i<250)
427-
// "short" flux (1-249 samples, single Byte; 0 indicates end of Stream)
428-
sampleCounter+=i;
429-
else{
430-
// "long" flux (250-1524 samples, two Bytes)
431-
if (++p>=pEnd) // unexpected end of Stream?
432-
return CTrackReaderWriter::Invalid;
433-
sampleCounter+=250+(i-250)*255+*p-1;
434-
}
435-
result.AddTime(
436-
result.GetLastIndexTime()+sampleClock*( sampleCounterSinceIndex+=sampleCounter )
437-
);
438-
sampleCounter=0;
439-
}else{
440-
// special information
441-
if (++p>=pEnd) // unexpected end of Stream? (incl. below Opcode)
442-
return CTrackReaderWriter::Invalid;
443-
switch (const TFluxOp opcode=(TFluxOp)*p++){
444-
case TFluxOp::Index:{ // index information
445-
if (p+sizeof(int)>=pEnd) // unexpected end of Stream?
446-
return CTrackReaderWriter::Invalid;
447-
const int value=ReadBits28(p);
448-
p+=sizeof(int)-1; // "-1" = see "p++" at the end of cycle
449-
result.AddIndexTime(
450-
result.GetLastIndexTime()+sampleClock*( sampleCounterSinceIndex+sampleCounter+value )
451-
);
452-
sampleCounterSinceIndex= -(sampleCounter+value);
453-
break;
454-
}
455-
case TFluxOp::Space: // "extra long" flux (1525-(2^28-1), seven Bytes, e.g. unformatted area)
456-
if (p+sizeof(int)>=pEnd) // unexpected end of Stream?
457-
return CTrackReaderWriter::Invalid;
458-
sampleCounter+=ReadBits28(p); // addendum to ...
459-
p+=sizeof(int)-1; // "-1" = see "p++" at the end of cycle
460-
break; // ... another flux
461-
//case TFluxOp::Astable:
462-
//commented out as Astable is intended for representation of non-formatted areas during writing, so it never appears during reading [personal communication with Keir Fraser]
463-
default:
464-
return CTrackReaderWriter::Invalid;
465-
}
466-
}
467-
}
468-
return result;
422+
for( int sampleCounter=0,sampleCounterSinceIndex=0; p<pEnd; p++ ){
423+
const BYTE i=*p;
424+
if (i<TFluxOp::Special){
425+
// flux information
426+
if (i<250)
427+
// "short" flux (1-249 samples, single Byte; 0 indicates end of Stream)
428+
sampleCounter+=i;
429+
else{
430+
// "long" flux (250-1524 samples, two Bytes)
431+
if (++p>=pEnd) // unexpected end of Stream?
432+
return CTrackReaderWriter::Invalid;
433+
sampleCounter+=250+(i-250)*255+*p-1;
434+
}
435+
result.AddTime(
436+
result.GetLastIndexTime()+sampleClock*( sampleCounterSinceIndex+=sampleCounter )
437+
);
438+
sampleCounter=0;
439+
}else{
440+
// special information
441+
if (++p>=pEnd) // unexpected end of Stream? (incl. below Opcode)
442+
return CTrackReaderWriter::Invalid;
443+
switch (const TFluxOp opcode=(TFluxOp)*p++){
444+
case TFluxOp::Index:{ // index information
445+
if (p+sizeof(int)>=pEnd) // unexpected end of Stream?
446+
return CTrackReaderWriter::Invalid;
447+
const int value=ReadBits28(p);
448+
p+=sizeof(int)-1; // "-1" = see "p++" at the end of cycle
449+
result.AddIndexTime(
450+
result.GetLastIndexTime()+sampleClock*( sampleCounterSinceIndex+sampleCounter+value )
451+
);
452+
sampleCounterSinceIndex= -(sampleCounter+value);
453+
break;
454+
}
455+
case TFluxOp::Space: // "extra long" flux (1525-(2^28-1), seven Bytes, e.g. unformatted area)
456+
if (p+sizeof(int)>=pEnd) // unexpected end of Stream?
457+
return CTrackReaderWriter::Invalid;
458+
sampleCounter+=ReadBits28(p); // addendum to ...
459+
p+=sizeof(int)-1; // "-1" = see "p++" at the end of cycle
460+
break; // ... another flux
461+
//case TFluxOp::Astable:
462+
//commented out as Astable is intended for representation of non-formatted areas during writing, so it never appears during reading [personal communication with Keir Fraser]
463+
default:
464+
return CTrackReaderWriter::Invalid;
465+
}
466+
}
467+
}
468+
return result;
469469
}
470470

471471
CImage::CTrackReader CGreaseweazleV4::ReadTrack(TCylinder cyl,THead head) const{
@@ -650,6 +650,7 @@
650650
}
651651

652652
void CGreaseweazleV4::SetPathName(LPCTSTR lpszPathName,BOOL bAddToMRU){
653-
__super::SetPathName( lpszPathName, bAddToMRU );
654-
m_strPathName=lpszPathName;
653+
TCHAR copy[DEVICE_NAME_CHARS_MAX+1];
654+
__super::SetPathName( ::lstrcpy(copy,lpszPathName), bAddToMRU );
655+
m_strPathName=copy;
655656
}

‎Main/src/KryoFluxDevice.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@
914914
}
915915

916916
void CKryoFluxDevice::SetPathName(LPCTSTR lpszPathName,BOOL bAddToMRU){
917-
__super::SetPathName( lpszPathName, bAddToMRU );
918-
m_strPathName=lpszPathName;
917+
TCHAR copy[DEVICE_NAME_CHARS_MAX+1];
918+
__super::SetPathName( ::lstrcpy(copy,lpszPathName), bAddToMRU );
919+
m_strPathName=copy;
919920
}

0 commit comments

Comments
 (0)
Please sign in to comment.