Skip to content

Commit

Permalink
Supporting ADFs with less than 80 cylinders (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Apr 25, 2023
1 parent 4b57265 commit 2ad67c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions Emulator/Media/DiskFiles/ADFFile.cpp
Expand Up @@ -31,18 +31,15 @@ bool
ADFFile::isCompatible(std::istream &stream)
{
isize length = util::streamLength(stream);

// Some ADFs contain an additional byte at the end. Ignore it.
length &= ~1;

// There are no magic bytes. Hence, we only check the file size.
return
length == ADFSIZE_35_DD ||
length == ADFSIZE_35_DD_81 ||
length == ADFSIZE_35_DD_82 ||
length == ADFSIZE_35_DD_83 ||
length == ADFSIZE_35_DD_84 ||
length == ADFSIZE_35_HD;

// The size must be a multiple of the cylinder size
if (length % 11264) return false;

// Check some more limits
return length <= ADFSIZE_35_DD_84 || length == ADFSIZE_35_HD;
}

isize
Expand Down Expand Up @@ -138,6 +135,13 @@ ADFFile::init(MutableFileSystem &volume)
volume.exportVolume(data.ptr, data.size);
}

void
ADFFile::finalizeRead()
{
// Add some empty cylinders if the file contains less than 80
if (data.size < ADFSIZE_35_DD) data.resize(ADFSIZE_35_DD, 0);
}

isize
ADFFile::numCyls() const
{
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Media/DiskFiles/ADFFile.h
Expand Up @@ -79,7 +79,7 @@ class ADFFile : public FloppyFile {
bool isCompatiblePath(const string &path) const override { return isCompatible(path); }
bool isCompatibleStream(std::istream &stream) const override { return isCompatible(stream); }
FileType type() const override { return FILETYPE_ADF; }

void finalizeRead() override;

//
// Methods from DiskFile
Expand Down

0 comments on commit 2ad67c0

Please sign in to comment.