Adding asdisk converters

This commit is contained in:
mlong 2021-03-08 11:34:43 -06:00
parent 4a9dcf3b73
commit b093bf432a
7 changed files with 505 additions and 2 deletions

View File

@ -0,0 +1,175 @@
/*****************************************************************************
* 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 "asdiskdata.h"
ASDiskData::ASDiskData()
{
}
ASDiskData::~ASDiskData()
{
}
void ASDiskData::setUseSectors(int numSectors, int numTracks)
{
m_numsectors = numSectors;
m_numtracks = numTracks;
m_dataformat = DataFormat::Sectors;
}
void ASDiskData::setUseBlocks(int numBlocks)
{
m_numblocks = numBlocks;
m_dataformat = DataFormat::Blocks;
}
void ASDiskData::addSector(int track, int sector, QByteArray sectordata)
{
auto offset = tsToOffset(track,sector);
m_chunks[offset] = sectordata;
}
void ASDiskData::addBlock(int number, QByteArray blockdata)
{
m_chunks[number] = blockdata;
}
ASDiskData::SectorData &ASDiskData::getSector(int track, int sector)
{
auto offset = tsToOffset(track,sector);
return m_chunks[offset];
}
ASDiskData::BlockData &ASDiskData::getBlock(int blocknum)
{
return m_chunks[blocknum];
}
int ASDiskData::numTracks() const
{
return m_numtracks;
}
int ASDiskData::numSectorsPerTrack() const
{
return m_numsectors;
}
int ASDiskData::sectorSize() const
{
return m_sectorsize;
}
int ASDiskData::numBlocks() const
{
return m_numblocks;
}
int ASDiskData::blockSize() const
{
return m_blocksize;
}
QDataStream &ASDiskData::read(QDataStream &dataStream)
{
QString id;
dataStream >> id;
if (id == "ASDiskData")
{
quint32 version;
dataStream >> version;
if (version == 1)
{
bool doWeUseSectors;
dataStream >> doWeUseSectors;
if (doWeUseSectors)
{
m_dataformat = DataFormat::Sectors;
}
else
{
m_dataformat = DataFormat::Blocks;
}
dataStream >> m_sectorsize;
dataStream >> m_blocksize;
dataStream >> m_numsectors;
dataStream >> m_numtracks;
dataStream >> m_numblocks;
dataStream >> m_filename;
dataStream >> m_fstype;
dataStream >> m_fsname;
m_metadata.clear();
dataStream >> m_metadata;
m_chunks.clear();
dataStream >> m_chunks;
m_original_file_contents.clear();
dataStream >> m_original_file_contents;
}
else
{
qWarning("Unrecognized version in ASDiskData stream!");
}
}
else
{
qWarning("Cannot read ASDiskData from input stream!");
}
return dataStream;
}
QDataStream &ASDiskData::write(QDataStream &dataStream) const
{
dataStream << "ASDiskData" << quint32(1); // ID & Version
dataStream << (m_dataformat == DataFormat::Sectors);
dataStream << m_sectorsize << m_blocksize;
dataStream << m_numsectors << m_numtracks << m_numblocks;
dataStream << m_filename;
dataStream << m_fstype;
dataStream << m_fsname;
dataStream << m_metadata;
dataStream << m_chunks;
dataStream << m_original_file_contents;
return dataStream;
}
void ASDiskData::setFSInfo(QString name, int fstypeval)
{
m_fsname = name;
m_fstype = fstypeval;
}
int ASDiskData::tsToOffset(int track, int sector)
{
return (track * m_numsectors) + sector;
}
QDataStream &operator<<(QDataStream &out, const ASDiskData &outObject)
{
return outObject.write(out);
}
QDataStream &operator>>(QDataStream &in, ASDiskData &inObject)
{
return inObject.read(in);
}

View File

@ -0,0 +1,116 @@
/*****************************************************************************
* 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 ASDISKDATA_H
#define ASDISKDATA_H
#include <QString>
#include <QMap>
#include <QVariant>
#include <QDataStream>
class ASDiskData
{
using AttributeMap = QMap<QString, QVariant>;
using ChunkData = QByteArray;
using DataMap = QMap<int,ChunkData>;
public:
using SectorData = QByteArray;
using BlockData = QByteArray;
enum class DataFormat { Sectors, Blocks };
ASDiskData();
virtual ~ASDiskData();
QStringList attributeList() const { return m_metadata.keys(); }
QVariant getAttribute(QString key) const;
bool setAttribute(QString key, QVariant value);
void setUseSectors(int numSectors = 16, int numTracks = 35);
void setUseBlocks(int numBlocks);
void setDataFormat(DataFormat format) { m_dataformat = format; }
bool useSectors() const { return m_dataformat == DataFormat::Sectors; }
bool useBlocks() const { return m_dataformat == DataFormat::Blocks; }
DataFormat dataFormat() const { return m_dataformat; }
void addSector(int track, int sector, QByteArray sectordata);
void addBlock(int number, QByteArray blockdata);
SectorData &getSector(int track, int sector);
BlockData &getBlock(int blocknum);
int numTracks() const;
int numSectorsPerTrack() const;
void setNumSectorsPerTrack(int val) { m_numsectors = val; }
void setNumTracks(int val) { m_numtracks = val; }
void setSectorSize(int size) { m_sectorsize = size; }
int sectorSize() const;
int numBlocks() const;
void setNumBlocks(int val) { m_numblocks = val; }
void setBlockSize(int size) { m_blocksize = size; }
int blockSize() const;
void setFilename(const QString &filename) { m_filename = filename; }
const QString &filename() const { return m_filename; }
void setFSInfo(QString name, int fstypeval);
QString fileSystemName() const { return m_fsname; };
int fileSystemType() const { return m_fstype; }
void setOriginalFileContents(QByteArray data) { m_original_file_contents = data; }
QByteArray originalFileContents() const { return m_original_file_contents; }
QDataStream &read(QDataStream &dataStream);
QDataStream &write(QDataStream &dataStream) const;
protected:
int tsToOffset(int track, int sector);
protected:
QString m_filename { "[unknown]" };
QString m_fsname { "[unknown]" };
int m_fstype { 0 };
DataFormat m_dataformat { DataFormat::Sectors };
int m_sectorsize { 256 };
int m_blocksize { 512 };
int m_numsectors { -1 };
int m_numtracks { -1 };
int m_numblocks { -1 };
AttributeMap m_metadata;
DataMap m_chunks;
QByteArray m_original_file_contents;
};
QDataStream &operator<<(QDataStream &out, const ASDiskData &outData);
QDataStream &operator>>(QDataStream &in, ASDiskData &inData);
#endif // ASDISKDATA_H

View File

@ -0,0 +1,112 @@
/*****************************************************************************
* 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 "asdiskimporter.h"
#include "DiskImg.h"
#include <QDir>
#include <QFileInfo>
ASDiskImporter::ASDiskImporter(QObject *parent) : QObject(parent)
{
if (!DiskImgLib::Global::GetAppInitCalled())
{
DiskImgLib::Global::AppInit();
}
}
bool ASDiskImporter::importImage(QString filename, ASDiskData &into)
{
bool retval = false;
DiskImgLib::DiskImg image;
auto localname = QDir::toNativeSeparators(filename);
auto fileinfo = QFileInfo(filename);
auto result = image.OpenImage(filename.toLatin1(),QDir::separator().toLatin1(),true);
if (result == DiskImgLib::kDIErrNone)
{
result = image.AnalyzeImage();
if (result == DiskImgLib::kDIErrNone)
{
auto filesystemformat = image.GetFSFormat();
QString fsformatstr = DiskImgLib::DiskImg::ToString(filesystemformat);
auto fs = image.OpenAppropriateDiskFS(false);
result = fs->Initialize(&image,DiskImgLib::DiskFS::kInitFull);
if (result == DiskImgLib::kDIErrNone)
{
into.setFilename(fileinfo.fileName());
into.setFSInfo(fsformatstr, (int) filesystemformat);
int numblocks = image.GetNumBlocks();
into.setNumBlocks(numblocks);
int numtracks = image.GetNumTracks();
into.setNumTracks(numtracks);
int numsectors = image.GetNumSectPerTrack();\
into.setNumSectorsPerTrack(numsectors);
if (image.ShowAsBlocks())
{
into.setDataFormat(ASDiskData::DataFormat::Blocks);
char *buffer = new char[512]; // Todo: Remove magic number
for (int idx = 0; idx < numblocks; idx++)
{
image.ReadBlock(idx,buffer);
QByteArray array(buffer, 512);
into.addBlock(idx,array);
}
delete[] buffer;
}
else
{
into.setDataFormat(ASDiskData::DataFormat::Sectors);
char *buffer = new char[256]; // Todo: Remove magic number
for (int track = 0; track < numtracks; track++)
{
for (int sector = 0; sector < numsectors; sector++)
{
image.ReadTrackSector(track,sector,buffer);
QByteArray array(buffer, 256);
into.addSector(track,sector,array);
}
}
delete[] buffer;
}
QFile orig(filename);
if (orig.open(QIODevice::ReadOnly))
{
auto data = orig.readAll();
orig.close();
into.setOriginalFileContents(data);
retval = true;
}
image.RemoveDiskFS(fs);
}
}
image.CloseImage();
}
return retval;
}

View File

@ -0,0 +1,36 @@
/*****************************************************************************
* 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 ASDISKIMPORTER_H
#define ASDISKIMPORTER_H
#include <QObject>
#include "asdiskdata.h"
class ASDiskImporter : public QObject
{
Q_OBJECT
public:
explicit ASDiskImporter(QObject *parent = nullptr);
bool importImage(QString filename, ASDiskData &into);
};
#endif // ASDISKIMPORTER_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 "asdiskstore.h"
ASDiskStore::ASDiskStore(QObject *parent) : QObject(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 ASDISKSTORE_H
#define ASDISKSTORE_H
#include <QObject>
class ASDiskStore : public QObject
{
Q_OBJECT
public:
explicit ASDiskStore(QObject *parent = nullptr);
signals:
};
#endif // ASDISKSTORE_H

View File

@ -114,7 +114,10 @@ SOURCES += \
./util/opcodes.cpp \
diskfiles/cpressdiskfs.cpp \
diskfiles/cpressdiskimage.cpp \
diskfiles/cpressfile.cpp
diskfiles/cpressfile.cpp \
diskfiles/diskstore/asdiskdata.cpp \
diskfiles/diskstore/asdiskimporter.cpp \
diskfiles/diskstore/asdiskstore.cpp
HEADERS += \
@ -199,7 +202,10 @@ HEADERS += \
./ui/widgets/asciiinfodialog.h \
diskfiles/cpressdiskfs.h \
diskfiles/cpressdiskimage.h \
diskfiles/cpressfile.h
diskfiles/cpressfile.h \
diskfiles/diskstore/asdiskdata.h \
diskfiles/diskstore/asdiskimporter.h \
diskfiles/diskstore/asdiskstore.h
FORMS += \
./sequence/sequenceviewer.ui \