diff --git a/AppleSAWS.pro b/AppleSAWS.pro index 599881f..014a08a 100644 --- a/AppleSAWS.pro +++ b/AppleSAWS.pro @@ -47,7 +47,8 @@ SOURCES += \ src/ui/viewers/disassemblerviewer.cpp \ src/ui/viewers/hexdumpviewer.cpp \ src/ui/viewers/texthexdumpviewer.cpp \ - src/relocatablefile/relocatablefile.cxx + src/relocatablefile/relocatablefile.cxx \ + src/ui/viewers/mazeviewer.cpp HEADERS += \ src/diskfiles/dos33/diskfile.h \ @@ -74,7 +75,8 @@ HEADERS += \ src/ui/viewers/disassemblerviewer.h \ src/ui/viewers/hexdumpviewer.h \ src/ui/viewers/texthexdumpviewer.h \ - src/relocatablefile/relocatablefile.h + src/relocatablefile/relocatablefile.h \ + src/ui/viewers/mazeviewer.h FORMS += \ src/ui/catalogwidget.ui \ diff --git a/images/missing_ring_good.dsk b/images/missing_ring_good.dsk index 31faec2..2c15e22 100644 Binary files a/images/missing_ring_good.dsk and b/images/missing_ring_good.dsk differ diff --git a/src/internals/memory.h b/src/internals/memory.h index 0b0c207..cd1fa4c 100644 --- a/src/internals/memory.h +++ b/src/internals/memory.h @@ -11,6 +11,7 @@ public: QByteArray &values() { return m_memory; } + quint8 at(quint16 addr) { return m_memory.at(addr); } private: QByteArray m_memory; diff --git a/src/main.cpp b/src/main.cpp index 12a6144..adb0dc8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "mainwindow.h" #include "binaryfile.h" @@ -10,10 +12,16 @@ int main(int argc, char** argv) { QApplication a(argc, argv); + QCoreApplication::setOrganizationName("AppleSAWS"); + QCoreApplication::setOrganizationDomain("ml.com"); + QCoreApplication::setApplicationName("AppleSAWS"); MainWindow w; - w.loadDiskFile("~/AppleSAWS/images/missing_ring_good.dsk"); -// w.loadDiskFile("~/AppleSAWS/images/dos.3.3.system.master.dsk"); -// w.loadDiskFile("~/AppleSAWS/images//montezuma_etc.dsk"); + QSettings settings; + QString lastOpened = settings.value("lastOpened").toString(); + if (!lastOpened.isEmpty()) + { + w.loadDiskFile(lastOpened); + } w.show(); return a.exec(); diff --git a/src/ui/catalogwidget.cxx b/src/ui/catalogwidget.cxx index 0a6b89c..d39951f 100644 --- a/src/ui/catalogwidget.cxx +++ b/src/ui/catalogwidget.cxx @@ -38,6 +38,8 @@ void CatalogWidget::showContextMenuForWidget(const QPoint &point) { [=](){ this->toggleHexView(selectedItem); hexViewAction->deleteLater();}); contextMenu.addAction(hexViewAction); + + // QAction *viewWithAction = new QAction("View With...",this); // connect(viewWithAction, &QAction::triggered, // [=](){ this->itemClicked(selectedItem); viewWithAction->deleteLater();}); @@ -153,3 +155,4 @@ void CatalogWidget::toggleHexView(QListWidgetItem *item) } + diff --git a/src/ui/mainwindow.cxx b/src/ui/mainwindow.cxx index 3941dd4..70ef328 100644 --- a/src/ui/mainwindow.cxx +++ b/src/ui/mainwindow.cxx @@ -9,12 +9,15 @@ #include "disassembler.h" #include "disassemblerviewer.h" #include "hexdumpviewer.h" +#include "mazeviewer.h" #include "texthexdumpviewer.h" #include "relocatablefile.h" #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : @@ -58,6 +61,8 @@ void MainWindow::loadDiskFile(QString filename) emit diskFileLoading(filename,m_disk); if (m_disk->read(filename)) { ui->action_Unload_Disk_Image->setEnabled(true); + QSettings settings; + settings.setValue("lastOpened",filename); emit diskFileLoaded(filename,m_disk); } else { emit diskFileLoadFailed(filename,m_disk); @@ -101,6 +106,14 @@ void MainWindow::openInDisassemblerViewer(BinaryFile *file) { hvwma->setFile(file); } +void MainWindow::openInMazeViewer(BinaryFile *file) { + MazeViewer *hvwma = new MazeViewer(0); + int cellw = 70; + hvwma->resize(cellw*8,cellw*10); + hvwma->show(); + hvwma->setFile(file); +} + void MainWindow::openInApplesoftFileViewer(ApplesoftFile *file) { ApplesoftFileViewer *afv = new ApplesoftFileViewer(0); @@ -119,6 +132,7 @@ void MainWindow::handleDiskItemSelectedHexViewOpen(DiskFile *disk, FileDescripti } + void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescriptiveEntry fde) { GenericFile *file = disk->getFile(fde); @@ -133,10 +147,13 @@ void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescripti { openInHiresViewWidget(binfile, AppleString(fde.filename).printable().trimmed()); } + else if (file->filename().contains("maze",Qt::CaseInsensitive)) + { + openInMazeViewer(binfile); + } else { openInDisassemblerViewer(binfile); - } } else if (dynamic_cast(file)) diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index f5318a7..2908446 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -42,6 +42,7 @@ protected: void openInApplesoftFileViewer(ApplesoftFile *file); void openInHiresViewWidget(BinaryFile *file, QString filename); void openInDisassemblerViewer(BinaryFile *file); + void openInMazeViewer(BinaryFile *file); private: Ui::MainWindow *ui; diff --git a/src/ui/viewers/hexdumpviewer.cpp b/src/ui/viewers/hexdumpviewer.cpp index 9749a20..73f8f56 100644 --- a/src/ui/viewers/hexdumpviewer.cpp +++ b/src/ui/viewers/hexdumpviewer.cpp @@ -1,6 +1,8 @@ #include "hexdumpviewer.h" #include "ui_hexdumpviewer.h" +#include + HexDumpViewer::HexDumpViewer(QWidget *parent) : QWidget(parent), ui(new Ui::HexDumpViewer) @@ -8,6 +10,14 @@ HexDumpViewer::HexDumpViewer(QWidget *parent) : ui->setupUi(this); m_offset = 0; + QButtonGroup *bg = new QButtonGroup(this); + bg->addButton(ui->hexButton); + bg->addButton(ui->textButton); + ui->hexButton->setChecked(true); + + connect(ui->hexButton, SIGNAL(clicked(bool)), SLOT(showHexValues())); + connect(ui->textButton, SIGNAL(clicked(bool)), SLOT(showAsciiValues())); + QString title = QString("Hex Viewer"); setWindowTitle(title); } @@ -17,26 +27,21 @@ HexDumpViewer::~HexDumpViewer() delete ui; } -void HexDumpViewer::setFile(GenericFile *file, quint16 offset) +void HexDumpViewer::showHexValues() { - QString title = QString("Hex Viewer: %1").arg(file->filename()); - setWindowTitle(title); - - m_offset = offset; + int offset = ui->textArea->verticalScrollBar()->value(); QStringList lines; - QByteArray data = file->data(); - //TODO: Align text from x00 to xFF. Currently it will start with whatever the offset is. quint16 addr = m_offset; - for (int idx = 0; idx <= data.count()/16; idx++) { + for (int idx = 0; idx <= m_data.count()/16; idx++) { QString line = QString("%1: ").arg(m_offset+(idx*16),4,16,QChar('0')); for (int jdx = (idx*16); jdx < (idx*16)+16; jdx++) { addr++; - if (jdx < data.count()) { - line += QString(" %1").arg((quint8) data[jdx],2,16,QChar('0')); + if (jdx < m_data.count()) { + line += QString(" %1").arg((quint8) m_data[jdx],2,16,QChar('0')); if ((addr % 16) == 0) { line += " "; } } } @@ -44,12 +49,89 @@ void HexDumpViewer::setFile(GenericFile *file, quint16 offset) lines.append(line); } } - setData(qPrintable(lines.join("\n").toUpper())); + setText(qPrintable(lines.join("
").toUpper())); + ui->textArea->verticalScrollBar()->setValue(offset); +} + +QString HexDumpViewer::valToAppleAscii(quint8 val) +{ + + typedef enum { + Inverse, + Flash, + Normal, + AltUC + } Zone; + + Zone zone; + + QString charval; + if (val <= 0x1F) { val += 0x40; charval = QString("%1").arg(QChar(val)); zone = Inverse; } //INV UC + else if (val <= 0x3F) { val = val; charval = QString("%1").arg(QChar(val)); zone = Inverse; } // INV SP + else if (val <= 0x5F) { val = val; charval = QString("%1").arg(QChar(val)); zone = Flash; } // FL UC + else if (val <= 0x7F) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = Flash; } // FL SP + else if (val <= 0x9F) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = AltUC; } // NORMx UC + else if (val <= 0xBF) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM SP + else if (val <= 0xDF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM UC + else if (val < 0xFF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM LC + else if (val == 0xFF) { val = val; charval = QString("\u25a0"); zone = Normal; } + + QString htmlstr = charval.toHtmlEscaped(); + + QString retval; + if (zone == Inverse) { retval = QString("%1").arg(htmlstr); } + else if (zone == Flash) { retval = QString("%1").arg(htmlstr);} + else if (zone == AltUC) { retval = QString("%1").arg(htmlstr);} + else /* zone == Normal */ { retval = QString("%1").arg(htmlstr);} + + return retval; +} + +void HexDumpViewer::showAsciiValues() +{ + int offset = ui->textArea->verticalScrollBar()->value(); + QStringList lines; + + //TODO: Align text from x00 to xFF. Currently it will start with whatever the offset is. + + quint16 addr = m_offset; + for (int idx = 0; idx <= m_data.count()/16; idx++) { + QString line = QString("%1: ").arg(m_offset+(idx*16),4,16,QChar('0')); + + for (int jdx = (idx*16); jdx < (idx*16)+16; jdx++) { + addr++; + if (jdx < m_data.count()) { + + //line += QString(" %1").arg((quint8) m_data[jdx],2,16,QChar('0')); + line += valToAppleAscii(m_data[jdx]); + + // if ((addr % 16) == 0) { line += " "; } + } + } + if (line.length() > 6) { + lines.append(line); + } + } + setText(qPrintable(lines.join("
"))); + ui->textArea->verticalScrollBar()->setValue(offset); +} + +void HexDumpViewer::setFile(GenericFile *file, quint16 offset) +{ + QString title = QString("Hex Viewer: %1").arg(file->filename()); + setWindowTitle(title); + + m_offset = offset; + + m_data = file->data(); + + showHexValues(); + } void HexDumpViewer::setData(QByteArray data) { - ui->textArea->setText(data); + ui->textArea->setHtml(data); } void HexDumpViewer::setText(QString text) diff --git a/src/ui/viewers/hexdumpviewer.h b/src/ui/viewers/hexdumpviewer.h index 0fb3e39..b3f4fdc 100644 --- a/src/ui/viewers/hexdumpviewer.h +++ b/src/ui/viewers/hexdumpviewer.h @@ -21,13 +21,20 @@ public: ~HexDumpViewer(); void setFile(GenericFile *file, quint16 offset = 0); - void setData(QByteArray data); - void setText(QString text); + +public slots: + void showHexValues(); + void showAsciiValues(); private: + void setText(QString text); + void setData(QByteArray data); + QString valToAppleAscii(quint8 val); + Ui::HexDumpViewer *ui; quint16 m_offset; + QByteArray m_data; }; #endif // HEXDUMPVIEWER_H diff --git a/src/ui/viewers/hexdumpviewer.ui b/src/ui/viewers/hexdumpviewer.ui index c3c5df2..0aff58d 100644 --- a/src/ui/viewers/hexdumpviewer.ui +++ b/src/ui/viewers/hexdumpviewer.ui @@ -13,8 +13,77 @@ Form - + + + 1 + + + 1 + + + 1 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + + + Hex + + + true + + + + + + + Text + + + true + + + + + + + + + + Qt::Horizontal + + + + 728 + 20 + + + + +