Finished refactor of GenericFile. At least for now.
This commit is contained in:
parent
14301d7083
commit
5fb37304c0
|
@ -6,12 +6,15 @@
|
|||
#include <QRegularExpressionMatchIterator>
|
||||
#include <QList>
|
||||
|
||||
ApplesoftFile::ApplesoftFile(QByteArray data) : GenericFile(data)
|
||||
ApplesoftFile::ApplesoftFile(Dos33DiskImage *image, FileDescriptiveEntry &fde)
|
||||
: GenericFile(image,fde)
|
||||
{
|
||||
m_retokenizer = Q_NULLPTR;
|
||||
m_data_end = data.length();
|
||||
m_data_end = data().length();
|
||||
|
||||
setAddress(0x801);
|
||||
|
||||
processData();
|
||||
}
|
||||
|
||||
void ApplesoftFile::processData()
|
||||
|
@ -22,9 +25,9 @@ void ApplesoftFile::processData()
|
|||
}
|
||||
|
||||
m_length = dataWordAt(0);
|
||||
setIgnoreOffset(2);
|
||||
QByteArray tmp = rawData().asQByteArray().mid(2);
|
||||
|
||||
m_retokenizer->setData(data());
|
||||
m_retokenizer->setData(tmp);
|
||||
m_retokenizer->parse();
|
||||
m_data_end = m_retokenizer->getEndOfDataOffset();
|
||||
m_lines = m_retokenizer->getRetokenizedLines();
|
||||
|
|
|
@ -29,7 +29,8 @@ protected:
|
|||
void processData();
|
||||
|
||||
private:
|
||||
ApplesoftFile(QByteArray data = QByteArray());
|
||||
ApplesoftFile(Dos33DiskImage *image, FileDescriptiveEntry &fde);
|
||||
|
||||
QVector<ApplesoftLine> m_lines;
|
||||
int m_data_end;
|
||||
quint16 m_length;
|
||||
|
|
|
@ -2,15 +2,16 @@
|
|||
#include "binaryfile.h"
|
||||
#include "util.h"
|
||||
|
||||
BinaryFile::BinaryFile(QByteArray data) : GenericFile(data)
|
||||
BinaryFile::BinaryFile(Dos33DiskImage *image, FileDescriptiveEntry &fde)
|
||||
: GenericFile(image,fde)
|
||||
{
|
||||
if (!data.isEmpty()) {
|
||||
setData(data);
|
||||
}
|
||||
setupData();
|
||||
}
|
||||
|
||||
void BinaryFile::setData(QByteArray data)
|
||||
void BinaryFile::setupData()
|
||||
{
|
||||
QByteArray data = rawData().asQByteArray();
|
||||
|
||||
if (data.length() >= 4) {
|
||||
QByteArray metadata = data.left(4);
|
||||
GenericFile::setData(data.mid(4));
|
||||
|
|
|
@ -12,8 +12,8 @@ public:
|
|||
void dump();
|
||||
|
||||
protected:
|
||||
BinaryFile(QByteArray data = QByteArray());
|
||||
void setData(QByteArray data) override;
|
||||
BinaryFile(Dos33DiskImage *image, FileDescriptiveEntry &fde);
|
||||
void setupData();
|
||||
};
|
||||
|
||||
#endif // BINARYFILE_H
|
||||
|
|
|
@ -160,34 +160,33 @@ GenericFile *Dos33DiskImage::getFile(FileDescriptiveEntry fde)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ChunkByteList data = getDataFromTrackSectorList(tsl);
|
||||
setFileType(fde.fileTypeIdentifier());
|
||||
auto type = fde.fileTypeIdentifier();
|
||||
|
||||
// if (fileType() == "A")
|
||||
// {
|
||||
// retval = new ApplesoftFile(data);
|
||||
// }
|
||||
// else if (fileType() == "B")
|
||||
// {
|
||||
// retval = new BinaryFile(data);
|
||||
// }
|
||||
// else if (fileType() == "R")
|
||||
// {
|
||||
// retval = new RelocatableFile(data);
|
||||
// }
|
||||
// else if ((fileType() == "T"))
|
||||
// {
|
||||
// retval = new TextFile(data);
|
||||
// }
|
||||
// else if ((fileType() == "I"))
|
||||
// {
|
||||
// retval = new IntBasicFile(data);
|
||||
// }
|
||||
// else
|
||||
if (type == "A")
|
||||
{
|
||||
retval = new GenericFile(data);
|
||||
retval = new ApplesoftFile(this,fde);
|
||||
}
|
||||
|
||||
else if (type == "B")
|
||||
{
|
||||
retval = new BinaryFile(this,fde);
|
||||
}
|
||||
else if (type == "R")
|
||||
{
|
||||
retval = new RelocatableFile(this,fde);
|
||||
}
|
||||
else if ((type == "T"))
|
||||
{
|
||||
retval = new TextFile(this,fde);
|
||||
}
|
||||
else if ((type == "I"))
|
||||
{
|
||||
retval = new IntBasicFile(this,fde);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = new GenericFile(this,fde);
|
||||
}
|
||||
retval->updateFromFDE(fde);
|
||||
m_files[fde] = retval;
|
||||
}
|
||||
if (retval) { retval->setDiskFile(this); }
|
||||
|
@ -199,6 +198,7 @@ ChunkByteList Dos33DiskImage::getDataFromTrackSectorList(TrackSectorList tsl)
|
|||
{
|
||||
ChunkByteList retval;
|
||||
|
||||
|
||||
foreach(TSPair pair, tsl.getDataTSPairs())
|
||||
{
|
||||
if (pair.isValid())
|
||||
|
@ -221,6 +221,24 @@ ChunkByteList Dos33DiskImage::getDataFromTrackSectorList(TrackSectorList tsl)
|
|||
return retval;
|
||||
}
|
||||
|
||||
ChunkByteList Dos33DiskImage::getDataFromTSPairList(TSPairList list)
|
||||
{
|
||||
ChunkByteList retval;
|
||||
foreach(TSPair pair, list)
|
||||
{
|
||||
if (pair.isValid())
|
||||
{
|
||||
Sector sec = getSector(pair);
|
||||
retval.appendChunk(sec.rawData());
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Not adding data from invalid TSPairList");
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
QList<FileDescriptiveEntry> Dos33DiskImage::getAllFDEs()
|
||||
{
|
||||
QList<FileDescriptiveEntry> retval;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "util.h"
|
||||
#include "sector.h"
|
||||
#include "vtoc.h"
|
||||
#include "tracksectorlist.h"
|
||||
|
||||
#include "rawdiskimage.h"
|
||||
#include "chunkbytelist.h"
|
||||
|
@ -38,6 +39,7 @@ public:
|
|||
GenericFile *getFile(FileDescriptiveEntry fde);
|
||||
|
||||
ChunkByteList getDataFromTrackSectorList(TrackSectorList tsl);
|
||||
ChunkByteList getDataFromTSPairList(TSPairList list);
|
||||
|
||||
QList<FileDescriptiveEntry> getAllFDEs();
|
||||
|
||||
|
@ -46,17 +48,13 @@ public:
|
|||
QString getDiskImageName() const { return m_disk_image->diskImageName(); }
|
||||
QString getFullDiskImageName() const { return m_disk_image->fullDiskImageName(); }
|
||||
QString getMetaDataPath() const;
|
||||
|
||||
QString fileType() const { return m_fileType; }
|
||||
void setFileType(QString type) { m_fileType = type; }
|
||||
RawDiskImage *rawImage() const { return m_disk_image; }
|
||||
|
||||
int sectorsPerTrack() const { return m_disk_image->sectorsPerTrack(); }
|
||||
int tracks() const { return m_disk_image->numTracks(); }
|
||||
|
||||
QList<GenericFile *> fileList();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
RawDiskImage *m_disk_image;
|
||||
|
@ -65,7 +63,6 @@ private:
|
|||
QMap<FileDescriptiveEntry, GenericFile *> m_files;
|
||||
QByteArray m_hash;
|
||||
|
||||
QString m_fileType;
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -1,2 +1,67 @@
|
|||
#include "filedescriptiveentry.h"
|
||||
#include "genericfile.h"
|
||||
|
||||
FileDescriptiveEntry::FileDescriptiveEntry() {
|
||||
fileTypeFlags = 0;
|
||||
lengthInSectors = 0;
|
||||
deleted = false;
|
||||
}
|
||||
|
||||
bool FileDescriptiveEntry::operator<(const FileDescriptiveEntry &f1) const {
|
||||
return f1.filename < filename;
|
||||
}
|
||||
|
||||
QString FileDescriptiveEntry::fileTypeIdentifier() {
|
||||
if (fileTypeFlags & (quint8) FileTypeFlag::Integer) { return "I"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::Applesoft) { return "A"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::Relocatable) { return "R"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::Binary) { return "B"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::TypeS) { return "S"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::TypeA) { return "a"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::TypeB) { return "b"; }
|
||||
else return "T";
|
||||
}
|
||||
|
||||
bool FileDescriptiveEntry::isLocked() { return (fileTypeFlags & (quint8) FileTypeFlag::IsLockedFlag); }
|
||||
|
||||
void FileDescriptiveEntry::dump() {
|
||||
|
||||
qDebug() << "First TS List Sector: Track: " << QString("%1").arg(firstTSListSector().track(),2,16,QChar('0')).toUpper()
|
||||
<< " Sector: " << QString("%1").arg(firstTSListSector().sector(),2,16,QChar('0')).toUpper();
|
||||
qDebug() << "File Type and Flags: " << QString::number((quint8) fileTypeFlags) << "(" << fileTypeIdentifier() << "," << (isLocked()?"Locked":"Unlocked") << ")";
|
||||
qDebug() << "Filename: " << filename.printable();
|
||||
qDebug() << "Length in Sectors: " << lengthInSectors;
|
||||
}
|
||||
|
||||
void FileDescriptiveEntry::catalog() {
|
||||
QString output = QString("%1 %2 %3 %4").arg(QString(isLocked()?"*":" "))
|
||||
.arg(lengthInSectors,3,10,QChar('0'))
|
||||
.arg(fileTypeIdentifier())
|
||||
.arg(filename.printable().trimmed());
|
||||
qDebug() << output;
|
||||
}
|
||||
|
||||
void FileDescriptiveEntry::setFirstTSListSector(TSPair ts)
|
||||
{
|
||||
if (ts.isValid())
|
||||
{
|
||||
m_firstTSListSector = ts;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_firstTSListSector = TSPair(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
TSPair FileDescriptiveEntry::firstTSListSector() const { return m_firstTSListSector; }
|
||||
|
||||
void FileDescriptiveEntry::updateGenericFile(GenericFile *file)
|
||||
{
|
||||
if (file)
|
||||
{
|
||||
file->setFileType(fileTypeIdentifier());
|
||||
file->setLocked(isLocked());
|
||||
file->setSectorCount(lengthInSectors);
|
||||
file->setFilename(filename);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,64 +5,34 @@
|
|||
#include <QDebug>
|
||||
#include "applestring.h"
|
||||
|
||||
struct FileDescriptiveEntry {
|
||||
class GenericFile;
|
||||
|
||||
|
||||
class FileDescriptiveEntry
|
||||
{
|
||||
public:
|
||||
|
||||
quint8 fileTypeFlags;
|
||||
AppleString filename;
|
||||
quint16 lengthInSectors;
|
||||
bool deleted;
|
||||
|
||||
FileDescriptiveEntry() {
|
||||
fileTypeFlags = 0;
|
||||
lengthInSectors = 0;
|
||||
deleted = false;
|
||||
}
|
||||
FileDescriptiveEntry();
|
||||
|
||||
bool operator<(const FileDescriptiveEntry& f1) const {
|
||||
return f1.filename < filename;
|
||||
}
|
||||
bool operator<(const FileDescriptiveEntry& f1) const;
|
||||
|
||||
QString fileTypeIdentifier() {
|
||||
if (fileTypeFlags & (quint8) FileTypeFlag::Integer) { return "I"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::Applesoft) { return "A"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::Relocatable) { return "R"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::Binary) { return "B"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::TypeS) { return "S"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::TypeA) { return "a"; }
|
||||
else if (fileTypeFlags & (quint8) FileTypeFlag::TypeB) { return "b"; }
|
||||
else return "T";
|
||||
}
|
||||
QString fileTypeIdentifier();
|
||||
|
||||
bool isLocked() { return (fileTypeFlags & (quint8) FileTypeFlag::IsLockedFlag); }
|
||||
bool isLocked();
|
||||
|
||||
void dump() {
|
||||
|
||||
qDebug() << "First TS List Sector: Track: " << QString("%1").arg(firstTSListSector().track(),2,16,QChar('0')).toUpper()
|
||||
<< " Sector: " << QString("%1").arg(firstTSListSector().sector(),2,16,QChar('0')).toUpper();
|
||||
qDebug() << "File Type and Flags: " << QString::number((quint8) fileTypeFlags) << "(" << fileTypeIdentifier() << "," << (isLocked()?"Locked":"Unlocked") << ")";
|
||||
qDebug() << "Filename: " << filename.printable();
|
||||
qDebug() << "Length in Sectors: " << lengthInSectors;
|
||||
}
|
||||
void dump();
|
||||
|
||||
void catalog() {
|
||||
QString output = QString("%1 %2 %3 %4").arg(QString(isLocked()?"*":" "))
|
||||
.arg(lengthInSectors,3,10,QChar('0'))
|
||||
.arg(fileTypeIdentifier())
|
||||
.arg(filename.printable().trimmed());
|
||||
qDebug() << output;
|
||||
}
|
||||
void catalog();
|
||||
|
||||
void setFirstTSListSector(TSPair ts)
|
||||
{
|
||||
if (ts.isValid())
|
||||
{
|
||||
m_firstTSListSector = ts;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_firstTSListSector = TSPair(0,0);
|
||||
}
|
||||
}
|
||||
TSPair firstTSListSector() const { return m_firstTSListSector; }
|
||||
void setFirstTSListSector(TSPair ts);
|
||||
TSPair firstTSListSector() const;
|
||||
|
||||
void updateGenericFile(GenericFile *file);
|
||||
|
||||
private:
|
||||
TSPair m_firstTSListSector;
|
||||
|
|
|
@ -1,58 +1,95 @@
|
|||
#include "genericfile.h"
|
||||
|
||||
GenericFile::GenericFile(QByteArray data)
|
||||
|
||||
quint8 GenericFile::rawDataAt(int offset)
|
||||
{
|
||||
m_data_loaded = false;
|
||||
m_diskfile = 0;
|
||||
if (!data.isEmpty()) {
|
||||
setData(data);
|
||||
m_data_loaded = true;
|
||||
return rawData().at(offset);
|
||||
}
|
||||
|
||||
quint16 GenericFile::rawDataWordAt(int offset)
|
||||
{
|
||||
return makeWord(dataAt(offset),dataAt(offset+1));
|
||||
}
|
||||
|
||||
quint8 GenericFile::dataAt(int offset)
|
||||
{
|
||||
return data().at(offset);
|
||||
}
|
||||
|
||||
|
||||
quint16 GenericFile::dataWordAt(int offset)
|
||||
{
|
||||
return makeWord(dataAt(offset),dataAt(offset+1));
|
||||
}
|
||||
|
||||
QByteArray GenericFile::data()
|
||||
{
|
||||
if (m_local_data.size() == 0)
|
||||
{
|
||||
if (m_data_cache.size() == 0)
|
||||
{
|
||||
m_data_cache = rawData().asQByteArray();
|
||||
}
|
||||
m_address = 0x00;
|
||||
m_length = 0x00;
|
||||
m_ignore_offset = 0;
|
||||
}
|
||||
|
||||
GenericFile::GenericFile(Dos33DiskImage *image, TSPairList pairs)
|
||||
{
|
||||
m_diskfile = image;
|
||||
m_ts_pairs = pairs;
|
||||
m_length = 0x00;
|
||||
m_address = 0x00;
|
||||
m_ignore_offset = 0;
|
||||
m_data_loaded = false;
|
||||
}
|
||||
|
||||
quint8 GenericFile::dataAt(int offset) const
|
||||
{
|
||||
return m_data[offset ];
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_local_data;
|
||||
}
|
||||
return m_data_cache;
|
||||
}
|
||||
|
||||
void GenericFile::setData(QByteArray data)
|
||||
{
|
||||
m_data_loaded = true;
|
||||
m_data = data;
|
||||
m_length = data.size();
|
||||
m_local_data = data;
|
||||
}
|
||||
|
||||
void GenericFile::resetToDefaultData()
|
||||
{
|
||||
m_local_data.clear();
|
||||
}
|
||||
|
||||
|
||||
QString GenericFile::getFileType() const
|
||||
ChunkByteList &GenericFile::rawData()
|
||||
{
|
||||
if (m_file_type == "A" || m_file_type == "B" || m_file_type == "T" ||
|
||||
m_file_type == "I" || m_file_type == "R" || m_file_type == "S" ||
|
||||
m_file_type == "a" || m_file_type == "b")
|
||||
if (!m_data_loaded)
|
||||
{
|
||||
return m_file_type;
|
||||
initDataFromImage();
|
||||
}
|
||||
else
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void GenericFile::updateFromFDE(FileDescriptiveEntry &fde)
|
||||
{
|
||||
fde.updateGenericFile(this);
|
||||
setLength(fde.lengthInSectors * m_diskfile->rawImage()->sectorSize());
|
||||
}
|
||||
|
||||
SectorData *GenericFile::peekFirstSector() const
|
||||
{
|
||||
SectorData *retval = nullptr;
|
||||
|
||||
if (m_diskfile)
|
||||
{
|
||||
return "?";
|
||||
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()
|
||||
{
|
||||
if (!m_data_loaded)
|
||||
{
|
||||
if (m_diskfile)
|
||||
{
|
||||
auto tsl = m_diskfile->getSector(m_fde.firstTSListSector()).asTrackSectorList();
|
||||
TSPairList pairs = tsl.getValidTSPairs();
|
||||
m_data_loaded = true;
|
||||
m_data = m_diskfile->getDataFromTSPairList(pairs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
quint16 GenericFile::dataWordAt(int offset) const
|
||||
{
|
||||
return makeWord(dataAt(offset),dataAt(offset+1));
|
||||
}
|
||||
|
|
|
@ -2,60 +2,100 @@
|
|||
#define GENERICFILE_H
|
||||
|
||||
#include "dos33diskimage.h"
|
||||
#include "filedescriptiveentry.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
|
||||
|
||||
class GenericFile
|
||||
{
|
||||
friend class Dos33DiskImage;
|
||||
|
||||
class GenericFile {
|
||||
public:
|
||||
virtual ~GenericFile() { }
|
||||
|
||||
virtual QByteArray data() { return m_data.mid(m_ignore_offset); }
|
||||
quint8 dataAt(int offset) const;
|
||||
quint16 dataWordAt(int offset) const;
|
||||
GenericFile() {
|
||||
m_length = 0;
|
||||
m_address = 0;
|
||||
m_file_type = "?";
|
||||
m_sector_count = 0;
|
||||
m_locked = false;
|
||||
m_diskfile = nullptr;
|
||||
m_data_loaded = false;
|
||||
}
|
||||
GenericFile (Dos33DiskImage *image, FileDescriptiveEntry &fde)
|
||||
: m_diskfile(image), m_fde(fde)
|
||||
{
|
||||
m_data_loaded = false;
|
||||
m_address = 0;
|
||||
updateFromFDE(fde);
|
||||
}
|
||||
virtual ~GenericFile() { };
|
||||
|
||||
virtual void setFilename(QString filename) { m_filename = filename; }
|
||||
QString filename() const { return m_filename; }
|
||||
|
||||
virtual void setAddress(quint16 location) { m_address = location; }
|
||||
virtual quint16 address() { return m_address; }
|
||||
|
||||
virtual quint16 address() const { return m_address; };
|
||||
|
||||
virtual void setLength(quint16 length) { m_length = length; }
|
||||
virtual int length() const { return m_length; }
|
||||
|
||||
Dos33DiskImage *diskFile() const { return m_diskfile; }
|
||||
void setDiskFile(Dos33DiskImage *diskfile) { m_diskfile = diskfile; }
|
||||
virtual quint8 rawDataAt(int offset) ;
|
||||
virtual quint16 rawDataWordAt(int offset);
|
||||
virtual ChunkByteList &rawData();
|
||||
|
||||
void setFileType(QString type) { m_file_type = type; }
|
||||
QString getFileType() const;
|
||||
|
||||
QByteArray rawData() const { return m_data; }
|
||||
[[deprecated("Only used for legacy purposes")]]
|
||||
virtual quint8 dataAt(int offset) ;
|
||||
[[deprecated("Only used for legacy purposes")]]
|
||||
virtual quint16 dataWordAt(int offset);
|
||||
[[deprecated("Only used for legacy purposes")]]
|
||||
/// Returns copy of rawData() unless user data is set.
|
||||
virtual QByteArray data();
|
||||
[[deprecated("Only used for legacy purposes")]]
|
||||
/// Overrides default data (copy of rawData) with user-supplied data
|
||||
virtual void setData(QByteArray data);
|
||||
[[deprecated("Only used for legacy purposes")]]
|
||||
/// Removes user-defined data
|
||||
virtual void resetToDefaultData();
|
||||
|
||||
void setIgnoreOffset(int offset) { m_ignore_offset = offset; }
|
||||
int ignoreOffset() const { return m_ignore_offset; }
|
||||
virtual void setFileType(QString type) { m_file_type = type; }
|
||||
virtual QString fileType() const {return m_file_type;}
|
||||
|
||||
virtual Dos33DiskImage *diskFile() const { return m_diskfile; }
|
||||
virtual void setDiskFile(Dos33DiskImage *diskfile) { m_diskfile = diskfile; }
|
||||
|
||||
virtual void setFilename(QString filename) { m_filename = filename; }
|
||||
virtual QString filename() const { return m_filename; }
|
||||
|
||||
virtual void setLocked(bool locked) { m_locked = locked; }
|
||||
virtual bool locked() const { return m_locked; }
|
||||
|
||||
virtual void updateFromFDE(FileDescriptiveEntry &fde);
|
||||
|
||||
virtual void setSectorCount(int count) { m_sector_count = count; };
|
||||
virtual int sectorCount() const { return m_sector_count; };
|
||||
|
||||
/// Called by rawData() and data() to lazily load data. Call manually to preload.
|
||||
void initDataFromImage();
|
||||
|
||||
protected:
|
||||
GenericFile(Dos33DiskImage *image, QList<TSPair> pairs);
|
||||
|
||||
GenericFile(QByteArray data = QByteArray());
|
||||
virtual void setLength(quint16 length) { m_length = length; }
|
||||
virtual void setData(QByteArray data);
|
||||
SectorData *peekFirstSector() const;
|
||||
|
||||
private:
|
||||
int m_ignore_offset;
|
||||
QByteArray m_data;
|
||||
QString m_filename;
|
||||
quint16 m_address;
|
||||
qint16 m_length;
|
||||
Dos33DiskImage * m_diskfile;
|
||||
bool m_data_loaded;
|
||||
TSPairList m_ts_pairs;
|
||||
FileDescriptiveEntry m_fde;
|
||||
|
||||
int m_length;
|
||||
quint16 m_address;
|
||||
QString m_file_type;
|
||||
int m_sector_count;
|
||||
bool m_locked;
|
||||
|
||||
QString m_filename;
|
||||
ChunkByteList m_data;
|
||||
|
||||
bool m_data_loaded;
|
||||
|
||||
QByteArray m_data_cache;
|
||||
QByteArray m_local_data;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // GENERICFILE_H
|
||||
|
|
|
@ -98,6 +98,8 @@ QList<TSPair> VTOC::sectorsNotInUse() const
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VTOC::dump()
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
class Sector;
|
||||
class QString;
|
||||
|
||||
|
||||
class VTOC
|
||||
{
|
||||
public:
|
||||
|
@ -30,6 +29,7 @@ public:
|
|||
QList<TSPair> sectorsInUse() const;
|
||||
QList<TSPair> sectorsNotInUse() const;
|
||||
|
||||
|
||||
private:
|
||||
QString buildUseString(quint8 track);
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "IntBasicFile.h"
|
||||
#include <QDebug>
|
||||
|
||||
IntBasicFile::IntBasicFile(QByteArray data)
|
||||
#include "util.h"
|
||||
|
||||
IntBasicFile::IntBasicFile(Dos33DiskImage *image, FileDescriptiveEntry &fde)
|
||||
: GenericFile(image,fde)
|
||||
{
|
||||
setData(data);
|
||||
|
||||
qDebug()<<detokenize();
|
||||
|
||||
setData(detokenize());
|
||||
/// Detokenize rawData() to Integer Basic
|
||||
this->setData(detokenize());
|
||||
}
|
||||
|
||||
QByteArray IntBasicFile::detokenize()
|
||||
|
@ -16,13 +16,9 @@ QByteArray IntBasicFile::detokenize()
|
|||
// uint = unsigned int
|
||||
// quint8 = unsigned char
|
||||
// ==========================================================================
|
||||
return dumpBufferAsIntBasicFile(data());
|
||||
return dumpBufferAsIntBasicFile(rawData().asQByteArray());
|
||||
}
|
||||
|
||||
quint16 IntBasicFile::get16(quint8 v1, quint8 v2)
|
||||
{
|
||||
return (quint16) v1 + ((quint16) v2 * 256);
|
||||
}
|
||||
|
||||
QByteArray IntBasicFile::dumpBufferAsIntBasicFile(QByteArray origdata)
|
||||
/*
|
||||
|
@ -161,7 +157,7 @@ QByteArray IntBasicFile::dumpBufferAsIntBasicFile(QByteArray origdata)
|
|||
int lastTOK = 0;
|
||||
|
||||
unsigned int lineno;
|
||||
lineno = get16(data[position],data[position+1]);
|
||||
lineno = makeWord(data[position],data[position+1]);
|
||||
position += 2;
|
||||
//fprintf( fptr, "%u ", lineno );
|
||||
retval.append(QString::asprintf("%u ", lineno ).toLocal8Bit());
|
||||
|
@ -174,7 +170,7 @@ QByteArray IntBasicFile::dumpBufferAsIntBasicFile(QByteArray origdata)
|
|||
if ( !inREM && !inQUOTE && !lastAN &&
|
||||
(data[position]>=0xb0 && data[position]<=0xb9) )
|
||||
{
|
||||
qint16 integerval = get16(data[position+1],data[position+2]);
|
||||
qint16 integerval = makeWord(data[position+1],data[position+2]);
|
||||
int leadspace = lastTOK && leadSP;
|
||||
retval.append(QString::asprintf(leadspace ? " %d" : "%d", (int) integerval ));
|
||||
position += 2;
|
||||
|
@ -212,7 +208,8 @@ QByteArray IntBasicFile::dumpBufferAsIntBasicFile(QByteArray origdata)
|
|||
case QUOTE_END: inQUOTE = false; break;
|
||||
default: break;
|
||||
}
|
||||
retval.append(QString::asprintf(leadspace ? " %s" : "%s", tok ));
|
||||
|
||||
retval += QString::asprintf(leadspace ? " %s" : "%s", tok ).toUtf8();
|
||||
lastAN = 0;
|
||||
leadSP = isalnum(lastchar) || lastchar == ')' || lastchar == '\"';
|
||||
lastTOK = 1;
|
||||
|
|
|
@ -12,8 +12,7 @@ public:
|
|||
QByteArray detokenize();
|
||||
|
||||
private:
|
||||
IntBasicFile(QByteArray data = QByteArray());
|
||||
quint16 get16(quint8 v1, quint8 v2);
|
||||
IntBasicFile(Dos33DiskImage *image, FileDescriptiveEntry &fde);
|
||||
QByteArray dumpBufferAsIntBasicFile(QByteArray origdata);
|
||||
};
|
||||
|
||||
|
|
|
@ -2,26 +2,27 @@
|
|||
#include "relocatablefile.h"
|
||||
#include "util.h"
|
||||
|
||||
RelocatableFile::RelocatableFile(QByteArray data) : GenericFile(data)
|
||||
RelocatableFile::RelocatableFile(Dos33DiskImage *image, FileDescriptiveEntry &fde)
|
||||
: GenericFile(image,fde)
|
||||
{
|
||||
// qDebug() << "Relocatable file ctor";
|
||||
if (!data.isEmpty()) {
|
||||
setData(data);
|
||||
}
|
||||
setupData();
|
||||
}
|
||||
|
||||
void RelocatableFile::setData(QByteArray /*data*/)
|
||||
void RelocatableFile::setupData()
|
||||
{
|
||||
|
||||
// qDebug() << "setData()";
|
||||
if (length() >= 6) {
|
||||
m_starting_ram_address = dataWordAt(0);
|
||||
m_ram_image_length = dataWordAt(2);
|
||||
m_code_image_length = dataWordAt(4);
|
||||
quint16 starting_ram_address = rawDataWordAt(0);
|
||||
setAddress(starting_ram_address);
|
||||
m_ram_image_length = rawDataWordAt(2);
|
||||
setLength(m_ram_image_length);
|
||||
m_code_image_length = rawDataWordAt(4);
|
||||
|
||||
int offset = 0;
|
||||
|
||||
for (int idx = 6; idx < m_code_image_length+6; idx++) {
|
||||
quint8 val = dataAt(idx);
|
||||
quint8 val = rawDataAt(idx);
|
||||
m_binary_code_image.append(val);
|
||||
}
|
||||
|
||||
|
@ -34,8 +35,8 @@ void RelocatableFile::setData(QByteArray /*data*/)
|
|||
// << uint8ToHex(m_data[offset+3]);
|
||||
|
||||
RelocatableDictItem rdi = RelocatableDictItem(
|
||||
dataAt(offset),dataAt(offset+1),
|
||||
dataAt(offset+2),dataAt(offset+3));
|
||||
rawDataAt(offset),rawDataAt(offset+1),
|
||||
rawDataAt(offset+2),rawDataAt(offset+3));
|
||||
m_relocatable_dict.append(rdi);
|
||||
if (rdi.isEndOfRLD()) { break; }
|
||||
}
|
||||
|
@ -45,7 +46,7 @@ void RelocatableFile::setData(QByteArray /*data*/)
|
|||
void RelocatableFile::dump()
|
||||
{
|
||||
qDebug() << "\nTotalLength: " << length();
|
||||
qDebug() << "Starting Ram Address: " << (quint16) m_starting_ram_address << uint16ToHex(m_starting_ram_address);
|
||||
qDebug() << "Starting Ram Address: " << (quint16) address() << uint16ToHex(address());
|
||||
qDebug() << "Length of Ram Image: " << (quint16) m_ram_image_length << uint16ToHex(m_ram_image_length);
|
||||
qDebug() << "Length of Code Image: " << (quint16) m_code_image_length << uint16ToHex(m_code_image_length);
|
||||
|
||||
|
|
|
@ -87,16 +87,14 @@ public:
|
|||
QByteArray getBinaryCodeImage() { return m_binary_code_image; }
|
||||
QList<RelocatableDictItem> getRelocatableDict() { return m_relocatable_dict; }
|
||||
|
||||
quint16 address() { return m_starting_ram_address; }
|
||||
quint16 codeImageLength() { return m_code_image_length; }
|
||||
|
||||
QStringList decodeRelocatableDict();
|
||||
|
||||
protected:
|
||||
RelocatableFile(QByteArray data = QByteArray());
|
||||
void setData(QByteArray data);
|
||||
RelocatableFile(Dos33DiskImage *image, FileDescriptiveEntry &fde);
|
||||
void setupData();
|
||||
|
||||
quint16 m_starting_ram_address;
|
||||
quint16 m_ram_image_length;
|
||||
quint16 m_code_image_length;
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include <QDebug>
|
||||
#include "textfile.h"
|
||||
|
||||
TextFile::TextFile(QByteArray data) : GenericFile(data)
|
||||
TextFile::TextFile(Dos33DiskImage *image, FileDescriptiveEntry &fde)
|
||||
: GenericFile(image,fde)
|
||||
{
|
||||
if (!data.isEmpty()) {
|
||||
setData(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public:
|
|||
void dump();
|
||||
|
||||
protected:
|
||||
TextFile(QByteArray data = QByteArray());
|
||||
TextFile(Dos33DiskImage *image, FileDescriptiveEntry &fde);
|
||||
};
|
||||
|
||||
#endif // TEXTFILE_H
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "chunkbytelist.h"
|
||||
|
||||
ChunkByteList::ChunkByteList() { }
|
||||
ChunkByteList::ChunkByteList()
|
||||
{
|
||||
m_preamble_size = 0;
|
||||
}
|
||||
|
||||
ChunkByteList &ChunkByteList::appendChunk(QByteArray *chunk)
|
||||
{
|
||||
|
@ -30,7 +33,7 @@ int ChunkByteList::count() const
|
|||
{
|
||||
size += chunk->size();
|
||||
}
|
||||
return size;
|
||||
return size - preambleLength();
|
||||
}
|
||||
|
||||
int ChunkByteList::size() const
|
||||
|
@ -56,20 +59,7 @@ bool ChunkByteList::isEmpty() const
|
|||
|
||||
char ChunkByteList::at(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;
|
||||
return preambleData(i + preambleLength());
|
||||
}
|
||||
|
||||
char ChunkByteList::operator[](int i) const
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QByteArray>
|
||||
#include <QList>
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
class ChunkByteList
|
||||
{
|
||||
public:
|
||||
|
@ -12,10 +14,33 @@ public:
|
|||
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;
|
||||
|
@ -24,7 +49,7 @@ public:
|
|||
int numChunks() const { return m_chunk_list.size(); }
|
||||
QByteArray *getChunk(int chunk) const { return m_chunk_list[chunk]; }
|
||||
|
||||
QByteArray asQByteArray() const {
|
||||
QByteArray asQByteArray() const {
|
||||
QByteArray retval;
|
||||
foreach (auto chunk, m_chunk_list)
|
||||
{
|
||||
|
@ -33,10 +58,11 @@ public:
|
|||
return retval;
|
||||
}
|
||||
|
||||
operator QByteArray() { return asQByteArray(); }
|
||||
explicit operator QByteArray() { return asQByteArray(); }
|
||||
|
||||
private:
|
||||
QList<QByteArray *> m_chunk_list;
|
||||
int m_preamble_size;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue