mirror of
https://github.com/markdavidlong/AppleSAWS.git
synced 2024-12-21 07:29:23 +00:00
Continuing work. Added text view to hex viewer.
This commit is contained in:
parent
b5558818e2
commit
e1efec04b0
@ -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 \
|
||||
|
Binary file not shown.
@ -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 <QByteArray> string_list;
|
||||
// QList <QByteArray> number_list;
|
||||
|
||||
@ -172,5 +170,7 @@ void Retokenizer::retokenize(ApplesoftLine &line)
|
||||
QByteArray Retokenizer::retokenizePart(QByteArray part) {
|
||||
QByteArray retval;
|
||||
|
||||
Q_UNUSED(part);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
quint16 length() const { return m_length; }
|
||||
|
||||
QByteArray rawData();
|
||||
|
||||
private:
|
||||
void parse(quint16 start_address = 0x0801);
|
||||
|
||||
|
43
src/binaryfile/binaryfilemetadata.cpp
Normal file
43
src/binaryfile/binaryfilemetadata.cpp
Normal file
@ -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);
|
||||
}
|
||||
}
|
52
src/binaryfile/binaryfilemetadata.h
Normal file
52
src/binaryfile/binaryfilemetadata.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef BINARYFILEMETADATA_H
|
||||
#define BINARYFILEMETADATA_H
|
||||
|
||||
#include <Qt>
|
||||
#include <QList>
|
||||
|
||||
|
||||
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<quint16> getEntryPoints() { return m_entryPoints; }
|
||||
QList<AddressRange> getDataRanges() { return m_dataRanges; }
|
||||
|
||||
private:
|
||||
QList<quint16> m_entryPoints;
|
||||
QList<AddressRange> m_dataRanges;
|
||||
|
||||
};
|
||||
|
||||
#endif // BINARYFILEMETADATA_H
|
@ -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);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "applesoftfileviewer.h"
|
||||
#include "ui_applesoftfileviewer.h"
|
||||
#include "applesoftformatter.h"
|
||||
#include <QDebug>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -21,6 +21,35 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,1">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="findText">
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="findButton">
|
||||
<property name="text">
|
||||
<string>Find</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="findResults">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTextBrowser" name="textArea">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "hexdumpviewer.h"
|
||||
#include "ui_hexdumpviewer.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QScrollBar>
|
||||
|
||||
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("<br>").toUpper()));
|
||||
@ -79,43 +86,14 @@ QString HexDumpViewer::valToAppleAscii(quint8 val)
|
||||
QString htmlstr = charval.toHtmlEscaped();
|
||||
|
||||
QString retval;
|
||||
if (zone == Inverse) { retval = QString("<b>%1</b>").arg(htmlstr); }
|
||||
else if (zone == Flash) { retval = QString("<i>%1</i>").arg(htmlstr);}
|
||||
else if (zone == AltUC) { retval = QString("%1").arg(htmlstr);}
|
||||
if (zone == Inverse) { retval = QString("<font color=\"blue\"><b>%1</b></font>").arg(htmlstr); }
|
||||
else if (zone == Flash) { retval = QString("<font color=\"green\"><b><i>%1</i></b></font>").arg(htmlstr);}
|
||||
else if (zone == AltUC) { retval = QString("<font color=\"red\"><i>%1</i></font>").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("<br>")));
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -15,75 +15,15 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QToolButton" name="hexButton">
|
||||
<property name="text">
|
||||
<string>Hex</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="textButton">
|
||||
<property name="text">
|
||||
<string>Text</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>728</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QTextBrowser" name="textArea">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "mazeviewer.h"
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#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";
|
||||
|
Loading…
Reference in New Issue
Block a user