From d652dad5c82f74c7e84b386d7096c9ffbf483c47 Mon Sep 17 00:00:00 2001 From: Mark Long Date: Fri, 4 Dec 2015 21:47:13 -0600 Subject: [PATCH] Various changes. --- src/binaryfile.h | 1 - src/diskfile.cxx | 40 ++++++++++++++++++++++--- src/diskfile.h | 6 ++-- src/filedescriptiveentry.h | 4 +++ src/genericfile.h | 2 ++ src/main.cpp | 4 +-- src/mainwindow.cxx | 61 ++++++++++++++++++++++++++++++++------ src/mainwindow.h | 2 +- 8 files changed, 101 insertions(+), 19 deletions(-) diff --git a/src/binaryfile.h b/src/binaryfile.h index bfc368e..2f674c1 100644 --- a/src/binaryfile.h +++ b/src/binaryfile.h @@ -12,7 +12,6 @@ public: quint16 address() { return m_address; } quint16 length() { return m_length; } - QByteArray data() { return m_data; } void dump(); protected: diff --git a/src/diskfile.cxx b/src/diskfile.cxx index 6267a61..bcc5fc6 100644 --- a/src/diskfile.cxx +++ b/src/diskfile.cxx @@ -5,6 +5,8 @@ #include #include "tracksectorlist.h" +#include "applesoftfile.h" +#include "binaryfile.h" DiskFile::DiskFile(QString filename) { @@ -14,6 +16,14 @@ DiskFile::DiskFile(QString filename) } } +DiskFile::~DiskFile() +{ + foreach (GenericFile *file, m_files) + { + delete file; + } +} + bool DiskFile::read(QString filename) { QFile infile(filename); @@ -68,11 +78,33 @@ QList DiskFile::getCatalogSectors() return retval; } -QByteArray DiskFile::getFile(FileDescriptiveEntry fde) +GenericFile *DiskFile::getFile(FileDescriptiveEntry fde) { - QByteArray retval; - TrackSectorList tsl = getSector(fde.firstTSListSector).promoteToTrackSectorList(); - return getDataFromTrackSectorList(tsl); + GenericFile *retval = 0; + if (m_files.contains(fde)) + { + retval = m_files[fde]; + } + else + { + TrackSectorList tsl = getSector(fde.firstTSListSector).promoteToTrackSectorList(); + QByteArray data = getDataFromTrackSectorList(tsl); + + if (fde.fileTypeAndFlags & ApplesoftBasicFile) + { + retval = new ApplesoftFile(data); + } + else if (fde.fileTypeAndFlags & RawBinaryFile) + { + retval = new BinaryFile(data); + } + else + { + retval = new GenericFile(data); + } + m_files[fde] = retval; + } + return retval; } diff --git a/src/diskfile.h b/src/diskfile.h index 54198f5..ec72daa 100644 --- a/src/diskfile.h +++ b/src/diskfile.h @@ -10,12 +10,13 @@ #include "sector.h" #include "vtoc.h" - +#include "genericfile.h" class DiskFile { public: DiskFile(QString filename = ""); + ~DiskFile(); bool read(QString filename); @@ -29,7 +30,7 @@ public: QList getCatalogSectors(); - QByteArray getFile(FileDescriptiveEntry fde); + GenericFile *getFile(FileDescriptiveEntry fde); QByteArray getDataFromTrackSectorList(TrackSectorList tsl); @@ -39,6 +40,7 @@ public: private: QMap< int, QMap< int, Sector> > m_contents; + QMap m_files; }; diff --git a/src/filedescriptiveentry.h b/src/filedescriptiveentry.h index 6179622..fdaa090 100644 --- a/src/filedescriptiveentry.h +++ b/src/filedescriptiveentry.h @@ -11,6 +11,10 @@ struct FileDescriptiveEntry { AppleString filename; quint16 lengthInSectors; + bool operator<(const FileDescriptiveEntry& f1) const { + return f1.filename < filename; + } + QString fileType() { if (fileTypeAndFlags & IntegerBasicFile) { return "I"; } if (fileTypeAndFlags & ApplesoftBasicFile) { return "A"; } diff --git a/src/genericfile.h b/src/genericfile.h index f505184..c703253 100644 --- a/src/genericfile.h +++ b/src/genericfile.h @@ -7,7 +7,9 @@ class GenericFile { public: GenericFile(QByteArray data = QByteArray()); + virtual ~GenericFile() { } virtual void setData(QByteArray data); + virtual QByteArray data() { return m_data; } protected: QByteArray m_data; diff --git a/src/main.cpp b/src/main.cpp index d069050..59cd445 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,8 +39,8 @@ int main(int argc, char** argv) QApplication a(argc, argv); MainWindow w; -// w.loadDiskFile("/home/mlong/Desktop/missing_ring_good.dsk"); - w.loadDiskFile("/home/mlong/Desktop/dos.3.3.system.master.dsk"); + w.loadDiskFile("/home/mlong/Desktop/missing_ring_good.dsk"); +// w.loadDiskFile("/home/mlong/Desktop/dos.3.3.system.master.dsk"); w.show(); return a.exec(); diff --git a/src/mainwindow.cxx b/src/mainwindow.cxx index a1ce9d9..fff6040 100644 --- a/src/mainwindow.cxx +++ b/src/mainwindow.cxx @@ -3,7 +3,11 @@ #include #include "hiresviewwidget.h" +#include "applesoftfileviewer.h" #include +#include "binaryfile.h" +#include "applesoftfile.h" +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -18,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->action_Load_Disk_Image, SIGNAL(triggered()), SLOT(showLoadDialog())); connect(ui->action_Unload_Disk_Image, SIGNAL(triggered()), SLOT(unloadDiskFile())); connect(ui->catalogWidget,SIGNAL(itemSelected(DiskFile*,FileDescriptiveEntry)), - SLOT(handleDiskItemSelected(DiskFile*,FileDescriptiveEntry))); + SLOT(handleDiskItemSelectedDefaultOpen(DiskFile*,FileDescriptiveEntry))); connect(this, SIGNAL(diskFileLoading(QString, DiskFile*)), @@ -73,15 +77,54 @@ void MainWindow::showLoadDialog() } } -void MainWindow::handleDiskItemSelected(DiskFile *disk, FileDescriptiveEntry fde) +void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescriptiveEntry fde) { - HiresViewWidget *hvwma = new HiresViewWidget(0); - hvwma->resize(280,192); - QString title = QString("Image: %1").arg(AppleString(fde.filename).printable().trimmed()); - hvwma->setWindowTitle(title); - hvwma->show(); + GenericFile *file = disk->getFile(fde); + + if (dynamic_cast(file)) { + if (fde.lengthInSectors == 34) + { + HiresViewWidget *hvwma = new HiresViewWidget(0); + hvwma->resize(280,192); + QString title = QString("Image: %1").arg(AppleString(fde.filename).printable().trimmed()); + hvwma->setWindowTitle(title); + hvwma->show(); + hvwma->setData(file->data()); + } + } + else if (dynamic_cast(file)) + { + ApplesoftFile *abf = dynamic_cast(file); + ApplesoftFileViewer *afv = new ApplesoftFileViewer(0); + QString title = QString("AppleSoft Viewer: %1").arg(AppleString(fde.filename).printable().trimmed()); + afv->setWindowTitle(title); + QStringList strings; + foreach (ApplesoftLine line, abf->detokenized()) + { + QString linestring = QString("%1 %2").arg(line.linenum,5,10,QChar(' ')).arg(line.detokenized_line); + strings.append(linestring); + } + QString fulltext = Qt::convertFromPlainText(strings.join("\n")); + fulltext.replace("POKE","POKE"); + fulltext.replace("PEEK","PEEK"); + fulltext.replace("CALL","CALL"); + fulltext.replace("GOTO","GOTO"); + fulltext.replace("GOSUB","GOSUB"); +// fulltext.replace("0","0"); +// fulltext.replace("1","1"); +// fulltext.replace("2","2"); +// fulltext.replace("3","3"); +// fulltext.replace("4","4"); +// fulltext.replace("5","5"); +// fulltext.replace("6","6"); +// fulltext.replace("7","7"); +// fulltext.replace("8","8"); +// fulltext.replace("9","9"); + fulltext.replace("RETURN","RETURN

"); + + afv->setText(fulltext); + afv->show(); + } - QByteArray data = disk->getFile(fde).mid(4); - hvwma->setData(data); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 7fbcd88..0c6429e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -24,7 +24,7 @@ public slots: void showLoadDialog(); private slots: - void handleDiskItemSelected(DiskFile *disk, FileDescriptiveEntry fde); + void handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescriptiveEntry fde); signals: void diskFileLoading(QString filename, DiskFile *file);