Skip to content

Commit 8b59663

Browse files
committedDec 29, 2023
[#80] Support for HxC Floppy Emulator *.HFE images (Part 1.6: Fixes)
1 parent 3e267b6 commit 8b59663

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed
 

‎Main/src/HFE.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929

3030

31-
#define HEADER_SIGNATURE "HXCPICFE"
31+
#define HEADER_SIGNATURE "HXCPICFE"
3232

33-
CHFE::UHeader::UHeader(){
33+
CHFE::UHeader::UHeader(){
3434
// ctor
3535
::ZeroMemory( this, sizeof(*this) );
36-
::lstrcpyA( signature, HEADER_SIGNATURE );
36+
::lstrcpyA( signature, HEADER_SIGNATURE );
3737
trackEncoding=TTrackEncoding::UNKNOWN;
3838
floppyInterface=TFloppyInterface::DISABLED;
3939
cylInfosBegin=1;
@@ -43,10 +43,10 @@
4343

4444
bool CHFE::UHeader::IsValid() const{
4545
// True <=> this Header follows HFE specification, otherwise False
46-
return !::memcmp( signature, HEADER_SIGNATURE, sizeof(signature) )
46+
return !::memcmp( signature, HEADER_SIGNATURE, sizeof(signature) )
47+
&&
48+
formatRevision==0
4749
&&
48-
formatRevision==0
49-
&&
5050
0<nCylinders // mustn't be zero for 'capsImageInfo.maxcylinder' is inclusive! (and "-1" isn't valid)
5151
&&
5252
0<nHeads && nHeads<=2
@@ -67,7 +67,7 @@
6767

6868
CHFE::CTrackBytes::CTrackBytes(WORD count)
6969
// ctor
70-
: Utils::CCallocPtr<BYTE>( Utils::RoundUpToMuls(count,(WORD)sizeof(TTrackData)), 0 )
70+
: Utils::CCallocPtr<BYTE>( Utils::RoundUpToMuls<int>(count,sizeof(TTrackData)), 0 )
7171
, count(count) {
7272
ASSERT( count>0 ); // call Invalidate() to indicate "no Bytes"
7373
}
@@ -85,7 +85,7 @@
8585

8686
void CHFE::CTrackBytes::ReverseBitsInEachByte() const{
8787
// reverses the order of bits in each Byte
88-
for( PBYTE p=*this,pLast=p+count; p<pLast; p++ )
88+
for( PBYTE p=*this,pLast=GetEnd(); p<pLast; p++ )
8989
*p=Utils::GetReversedByte(*p);
9090
}
9191

@@ -95,13 +95,13 @@
9595

9696

9797

98-
98+
9999
#define INI_SECTION _T("HxC2k1")
100100

101-
CHFE::CHFE()
102-
// ctor
103-
: CCapsBase( &Properties, '\0', true, INI_SECTION ) {
104-
Reset();
101+
CHFE::CHFE()
102+
// ctor
103+
: CCapsBase( &Properties, '\0', true, INI_SECTION ) {
104+
Reset();
105105
}
106106

107107

@@ -232,8 +232,9 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT);
232232
else
233233
return ERROR_UNRECOGNIZED_MEDIA;
234234
// - base
235-
if (floppyType!=pFormat->mediumType)
236-
DestroyAllTracks(); // must reconstruct all Tracks with parameters corresponding to new Medium Type
235+
if (floppyType!=pFormat->mediumType) // must reconstruct all Tracks with parameters corresponding to new Medium Type?
236+
if (m_strPathName.GetLength()>0)
237+
DestroyAllTracks();
237238
return __super::SetMediumTypeAndGeometry( pFormat, sideMap, firstSectorNumber );
238239
}
239240

@@ -249,12 +250,12 @@ formatError: ::SetLastError(ERROR_BAD_FORMAT);
249250
if (const TStdWinError err=__super::Reset())
250251
return err;
251252
// - reinitializing to an empty Image
252-
header=UHeader();
253+
header=UHeader();
253254
::ZeroMemory( cylInfos, sizeof(cylInfos) );
254255
::ZeroMemory( &capsImageInfo, sizeof(capsImageInfo) );
255256
return ERROR_SUCCESS;
256257
}
257-
258+
258259

259260
CHFE::CTrackBytes CHFE::ReadTrackBytes(TCylinder cyl,THead head) const{
260261
// reads from File and returns raw data of specified Track

‎Main/src/HFE.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
WORD nBlocksOffset;
8181
WORD nBytesLength;
8282

83-
inline bool IsValid() const{ return nBlocksOffset!=0 && nBytesLength!=0; }
83+
inline bool IsValid() const{ return nBlocksOffset>=2 && nBytesLength!=0; }
8484
} cylInfos[FDD_CYLINDERS_MAX];
8585

8686
class CTrackBytes sealed:public Utils::CCallocPtr<BYTE>{
@@ -91,6 +91,7 @@
9191

9292
inline operator PBYTE() const{ return get(); }
9393
inline WORD GetCount() const{ return count; }
94+
inline PBYTE GetEnd() const{ return get()+count; }
9495
void Invalidate();
9596
void ReverseBitsInEachByte() const;
9697
};

0 commit comments

Comments
 (0)
Please sign in to comment.