From e1efec04b0d04e30e7bcdb7ff0d8c9eef966adeb Mon Sep 17 00:00:00 2001 From: Mark Long Date: Tue, 5 Jul 2016 08:35:38 -0500 Subject: [PATCH] Continuing work. Added text view to hex viewer. --- AppleSAWS.pro | 6 ++- images/missing_ring_good.dsk | Bin 143360 -> 143360 bytes src/applesoftfile/applesoftfile.cxx | 6 +-- src/applesoftfile/applesoftfile.h | 1 + src/binaryfile/binaryfilemetadata.cpp | 43 +++++++++++++++ src/binaryfile/binaryfilemetadata.h | 52 ++++++++++++++++++ src/ui/mainwindow.cxx | 2 +- src/ui/viewers/applesoftfileviewer.cxx | 52 ++++++++++++++++++ src/ui/viewers/applesoftfileviewer.h | 4 +- src/ui/viewers/applesoftfileviewer.ui | 29 ++++++++++ src/ui/viewers/hexdumpviewer.cpp | 70 +++++++++---------------- src/ui/viewers/hexdumpviewer.h | 3 +- src/ui/viewers/hexdumpviewer.ui | 66 ++--------------------- src/ui/viewers/mazeviewer.cpp | 25 +++++++-- 14 files changed, 238 insertions(+), 121 deletions(-) create mode 100644 src/binaryfile/binaryfilemetadata.cpp create mode 100644 src/binaryfile/binaryfilemetadata.h diff --git a/AppleSAWS.pro b/AppleSAWS.pro index 014a08a..b431c52 100644 --- a/AppleSAWS.pro +++ b/AppleSAWS.pro @@ -48,7 +48,8 @@ SOURCES += \ src/ui/viewers/hexdumpviewer.cpp \ src/ui/viewers/texthexdumpviewer.cpp \ src/relocatablefile/relocatablefile.cxx \ - src/ui/viewers/mazeviewer.cpp + src/ui/viewers/mazeviewer.cpp \ + src/binaryfile/binaryfilemetadata.cpp HEADERS += \ src/diskfiles/dos33/diskfile.h \ @@ -76,7 +77,8 @@ HEADERS += \ src/ui/viewers/hexdumpviewer.h \ src/ui/viewers/texthexdumpviewer.h \ src/relocatablefile/relocatablefile.h \ - src/ui/viewers/mazeviewer.h + src/ui/viewers/mazeviewer.h \ + src/binaryfile/binaryfilemetadata.h FORMS += \ src/ui/catalogwidget.ui \ diff --git a/images/missing_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rO`ov zW&dLxd!wvhAv4aLIQX$mJj9vP-eQRsb6Tte{0Ezu^EkWl-*hDVIP z#$y4r2s&>VuV1}=cb~W!+yrzY(Dgvq8^Xi1TbuoW69z)<`)8ax=jY#G!IQ2qs7D|X zU#w7ZR{Wz;?oWUFfYw#ByR@8bu{~`jbno3dMMAMar5RXQLSZ6WVS{Cx)E#LE?n<{z zG0h~SyOLQ_B;7D6BKOa7VUx$&)uoCVa*CVM;^oPE@b$;wH}$^?S*WeTtt+W9xWmXj zp&mN30Ai>B>sn4_5MIKDzRs02pIs!|L*Fjo)hBRxca(TFGeNeA0k~Ys(m+CYxkRK? zQQn34zhL01c|xigq9V`WJss-4rZN@cfu$~??L=acsU*$RzqE#l(=2M6Q9IMGMvFlf k0OzLJq$U_qJEGg_K;l2$vOGC`oaUVKwm)_H(UaQFUtyKJ%m4rY diff --git a/src/applesoftfile/applesoftfile.cxx b/src/applesoftfile/applesoftfile.cxx index 1f42152..5c1a570 100644 --- a/src/applesoftfile/applesoftfile.cxx +++ b/src/applesoftfile/applesoftfile.cxx @@ -61,9 +61,6 @@ void ApplesoftFile::parse(quint16 start_address) if (idx < m_data.length()) { qDebug() << QString("%1 byte(s) unaccounted for.").arg(m_data.length() - idx); } -// if (idx < m_length) { -// qDebug() << QString("%1 byte(s) unaccounted for.").arg(m_length - idx); -// } } QStringList ApplesoftFile::extraDataHexValues() { @@ -95,6 +92,7 @@ QByteArray ApplesoftFile::extraData() void Retokenizer::retokenize(ApplesoftLine &line) { + Q_UNUSED(line); // QList string_list; // QList number_list; @@ -172,5 +170,7 @@ void Retokenizer::retokenize(ApplesoftLine &line) QByteArray Retokenizer::retokenizePart(QByteArray part) { QByteArray retval; + Q_UNUSED(part); + return retval; } diff --git a/src/applesoftfile/applesoftfile.h b/src/applesoftfile/applesoftfile.h index ea0cb30..723bec1 100644 --- a/src/applesoftfile/applesoftfile.h +++ b/src/applesoftfile/applesoftfile.h @@ -24,6 +24,7 @@ public: quint16 length() const { return m_length; } QByteArray rawData(); + private: void parse(quint16 start_address = 0x0801); diff --git a/src/binaryfile/binaryfilemetadata.cpp b/src/binaryfile/binaryfilemetadata.cpp new file mode 100644 index 0000000..2e941b1 --- /dev/null +++ b/src/binaryfile/binaryfilemetadata.cpp @@ -0,0 +1,43 @@ +#include "binaryfilemetadata.h" + +BinaryFileMetadata::BinaryFileMetadata() +{ + +} + +void BinaryFileMetadata::addEntryPoint(quint16 address) +{ + if (!containsEntryPoint(address)) + { + m_entryPoints.append(address); + qSort(m_entryPoints); + } +} + +void BinaryFileMetadata::addDataRange(AddressRange range) +{ + m_dataRanges.append(range); +} + +bool BinaryFileMetadata::load() +{ + return false; +} + +bool BinaryFileMetadata::save() +{ + return false; +} + +bool BinaryFileMetadata::containsEntryPoint(quint16 address) +{ + return m_entryPoints.contains(address); +} + +void BinaryFileMetadata::removeEntryPoint(quint16 address) +{ + if (containsEntryPoint(address)) + { + m_entryPoints.removeAll(address); + } +} diff --git a/src/binaryfile/binaryfilemetadata.h b/src/binaryfile/binaryfilemetadata.h new file mode 100644 index 0000000..d651724 --- /dev/null +++ b/src/binaryfile/binaryfilemetadata.h @@ -0,0 +1,52 @@ +#ifndef BINARYFILEMETADATA_H +#define BINARYFILEMETADATA_H + +#include +#include + + +struct AddressRange +{ +public: + quint16 start; + quint16 end; + + quint16 length() { return end-start; } + + bool contains(quint16 address) { return (address >= start && address <= end); } + +}; + +class BinaryFileMetadata +{ +public: + enum UseType { + UNKNOWN = 0x00, + ROM = 0x01, + IO = 0x02, + BASIC = 0x04, + OPCODE = 0x08, + DATA = 0x10 + }; + + BinaryFileMetadata(); + + void addEntryPoint(quint16 address); + void addDataRange(AddressRange range); + + bool load(); + bool save(); + + bool containsEntryPoint(quint16 address); + void removeEntryPoint(quint16 address); + + QList getEntryPoints() { return m_entryPoints; } + QList getDataRanges() { return m_dataRanges; } + +private: + QList m_entryPoints; + QList m_dataRanges; + +}; + +#endif // BINARYFILEMETADATA_H diff --git a/src/ui/mainwindow.cxx b/src/ui/mainwindow.cxx index 70ef328..5b2b0a4 100644 --- a/src/ui/mainwindow.cxx +++ b/src/ui/mainwindow.cxx @@ -108,7 +108,7 @@ void MainWindow::openInDisassemblerViewer(BinaryFile *file) { void MainWindow::openInMazeViewer(BinaryFile *file) { MazeViewer *hvwma = new MazeViewer(0); - int cellw = 70; + int cellw = 90; hvwma->resize(cellw*8,cellw*10); hvwma->show(); hvwma->setFile(file); diff --git a/src/ui/viewers/applesoftfileviewer.cxx b/src/ui/viewers/applesoftfileviewer.cxx index 38af881..9bd717a 100644 --- a/src/ui/viewers/applesoftfileviewer.cxx +++ b/src/ui/viewers/applesoftfileviewer.cxx @@ -1,6 +1,7 @@ #include "applesoftfileviewer.h" #include "ui_applesoftfileviewer.h" #include "applesoftformatter.h" +#include ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) : QWidget(parent), @@ -12,6 +13,12 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) : m_formatter = new ApplesoftFormatter(this); m_formatter->setFlags(ApplesoftFormatter::PrettyFlags); + + connect(ui->findButton,SIGNAL(clicked(bool)), SLOT(findText())); + m_isFirstFind = true; + ui->textArea->setUndoRedoEnabled(false); + ui->textArea->setUndoRedoEnabled(true); + } ApplesoftFileViewer::~ApplesoftFileViewer() @@ -38,3 +45,48 @@ void ApplesoftFileViewer::setText(QString text) { ui->textArea->setHtml(text); } + +void ApplesoftFileViewer::findText() +{ + QString searchString = ui->findText->text(); + QTextDocument *document = ui->textArea->document(); + + if (m_isFirstFind == false) + { + document->undo(); + } + + if (searchString.isEmpty()) { + ui->findResults->setText(""); + return; + } + + QTextCursor highlightCursor(document); + QTextCursor cursor(document); + + cursor.beginEditBlock(); + + QTextCharFormat plainFormat(highlightCursor.charFormat()); + QTextCharFormat colorFormat = plainFormat; + colorFormat.setBackground(Qt::yellow); + int count = 0; + while(!highlightCursor.isNull() && !highlightCursor.atEnd()) { + highlightCursor = document->find(searchString, highlightCursor); + + if (!highlightCursor.isNull()) { + count++; + int position = highlightCursor.position(); + highlightCursor.setPosition(position,QTextCursor::KeepAnchor); + //highlightCursor.movePosition(QTextCursor::WordRight,QTextCursor::KeepAnchor); + highlightCursor.mergeCharFormat(colorFormat); + } + } + QString results = QString("%1 match%2").arg(count).arg(count != 1?"es":""); + ui->findResults->setText(results); + cursor.endEditBlock(); + ui->textArea->ensureCursorVisible(); + + m_isFirstFind = false; + + +} diff --git a/src/ui/viewers/applesoftfileviewer.h b/src/ui/viewers/applesoftfileviewer.h index 0460955..4b0d925 100644 --- a/src/ui/viewers/applesoftfileviewer.h +++ b/src/ui/viewers/applesoftfileviewer.h @@ -23,11 +23,13 @@ public slots: void setFile(ApplesoftFile *m_file); void setData(QByteArray data); void setText(QString text); + void findText(); + private: ApplesoftFile *m_file; ApplesoftFormatter *m_formatter; - + bool m_isFirstFind; Ui::ApplesoftFileViewer *ui; }; diff --git a/src/ui/viewers/applesoftfileviewer.ui b/src/ui/viewers/applesoftfileviewer.ui index 1976fc6..3c310c8 100644 --- a/src/ui/viewers/applesoftfileviewer.ui +++ b/src/ui/viewers/applesoftfileviewer.ui @@ -21,6 +21,35 @@ + + + + + + + false + + + + + + + Find + + + + + + + + + + + + + + + diff --git a/src/ui/viewers/hexdumpviewer.cpp b/src/ui/viewers/hexdumpviewer.cpp index 73f8f56..87b8b2c 100644 --- a/src/ui/viewers/hexdumpviewer.cpp +++ b/src/ui/viewers/hexdumpviewer.cpp @@ -1,6 +1,7 @@ #include "hexdumpviewer.h" #include "ui_hexdumpviewer.h" +#include #include HexDumpViewer::HexDumpViewer(QWidget *parent) : @@ -10,14 +11,6 @@ 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); } @@ -27,7 +20,7 @@ HexDumpViewer::~HexDumpViewer() delete ui; } -void HexDumpViewer::showHexValues() +void HexDumpViewer::showHexAndAsciiValues() { int offset = ui->textArea->verticalScrollBar()->value(); @@ -37,16 +30,30 @@ void HexDumpViewer::showHexValues() 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')); + QString line = QString("(%1) %2: ") + .arg(m_offset+(idx*16),4,10,QChar('0')) + .arg(m_offset+(idx*16),4,16,QChar('0')); + QString asciiline; + for (int jdx = (idx*16); jdx < (idx*16)+16; jdx++) { addr++; if (jdx < m_data.count()) { + asciiline += valToAppleAscii(m_data[jdx]); + line += QString(" %1").arg((quint8) m_data[jdx],2,16,QChar('0')); - if ((addr % 16) == 0) { line += " "; } } } - if (line.length() > 6) { - lines.append(line); + + if (line.length() > 14) { + int diff = (62 - line.length()); + if (diff < 0) { diff = 0; } + if (diff>0) { + for (int pdx = 0; pdx < diff; pdx++) + { + line.append(" "); + } + } + lines.append(line + "  " + asciiline); } } setText(qPrintable(lines.join("
").toUpper())); @@ -79,43 +86,14 @@ QString HexDumpViewer::valToAppleAscii(quint8 val) 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);} + 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()); @@ -125,7 +103,7 @@ void HexDumpViewer::setFile(GenericFile *file, quint16 offset) m_data = file->data(); - showHexValues(); + showHexAndAsciiValues(); } diff --git a/src/ui/viewers/hexdumpviewer.h b/src/ui/viewers/hexdumpviewer.h index b3f4fdc..1217fd7 100644 --- a/src/ui/viewers/hexdumpviewer.h +++ b/src/ui/viewers/hexdumpviewer.h @@ -23,8 +23,7 @@ public: void setFile(GenericFile *file, quint16 offset = 0); public slots: - void showHexValues(); - void showAsciiValues(); + void showHexAndAsciiValues(); private: void setText(QString text); diff --git a/src/ui/viewers/hexdumpviewer.ui b/src/ui/viewers/hexdumpviewer.ui index 0aff58d..57659a1 100644 --- a/src/ui/viewers/hexdumpviewer.ui +++ b/src/ui/viewers/hexdumpviewer.ui @@ -15,75 +15,15 @@
- 1 + 8 - 1 + 8 1 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - - - Hex - - - true - - - - - - - Text - - - true - - - - - - - - - - Qt::Horizontal - - - - 728 - 20 - - - - - + diff --git a/src/ui/viewers/mazeviewer.cpp b/src/ui/viewers/mazeviewer.cpp index 2796fb8..948fe19 100644 --- a/src/ui/viewers/mazeviewer.cpp +++ b/src/ui/viewers/mazeviewer.cpp @@ -1,6 +1,7 @@ #include "mazeviewer.h" #include #include +#include #include "memory.h" @@ -64,6 +65,7 @@ void MazeViewer::drawMaze() { for (int jdx = 0; jdx < 10; jdx++) { + int currentRoom = (jdx*8) + idx; double cellTop = jdx * cellHeight + 1; double cellBot = (jdx+1) * cellHeight - 1; @@ -206,10 +208,27 @@ void MazeViewer::drawMaze() // .arg(tr,2,16,QChar('0')) // .arg(mo,2,16,QChar('0')); - QString str = QString("%1\n%2\n%3") + int playerCount = mem.at(0x80fd); + + QString pl; + for (int rdx = 0; rdx < playerCount; rdx++) + { + quint8 roomPlayerIsIn = mem.at(0x8008 + (32*rdx)); + + if (roomPlayerIsIn == currentRoom) { + if (rdx == 0) { pl += QString("\u2460"); } + if (rdx == 1) { pl += QString("\u2461"); } + if (rdx == 2) { pl += QString("\u2462"); } + if (rdx == 3) { pl += QString("\u2463"); } + if (rdx == 4) { pl += QString("\u2464"); } + } + } + + QString str = QString("%1\n%2\n%3\n%4") .arg(idx+(jdx*8)) .arg(mos) - .arg(trs); + .arg(trs) + .arg(pl); painter.drawText(QRect(cellLeft+2,cellTop+2,cellWidth-2,cellHeight-2),str); } @@ -367,7 +386,7 @@ QString MazeViewer::monsterToString(quint8 mc) name = "Hmncls"; break; case 0x0e: - name = "UNKN"; + name = "(INVAL)"; break; case 0x0f: name = "EvlMage";