Cleaned up disassembler.cxx and disassembler.h

This commit is contained in:
Mark Long 2016-10-26 02:48:01 -05:00
parent 6e8da24b47
commit ae7b8c83dd
2 changed files with 78 additions and 68 deletions

View File

@ -705,3 +705,75 @@ void Disassembler::makeOpcodeTable()
#endif #endif
} }
AssyInstruction::AssyInstruction(quint8 opcode, QString mnemonic, AddressMode am) {
m_opcode = opcode;
m_mnemonic = mnemonic;
m_addressMode = am;
}
quint8 AssyInstruction::numArgs() {
switch (m_addressMode) {
case AM_Absolute:
case AM_AbsoluteIndexedIndirect:
case AM_AbsoluteIndexedWithX:
case AM_AbsoluteIndexedWithY:
case AM_AbsoluteIndirect:
return 2;
case AM_ProgramCounterRelative:
case AM_ZeroPage:
case AM_ZeroPageIndirectIndexedWithY:
case AM_ZeroPageIndexedIndirect:
case AM_ZeroPageIndexedWithX:
case AM_ZeroPageIndexedWithY:
case AM_ZeroPageIndirect:
case AM_Immediate:
return 1;
case AM_InvalidOp:
case AM_Implied:
case AM_Accumulator:
default:
return 0;
}
}
DisassembledItem::DisassembledItem(AssyInstruction instr) {
setInstruction(instr);
}
void DisassembledItem::setInstruction(AssyInstruction instr) {
m_instruction = instr;
if (instr.opcode() == 0x20) { m_is_jsr = true; }
if (instr.opcode() == 0x10) { m_is_branch = true; } // BPL
if (instr.opcode() == 0x30) { m_is_branch = true; } // BMI
if (instr.opcode() == 0x50) { m_is_branch = true; } // BVC
if (instr.opcode() == 0x70) { m_is_branch = true; } // BVS
if (instr.opcode() == 0x90) { m_is_branch = true; } // BCC
if (instr.opcode() == 0xB0) { m_is_branch = true; } // BCS
if (instr.opcode() == 0xD0) { m_is_branch = true; } // BNE
if (instr.opcode() == 0xF0) { m_is_branch = true; } // BEQ
if (instr.opcode() == 0x80) { m_is_jump = true; } // BRA
if (instr.opcode() == 0x4C) { m_is_jump = true; } // JMP a
if (instr.opcode() == 0x6C) { m_is_jump = true; } // JMP (a)
if (instr.opcode() == 0x7C) { m_is_jump = true; } // JMP (a,x)
}
QString DisassembledItem::disassembledString() {
QString retval = rawDisassembledString();
if (hasArg()) {
if (retval.contains("_ARG16_")) {
retval.replace("_ARG16_","$"+arg16Str());
} else if (retval.contains("_ARG8_")) {
retval.replace("_ARG8_","$"+arg8Str());
}
}
return retval;
}
void DisassembledItem::init() {
m_address = m_target_address = 0;
m_is_jump = m_is_branch = m_is_jsr = false;
m_unknown_ta = true;
m_raw_arg = 0;
m_has_arg = false;
}

View File

@ -29,11 +29,7 @@ struct AssyInstruction {
public: public:
AssyInstruction(quint8 opcode = 0x00, QString mnemonic = "???", AddressMode am = AM_InvalidOp) { AssyInstruction(quint8 opcode = 0x00, QString mnemonic = "???", AddressMode am = AM_InvalidOp);
m_opcode = opcode;
m_mnemonic = mnemonic;
m_addressMode = am;
}
AddressMode addressMode() { return m_addressMode; } AddressMode addressMode() { return m_addressMode; }
@ -41,32 +37,7 @@ public:
quint8 opcode() { return m_opcode; } quint8 opcode() { return m_opcode; }
quint8 numArgs();
quint8 numArgs() {
switch (m_addressMode) {
case AM_Absolute:
case AM_AbsoluteIndexedIndirect:
case AM_AbsoluteIndexedWithX:
case AM_AbsoluteIndexedWithY:
case AM_AbsoluteIndirect:
return 2;
case AM_ProgramCounterRelative:
case AM_ZeroPage:
case AM_ZeroPageIndirectIndexedWithY:
case AM_ZeroPageIndexedIndirect:
case AM_ZeroPageIndexedWithX:
case AM_ZeroPageIndexedWithY:
case AM_ZeroPageIndirect:
case AM_Immediate:
return 1;
case AM_InvalidOp:
case AM_Implied:
case AM_Accumulator:
default:
return 0;
}
}
private: private:
QString m_mnemonic; QString m_mnemonic;
@ -79,27 +50,10 @@ class DisassembledItem {
public: public:
DisassembledItem() { init(); } DisassembledItem() { init(); }
DisassembledItem(AssyInstruction instr) { DisassembledItem(AssyInstruction instr);
setInstruction(instr);
}
void setInstruction(AssyInstruction instr) { void setInstruction(AssyInstruction instr);
m_instruction = instr;
if (instr.opcode() == 0x20) { m_is_jsr = true; }
if (instr.opcode() == 0x10) { m_is_branch = true; } // BPL
if (instr.opcode() == 0x30) { m_is_branch = true; } // BMI
if (instr.opcode() == 0x50) { m_is_branch = true; } // BVC
if (instr.opcode() == 0x70) { m_is_branch = true; } // BVS
if (instr.opcode() == 0x90) { m_is_branch = true; } // BCC
if (instr.opcode() == 0xB0) { m_is_branch = true; } // BCS
if (instr.opcode() == 0xD0) { m_is_branch = true; } // BNE
if (instr.opcode() == 0xF0) { m_is_branch = true; } // BEQ
if (instr.opcode() == 0x80) { m_is_jump = true; } // BRA
if (instr.opcode() == 0x4C) { m_is_jump = true; } // JMP a
if (instr.opcode() == 0x6C) { m_is_jump = true; } // JMP (a)
if (instr.opcode() == 0x7C) { m_is_jump = true; } // JMP (a,x)
}
void setAddress(quint16 add) { m_address = add; } void setAddress(quint16 add) { m_address = add; }
void setDisassembledString(QString ds) { m_disassembly_text = ds; } void setDisassembledString(QString ds) { m_disassembly_text = ds; }
@ -113,17 +67,7 @@ public:
AssyInstruction assyInstruction() const { return m_instruction; } AssyInstruction assyInstruction() const { return m_instruction; }
QString rawDisassembledString() const { return m_disassembly_text; } QString rawDisassembledString() const { return m_disassembly_text; }
QString disassembledString() { QString disassembledString();
QString retval = rawDisassembledString();
if (hasArg()) {
if (retval.contains("_ARG16_")) {
retval.replace("_ARG16_","$"+arg16Str());
} else if (retval.contains("_ARG8_")) {
retval.replace("_ARG8_","$"+arg8Str());
}
}
return retval;
}
quint16 address() const { return m_address; } quint16 address() const { return m_address; }
QString hexAddress() const { return QString("%1").arg(m_address,4,16,QChar('0')).toUpper(); } QString hexAddress() const { return QString("%1").arg(m_address,4,16,QChar('0')).toUpper(); }
QByteArray hexValues() const { return m_hexvalues; } QByteArray hexValues() const { return m_hexvalues; }
@ -142,13 +86,7 @@ public:
QString arg8Str() { return QString("%1").arg(arg8(),2,16,QChar('0')).toUpper(); } QString arg8Str() { return QString("%1").arg(arg8(),2,16,QChar('0')).toUpper(); }
private: private:
void init() { void init();
m_address = m_target_address = 0;
m_is_jump = m_is_branch = m_is_jsr = false;
m_unknown_ta = true;
m_raw_arg = 0;
m_has_arg = false;
}
quint16 m_address; quint16 m_address;
QByteArray m_hexvalues; QByteArray m_hexvalues;