From 9b00d7c0f077678f6a237f479ec6507d819498ea Mon Sep 17 00:00:00 2001 From: Mark Long Date: Fri, 14 Oct 2016 08:52:43 -0500 Subject: [PATCH] Added relocation dictionary entries to end of Relocatable File disassembly viewer. --- src/applesoftfile/applesoftformatter.cxx | 25 +++++----- src/applesoftfile/applesoftformatter.h | 2 + src/applesoftfile/applesofttoken.cxx | 4 +- src/relocatablefile/relocatablefile.cxx | 29 +++++++++++ src/relocatablefile/relocatablefile.h | 2 + src/ui/viewers/applesoftfileviewer.ui | 5 +- src/ui/viewers/disassemblerviewer.cpp | 9 ++-- src/ui/widgets/hrcgcontrolsinfo.ui | 62 ++++++++++++------------ 8 files changed, 88 insertions(+), 50 deletions(-) diff --git a/src/applesoftfile/applesoftformatter.cxx b/src/applesoftfile/applesoftformatter.cxx index 5b4b5de..485ab25 100644 --- a/src/applesoftfile/applesoftformatter.cxx +++ b/src/applesoftfile/applesoftformatter.cxx @@ -20,6 +20,7 @@ QString ApplesoftFormatter::formatText() } QString retval; + m_flowTargets.clear(); foreach (ApplesoftLine line, m_file->getLines()) { QString linestring = QString("%1 ").arg(line.linenum,5,10,QChar(' ')); @@ -33,6 +34,7 @@ QString ApplesoftFormatter::formatText() while (tokenIt.hasNext()) { ApplesoftToken token = tokenIt.next(); + bool isFlowTarget = false; QString tokenstr = token.getRawPrintableString(); @@ -45,17 +47,20 @@ QString ApplesoftFormatter::formatText() firstToken = false; } + //TODO: Move this to the parser... + if (previousToken.getTokenId() == ApplesoftToken::ASGoto || + previousToken.getTokenId() == ApplesoftToken::ASGosub || + previousToken.getTokenId() == ApplesoftToken::ASThen) + { + isFlowTarget = true; + m_flowTargets.append(line.linenum); + } + if (m_format_options.testFlag(ShowIntsAsHex)) { if (token.getTokenId() == ApplesoftToken::IntegerTokenVal) { - bool okToConvert = true; - if (previousToken.getTokenId() == ApplesoftToken::ASGoto || - previousToken.getTokenId() == ApplesoftToken::ASGosub || - previousToken.getTokenId() == ApplesoftToken::ASThen) - { - qDebug() << "previous token: " << uint16ToHex(tokenIt.peekPrevious().getTokenId()); - okToConvert = false; - } + bool okToConvert = !isFlowTarget; + if (okToConvert) { @@ -78,7 +83,6 @@ QString ApplesoftFormatter::formatText() } } - if (m_format_options.testFlag(BreakAfterReturn)) { if (token.getTokenId() == ApplesoftToken::ASReturn) { @@ -128,7 +132,7 @@ QString ApplesoftFormatter::formatText() #endif - // if (m_format_options.testFlag(ShowCtrlChars)) + if (m_format_options.testFlag(ShowCtrlChars)) { tokenstr.replace(QChar(0x7f),QChar(0x2401)); @@ -150,6 +154,5 @@ QString ApplesoftFormatter::formatText() } } - return retval; } diff --git a/src/applesoftfile/applesoftformatter.h b/src/applesoftfile/applesoftformatter.h index ccc5f00..66111a0 100644 --- a/src/applesoftfile/applesoftformatter.h +++ b/src/applesoftfile/applesoftformatter.h @@ -33,6 +33,7 @@ public: QString formatText(); + signals: void newFile(ApplesoftFile *file); @@ -40,6 +41,7 @@ public slots: private: FormatOptions m_format_options; + QList m_flowTargets; ApplesoftFile *m_file; diff --git a/src/applesoftfile/applesofttoken.cxx b/src/applesoftfile/applesofttoken.cxx index a56c842..6f40f59 100644 --- a/src/applesoftfile/applesofttoken.cxx +++ b/src/applesoftfile/applesofttoken.cxx @@ -27,7 +27,7 @@ void ApplesoftToken::setTokenId(quint16 id) m_token_type = UNKNOWN_TOKEN; m_command_type = NONE; - if (id <= 0xff) { + if (id <= 0x7f) { setValue(id); m_token_type = ASCIICHAR_TOKEN; m_command_type = NONE; @@ -81,7 +81,6 @@ void ApplesoftToken::setTokenId(quint16 id) m_token_type = STRING_ARY_VARIABLE_TOKEN; m_command_type = NONE; } - } void ApplesoftToken::setValue(QVariant value) @@ -107,7 +106,6 @@ QString ApplesoftToken::getHtmlPrintableString() return QString("%1").arg(baseval); return QString("%1").arg(baseval); - } QString ApplesoftToken::getRawPrintableString() const diff --git a/src/relocatablefile/relocatablefile.cxx b/src/relocatablefile/relocatablefile.cxx index 06e486d..5950360 100644 --- a/src/relocatablefile/relocatablefile.cxx +++ b/src/relocatablefile/relocatablefile.cxx @@ -69,3 +69,32 @@ void RelocatableFile::dump() } + +QStringList RelocatableFile::decodeRelocatableDict() +{ + QStringList retval; + int idx = 0; + foreach (RelocatableDictItem item, m_relocatable_dict) { + Byte4ReturnType b4rt = item.getByte4(); + QString typestr; + if (b4rt.first == ESDSymbol) { typestr = "ESDSymbol"; } + else if (b4rt.first == ByteHi) { typestr = "Hi Byte"; } + else { typestr = "Lo Byte"; } + quint16 fo = item.getFieldOffset(); + qDebug() << " Item #" << idx + << "Field Offset: " << uint16ToHex(fo) + << "FieldSize: " << ((item.getFieldSize()==RFS2Byte)?"2-Byte":"1-Byte") + << typestr << uint8ToHex(b4rt.second) + << ((item.isNotEndOfRLD())?"NotEndOfRLD":"EndOfRLD") + << " " << ((item.isExtern())?"Extern":"Not Extern"); + + retval.append(QString("Item %1, Offset %2, @ %3, %4 Field, %5") + .arg(idx++) + .arg(uint16ToHex(fo)) + .arg(uint16ToHex(fo+address()+6)) + .arg((item.getFieldSize()==RFS2Byte)?"2-Byte":"1-Byte") + .arg((item.isExtern())?"Extern":"Not Extern")); + } + + return retval; +} diff --git a/src/relocatablefile/relocatablefile.h b/src/relocatablefile/relocatablefile.h index b697af9..71adfc9 100644 --- a/src/relocatablefile/relocatablefile.h +++ b/src/relocatablefile/relocatablefile.h @@ -91,6 +91,8 @@ public: quint16 address() { return m_starting_ram_address; } quint16 codeImageLength() { return m_code_image_length; } + QStringList decodeRelocatableDict(); + protected: quint16 m_starting_ram_address; quint16 m_ram_image_length; diff --git a/src/ui/viewers/applesoftfileviewer.ui b/src/ui/viewers/applesoftfileviewer.ui index 53f4627..ffb1088 100644 --- a/src/ui/viewers/applesoftfileviewer.ui +++ b/src/ui/viewers/applesoftfileviewer.ui @@ -76,8 +76,9 @@ Misc Fixed 14 - 75 - true + 50 + false + PreferAntialias diff --git a/src/ui/viewers/disassemblerviewer.cpp b/src/ui/viewers/disassemblerviewer.cpp index 0231fe9..d9ba801 100644 --- a/src/ui/viewers/disassemblerviewer.cpp +++ b/src/ui/viewers/disassemblerviewer.cpp @@ -61,12 +61,13 @@ void DisassemblerViewer::setFile(RelocatableFile *file) { QString title = QString("Disassembler Viewer: %1").arg(m_file->filename()); setWindowTitle(title); - quint16 address = file->address(); + quint16 address = file->address() + 6 ; // Handle offset for relocatable metadata + Memory mem; mem.addFile(file->getBinaryCodeImage(), address); Disassembler dis(mem.values()); - QList lines = dis.disassemble(file->address(), file->address()+file->codeImageLength()); + QList lines = dis.disassemble(address, address+file->codeImageLength()-1); QStringList formattedLines; @@ -86,7 +87,9 @@ void DisassemblerViewer::setFile(RelocatableFile *file) { } QByteArray joinedlines = qPrintable(formattedLines.join("\n")); - setData(joinedlines); + QStringList rd = file->decodeRelocatableDict(); + QByteArray rdlines = qPrintable(rd.join("\n")); + setData(joinedlines + '\n' + rdlines); } diff --git a/src/ui/widgets/hrcgcontrolsinfo.ui b/src/ui/widgets/hrcgcontrolsinfo.ui index e9efd67..4bb725d 100644 --- a/src/ui/widgets/hrcgcontrolsinfo.ui +++ b/src/ui/widgets/hrcgcontrolsinfo.ui @@ -220,7 +220,7 @@ - 0x01 n + $01 n @@ -245,7 +245,7 @@ - 0x02 + $02 @@ -270,7 +270,7 @@ - 0x03 + $03 @@ -295,7 +295,7 @@ - 0x04 + $04 @@ -320,7 +320,7 @@ - 0x05 + $05 @@ -345,7 +345,7 @@ - 0x06 + $06 @@ -370,7 +370,7 @@ - 0x09 + $09 @@ -395,7 +395,7 @@ - 0x0B + $0B @@ -420,7 +420,7 @@ - 0x0C + $0C @@ -445,7 +445,7 @@ - 0x0E + $0E @@ -470,7 +470,7 @@ - 0x0F 0x01 + $0F $01 @@ -495,7 +495,7 @@ - 0x0F 0x02 + $0F $02 @@ -520,7 +520,7 @@ - 0x0F 0x03 + $0F $03 @@ -545,7 +545,7 @@ - 0x0F 0x04 + $0F $04 @@ -570,7 +570,7 @@ - 0x0F 0x0F + $0F $0F @@ -595,7 +595,7 @@ - 0x0F 0x10 + $0F $10 @@ -620,7 +620,7 @@ - 0x0F 0x12 + $0F $12 @@ -645,7 +645,7 @@ - 0x0F 0x13 + $0F $13 @@ -670,7 +670,7 @@ - 0x0F 0x14 + $0F $14 @@ -695,7 +695,7 @@ - 0x0F 0x17 + $0F $17 @@ -720,7 +720,7 @@ - 0x0F 0x18 + $0F $18 @@ -735,7 +735,7 @@ - Call User Sub A + Call User Sub A (@ RLOAD + $0A/0B) @@ -745,7 +745,7 @@ - 0x0F 0x1A + $0F $1A @@ -760,7 +760,7 @@ - Call User Sub B + Call User Sub B (@ RLOAD + $0D/0E) @@ -770,7 +770,7 @@ - 0x10 + $10 @@ -795,7 +795,7 @@ - 0x11 + $11 @@ -820,7 +820,7 @@ - 0x13 + $13 @@ -845,7 +845,7 @@ - 0x16 + $16 @@ -870,7 +870,7 @@ - 0x17 + $17 @@ -895,7 +895,7 @@ - 0x19 + $19 @@ -920,7 +920,7 @@ - 0x1A + $1A