mirror of
https://github.com/markdavidlong/AppleSAWS.git
synced 2024-11-25 05:31:54 +00:00
Cleaned up disassembler.cxx and disassembler.h
This commit is contained in:
parent
6e8da24b47
commit
ae7b8c83dd
@ -705,3 +705,75 @@ void Disassembler::makeOpcodeTable()
|
||||
#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;
|
||||
}
|
||||
|
@ -29,11 +29,7 @@ struct AssyInstruction {
|
||||
|
||||
public:
|
||||
|
||||
AssyInstruction(quint8 opcode = 0x00, QString mnemonic = "???", AddressMode am = AM_InvalidOp) {
|
||||
m_opcode = opcode;
|
||||
m_mnemonic = mnemonic;
|
||||
m_addressMode = am;
|
||||
}
|
||||
AssyInstruction(quint8 opcode = 0x00, QString mnemonic = "???", AddressMode am = AM_InvalidOp);
|
||||
|
||||
AddressMode addressMode() { return m_addressMode; }
|
||||
|
||||
@ -41,32 +37,7 @@ public:
|
||||
|
||||
quint8 opcode() { return m_opcode; }
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
quint8 numArgs();
|
||||
|
||||
private:
|
||||
QString m_mnemonic;
|
||||
@ -79,27 +50,10 @@ class DisassembledItem {
|
||||
public:
|
||||
DisassembledItem() { init(); }
|
||||
|
||||
DisassembledItem(AssyInstruction instr) {
|
||||
setInstruction(instr);
|
||||
}
|
||||
DisassembledItem(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 setInstruction(AssyInstruction instr);
|
||||
|
||||
void setAddress(quint16 add) { m_address = add; }
|
||||
void setDisassembledString(QString ds) { m_disassembly_text = ds; }
|
||||
@ -113,17 +67,7 @@ public:
|
||||
|
||||
AssyInstruction assyInstruction() const { return m_instruction; }
|
||||
QString rawDisassembledString() const { return m_disassembly_text; }
|
||||
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;
|
||||
}
|
||||
QString disassembledString();
|
||||
quint16 address() const { return m_address; }
|
||||
QString hexAddress() const { return QString("%1").arg(m_address,4,16,QChar('0')).toUpper(); }
|
||||
QByteArray hexValues() const { return m_hexvalues; }
|
||||
@ -142,13 +86,7 @@ public:
|
||||
QString arg8Str() { return QString("%1").arg(arg8(),2,16,QChar('0')).toUpper(); }
|
||||
|
||||
private:
|
||||
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;
|
||||
}
|
||||
void init();
|
||||
|
||||
quint16 m_address;
|
||||
QByteArray m_hexvalues;
|
||||
|
Loading…
Reference in New Issue
Block a user