Adding Cpress wrapper classes

This commit is contained in:
mlong 2021-03-07 08:19:05 -06:00
parent a3d4302df6
commit 87bd04eb55
6 changed files with 775 additions and 0 deletions

View File

@ -0,0 +1,70 @@
/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "cpressdiskfs.h"
#include "cpressdiskimage.h"
CPressDiskFS::~CPressDiskFS()
{
((CPressDiskImage *) parent())->rawDIDiskImg()->RemoveDiskFS(m_fs);
}
QString CPressDiskFS::volumeName() const
{
Q_ASSERT(m_fs);
return QString(m_fs->GetVolumeName());
}
QString CPressDiskFS::volumeID() const
{
Q_ASSERT(m_fs);
return QString(m_fs->GetVolumeID());
}
QString CPressDiskFS::bareVolumeName() const
{
Q_ASSERT(m_fs);
return QString(m_fs->GetBareVolumeName());
}
bool CPressDiskFS::isDamaged() const
{
Q_ASSERT(m_fs);
return m_fs->GetFSDamaged();
}
int CPressDiskFS::numFSBlocks() const
{
Q_ASSERT(m_fs);
return (int) m_fs->GetFSNumBlocks();
}
int CPressDiskFS::fileCount() const
{
Q_ASSERT(m_fs);
return (int) m_fs->GetFileCount();
}
CPressDiskFS::CPressDiskFS(CPressDiskImage *parent) : QObject(parent)
{
m_fs = parent->rawDIDiskImg()->OpenAppropriateDiskFS(true);
m_fs->SetScanForSubVolumes(DiskImgLib::DiskFS::kScanSubEnabled);
m_fs->Initialize(parent->rawDIDiskImg(),DiskImgLib::DiskFS::kInitFull);
}

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef CPRESSDISKFS_H
#define CPRESSDISKFS_H
#include <QObject>
#include "DiskImg.h"
class CPressDiskFS : public QObject
{
Q_OBJECT
public:
friend class CPressDiskImage;
~CPressDiskFS();
QString volumeName() const;
QString volumeID() const;
QString bareVolumeName() const;
bool isDamaged() const;
int numFSBlocks() const;
int fileCount() const;
protected:
explicit CPressDiskFS(CPressDiskImage *parent);
DiskImgLib::DiskFS *m_fs { nullptr };
};
#endif // CPRESSDISKFS_H

View File

@ -0,0 +1,428 @@
/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "cpressdiskimage.h"
#include <QFile>
#include <QDebug>
CPressDiskImage::CPressDiskImage(QObject *parent) : QObject(parent)
{
DiskImgLib::Global::AppInit();
m_image = new DiskImgLib::DiskImg();
}
CPressDiskImage::~CPressDiskImage()
{
close();
delete m_image;
}
QString CPressDiskImage::errorString() const
{
return QString(DiskImgLib::DIStrError(lastDIError()));
}
bool CPressDiskImage::openAndPrepare(const QString &filename)
{
bool retval = open(filename);
if (retval)
{
auto fs = new CPressDiskFS(this);
m_fs = QSharedPointer<CPressDiskFS>(fs);
}
return retval;
}
bool CPressDiskImage::open(const QString &filename)
{
#if 0
setImageName(filename);
QFile file(filename);
if (file.open(QIODevice::ReadOnly))
{
auto contents = file.readAll();
auto result = open(contents);
m_image->AnalyzeImage();
return result;
}
else
{
return false;
}
#else
auto fn = filename;
setImageName(fn);
auto result = m_image->OpenImage(qPrintable(fn),'\\',true);
m_image->AnalyzeImage();
return isDIOk(result);
#endif
}
bool CPressDiskImage::open(QByteArray &data)
{
Q_ASSERT(m_image);
auto result = m_image->OpenImageFromBufferRO((const uint8_t*)(data.data()),data.length());
m_last_di_error = result;
// m_image->AnalyzeImage();
// m_image->AnalyzeImageFS();
return (isDIOk(result));
}
bool CPressDiskImage::close()
{
Q_ASSERT(m_image);
auto result = m_image->CloseImage();
m_last_di_error = result;
return (isDIOk(result));
}
bool CPressDiskImage::analyzeImage()
{
Q_ASSERT(m_image);
// auto result = m_image->AnalyzeImage();
// m_last_di_error = result;
// if (isDIOk(result))
{
// m_image->AnalyzeImageFS();
}
// return (isDIOk(result));
return true;
}
bool CPressDiskImage::showAsBlocks() const
{
Q_ASSERT(m_image);
return m_image->ShowAsBlocks();
}
CPressDiskImage::OuterFormat CPressDiskImage::GetOuterFormat() const
{
Q_ASSERT(m_image);
switch (m_image->GetOuterFormat())
{
case DiskImgLib::DiskImg::kOuterFormatNone:
return OuterFormat::Unknown;
break;
case DiskImgLib::DiskImg::kOuterFormatCompress:
return OuterFormat::Compress;
break;
case DiskImgLib::DiskImg::kOuterFormatGzip:
return OuterFormat::GZip;
break;
case DiskImgLib::DiskImg::kOuterFormatBzip2:
return OuterFormat::BZip2;
break;
case DiskImgLib::DiskImg::kOuterFormatZip:
return OuterFormat::Zip;
break;
case DiskImgLib::DiskImg::kOuterFormatUnknown:
default:
return OuterFormat::Unknown;
break;
}
}
CPressDiskImage::FileFormat CPressDiskImage::GetFileFormat() const
{
Q_ASSERT(m_image);
switch (m_image->GetFileFormat())
{
case DiskImgLib::DiskImg::kFileFormatUnadorned:
return FileFormat::Unadorned;
break;
case DiskImgLib::DiskImg::kFileFormat2MG:
return FileFormat::TwoMG;
break;
case DiskImgLib::DiskImg::kFileFormatDiskCopy42:
return FileFormat::DiskCopy42;
break;
case DiskImgLib::DiskImg::kFileFormatDiskCopy60:
return FileFormat::DiskCopy60;
break;
case DiskImgLib::DiskImg::kFileFormatDavex:
return FileFormat::Davex;
break;
case DiskImgLib::DiskImg::kFileFormatSim2eHDV:
return FileFormat::Sim2eHDV;
break;
case DiskImgLib::DiskImg::kFileFormatTrackStar:
return FileFormat::TrackStar;
break;
case DiskImgLib::DiskImg::kFileFormatFDI:
return FileFormat::FDI;
break;
case DiskImgLib::DiskImg::kFileFormatNuFX:
return FileFormat::NuFX;
break;
case DiskImgLib::DiskImg::kFileFormatDDD:
return FileFormat::DDD;
break;
case DiskImgLib::DiskImg::kFileFormatDDDDeluxe:
return FileFormat::DDDDeluxe;
break;
case DiskImgLib::DiskImg::kFileFormatUnknown:
default:
return FileFormat::Unknown;
break;
}
}
CPressDiskImage::PhysicalFormat CPressDiskImage::GetPhysicalFormat() const
{
Q_ASSERT(m_image);
switch (m_image->GetPhysicalFormat())
{
case DiskImgLib::DiskImg::kPhysicalFormatSectors:
return PhysicalFormat::Sectors;
break;
case DiskImgLib::DiskImg::kPhysicalFormatNib525_6656:
return PhysicalFormat::Nib525_6656;
break;
case DiskImgLib::DiskImg::kPhysicalFormatNib525_6384:
return PhysicalFormat::Nib525_6384;
break;
case DiskImgLib::DiskImg::kPhysicalFormatNib525_Var:
return PhysicalFormat::Nib525_Var;
break;
default:
case DiskImgLib::DiskImg::kPhysicalFormatUnknown:
return PhysicalFormat::Unknown;
break;
}
}
CPressDiskImage::SectorOrder CPressDiskImage::GetSectorOrder() const
{
Q_ASSERT(m_image);
switch (m_image->GetSectorOrder())
{
case DiskImgLib::DiskImg::kSectorOrderProDOS:
return SectorOrder::ProDOS;
break;
case DiskImgLib::DiskImg::kSectorOrderDOS:
return SectorOrder::DOS;
break;
case DiskImgLib::DiskImg::kSectorOrderCPM:
return SectorOrder::CPM;
break;
case DiskImgLib::DiskImg::kSectorOrderPhysical:
return SectorOrder::Physical;
break;
default:
case DiskImgLib::DiskImg::kSectorOrderUnknown:
return SectorOrder::Unknown;
break;
}
}
CPressDiskImage::FSFormat CPressDiskImage::GetFSFormat() const
{
Q_ASSERT(m_image);
switch (m_image->GetFSFormat())
{
case DiskImgLib::DiskImg::kFormatProDOS:
return FSFormat::ProDOS;
break;
case DiskImgLib::DiskImg::kFormatDOS33:
return FSFormat::DOS33;
break;
case DiskImgLib::DiskImg::kFormatDOS32:
return FSFormat::DOS32;
break;
case DiskImgLib::DiskImg::kFormatPascal:
return FSFormat::Pascal;
break;
case DiskImgLib::DiskImg::kFormatMacHFS:
return FSFormat::MacHFS;
break;
case DiskImgLib::DiskImg::kFormatMacMFS:
return FSFormat::MacMFS;
break;
case DiskImgLib::DiskImg::kFormatLisa:
return FSFormat::Lisa;
break;
case DiskImgLib::DiskImg::kFormatCPM:
return FSFormat::CPM;
break;
case DiskImgLib::DiskImg::kFormatMSDOS:
return FSFormat::MSDOS;
break;
case DiskImgLib::DiskImg::kFormatISO9660:
return FSFormat::ISO9660;
break;
case DiskImgLib::DiskImg::kFormatRDOS33:
return FSFormat::RDOS33;
break;
case DiskImgLib::DiskImg::kFormatRDOS32:
return FSFormat::RDOS32;
break;
case DiskImgLib::DiskImg::kFormatRDOS3:
return FSFormat::RDOS3;
break;
case DiskImgLib::DiskImg::kFormatGenericPhysicalOrd:
return FSFormat::GenericPhysicalOrd;
break;
case DiskImgLib::DiskImg::kFormatGenericProDOSOrd:
return FSFormat::GenericProDOSOrd;
break;
case DiskImgLib::DiskImg::kFormatGenericDOSOrd:
return FSFormat::GenericDOSOrd;
break;
case DiskImgLib::DiskImg::kFormatGenericCPMOrd:
return FSFormat::GenericCPMOrd;
break;
case DiskImgLib::DiskImg::kFormatUNIDOS:
return FSFormat::UNIDOS;
break;
case DiskImgLib::DiskImg::kFormatOzDOS:
return FSFormat::OzDOS;
break;
case DiskImgLib::DiskImg::kFormatCFFA4:
return FSFormat::CFFA4;
break;
case DiskImgLib::DiskImg::kFormatCFFA8:
return FSFormat::CFFA8;
break;
case DiskImgLib::DiskImg::kFormatMacPart:
return FSFormat::MacPart;
break;
case DiskImgLib::DiskImg::kFormatMicroDrive:
return FSFormat::MicroDrive;
break;
case DiskImgLib::DiskImg::kFormatFocusDrive:
return FSFormat::FocusDrive;
break;
case DiskImgLib::DiskImg::kFormatGutenberg:
return FSFormat::Gutenberg;
break;
default:
case DiskImgLib::DiskImg::kFormatUnknown:
return FSFormat::Unknown;
break;
}
}
int CPressDiskImage::numTracks() const
{
Q_ASSERT(m_image);
return (int) m_image->GetNumTracks();
}
int CPressDiskImage::sectorsPerTrack() const
{
Q_ASSERT(m_image);
return (int) m_image->GetNumSectPerTrack();
}
int CPressDiskImage::numBlocks() const
{
Q_ASSERT(m_image);
return (int) m_image->GetNumBlocks();
}
bool CPressDiskImage::checkForBadBlocks(int startBlock, int numBlocks)
{
Q_ASSERT(m_image);
return m_image->CheckForBadBlocks(startBlock, numBlocks);
}
short CPressDiskImage::dosVolumeNumber() const
{
Q_ASSERT(m_image);
return m_image->GetDOSVolumeNum();
}
bool CPressDiskImage::hasSectors() const
{
Q_ASSERT(m_image);
return m_image->GetHasSectors();
}
bool CPressDiskImage::hasBlocks() const
{
Q_ASSERT(m_image);
return m_image->GetHasBlocks();
}
bool CPressDiskImage::hasNibbles() const
{
Q_ASSERT(m_image);
return m_image->GetHasNibbles();
}
QByteArray CPressDiskImage::readTrackSector(int track, int sector)
{
QByteArray retval;
Q_ASSERT(m_image);
char data[256];
auto result = m_image->ReadTrackSector(track,sector,data);
m_last_di_error = result;
if (isDIOk(result))
{
retval.resize(256);
for (int idx = 0; idx < 256; idx++)
{
retval[idx] = data[idx];
}
}
// qDebug() << "Read track " << track << " sector " << sector << " = " << retval.size() << "bytes";
return retval;
}
QByteArray CPressDiskImage::readBlock(int block)
{
QByteArray retval;
Q_ASSERT(m_image);
char data[512];
auto result = m_image->ReadBlock(block,data);
m_last_di_error = result;
if (isDIOk(result))
{
retval.resize(512);
for (int idx = 0; idx < 512; idx++)
{
retval[idx] = data[idx];
}
}
return retval;
}
QByteArray CPressDiskImage::readBlocks(int startBlock, int numBlocks)
{
QByteArray retval;
Q_ASSERT(m_image);
char *data = new char[512*numBlocks];
auto result = m_image->ReadBlocks(startBlock,numBlocks,data);
m_last_di_error = result;
if (isDIOk(result))
{
retval.resize(512*numBlocks);
for (int idx = 0; idx < 512*numBlocks; idx++)
{
retval[idx] = data[idx];
}
}
delete[] data;
return retval;
}

View File

@ -0,0 +1,168 @@
/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef CPRESSDISKIMAGE_H
#define CPRESSDISKIMAGE_H
#include "DiskImg.h"
#include "cpressdiskfs.h"
#include <QObject>
#include <QSharedPointer>
using DIErrorCode = DiskImgLib::DIError;
class CPressDiskImage : public QObject
{
Q_OBJECT
public:
enum class OuterFormat {
Unknown = 0,
None = 1,
Compress = 2,
GZip = 3,
BZip2 = 4,
Zip = 10
};
enum class FileFormat { // format of the image "wrapper"
Unknown = 0,
Unadorned = 1, // .po, .do, ,nib, .raw, .d13
TwoMG = 2, // .2mg, .2img, $e0/0130
DiskCopy42 = 3, // .dsk/.disk, maybe .dc
DiskCopy60 = 4, // .dc6 (often just raw format)
Davex = 5, // $e0/8004
Sim2eHDV = 6, // .hdv
TrackStar = 7, // .app (40-track or 80-track)
FDI = 8, // .fdi (5.25" or 3.5")
NuFX = 20, // .shk, .sdk, .bxy
DDD = 21, // .ddd
DDDDeluxe = 22, // $DD, .ddd
};
enum class PhysicalFormat { // format of the image data stream
Unknown = 0,
Sectors = 1, // sequential 256-byte sectors (13/16/32)
Nib525_6656 = 2, // 5.25" disk ".nib" (6656 bytes/track)
Nib525_6384 = 3, // 5.25" disk ".nb2" (6384 bytes/track)
Nib525_Var = 4, // 5.25" disk (variable len, e.g. ".app")
};
enum class SectorOrder { // sector ordering for "sector" format images
Unknown = 0,
ProDOS = 1, // written as series of ProDOS blocks
DOS = 2, // written as series of DOS sectors
CPM = 3, // written as series of 1K CP/M blocks
Physical = 4 // written as un-interleaved sectors
};
enum class FSFormat { // main filesystem format (based on NuFX enum)
Unknown = 0,
ProDOS = 1,
DOS33 = 2,
DOS32 = 3,
Pascal = 4,
MacHFS = 5,
MacMFS = 6,
Lisa = 7,
CPM = 8,
MSDOS = 10, // any FAT filesystem
ISO9660 = 12,
RDOS33 = 20, // 16-sector RDOS disk
RDOS32 = 21, // 13-sector RDOS disk
RDOS3 = 22, // 13-sector RDOS disk converted to 16
GenericPhysicalOrd = 30, // unknown, but physical-sector-ordered
GenericProDOSOrd = 31, // unknown, but ProDOS-block-ordered
GenericDOSOrd = 32, // unknown, but DOS-sector-ordered
GenericCPMOrd = 33, // unknown, but CP/M-block-ordered
UNIDOS = 40, // two 400K DOS 3.3 volumes
OzDOS = 41, // two 400K DOS 3.3 volumes, weird order
CFFA4 = 42, // CFFA image with 4 or 6 partitions
CFFA8 = 43, // CFFA image with 8 partitions
MacPart = 44, // Macintosh-style partitioned disk
MicroDrive = 45, // ///SHH Systeme's MicroDrive format
FocusDrive = 46, // Parsons Engineering FocusDrive format
Gutenberg = 47, // Gutenberg word processor format
};
explicit CPressDiskImage(QObject *parent = nullptr);
virtual ~CPressDiskImage();
DIErrorCode lastDIError() const { return m_last_di_error; };
QString errorString() const;
bool openAndPrepare(const QString &filename);
bool open(const QString &filename);
bool open(QByteArray &data);
void setImageName(const QString &filename) { m_image_name = filename; }
QString imageName() const { return m_image_name; }
bool close();
bool analyzeImage();
bool showAsBlocks() const;
OuterFormat GetOuterFormat(void) const;
FileFormat GetFileFormat(void) const;
PhysicalFormat GetPhysicalFormat(void) const;
SectorOrder GetSectorOrder(void) const;
FSFormat GetFSFormat(void) const;
int numTracks(void) const;
int sectorsPerTrack(void) const;
int numBlocks(void) const;
bool checkForBadBlocks(int startBlock, int numBlocks);
short dosVolumeNumber() const;
bool hasSectors() const;
bool hasBlocks() const;
bool hasNibbles() const;
QSharedPointer<CPressDiskFS> diskFS() { return m_fs; }
QByteArray readTrackSector(int track, int sector);
QByteArray readBlock(int block);
QByteArray readBlocks(int startBlock, int numBlocks);
DiskImgLib::DiskImg* rawDIDiskImg() const { return m_image; }
protected:
bool isDIOk(DIErrorCode code) { return code == DiskImgLib::kDIErrNone; }
protected:
DIErrorCode m_last_di_error { DiskImgLib::kDIErrNone };
DiskImgLib::DiskImg *m_image { nullptr };
QSharedPointer<CPressDiskFS> m_fs { nullptr };
QString m_image_name { "[unnamed image]" };
};
#endif // CPRESSDISKIMAGE_H

View File

@ -0,0 +1,24 @@
/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "cpressfile.h"
CPressFile::CPressFile(QObject *parent) : QFileDevice(parent)
{
}

View File

@ -0,0 +1,34 @@
/*****************************************************************************
* AppleSAWS - The Apple Software Analysis WorkShop *
* Copyright (C) 2015-2021 Mark D. Long *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef CPRESSFILE_H
#define CPRESSFILE_H
#include <QFileDevice>
class CPressFile : public QFileDevice
{
Q_OBJECT
public:
explicit CPressFile(QObject *parent = nullptr);
signals:
};
#endif // CPRESSFILE_H