Debugger: Diassemble more code than before (assume what follows conditional jumps is also valid code)

This commit is contained in:
Souryo 2016-11-18 20:28:11 -05:00
parent 3b2840ef81
commit 5a24608f8f
2 changed files with 15 additions and 6 deletions

View file

@ -93,6 +93,11 @@ Disassembler::~Disassembler()
{
}
bool Disassembler::IsUnconditionalJump(uint8_t opCode)
{
return opCode == 0x40 || opCode == 0x60 || opCode == 0x6C || opCode == 0x4C || opCode == 0x20;
}
uint32_t Disassembler::BuildCache(int32_t absoluteAddr, int32_t absoluteRamAddr, uint16_t memoryAddr, bool isSubEntryPoint)
{
if(memoryAddr < 0x2000) {
@ -113,24 +118,26 @@ uint32_t Disassembler::BuildCache(int32_t absoluteAddr, int32_t absoluteRamAddr,
}
if(absoluteAddr >= 0) {
if(!cache[absoluteAddr]) {
shared_ptr<DisassemblyInfo> disInfo = cache[absoluteAddr];
if(!disInfo) {
while(absoluteAddr < (int32_t)_prgSize && !cache[absoluteAddr]) {
shared_ptr<DisassemblyInfo> disInfo(new DisassemblyInfo(&source[absoluteAddr], isSubEntryPoint));
bool isJump = IsUnconditionalJump(source[absoluteAddr]);
disInfo = shared_ptr<DisassemblyInfo>(new DisassemblyInfo(&source[absoluteAddr], isSubEntryPoint));
isSubEntryPoint = false;
cache[absoluteAddr] = disInfo;
uint8_t opCode = source[absoluteAddr];
absoluteAddr += disInfo->GetSize();
if(opCode == 0x10 || opCode == 0x20 || opCode == 0x30 || opCode == 0x40 || opCode == 0x50 || opCode == 0x60 || opCode == 0x70 || opCode == 0x90 || opCode == 0xB0 || opCode == 0xD0 || opCode == 0xF0 || opCode == 0x4C || opCode == 0x6C) {
if(isJump) {
//Hit a jump/return instruction, can't assume that what follows is actual code, stop disassembling
break;
}
}
} else {
if(isSubEntryPoint) {
cache[absoluteAddr]->SetSubEntryPoint();
disInfo->SetSubEntryPoint();
}
absoluteAddr += cache[absoluteAddr]->GetSize();
absoluteAddr += disInfo->GetSize();
}
}
return absoluteAddr;

View file

@ -15,6 +15,8 @@ private:
uint8_t* _prgRam;
uint32_t _prgSize;
bool IsUnconditionalJump(uint8_t opCode);
public:
Disassembler(uint8_t* internalRam, uint8_t* prgRom, uint32_t prgSize, uint8_t* prgRam, uint32_t prgRamSize);
~Disassembler();