diff --git a/ads b/ads index 1385357..6f8995c 160000 --- a/ads +++ b/ads @@ -1 +1 @@ -Subproject commit 13853573ea51f9f0e682f7d005ca4443398512ae +Subproject commit 6f8995cbd1b2999ba6ded903731eb4dd2a0af333 diff --git a/cpress/ciderpress b/cpress/ciderpress index 7c637c4..169a132 160000 --- a/cpress/ciderpress +++ b/cpress/ciderpress @@ -1 +1 @@ -Subproject commit 7c637c4e6d2e0f7e0a60676bbda1bcd4618e1234 +Subproject commit 169a13206f4ff02a13cf22d3f3c2a5821a432686 diff --git a/src/applesoftfile/applesoftfile.cxx b/src/applesoftfile/applesoftfile.cxx index 51d6416..065e015 100644 --- a/src/applesoftfile/applesoftfile.cxx +++ b/src/applesoftfile/applesoftfile.cxx @@ -45,7 +45,7 @@ void ApplesoftFile::processData() } m_length = dataWordAt(0); - QByteArray tmp = rawData().asQByteArray().mid(2); + QByteArray tmp = rawData().mid(2); m_retokenizer->setData(tmp); m_retokenizer->parse(); diff --git a/src/binaryfile/binaryfile.cxx b/src/binaryfile/binaryfile.cxx index f97b0ad..b0b186a 100644 --- a/src/binaryfile/binaryfile.cxx +++ b/src/binaryfile/binaryfile.cxx @@ -28,7 +28,7 @@ BinaryFile::BinaryFile(Dos33DiskImage *image, FileDescriptiveEntry &fde) void BinaryFile::setupData() { - QByteArray data = rawData().asQByteArray(); + QByteArray data = rawData(); if (data.length() >= 4) { QByteArray metadata = data.left(4); diff --git a/src/diskfiles/diskstore/asdiskdata.cpp b/src/diskfiles/diskstore/asdiskdata.cpp index cfda6c6..7b369f1 100644 --- a/src/diskfiles/diskstore/asdiskdata.cpp +++ b/src/diskfiles/diskstore/asdiskdata.cpp @@ -18,7 +18,9 @@ #include "asdiskdata.h" -ASDiskData::ASDiskData() +#include + +ASDiskData::ASDiskData(QObject *parent) : QObject(parent) { } @@ -28,39 +30,63 @@ ASDiskData::~ASDiskData() } -void ASDiskData::setUseSectors(int numSectors, int numTracks) +void ASDiskData::setUseSectors(int numTracks, int numSectors) { m_numsectors = numSectors; m_numtracks = numTracks; m_dataformat = DataFormat::Sectors; + m_chunk_data.resize(m_numsectors * m_numtracks * 256); // Todo: magic number } void ASDiskData::setUseBlocks(int numBlocks) { m_numblocks = numBlocks; m_dataformat = DataFormat::Blocks; + m_chunk_data.resize(m_numblocks * 512);// Todo: magic number } void ASDiskData::addSector(int track, int sector, QByteArray sectordata) { + if (sectordata.length() != 256 || track >= m_numtracks || sector >= m_numsectors + || track < 0 || sector < 0) + { + qWarning("Invalid data in addSector."); + return; + } auto offset = tsToOffset(track,sector); - m_chunks[offset] = sectordata; + m_chunk_data.replace(offset*256,256,sectordata); } void ASDiskData::addBlock(int number, QByteArray blockdata) { - m_chunks[number] = blockdata; + if (blockdata.length() != 512 || number >= m_numblocks || number < 0) + { + qWarning("Invalid data in addBlock."); + return; + }; + m_chunk_data.replace(number*512,512,blockdata); } -ASDiskData::SectorData &ASDiskData::getSector(int track, int sector) +QByteArray ASDiskData::getSector(int track, int sector) const { auto offset = tsToOffset(track,sector); - return m_chunks[offset]; + + if (offset >= m_chunk_data.size() / 256) + { + qWarning("Sector %d,%d out of bounds! Returning null data!",track,sector); + return QByteArray(); + } + return m_chunk_data.mid(offset*256,256); } -ASDiskData::BlockData &ASDiskData::getBlock(int blocknum) +QByteArray ASDiskData::getBlock(int blocknum) const { - return m_chunks[blocknum]; + if (blocknum >= m_chunk_data.size() / 256) + { + qWarning("Block %d out of bounds! Returning null data!",blocknum); + return QByteArray(); + } + return m_chunk_data.mid(blocknum*512,512); } int ASDiskData::numTracks() const @@ -119,8 +145,8 @@ QDataStream &ASDiskData::read(QDataStream &dataStream) dataStream >> m_fsname; m_metadata.clear(); dataStream >> m_metadata; - m_chunks.clear(); - dataStream >> m_chunks; + m_chunk_data.clear(); + dataStream >> m_chunk_data; m_original_file_contents.clear(); dataStream >> m_original_file_contents; } @@ -147,7 +173,7 @@ QDataStream &ASDiskData::write(QDataStream &dataStream) const dataStream << m_fstype; dataStream << m_fsname; dataStream << m_metadata; - dataStream << m_chunks; + dataStream << m_chunk_data; dataStream << m_original_file_contents; return dataStream; @@ -159,9 +185,11 @@ void ASDiskData::setFSInfo(QString name, int fstypeval) m_fstype = fstypeval; } -int ASDiskData::tsToOffset(int track, int sector) +int ASDiskData::tsToOffset(int track, int sector) const { - return (track * m_numsectors) + sector; + int val = (track * m_numsectors) + sector; + //qDebug() << "TsToOffset: " << track << "," << sector << " = " << val; + return val; } QDataStream &operator<<(QDataStream &out, const ASDiskData &outObject) diff --git a/src/diskfiles/diskstore/asdiskdata.h b/src/diskfiles/diskstore/asdiskdata.h index b7299cb..475f0f7 100644 --- a/src/diskfiles/diskstore/asdiskdata.h +++ b/src/diskfiles/diskstore/asdiskdata.h @@ -20,32 +20,33 @@ #define ASDISKDATA_H #include -#include +#include #include #include -class ASDiskData +class ASDiskData : public QObject { + Q_OBJECT + using AttributeMap = QMap; using ChunkData = QByteArray; - using DataMap = QMap; + public: - using SectorData = QByteArray; - using BlockData = QByteArray; + // using SectorData = QByteArray; + // using BlockData = QByteArray; enum class DataFormat { Sectors, Blocks }; - ASDiskData(); + ASDiskData(QObject *parent = nullptr); 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 setUseSectors(int numTracks = 35, int numSectors = 16); 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; } @@ -54,8 +55,8 @@ public: void addSector(int track, int sector, QByteArray sectordata); void addBlock(int number, QByteArray blockdata); - SectorData &getSector(int track, int sector); - BlockData &getBlock(int blocknum); + QByteArray getSector(int track, int sector) const; + QByteArray getBlock(int blocknum) const; int numTracks() const; int numSectorsPerTrack() const; @@ -84,7 +85,7 @@ public: QDataStream &write(QDataStream &dataStream) const; protected: - int tsToOffset(int track, int sector); + int tsToOffset(int track, int sector) const; protected: QString m_filename { "[unknown]" }; @@ -102,9 +103,11 @@ protected: AttributeMap m_metadata; - DataMap m_chunks; + QByteArray m_chunk_data; QByteArray m_original_file_contents; + + QByteArray m_nulldata; }; QDataStream &operator<<(QDataStream &out, const ASDiskData &outData); diff --git a/src/diskfiles/diskstore/asdiskimporter.cpp b/src/diskfiles/diskstore/asdiskimporter.cpp index 43380d0..0a15a58 100644 --- a/src/diskfiles/diskstore/asdiskimporter.cpp +++ b/src/diskfiles/diskstore/asdiskimporter.cpp @@ -62,9 +62,11 @@ bool ASDiskImporter::importImage(QString filename, ASDiskData &into) int numsectors = image.GetNumSectPerTrack();\ into.setNumSectorsPerTrack(numsectors); + + if (image.ShowAsBlocks()) { - into.setDataFormat(ASDiskData::DataFormat::Blocks); + into.setUseBlocks(numblocks); char *buffer = new char[512]; // Todo: Remove magic number for (int idx = 0; idx < numblocks; idx++) @@ -77,7 +79,7 @@ bool ASDiskImporter::importImage(QString filename, ASDiskData &into) } else { - into.setDataFormat(ASDiskData::DataFormat::Sectors); + into.setUseSectors(numtracks,numsectors); char *buffer = new char[256]; // Todo: Remove magic number for (int track = 0; track < numtracks; track++) diff --git a/src/diskfiles/dos33/catalogsector.cxx b/src/diskfiles/dos33/catalogsector.cxx index e470c1b..551631f 100644 --- a/src/diskfiles/dos33/catalogsector.cxx +++ b/src/diskfiles/dos33/catalogsector.cxx @@ -19,7 +19,7 @@ #include "catalogsector.h" #include "sector.h" -CatalogSector::CatalogSector(Sector *data) +CatalogSector::CatalogSector(QSharedPointer data) { m_data = data; @@ -42,13 +42,13 @@ CatalogSector::CatalogSector(Sector *data) { FileDescriptiveEntry fde = makeFDE(idx*0x23+0x0B); if (fde.firstTSListSector() != TSPair(0,0)) { - // if (fde.firstTSListSector().isValid()) + if (fde.firstTSListSector().isValid()) { m_fdes.append(fde); } - // else qDebug() << "Not appending invalid TSPair."; + else qDebug() << "Not appending invalid TSPair."; } - // else { qWarning("fde.firstTSListSector() is 0,0"); } + // else { qWarning("fde.firstTSListSector() is 0,0"); } } } diff --git a/src/diskfiles/dos33/catalogsector.h b/src/diskfiles/dos33/catalogsector.h index e2d9193..d65fc19 100644 --- a/src/diskfiles/dos33/catalogsector.h +++ b/src/diskfiles/dos33/catalogsector.h @@ -33,11 +33,10 @@ class Sector; - class CatalogSector { public: - CatalogSector(Sector *sector); + CatalogSector(QSharedPointer sector); FileDescriptiveEntry getFDE(quint8 number) { if (m_fdes.length() == 0) { return FileDescriptiveEntry(); } @@ -53,7 +52,7 @@ public: void dumpFDEs(); - Sector *getSector() const { return m_data; } + QSharedPointer getSector() const { return m_data; } FileDescriptiveEntry makeFDE(int offset); @@ -61,7 +60,7 @@ public: private: private: - Sector *m_data; + QSharedPointer m_data; QList m_fdes; TSPair m_next; }; diff --git a/src/diskfiles/dos33/dos33diskimage.cxx b/src/diskfiles/dos33/dos33diskimage.cxx index 24f1021..2407692 100644 --- a/src/diskfiles/dos33/dos33diskimage.cxx +++ b/src/diskfiles/dos33/dos33diskimage.cxx @@ -35,120 +35,44 @@ Dos33DiskImage::Dos33DiskImage(QString filename) { - m_disk_image = new RawDiskImage(filename); - + m_disk_image = new ASDiskData(); if (!filename.isEmpty()) { read(filename); - //TODO: Cross reference & dbl. check sec/track with VTOC } - auto dummy_data = new SectorData; - dummy_data->resize(256); - m_dummy_sector.setData(dummy_data); -} - -Dos33DiskImage::Dos33DiskImage(RawDiskImage *rawImage) -{ - m_disk_image = rawImage; - //TODO: Cross reference & dbl. check sec/track with VTOC - } Dos33DiskImage::~Dos33DiskImage() { - // foreach (GenericFile *file, m_files) - // { - // delete file; - // } + delete m_disk_image; } bool Dos33DiskImage::read(QString filename) { - bool retval = m_disk_image->read(filename); + ASDiskImporter importer; + bool retval = importer.importImage(filename, *m_disk_image); - if (retval) - { - for (auto tracknum = 0; tracknum < m_disk_image->numTracks(); tracknum++) - { - for (auto secnum = 0; secnum < m_disk_image->sectorsPerTrack(); secnum++) - { - TSPair tmpts(tracknum,secnum); - Sector newSec; - SectorData * data = m_disk_image->sectorAt(tmpts); - newSec.setData(data); - newSec.setTrackSector(tmpts); - m_contents[tmpts] = newSec; - } - } - } + // TODO: Cache sectors!! return retval; - - // m_fullImageName = filename; - // m_imageName = QFileInfo(filename).fileName(); - // QFile infile(filename); - // QCryptographicHash hash(QCryptographicHash::Md5); - - // if (infile.open(QIODevice::ReadOnly)) - // { - // QByteArray contents = infile.readAll(); - // int expectedsize = sectorsPerTrack() * tracks() * 256; - // if (contents.size() != expectedsize) - // { - // if (contents.size() == 35*16*256) { m_sectors_per_track = 16; } - // else if (contents.size() == 35*13*256) { m_sectors_per_track = 13; } - // else qWarning() << QString("Size mismatch in file! Expected %1, got %2") - // .arg(expectedsize) - // .arg(contents.size()); - // } - - // QDataStream qds(contents); - // for (int track = 0; track < 35; track++) - // { - // for (int sector = 0; sector < m_sectors_per_track; sector++) - // { - // char buffer[256]; - // if (qds.readRawData(buffer,256) == 256) - // { - // TSPair tmpts(track,sector); - // Sector newSec; - // newSec.setTrackSector(tmpts); - // newSec.setData(QByteArray(buffer,256)); - // m_contents[tmpts] = newSec; - // } - // else - // { - // qDebug() << "Invalid sector read!"; - // return false; - // } - // } - // } - // hash.addData(contents); - - // m_hash = hash.result(); - // // qDebug() << "Hash: " << m_hash; - - // return true; - // } - // else - // qDebug() << "Could not open file " << filename; - // return false; } -Sector &Dos33DiskImage::getSector(TSPair ts) { - if (m_contents.contains(ts)) - return m_contents[ts]; - else - return m_dummy_sector; +pSector Dos33DiskImage::getSector(TSPair ts) const { + return getSector(ts.track(),ts.sector()); } -Sector &Dos33DiskImage::getSector(int track, int sector) { - return getSector(TSPair(track,sector)); +pSector Dos33DiskImage::getSector(int track, int sector) const { + auto sectorData + = m_disk_image->getSector(track,sector); + qDebug() << "Dos33DiskImage::getSector("<(new Sector(sectorData, track, sector)); + val->dump(); + return val; } -VTOC Dos33DiskImage::getVTOC() +VTOC Dos33DiskImage::getVTOC() const { - return getSector(17,0).promoteToVTOC(); + return getSector(17,0)->promoteToVTOC(); } QList Dos33DiskImage::getCatalogSectors() @@ -156,12 +80,15 @@ QList Dos33DiskImage::getCatalogSectors() QList retval; VTOC vtoc = getVTOC(); TSPair ts = vtoc.firstCatalogSector(); + qDebug() << "First TSPair for catalogsectors is " << ts.track() << "," << ts.sector(); - CatalogSector cs = getSector(ts).asCatalogSector(); + CatalogSector cs = getSector(ts)->asCatalogSector(); retval.append(cs); while (cs.nextCatalogSector() != TSPair(0,0)) { ts = cs.nextCatalogSector(); - cs = getSector(ts).asCatalogSector(); + qDebug() << "Next TSPair for catalogsectors is " << ts.track() << "," << ts.sector(); + + cs = getSector(ts)->asCatalogSector(); retval.append(cs); } @@ -183,7 +110,7 @@ GenericFile *Dos33DiskImage::getFile(FileDescriptiveEntry fde) return nullptr; } - TrackSectorList tsl = getSector(fde.firstTSListSector()).asTrackSectorList(); + TrackSectorList tsl = getSector(fde.firstTSListSector())->asTrackSectorList(); if (!fde.firstTSListSector().isValid()) { qWarning(" Not returning a file from invalid TSList!"); @@ -224,17 +151,17 @@ GenericFile *Dos33DiskImage::getFile(FileDescriptiveEntry fde) } -ChunkByteList Dos33DiskImage::getDataFromTrackSectorList(TrackSectorList tsl) +QByteArray Dos33DiskImage::getDataFromTrackSectorList(TrackSectorList tsl) { - ChunkByteList retval; + QByteArray retval; foreach(TSPair pair, tsl.getDataTSPairs()) { if (pair.isValid()) { - Sector sec = getSector(pair); - retval.appendChunk(sec.rawData()); + pSector sec = getSector(pair); + retval.append(sec->rawData()); } else { @@ -244,22 +171,22 @@ ChunkByteList Dos33DiskImage::getDataFromTrackSectorList(TrackSectorList tsl) auto next = tsl.getNextTSList(); if (next.isValid() && next != TSPair(0,0)) { - TrackSectorList nextTsl = getSector(tsl.getNextTSList()).asTrackSectorList(); - retval.appendChunkList(getDataFromTrackSectorList(nextTsl)); + TrackSectorList nextTsl = getSector(tsl.getNextTSList())->asTrackSectorList(); + retval.append(getDataFromTrackSectorList(nextTsl)); } return retval; } -ChunkByteList Dos33DiskImage::getDataFromTSPairList(TSPairList list) +QByteArray Dos33DiskImage::getDataFromTSPairList(TSPairList list) { - ChunkByteList retval; + QByteArray retval; foreach(TSPair pair, list) { if (pair.isValid()) { - Sector sec = getSector(pair); - retval.appendChunk(sec.rawData()); + pSector sec = getSector(pair); + retval.append(sec->rawData()); } else { diff --git a/src/diskfiles/dos33/dos33diskimage.h b/src/diskfiles/dos33/dos33diskimage.h index 462f564..6d218d4 100644 --- a/src/diskfiles/dos33/dos33diskimage.h +++ b/src/diskfiles/dos33/dos33diskimage.h @@ -32,9 +32,11 @@ #include "vtoc.h" #include "tracksectorlist.h" -#include "rawdiskimage.h" #include "chunkbytelist.h" +#include "asdiskimporter.h" +#include "asdiskdata.h" + class GenericFile; @@ -44,48 +46,43 @@ class Dos33DiskImage { public: Dos33DiskImage(QString filename = ""); - Dos33DiskImage(RawDiskImage *rawImage); ~Dos33DiskImage(); bool read(QString filename); - Sector &getSector(TSPair ts); - Sector &getSector(int track, int sector); + pSector getSector(TSPair ts) const; + pSector getSector(int track, int sector) const; - VTOC getVTOC(); + VTOC getVTOC() const; QList getCatalogSectors(); GenericFile *getFile(FileDescriptiveEntry fde); - ChunkByteList getDataFromTrackSectorList(TrackSectorList tsl); - ChunkByteList getDataFromTSPairList(TSPairList list); + QByteArray getDataFromTrackSectorList(TrackSectorList tsl); + QByteArray getDataFromTSPairList(TSPairList list); QList getAllFDEs(); QByteArray fileHash() const { return m_hash; } - QString getDiskImageName() const { return m_disk_image->diskImageName(); } - QString getFullDiskImageName() const { return m_disk_image->fullDiskImageName(); } + QString getDiskImageName() const { return m_disk_image->filename(); } + QString getFullDiskImageName() const { return m_disk_image->/*fullDiskImageName*/filename(); } QString getMetaDataPath() const; - RawDiskImage *rawImage() const { return m_disk_image; } + ASDiskData *rawImage() const { return m_disk_image; } - int sectorsPerTrack() const { return m_disk_image->sectorsPerTrack(); } + int sectorsPerTrack() const { return m_disk_image->numSectorsPerTrack(); } int tracks() const { return m_disk_image->numTracks(); } QList fileList(); private: - RawDiskImage *m_disk_image; + ASDiskData *m_disk_image; - QMap m_contents; QMap m_files; QByteArray m_hash; - Sector m_dummy_sector; // Returned for non-existant sectors on disk - - }; #endif // DOS33DISKIMAGE_H diff --git a/src/diskfiles/dos33/dos33disktreeview.h b/src/diskfiles/dos33/dos33disktreeview.h index c1e6950..5b08ea5 100644 --- a/src/diskfiles/dos33/dos33disktreeview.h +++ b/src/diskfiles/dos33/dos33disktreeview.h @@ -34,7 +34,6 @@ public: protected: - signals: void fileClicked(const FileDescriptiveEntry &fde); void fileRightClicked(const FileDescriptiveEntry &fde); @@ -45,14 +44,11 @@ signals: void sectorRightClicked(TSPair ts); void sectorDoubleClicked(TSPair ts); - private slots: void handleClick(const QModelIndex &index); void handleDoubleClick(const QModelIndex &index); void handlePress(const QModelIndex &index); - - }; #endif // DOS33DISKTREEVIEW_H diff --git a/src/diskfiles/dos33/dos33imagemodel.h b/src/diskfiles/dos33/dos33imagemodel.h index 84909dc..2332ba1 100644 --- a/src/diskfiles/dos33/dos33imagemodel.h +++ b/src/diskfiles/dos33/dos33imagemodel.h @@ -19,8 +19,6 @@ * along with this program. If not, see . * *****************************************************************************/ - - #include "dos33treeitem.h" #include "dos33diskimage.h" @@ -42,7 +40,6 @@ enum class Dos33ItemType { DiskImage }; - class Dos33ImageModel : public QStandardItemModel { Q_OBJECT @@ -57,8 +54,6 @@ public: Dos33DiskImage *getDiskImage(QString name); Dos33DiskImage *removeDiskImage(QString name); - - private: QIcon m_icon_A; QIcon m_icon_a; diff --git a/src/diskfiles/dos33/dos33treeitem.h b/src/diskfiles/dos33/dos33treeitem.h index edc02f8..693840e 100644 --- a/src/diskfiles/dos33/dos33treeitem.h +++ b/src/diskfiles/dos33/dos33treeitem.h @@ -19,8 +19,6 @@ * along with this program. If not, see . * *****************************************************************************/ - - #include class Dos33TreeItem : public QStandardItem diff --git a/src/diskfiles/dos33/genericfile.cxx b/src/diskfiles/dos33/genericfile.cxx index 346972d..1cf515e 100644 --- a/src/diskfiles/dos33/genericfile.cxx +++ b/src/diskfiles/dos33/genericfile.cxx @@ -51,7 +51,7 @@ QByteArray GenericFile::data() { if (m_data_cache.size() == 0) { - m_data_cache = rawData().asQByteArray(); + m_data_cache = rawData(); } } else @@ -72,7 +72,7 @@ void GenericFile::resetToDefaultData() } -ChunkByteList &GenericFile::rawData() +QByteArray GenericFile::rawData() { if (!m_data_loaded) { @@ -87,20 +87,13 @@ void GenericFile::updateFromFDE(FileDescriptiveEntry &fde) setLength(fde.lengthInSectors * m_diskfile->rawImage()->sectorSize()); } -SectorData *GenericFile::peekFirstSector() const +QByteArray GenericFile::peekFirstSector() const { - SectorData *retval = nullptr; + auto tsl = m_diskfile->getSector(m_fde.firstTSListSector())->asTrackSectorList(); + TSPairList pairs = tsl.getValidTSPairs(); + + return m_diskfile->getSector(pairs.first())->rawData(); - if (m_diskfile) - { - auto tsl = m_diskfile->getSector(m_fde.firstTSListSector()).asTrackSectorList(); - TSPairList pairs = tsl.getValidTSPairs(); - if (pairs.size()) - { - retval = m_diskfile->getSector(pairs.first()).rawData(); - } - } - return retval; } void GenericFile::initDataFromImage() @@ -109,7 +102,7 @@ void GenericFile::initDataFromImage() { if (m_diskfile) { - auto tsl = m_diskfile->getSector(m_fde.firstTSListSector()).asTrackSectorList(); + auto tsl = m_diskfile->getSector(m_fde.firstTSListSector())->asTrackSectorList(); TSPairList pairs = tsl.getValidTSPairs(); m_data_loaded = true; m_data = m_diskfile->getDataFromTSPairList(pairs); diff --git a/src/diskfiles/dos33/genericfile.h b/src/diskfiles/dos33/genericfile.h index a61c9a4..1b825b8 100644 --- a/src/diskfiles/dos33/genericfile.h +++ b/src/diskfiles/dos33/genericfile.h @@ -55,7 +55,7 @@ public: virtual quint8 rawDataAt(int offset) ; virtual quint16 rawDataWordAt(int offset); - virtual ChunkByteList &rawData(); + virtual QByteArray rawData(); [[deprecated("Only used for legacy purposes")]] @@ -93,7 +93,7 @@ public: void initDataFromImage(); protected: - SectorData *peekFirstSector() const; + QByteArray peekFirstSector() const; private: Dos33DiskImage * m_diskfile; @@ -106,7 +106,7 @@ private: bool m_locked; QString m_filename; - ChunkByteList m_data; + QByteArray m_data; bool m_data_loaded; diff --git a/src/diskfiles/dos33/sector.cxx b/src/diskfiles/dos33/sector.cxx index d362421..8590cfc 100644 --- a/src/diskfiles/dos33/sector.cxx +++ b/src/diskfiles/dos33/sector.cxx @@ -21,18 +21,19 @@ #include #include -quint8 Sector::operator[](uint offset) const { - if (offset > 255) { - offset = 255; - } - if ((int) offset >= m_raw_data->size()) return 0; +//quint8 Sector::operator[](uint offset) const { +// if (offset > 255) { +// offset = 255; +// } +// if ((int) offset >= m_raw_data.size()) return 0; - return m_raw_data->at(offset); -} +// return m_raw_data.at(offset); +//} -void Sector::dump() { +void Sector::dump() const { qDebug() << "Dumping Track " << track() << "Sector " << sector() << " ..."; + qDebug() << " RawData size: " << m_raw_data.size(); for (int jdx = 0; jdx < 16; jdx++) { QString line; @@ -41,8 +42,8 @@ void Sector::dump() { for (int idx = 0; idx < 16; idx++) { int offset = (jdx*16) + idx; - quint8 val = m_raw_data->at(offset); - line += QString("%1 ").arg(uint16ToHex(val)); + quint8 val = m_raw_data.at(offset); + line += QString("%1 ").arg(uint8ToHex(val)); if (idx == 7) line += " "; } line = line.toUpper(); @@ -50,7 +51,7 @@ void Sector::dump() { for (int idx = 0; idx < 16; idx++) { int offset = (jdx*16) + idx; - quint8 val = m_raw_data->at(offset); + quint8 val = m_raw_data.at(offset); if (val > 127) { val -= 128; } QChar ch(val); line += QString("%1").arg(ch.isPrint()?ch:'.'); diff --git a/src/diskfiles/dos33/sector.h b/src/diskfiles/dos33/sector.h index 568b158..2b2536b 100644 --- a/src/diskfiles/dos33/sector.h +++ b/src/diskfiles/dos33/sector.h @@ -1,14 +1,3 @@ -#ifndef SECTOR_H -#define SECTOR_H - -#include - -#include "rawdiskimage.h" - -#include "vtoc.h" -#include "catalogsector.h" -#include "tracksectorlist.h" - /***************************************************************************** * AppleSAWS - The Apple Software Analysis WorkShop * * Copyright (C) 2015-2021 Mark D. Long * @@ -27,68 +16,78 @@ * along with this program. If not, see . * *****************************************************************************/ +#ifndef SECTOR_H +#define SECTOR_H +#include +#include +//#include "rawdiskimage.h" -class Sector +#include "vtoc.h" +#include "catalogsector.h" +#include "tracksectorlist.h" + +#include "asdiskdata.h" + +class Sector; + +using pSector = QSharedPointer; + +class Sector : public QEnableSharedFromThis { public: - Sector(SectorData *data = nullptr) { - setData(data); - m_track = 255; - m_sector = 255; - } - - void setData(SectorData *data) + Sector(QByteArray &data, int track, int sector ) { - m_raw_data = data; + qDebug() << "Sector ctor: Datasize: " << data.size() << " t/s: " << track << "," << sector; + m_track = track; + m_sector = sector; + m_raw_data = data; + m_raw_data.append(12); + m_raw_data.chop(1); + if (m_raw_data.size() != 256) + { + qWarning() << "Setting sector with invalid sized data! [Size = " << data.size() << "]"; + } } - VTOC promoteToVTOC() { - return VTOC(this); + ~Sector() { qDebug() << "Sector dtor for " << m_track << "," << m_sector; } + + VTOC promoteToVTOC() const { + return VTOC(sharedFromThis()); } - CatalogSector asCatalogSector() { - return CatalogSector(this); + CatalogSector asCatalogSector() const { + return CatalogSector(sharedFromThis()); } - TrackSectorList asTrackSectorList() { - return TrackSectorList(this); + TrackSectorList asTrackSectorList() const { + return TrackSectorList(sharedFromThis()); } - int sector() { return m_sector; } - int track() { return m_track; } + int sector() const { return m_sector; } + int track() const { return m_track; } - void setTrackSector(int track, int sector) { - setTrack(track); - setSector(sector); + quint8 at(int offset) const { + if (offset >= m_raw_data.size()) { + + qWarning() << "sector::at() offset = " << offset + << ". m_raw_data.size() == " << m_raw_data.size(); + } + + return m_raw_data.at(offset); } - void setTrackSector(TSPair ts) - { - setTrackSector(ts.track(),ts.sector()); - } + void dump() const; - void setTrack(int track) { m_track = track; } - void setSector(int sector) { m_sector = sector; } - - quint8 operator[](uint offset) const; - quint8 at(int offset) { - if (offset >= m_raw_data->size()) return 0; - - return m_raw_data->at(offset); - } - - void dump(); - - SectorData *rawData() { return m_raw_data; } + QByteArray rawData() { return m_raw_data; } private: - // QByteArray m_data; int m_track; int m_sector; - SectorData *m_raw_data; + QByteArray m_raw_data; }; + #endif // SECTOR_H diff --git a/src/diskfiles/dos33/tracksectorlist.cxx b/src/diskfiles/dos33/tracksectorlist.cxx index c485f91..71252fa 100644 --- a/src/diskfiles/dos33/tracksectorlist.cxx +++ b/src/diskfiles/dos33/tracksectorlist.cxx @@ -20,7 +20,7 @@ #include "sector.h" -TrackSectorList::TrackSectorList(Sector *data) +TrackSectorList::TrackSectorList(QSharedPointer data) { m_data = data; diff --git a/src/diskfiles/dos33/tracksectorlist.h b/src/diskfiles/dos33/tracksectorlist.h index db099b6..6f8c88d 100644 --- a/src/diskfiles/dos33/tracksectorlist.h +++ b/src/diskfiles/dos33/tracksectorlist.h @@ -23,6 +23,8 @@ #include "tspair.h" +#include + class Sector; using TSPairList = QList; @@ -30,7 +32,7 @@ using TSPairList = QList; class TrackSectorList { public: - TrackSectorList(Sector *data); + TrackSectorList(QSharedPointer data); TSPair getNextTSList() const { return m_next_tslist; } bool isNextTSListValid() const; @@ -47,7 +49,7 @@ private: TSPair m_sector_offset; TSPairList m_ts_pairs_for_data; - Sector *m_data; + QSharedPointer m_data; }; #endif // TRACKSECTORLIST_H diff --git a/src/diskfiles/dos33/vtoc.cxx b/src/diskfiles/dos33/vtoc.cxx index df2b57f..346b2a6 100644 --- a/src/diskfiles/dos33/vtoc.cxx +++ b/src/diskfiles/dos33/vtoc.cxx @@ -24,35 +24,54 @@ #include "sector.h" #include "util.h" -VTOC::VTOC(Sector *data) +VTOC::VTOC(QSharedPointer data) { m_data = data; + m_first_catalog_sector = TSPair(m_data->at(0x01), m_data->at(0x02)); + m_dos_version = m_data->at(0x03); + m_volnum = m_data->at(0x06); + m_max_ts_pairs = m_data->at(0x27); + m_last_track_alloc = m_data->at(0x30); + m_dir_of_alloc= m_data->at(0x31); + m_tracks_per_disk = m_data->at(0x34); + m_sec_per_track = m_data->at(0x35); + m_byte_per_sec = makeWord(m_data->at(0x36), + m_data->at(0x37)); + } -TSPair VTOC::firstCatalogSector() { +TSPair VTOC::firstCatalogSector() const { + + // return TSPair(0x11,0x0f); // Force to look at the normal location - return TSPair(m_data->at(0x01), m_data->at(0x02)); + // return TSPair(m_data->at(0x01), m_data->at(0x02)); + return m_first_catalog_sector; } quint8 VTOC::dosVersion() { - return m_data->at(0x03); + return m_dos_version; + //return m_data->at(0x03); } quint8 VTOC::volumeNumber() { - return m_data->at(0x06); + return m_volnum; + //return m_data->at(0x06); } quint8 VTOC::maxTSPairs() { - return m_data->at(0x27); + //return m_data->at(0x27); + return m_max_ts_pairs; } quint8 VTOC::lastTrackAllocated() { - return m_data->at(0x30); + return m_last_track_alloc; + //return m_data->at(0x30); } qint8 VTOC::directionOfAllocation() { - return m_data->at(0x31); + return m_dir_of_alloc; + //return m_data->at(0x31); } quint8 VTOC::tracksPerDisk() { @@ -60,12 +79,14 @@ quint8 VTOC::tracksPerDisk() { } quint8 VTOC::sectorsPerTrack() { - return m_data->at(0x35); + return m_sec_per_track; + //return m_data->at(0x35); } qint16 VTOC::bytesPerSector() { - return makeWord(m_data->at(0x36), - m_data->at(0x37)); + return m_byte_per_sec; +// return makeWord(m_data->at(0x36), +// m_data->at(0x37)); } bool VTOC::isSectorInUse(TSPair ts) const { diff --git a/src/diskfiles/dos33/vtoc.h b/src/diskfiles/dos33/vtoc.h index c4b6cf2..1c17b68 100644 --- a/src/diskfiles/dos33/vtoc.h +++ b/src/diskfiles/dos33/vtoc.h @@ -26,15 +26,18 @@ #include "tspair.h" class Sector; + + + class QString; class VTOC { public: - VTOC(Sector *data); + VTOC(QSharedPointer data); void dump(); - TSPair firstCatalogSector(); + TSPair firstCatalogSector() const; quint8 dosVersion(); quint8 volumeNumber(); quint8 maxTSPairs(); @@ -53,7 +56,18 @@ public: private: QString buildUseString(quint8 track); - Sector *m_data; + QSharedPointer m_data; + + TSPair m_first_catalog_sector; + quint8 m_dos_version; + quint8 m_volnum; + quint8 m_max_ts_pairs; + quint8 m_last_track_alloc; + qint8 m_dir_of_alloc; + quint8 m_tracks_per_disk; + quint8 m_sec_per_track; + quint16 m_byte_per_sec; + }; #endif // VTOC_H diff --git a/src/diskfiles/rawdiskimage.cpp b/src/diskfiles/rawdiskimage.cpp deleted file mode 100644 index f45c413..0000000 --- a/src/diskfiles/rawdiskimage.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/***************************************************************************** -* 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 . * -*****************************************************************************/ - -#include "rawdiskimage.h" - -#include -#include -#include -#include - -RawDiskImage::RawDiskImage(QString name) -{ - setCustomOrderMap0(dosOrderMap()); - setCustomOrderMap1(prodosOrderMap()); - - // Set everything up assuming a 140k DOS image as a default for now - - m_track_count = 35; - m_sector_size = 256; - m_sectors_per_track = 16; - m_sector_order = SectorOrder::Dos33; - m_empty_image = true; - - if (!name.isEmpty()) - { - read(name); - } -} - -RawDiskImage::~RawDiskImage() -{ - foreach (auto track, m_tracks) - { - while (track.count()) - { - auto sectorblock = track.takeFirst(); - delete sectorblock; - } - } -} - -bool RawDiskImage::read(QString filename) -{ - if (!isEmpty()) return false; // Don't reread a disk! - - m_full_filename = filename; - m_filename = QFileInfo(filename).fileName(); - - if (m_filename.toUpper().contains(".D13")) - { - setSectorsPerTrack(13); - } - else - { - setSectorsPerTrack(16); - } - - QFile infile(filename); - QCryptographicHash hash(QCryptographicHash::Md5); - - - if (infile.open(QIODevice::ReadOnly)) - { - QByteArray contents = infile.readAll(); - - - int expectedsize = sectorsPerTrack() * numTracks() * 256; - if (contents.size() != expectedsize) - { - if (contents.size() == 35*16*256) { m_sectors_per_track = 16; } - else if (contents.size() == 35*13*256) { m_sectors_per_track = 13; } - else qWarning() << QString("Size mismatch in file! Expected %1, got %2") - .arg(expectedsize) - .arg(contents.size()); - } - - QDataStream qds(contents); - for (int track = 0; track < numTracks(); track++) - { - TrackData td; - for (int sector = 0; sector < m_sectors_per_track; sector++) - { - char buffer[256]; - if (qds.readRawData(buffer,sectorSize()) == sectorSize()) - { - TSPair tmpts(track,sector); - SectorData *newSec = new SectorData(); - *newSec = QByteArray(buffer,sectorSize()); - td.append(newSec); - } - else - { - qDebug() << "Invalid sector read!"; - return false; - } - } - m_tracks.append(td); - } - hash.addData(contents); - - m_hash = hash.result(); - - return true; - } - else - { - qDebug() << "Could not open file " << filename; - return false; - } -} - -bool RawDiskImage::isEmpty() const { return m_empty_image; } - -HashValue RawDiskImage::hash() const { return m_hash; } - -QString RawDiskImage::diskImageName() const { return m_filename; } - -QString RawDiskImage::fullDiskImageName() const { return m_full_filename; } - -void RawDiskImage::setNumTracks(int count) { m_track_count = count; } - -int RawDiskImage::numTracks() const { return m_track_count; } - -bool RawDiskImage::hasSectors() const {return true; } - -int RawDiskImage::sectorSize() const { return m_sector_size; } - -void RawDiskImage::setSectorSize(int size) { m_sector_size = size; } - -void RawDiskImage::setSectorsPerTrack(int spt) { m_sectors_per_track = spt; } - -int RawDiskImage::sectorsPerTrack() const { return m_sectors_per_track; } - -void RawDiskImage::setSectorOrder(SectorOrder order) { m_sector_order = order; } - -SectorOrder RawDiskImage::sectorOrder() const { return m_sector_order; } - -bool RawDiskImage::reorderSectorsTo(SectorOrder) -{ - //TODO: Handle Reordering - return false; -} - -SectorData *RawDiskImage::sectorAt(int track, int sector) -{ - if (track >= numTracks() || sector >= sectorsPerTrack()) - { - return nullptr; - } - - return m_tracks[track][sector]; -} - -SectorData *RawDiskImage::sectorAt(TSPair ts) -{ - return sectorAt(ts.track(),ts.sector()); -} - -SectorOrderMap RawDiskImage::dosOrderMap() const { - return QByteArrayLiteral("\x0\xD\xB\x9\x7\x5\x3\x1\xE\xC\xA\x8\x6\x4\x2\xF"); -} - -SectorOrderMap RawDiskImage::prodosOrderMap() const { - return QByteArrayLiteral("\x0\x8\x1\x9\x2\xA\x3\xB\x4\xC\x5\xD\x6\xE\x7\xF"); -} - -SectorOrderMap RawDiskImage::pascalOrderMap() const { - return QByteArrayLiteral("\x0\x2\x4\x6\x8\xA\xC\xE\x1\x3\x5\x7x9xBxDxF"); -} - -SectorOrderMap RawDiskImage::cpmOrderMap() const { - return QByteArrayLiteral("\x0\x3\x6\x9\xC\xF\x2\x5\x8\xB\xE\x1\x4\x7\xA\xD"); -} - -SectorOrderMap RawDiskImage::customOrderMap0() const { return m_custom_order_map_0; } - -SectorOrderMap RawDiskImage::customOrderMap1() const { return m_custom_order_map_0; } - -bool RawDiskImage::setCustomOrderMap0(SectorOrderMap map) -{ - if (map.count() < m_sectors_per_track) - { - return false; - } - - m_custom_order_map_0 = map.left(m_sectors_per_track); - return true; -} - -bool RawDiskImage::setCustomOrderMap1(SectorOrderMap map) -{ - if (map.count() < m_sectors_per_track) - { - return false; - } - - m_custom_order_map_1 = map.left(m_sectors_per_track); - return true; -} diff --git a/src/diskfiles/rawdiskimage.h b/src/diskfiles/rawdiskimage.h deleted file mode 100644 index 13dd1e6..0000000 --- a/src/diskfiles/rawdiskimage.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef RAWDISKIMAGE_H -#define RAWDISKIMAGE_H - -/***************************************************************************** -* 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 . * -*****************************************************************************/ - - - -#include "tspair.h" - -#include -#include -#include - -using SectorOrderMap = QByteArray; - -using SectorData = QByteArray; -//PRODOS using BlockData = QByteArray; -//PRODOS using BlockPair = QPair; -using TrackData = QList; -using TrackList = QList; - -using HashValue = QByteArray; - - -enum class SectorOrder -{ - Unknown = 0, - Dos33 = 0, - ProDos, - Pascal, - CPM, - Custom1, - Custom2 -}; - - -class RawDiskImage -{ -public: - - RawDiskImage(QString filename = QString()); - ~RawDiskImage(); - bool read(QString filename); - - bool isEmpty() const; - - HashValue hash() const; - - QString diskImageName() const; - QString fullDiskImageName() const; - - void setNumTracks(int count); - int numTracks() const; - - bool hasSectors() const; - int sectorSize() const; - void setSectorSize(int size); - void setSectorsPerTrack(int spt); - int sectorsPerTrack() const; - -//PRODOS bool hasBlocks(); -//PRODOS int blockSize(); -//PRODOS int blocksPerTrack(); - - void setSectorOrder(SectorOrder order); - SectorOrder sectorOrder() const; - - bool reorderSectorsTo(SectorOrder newOrder); - - SectorData *sectorAt(int track, int sector); - SectorData *sectorAt(TSPair ts); - - inline SectorOrderMap dosOrderMap() const;; - inline SectorOrderMap prodosOrderMap() const; - inline SectorOrderMap pascalOrderMap() const; - inline SectorOrderMap cpmOrderMap() const; - - SectorOrderMap customOrderMap0() const; - SectorOrderMap customOrderMap1() const; - - bool setCustomOrderMap0(SectorOrderMap map); - bool setCustomOrderMap1(SectorOrderMap map); - -private: -//PRODOS BlockPair mapBlockToTS(int blocknum); - -private: - TrackList m_tracks; - - bool m_empty_image; - - int m_sector_size; - int m_sectors_per_track; - int m_track_count; - - QString m_full_filename; - QString m_filename; - - SectorOrder m_sector_order; - - SectorOrderMap m_custom_order_map_0; - SectorOrderMap m_custom_order_map_1; - - HashValue m_hash; -}; - -#endif // RAWDISKIMAGE_H diff --git a/src/diskfiles/tspair.h b/src/diskfiles/tspair.h index a5e0fa2..b5ac3c9 100644 --- a/src/diskfiles/tspair.h +++ b/src/diskfiles/tspair.h @@ -31,6 +31,7 @@ public: TSPair(int trackval, int secval) { m_track=trackval; m_sector = secval; } TSPair(QPair pair) { m_track = pair.first; m_sector = pair.second;} + void setTrack(int tracknum) { if (tracknum > 34 && tracknum != 0xff) { diff --git a/src/intbasic/IntBasicFile.cxx b/src/intbasic/IntBasicFile.cxx index cb049fa..97ffab2 100644 --- a/src/intbasic/IntBasicFile.cxx +++ b/src/intbasic/IntBasicFile.cxx @@ -34,7 +34,7 @@ QByteArray IntBasicFile::detokenize() // uint = unsigned int // quint8 = unsigned char // ========================================================================== - return dumpBufferAsIntBasicFile(rawData().asQByteArray()); + return dumpBufferAsIntBasicFile(rawData()); } @@ -152,9 +152,10 @@ QByteArray IntBasicFile::dumpBufferAsIntBasicFile(QByteArray origdata) QByteArray retval; - QVector data; + QList data; QByteArray data0 = origdata; + if (origdata.size() == 0) return retval; foreach (quint8 value, origdata) { diff --git a/src/main.cpp b/src/main.cpp index 07ec784..71c13ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,8 +29,23 @@ #include "applesoftfile.h" #include "startupdialog.h" +//#include +//#include "sector.h" + int main(int argc, char** argv) { +// QByteArray ba(256,0xff); +// Sector s(ba,1,2); +// s.dump(); +// Sector t(s); +// t.dump(); + +//qDebug () << "S at 1: " << s.at(1); +//qDebug () << "T at 1: " << s.at(1); +//qDebug () << "S at 2: " << s.at(2); +//qDebug () << "T at 2: " << s.at(2); +// return 0; + QApplication a(argc, argv); QCoreApplication::setOrganizationName("LydianScaleSoftware"); diff --git a/src/src.pro b/src/src.pro index bd517fa..9a1d5ca 100644 --- a/src/src.pro +++ b/src/src.pro @@ -31,16 +31,17 @@ INCLUDEPATH += ./memory INCLUDEPATH += ./memory/roles INCLUDEPATH += ./sequence INCLUDEPATH += ./ui/central +INCLUDEPATH += ./diskfiles/diskstore INCLUDEPATH += ../ads/src/ INCLUDEPATH += ../cpress/ciderpress/diskimg/ + DEFINES += WS_VIDEO SOURCES += \ ./diskfiles/dos33/dos33disktreeview.cpp \ - ./diskfiles/rawdiskimage.cpp \ ./intbasic/IntBasicFile.cxx \ ./main.cpp \ ./diskfiles/dos33/dos33diskimage.cxx \ @@ -132,7 +133,6 @@ HEADERS += \ ./diskfiles/tspair.h \ ./diskfiles/dos33/dos33imagemodel.h\ ./diskfiles/dos33/dos33treeitem.h\ - ./diskfiles/rawdiskimage.h \ ./intbasic/IntBasicFile.h \ ./memory/attributedmemory.h \ ./memory/memorycell.h \ @@ -205,7 +205,8 @@ HEADERS += \ diskfiles/cpressfile.h \ diskfiles/diskstore/asdiskdata.h \ diskfiles/diskstore/asdiskimporter.h \ - diskfiles/diskstore/asdiskstore.h + diskfiles/diskstore/asdiskstore.h \ + util/referencelist.h FORMS += \ ./sequence/sequenceviewer.ui \ diff --git a/src/ui/diskexplorer/DiskExplorer.cpp b/src/ui/diskexplorer/DiskExplorer.cpp index db45f86..37cd1e6 100644 --- a/src/ui/diskexplorer/DiskExplorer.cpp +++ b/src/ui/diskexplorer/DiskExplorer.cpp @@ -230,7 +230,7 @@ void DiskExplorer::handleShowSectorData(QByteArray /*data*/, int track, int sect } } auto sec = m_disk->getSector(track,sector); - m_vws->setSector(&sec, viewer); + m_vws->setSector(sec, viewer); } void DiskExplorer::showLoadDialog(bool parentToThis) diff --git a/src/ui/diskexplorer/DiskExplorerMapWidget.cpp b/src/ui/diskexplorer/DiskExplorerMapWidget.cpp index 760317b..d2e3612 100644 --- a/src/ui/diskexplorer/DiskExplorerMapWidget.cpp +++ b/src/ui/diskexplorer/DiskExplorerMapWidget.cpp @@ -170,10 +170,10 @@ void DiskExplorerMapWidget::handleButtonCheck(int track, int sector, bool checke if (checked) { - Sector sec = m_disk->getSector(track,sector); - QByteArray *data = sec.rawData(); - emit showSectorData(*data,track,sector,QVariant((int) m_roles[TSPair(track,sector)])); - emit showSector(&sec,track,sector,m_roles[TSPair(track,sector)]); + pSector sec = m_disk->getSector(track,sector); + const QByteArray data = sec->rawData(); + emit showSectorData(data,track,sector,QVariant((int) m_roles[TSPair(track,sector)])); + emit showSector(sec,track,sector,m_roles[TSPair(track,sector)]); m_trackSectorLabel->setText( QString("Track: %1 Sector: %2 (%3)") @@ -338,6 +338,8 @@ void DiskExplorerMapWidget::defineRoles(TSPair vtoc) m_numbers.clear(); m_roles.clear(); + qDebug() << "in defineRoles with vtoc at : " << vtoc.track() << "," << vtoc.sector(); + int buttonNumber = 0; for (auto track = 0; track < m_numtracks; track++) @@ -380,14 +382,19 @@ void DiskExplorerMapWidget::defineRoles(TSPair vtoc) void DiskExplorerMapWidget::mapCatalogSectors(int &buttonNumber) { int catSectorCount = 0; - foreach (CatalogSector cs, m_disk->getCatalogSectors()) + foreach (auto cs, m_disk->getCatalogSectors()) { - TSPair ts(cs.sectorLocation()); + qDebug() << "Processing buttons for catalog sectors"; + TSPair ts = cs.sectorLocation(); + qDebug() << "Sector location: " << ts.track() << "," << ts.sector(); if (setButtonRole(ts,DiskSectorRole::CatalogSector)) { QString desc = QString("Catalog Sector #%1").arg(++catSectorCount); + qDebug() << "Desc: " << desc; setDescription(ts,desc); setButtonNumber(ts,buttonNumber++); +// qDebug() << "Setting button number " << buttonNumber-1 +// << " at " << ts.track() << "," << ts.sector(); int fdeNum = 0; foreach (FileDescriptiveEntry fde, cs.getFDEs()) @@ -444,7 +451,7 @@ void DiskExplorerMapWidget::mapTSListSector(TSPair location, return; } - Sector *s = &(m_disk->getSector(location)); + pSector s = m_disk->getSector(location); TrackSectorList tsl(s); if (setButtonRole(location,DiskSectorRole::TSList)) @@ -608,7 +615,7 @@ void DiskExplorerMapWidget::mapButtonsFromRoles() void DiskExplorerMapWidget::checkForUsedButUnknown(TSPair vtoc) { - auto vtocsector = m_disk->getSector(vtoc).promoteToVTOC(); + auto vtocsector = m_disk->getSector(vtoc)->promoteToVTOC(); for (auto track = 0; track < m_numtracks; track++) { diff --git a/src/ui/diskexplorer/DiskExplorerMapWidget.h b/src/ui/diskexplorer/DiskExplorerMapWidget.h index 428ba26..7133ba3 100644 --- a/src/ui/diskexplorer/DiskExplorerMapWidget.h +++ b/src/ui/diskexplorer/DiskExplorerMapWidget.h @@ -180,7 +180,7 @@ public: signals: void showSectorData(QByteArray data, int track, int sector, QVariant metadata); - void showSector(Sector *sec, int track, int sector, DiskSectorRole role); + void showSector(pSector sec, int track, int sector, DiskSectorRole role); public slots: void handleButtonCheck(int track, int sector, bool checked); diff --git a/src/ui/diskexplorer/catalogsectorview.cpp b/src/ui/diskexplorer/catalogsectorview.cpp index 1b03fa3..0fd38ec 100644 --- a/src/ui/diskexplorer/catalogsectorview.cpp +++ b/src/ui/diskexplorer/catalogsectorview.cpp @@ -48,7 +48,7 @@ CatalogSectorView::~CatalogSectorView() delete ui; } -void CatalogSectorView::setSector(Sector *sec) +void CatalogSectorView::setSector(QSharedPointersec) { m_sector = sec; diff --git a/src/ui/diskexplorer/catalogsectorview.h b/src/ui/diskexplorer/catalogsectorview.h index 3651898..5d03592 100644 --- a/src/ui/diskexplorer/catalogsectorview.h +++ b/src/ui/diskexplorer/catalogsectorview.h @@ -37,12 +37,12 @@ public: explicit CatalogSectorView(QWidget *parent = nullptr); ~CatalogSectorView(); - void setSector(Sector *sec); + void setSector(QSharedPointer sec); private: Ui::CatalogSectorView *ui; - Sector *m_sector; + QSharedPointer m_sector; }; #endif // CATALOGSECTORVIEW_H diff --git a/src/ui/diskexplorer/tslistview.cpp b/src/ui/diskexplorer/tslistview.cpp index e5fc445..8441273 100644 --- a/src/ui/diskexplorer/tslistview.cpp +++ b/src/ui/diskexplorer/tslistview.cpp @@ -24,7 +24,7 @@ TSListView::TSListView(QWidget *parent) : QTextBrowser(parent) } -void TSListView::setSector(Sector *sec) +void TSListView::setSector(pSector sec) { m_sector = sec; if (sec) diff --git a/src/ui/diskexplorer/tslistview.h b/src/ui/diskexplorer/tslistview.h index b5be90f..3c5db9b 100644 --- a/src/ui/diskexplorer/tslistview.h +++ b/src/ui/diskexplorer/tslistview.h @@ -31,12 +31,12 @@ class TSListView : public QTextBrowser public: explicit TSListView(QWidget *parent = nullptr); - void setSector(Sector *sec); + void setSector(QSharedPointer sec); signals: private: - Sector *m_sector; + QSharedPointer m_sector; }; diff --git a/src/ui/diskexplorer/viewwidgetstack.cpp b/src/ui/diskexplorer/viewwidgetstack.cpp index bfaa4eb..8080b34 100644 --- a/src/ui/diskexplorer/viewwidgetstack.cpp +++ b/src/ui/diskexplorer/viewwidgetstack.cpp @@ -29,11 +29,11 @@ ViewWidgetStack::ViewWidgetStack(QWidget *parent) : QTabWidget(parent) setSector(nullptr); } -void ViewWidgetStack::setSector(Sector *sec, PreferredViewer viewer) +void ViewWidgetStack::setSector(QSharedPointer sec, PreferredViewer viewer) { if (sec) { - m_hdv->setRawData(*(sec->rawData())); + m_hdv->setRawData(sec->rawData()); } else { @@ -79,7 +79,7 @@ void ViewWidgetStack::makeWidgets() setCurrentWidget(m_hdv); } -void ViewWidgetStack::handleShowSectorData(Sector *data, int /*track*/, +void ViewWidgetStack::handleShowSectorData(pSector data, int /*track*/, int /*sector*/, DiskSectorRole role) { ViewWidgetStack::PreferredViewer viewer = diff --git a/src/ui/diskexplorer/viewwidgetstack.h b/src/ui/diskexplorer/viewwidgetstack.h index 573b1f1..2fe42f8 100644 --- a/src/ui/diskexplorer/viewwidgetstack.h +++ b/src/ui/diskexplorer/viewwidgetstack.h @@ -47,9 +47,9 @@ public: explicit ViewWidgetStack(QWidget *parent = nullptr); public slots: - void setSector(Sector *sec, PreferredViewer viewer = PreferredViewer::DontCare); + void setSector(QSharedPointer sec, PreferredViewer viewer = PreferredViewer::DontCare); - void handleShowSectorData(Sector *data, int track, int sector, DiskSectorRole role); + void handleShowSectorData(QSharedPointer data, int track, int sector, DiskSectorRole role); diff --git a/src/ui/diskexplorer/vtocview.cpp b/src/ui/diskexplorer/vtocview.cpp index 5a5b37c..9ca88cd 100644 --- a/src/ui/diskexplorer/vtocview.cpp +++ b/src/ui/diskexplorer/vtocview.cpp @@ -31,7 +31,7 @@ VTOCView::~VTOCView() { delete ui; } -void VTOCView::setSector(Sector *sec) +void VTOCView::setSector(QSharedPointer sec) { m_sector = sec; diff --git a/src/ui/diskexplorer/vtocview.h b/src/ui/diskexplorer/vtocview.h index 7a8d6e6..eb72a8e 100644 --- a/src/ui/diskexplorer/vtocview.h +++ b/src/ui/diskexplorer/vtocview.h @@ -37,12 +37,12 @@ public: explicit VTOCView(QWidget *parent = nullptr); ~VTOCView(); - void setSector(Sector *sec); + void setSector(QSharedPointer sec); private: Ui::VTOCView *ui; - Sector *m_sector; + QSharedPointer m_sector; }; diff --git a/src/util/chunkbytelist.cpp b/src/util/chunkbytelist.cpp deleted file mode 100644 index 3e4ddd8..0000000 --- a/src/util/chunkbytelist.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/***************************************************************************** -* 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 . * -*****************************************************************************/ - -#include "chunkbytelist.h" - -ChunkByteList::ChunkByteList() -{ - m_preamble_size = 0; -} - -ChunkByteList &ChunkByteList::appendChunk(QByteArray *chunk) -{ - if (chunk) - { - m_chunk_list.append(chunk); - } - return *this; -} - -ChunkByteList &ChunkByteList::appendChunkList(ChunkByteList other) -{ - if (&other != this) - { - for (auto count = 0; count < other.numChunks(); count++) - { - m_chunk_list.append(other.getChunk(count)); - } - } - return *this; -} - -int ChunkByteList::count() const -{ - int size = 0; - foreach (auto chunk, m_chunk_list) - { - size += chunk->size(); - } - return size - preambleLength(); -} - -int ChunkByteList::size() const -{ - return count(); -} - -int ChunkByteList::length() const -{ - return count(); -} - -bool ChunkByteList::isEmpty() const -{ - if (m_chunk_list.size() == 0) return true; - - foreach (auto chunk, m_chunk_list) - { - if (!chunk->isEmpty()) return false; - } - return false; -} - -char ChunkByteList::at(int i) const -{ - return preambleData(i + preambleLength()); -} - -char ChunkByteList::operator[](int i) const -{ - return at(i); -} - - diff --git a/src/util/chunkbytelist.h b/src/util/chunkbytelist.h deleted file mode 100644 index 3787c5c..0000000 --- a/src/util/chunkbytelist.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef CHUNKBYTELIST_H -#define CHUNKBYTELIST_H - -/***************************************************************************** -* 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 . * -*****************************************************************************/ - -#include -#include - -#include - -class ChunkByteList -{ -public: - ChunkByteList(); - - ChunkByteList &appendChunk(QByteArray *chunk); - ChunkByteList &appendChunkList(ChunkByteList other); - - void setPreambleLength(int bytes) { m_preamble_size = bytes; }; - int preambleLength() const { return m_preamble_size; }; - - int count() const; - int size() const; - int length() const; - - char preambleData(int i) const - { - int offset = 0; - foreach (auto chunk, m_chunk_list) - { - int upperbound = offset + chunk->size(); - if (i < upperbound) - { - return chunk->at(i-offset); - } - else - { - offset += chunk->size(); - } - } - return 0; - } - - int actualSize() const { return count() + preambleLength(); } - - bool isEmpty() const; - - char at(int i) const; - char operator[](int i) const; - - int numChunks() const { return m_chunk_list.size(); } - QByteArray *getChunk(int chunk) const { return m_chunk_list[chunk]; } - - QByteArray asQByteArray() const { - QByteArray retval; - foreach (auto chunk, m_chunk_list) - { - retval.append(*chunk); - } - return retval; - } - - explicit operator QByteArray() { return asQByteArray(); } - -private: - QList m_chunk_list; - int m_preamble_size; -}; - - -#endif // CHUNKBYTELIST_H diff --git a/src/util/referencelist.h b/src/util/referencelist.h new file mode 100644 index 0000000..e414481 --- /dev/null +++ b/src/util/referencelist.h @@ -0,0 +1,409 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * ReferenceList.h * + * * + * Copyright 2014 Tory Gaurnier * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License as published by * + * the Free Software Foundation; version 3. * + * * + * 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 Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public License * + * along with this program. If not, see . * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#ifndef REFERENCELIST_HPP +#define REFERENCELIST_HPP + + +#include +#include +#include + + +/** + * class ReferenceList + * + * Uses QList under the hood to store pointers, on the surface recieves and returns nothing but the + * references. + * + * NOTE: Any method that calls it's QList counterpart with parameter T, T must not be const, if + * it is then QList would have to be QList instead. + */ +template +class ReferenceList : public QList { + public: + // Forward declare iterators + class const_iterator; + class iterator; + + // Set iterators as friends + friend class const_iterator; + friend class iterator; + + + ReferenceList() {} + ReferenceList(const QList &other) : QList(other) { } + ReferenceList(const ReferenceList &other) : QList(other) { } + ReferenceList(ReferenceList &&other) : QList(std::move(other)) { } + ~ReferenceList() {} + + void append(T &value) { + QList::append(&value); + } + + void append(const ReferenceList other) { + QList::append(other); + } + + const T & at(int i) const { + return *QList::at(i); + } + + T & back() { + return *QList::back(); + } + + const T & back() const { + return *QList::back(); + } + + iterator begin() { + return iterator(iterator(QList::begin())); + } + + const_iterator begin() const { + return const_iterator(QList::begin()); + } + + const_iterator cbegin() const { + return const_iterator(QList::cbegin()); + } + + const_iterator cend() const { + return const_iterator(QList::cend()); + } + + void clear() { + QList::clear(); + } + + const_iterator constBegin() const { + return const_iterator(QList::constBegin()); + } + + const_iterator constEnd() const { + return const_iterator(QList::constEnd()); + } + + bool contains(T &value) const { + return QList::contains(&value); + } + + int count(T &value) const { + return QList::count(&value); + } + + int count() const { + return QList::count(); + } + + bool empty() const { + return QList::empty(); + } + + iterator end() { + return iterator(QList::end()); + } + + const_iterator end() const { + return const_iterator(QList::end()); + } + + bool endsWith(T &value) const { + return QList::endsWith(&value); + } + + iterator erase(iterator pos) { + return iterator(QList::erase(pos)); + } + + iterator erase(iterator begin, iterator end) { + return iterator(QList::erase(begin, end)); + + } + + T & first() { + return *QList::first(); + } + + const T & first() const { + return *QList::first(); + } + + /** + * Inherited "from" methods are unsupported. + */ + static ReferenceList fromSet(const QSet & set) = delete; + static ReferenceList fromStdList(const std::list & list) = delete; + static ReferenceList fromVector(const QVector & vector) = delete; + + T & front() { + return *QList::front(); + } + + const T & front() const { + return *QList::front(); + } + + int indexOf(T &value, int from = 0) const { + return QList::indexOf(&value, from); + } + + void insert(int i, T &value) { + QList::insert(i, &value); + } + + iterator insert(iterator before, T &value) { + return iterator(QList::insert(before, &value)); + } + + bool isEmpty() const { + return QList::isEmpty(); + } + + T & last() { + return *QList::last(); + } + + const T & last() const { + return *QList::last(); + } + + int lastIndexOf(T &value, int from = -1) const { + return QList::lastIndexOf(&value, from); + } + + int length() const { + return QList::length(); + } + + ReferenceList mid(int pos, int length = -1) const { + return ReferenceList(QList::mid(pos, length)); + } + + void move(int from, int to) { + QList::move(from, to); + } + + void pop_back() { + QList::pop_back(); + } + + void pop_front() { + QList::pop_front(); + } + + void prepend(T &value) { + QList::prepend(&value); + } + + void push_back(T &value) { + QList::push_back(&value); + } + + void push_front(T &value) { + QList::push_front(&value); + } + + int removeAll(T &value) { + return QList::removeAll(&value); + } + + void removeAt(int i) { + QList::removeAt(i); + } + + void removeFirst() { + QList::removeFirst(); + } + + void removeLast() { + QList::removeLast(); + } + + bool removeOne(T &value) { + return QList::removeOne(&value); + } + + void replace(int i, T &value) { + QList::replace(i, &value); + } + + void reserve(int alloc) { + QList::reserve(alloc); + } + + int size() const { + return QList::size(); + } + + bool startsWith(T &value) const { + return QList::startsWith(&value); + } + + void swap(ReferenceList &other) { + QList::swap(other); + } + + void swap(int i, int j) { + QList::swap(i, j); + } + + T & takeAt(int i) { + return *QList::takeAt(i); + } + + T & takeFirst() { + return *QList::takeFirst(); + } + + T & takeLast() { + return *QList::takeLast(); + } + + /** + * Inherited "to" methods are not supported. + */ + QSet toSet() const = delete; + std::list toStdList() const = delete; + QVector toVector() const = delete; + + T & value(int i) const { + return *QList::value(i); + } + + T & value(int i, T &default_value) const { + return *QList::value(i, &default_value); + } + + bool operator!=(const ReferenceList &other) const { + return QList::operator!=(other); + } + + ReferenceList operator+(const ReferenceList &other) const { + return ReferenceList(QList::operator+(other)); + } + + ReferenceList & operator+=(const ReferenceList &other) { + QList::operator+=(other); + return *this; + } + + ReferenceList & operator+=(T &value) { + QList::operator+=(&value); + return *this; + } + + ReferenceList & operator<<(const ReferenceList &other) { + QList::operator<<(other); + return *this; + } + + ReferenceList & operator<<(T &value) { + QList::operator<<(&value); + return *this; + } + + ReferenceList & operator=(ReferenceList &other) { + QList::operator=(other); + return *this; + } + + ReferenceList & operator=(ReferenceList &&other) { + QList::operator=(std::move(other)); + return *this; + } + + bool operator==(const ReferenceList &other) const { + return QList::operator==(other); + } + + T & operator[](int i) { + return *QList::operator[](i); + } + + const T & operator[](int i) const { + return *QList::operator[](i); + } + + + class iterator : public QList::iterator { + public: + iterator() { } + iterator(const typename QList::iterator &other) + : QList::iterator(other) { } + iterator(const iterator &other) : QList::iterator(other) { } + T & operator*() const { return *QList::iterator::operator*(); } + T * operator->() const { return *QList::iterator::operator->(); } + T & operator[](int j) const { return *QList::iterator::operator[](j); } + }; + + class const_iterator : public QList::const_iterator { + public: + const_iterator() { } + const_iterator(const typename QList::const_iterator &other) + : QList::const_iterator(other) { } + const_iterator(const const_iterator &other) + : QList::const_iterator(other) { } + const_iterator(const iterator &other) + : QList::const_iterator(other) { } + T & operator*() const { return *QList::const_iterator::operator*(); } + T * operator->() const { return *QList::const_iterator::operator->(); } + T & operator[](int j) const { return *QList::const_iterator::operator[](j); } + }; +}; + + +/** + * Implement QDebug << operator so that it will print out values rather than pointer addresses (do + * to it implicitly converting to QList). + */ +template +QDebug operator<<(QDebug debug, const ReferenceList &list) { + debug.nospace() << '('; + for(typename QList::size_type i = 0; i < list.count(); ++i) { + if(i) debug << ", "; + debug << list.at(i); + } + + debug << ')'; + + return debug.space(); +} + + +/** +* QDataStream << ReferenceList should have same output as the QDataStream << QList. +*/ +template +QDataStream & operator<<(QDataStream &out, const ReferenceList& list) { + out << quint32(list.size()); + for(int i = 0; i < list.size(); ++i) out << list.at(i); + return out; +} + + +/** +* Make sure QDataStream >> is not callable, there is no scenario where it would be useful with a +* ReferenceList. +*/ +template +QDataStream & operator>>(QDataStream &out, const ReferenceList& list) = delete; + +#endif