Added relocation dictionary entries to end of Relocatable File disassembly viewer.

This commit is contained in:
Mark Long 2016-10-14 08:52:43 -05:00
parent 4e104cd5fb
commit 9b00d7c0f0
8 changed files with 88 additions and 50 deletions

View File

@ -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;
}

View File

@ -33,6 +33,7 @@ public:
QString formatText();
signals:
void newFile(ApplesoftFile *file);
@ -40,6 +41,7 @@ public slots:
private:
FormatOptions m_format_options;
QList<quint16> m_flowTargets;
ApplesoftFile *m_file;

View File

@ -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("<font color=\"blue\">%1</font>").arg(baseval);
return QString("<font color=\"orange\">%1</font>").arg(baseval);
}
QString ApplesoftToken::getRawPrintableString() const

View File

@ -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;
}

View File

@ -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;

View File

@ -76,8 +76,9 @@
<font>
<family>Misc Fixed</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
<weight>50</weight>
<bold>false</bold>
<stylestrategy>PreferAntialias</stylestrategy>
</font>
</property>
<property name="acceptDrops">

View File

@ -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<DisassembledItem> lines = dis.disassemble(file->address(), file->address()+file->codeImageLength());
QList<DisassembledItem> 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);
}

View File

@ -220,7 +220,7 @@
</item>
<item row="0" column="1">
<property name="text">
<string>0x01 n</string>
<string>$01 n</string>
</property>
</item>
<item row="0" column="2">
@ -245,7 +245,7 @@
</item>
<item row="1" column="1">
<property name="text">
<string>0x02</string>
<string>$02</string>
</property>
</item>
<item row="1" column="2">
@ -270,7 +270,7 @@
</item>
<item row="2" column="1">
<property name="text">
<string>0x03</string>
<string>$03</string>
</property>
</item>
<item row="2" column="2">
@ -295,7 +295,7 @@
</item>
<item row="3" column="1">
<property name="text">
<string>0x04</string>
<string>$04</string>
</property>
</item>
<item row="3" column="2">
@ -320,7 +320,7 @@
</item>
<item row="4" column="1">
<property name="text">
<string>0x05</string>
<string>$05</string>
</property>
</item>
<item row="4" column="2">
@ -345,7 +345,7 @@
</item>
<item row="5" column="1">
<property name="text">
<string>0x06</string>
<string>$06</string>
</property>
</item>
<item row="5" column="2">
@ -370,7 +370,7 @@
</item>
<item row="6" column="1">
<property name="text">
<string>0x09</string>
<string>$09</string>
</property>
</item>
<item row="6" column="2">
@ -395,7 +395,7 @@
</item>
<item row="7" column="1">
<property name="text">
<string>0x0B</string>
<string>$0B</string>
</property>
</item>
<item row="7" column="2">
@ -420,7 +420,7 @@
</item>
<item row="8" column="1">
<property name="text">
<string>0x0C</string>
<string>$0C</string>
</property>
</item>
<item row="8" column="2">
@ -445,7 +445,7 @@
</item>
<item row="9" column="1">
<property name="text">
<string>0x0E</string>
<string>$0E</string>
</property>
</item>
<item row="9" column="2">
@ -470,7 +470,7 @@
</item>
<item row="10" column="1">
<property name="text">
<string>0x0F 0x01</string>
<string>$0F $01</string>
</property>
</item>
<item row="10" column="2">
@ -495,7 +495,7 @@
</item>
<item row="11" column="1">
<property name="text">
<string>0x0F 0x02</string>
<string>$0F $02</string>
</property>
</item>
<item row="11" column="2">
@ -520,7 +520,7 @@
</item>
<item row="12" column="1">
<property name="text">
<string>0x0F 0x03</string>
<string>$0F $03</string>
</property>
</item>
<item row="12" column="2">
@ -545,7 +545,7 @@
</item>
<item row="13" column="1">
<property name="text">
<string>0x0F 0x04</string>
<string>$0F $04</string>
</property>
</item>
<item row="13" column="2">
@ -570,7 +570,7 @@
</item>
<item row="14" column="1">
<property name="text">
<string>0x0F 0x0F</string>
<string>$0F $0F</string>
</property>
</item>
<item row="14" column="2">
@ -595,7 +595,7 @@
</item>
<item row="15" column="1">
<property name="text">
<string>0x0F 0x10</string>
<string>$0F $10</string>
</property>
</item>
<item row="15" column="2">
@ -620,7 +620,7 @@
</item>
<item row="16" column="1">
<property name="text">
<string>0x0F 0x12</string>
<string>$0F $12</string>
</property>
</item>
<item row="16" column="2">
@ -645,7 +645,7 @@
</item>
<item row="17" column="1">
<property name="text">
<string>0x0F 0x13</string>
<string>$0F $13</string>
</property>
</item>
<item row="17" column="2">
@ -670,7 +670,7 @@
</item>
<item row="18" column="1">
<property name="text">
<string>0x0F 0x14</string>
<string>$0F $14</string>
</property>
</item>
<item row="18" column="2">
@ -695,7 +695,7 @@
</item>
<item row="19" column="1">
<property name="text">
<string>0x0F 0x17</string>
<string>$0F $17</string>
</property>
</item>
<item row="19" column="2">
@ -720,7 +720,7 @@
</item>
<item row="20" column="1">
<property name="text">
<string>0x0F 0x18</string>
<string>$0F $18</string>
</property>
</item>
<item row="20" column="2">
@ -735,7 +735,7 @@
</item>
<item row="20" column="4">
<property name="text">
<string>Call User Sub A</string>
<string>Call User Sub A (@ RLOAD + $0A/0B)</string>
</property>
</item>
<item row="21" column="0">
@ -745,7 +745,7 @@
</item>
<item row="21" column="1">
<property name="text">
<string>0x0F 0x1A</string>
<string>$0F $1A</string>
</property>
</item>
<item row="21" column="2">
@ -760,7 +760,7 @@
</item>
<item row="21" column="4">
<property name="text">
<string>Call User Sub B</string>
<string>Call User Sub B (@ RLOAD + $0D/0E)</string>
</property>
</item>
<item row="22" column="0">
@ -770,7 +770,7 @@
</item>
<item row="22" column="1">
<property name="text">
<string>0x10</string>
<string>$10</string>
</property>
</item>
<item row="22" column="2">
@ -795,7 +795,7 @@
</item>
<item row="23" column="1">
<property name="text">
<string>0x11</string>
<string>$11</string>
</property>
</item>
<item row="23" column="2">
@ -820,7 +820,7 @@
</item>
<item row="24" column="1">
<property name="text">
<string>0x13</string>
<string>$13</string>
</property>
</item>
<item row="24" column="2">
@ -845,7 +845,7 @@
</item>
<item row="25" column="1">
<property name="text">
<string>0x16</string>
<string>$16</string>
</property>
</item>
<item row="25" column="2">
@ -870,7 +870,7 @@
</item>
<item row="26" column="1">
<property name="text">
<string>0x17</string>
<string>$17</string>
</property>
</item>
<item row="26" column="2">
@ -895,7 +895,7 @@
</item>
<item row="27" column="1">
<property name="text">
<string>0x19</string>
<string>$19</string>
</property>
</item>
<item row="27" column="2">
@ -920,7 +920,7 @@
</item>
<item row="28" column="1">
<property name="text">
<string>0x1A</string>
<string>$1A</string>
</property>
</item>
<item row="28" column="2">