Debugger: Improved dissassembler to disassemble ahead of time and process sep/rep instructions for X/M flags
This commit is contained in:
parent
194eff9cb2
commit
052cd63d5f
4 changed files with 52 additions and 16 deletions
|
@ -74,17 +74,10 @@ void CodeDataLogger::SetFlags(int32_t absoluteAddr, uint8_t flags)
|
|||
if(absoluteAddr >= 0 && absoluteAddr < (int32_t)_prgSize) {
|
||||
if((_cdlData[absoluteAddr] & flags) != flags) {
|
||||
if(flags & CdlFlags::Code) {
|
||||
if(IsData(absoluteAddr)) {
|
||||
//Remove the data flag from bytes that we are flagging as code
|
||||
_cdlData[absoluteAddr] &= ~CdlFlags::Data;
|
||||
_dataSize--;
|
||||
}
|
||||
_cdlData[absoluteAddr] |= flags;
|
||||
_codeSize++;
|
||||
_cdlData[absoluteAddr] = flags | (_cdlData[absoluteAddr] & ~(CdlFlags::Data | CdlFlags::IndexMode8 | CdlFlags::MemoryMode8));
|
||||
} else if(flags & CdlFlags::Data) {
|
||||
if(!IsCode(absoluteAddr)) {
|
||||
_cdlData[absoluteAddr] |= flags;
|
||||
_dataSize++;
|
||||
}
|
||||
} else {
|
||||
_cdlData[absoluteAddr] |= flags;
|
||||
|
@ -95,6 +88,8 @@ void CodeDataLogger::SetFlags(int32_t absoluteAddr, uint8_t flags)
|
|||
|
||||
CdlRatios CodeDataLogger::GetRatios()
|
||||
{
|
||||
CalculateStats();
|
||||
|
||||
CdlRatios ratios;
|
||||
ratios.CodeRatio = (float)_codeSize / (float)_prgSize;
|
||||
ratios.DataRatio = (float)_dataSize / (float)_prgSize;
|
||||
|
|
|
@ -88,17 +88,24 @@ uint32_t Disassembler::BuildCache(AddressInfo &addrInfo, uint8_t cpuFlags, CpuTy
|
|||
vector<DisassemblyInfo> *cache;
|
||||
GetSource(addrInfo, &source, sourceLength, &cache);
|
||||
|
||||
if(addrInfo.Address >= 0) {
|
||||
DisassemblyInfo disInfo = (*cache)[addrInfo.Address];
|
||||
if(!disInfo.IsInitialized()) {
|
||||
DisassemblyInfo disassemblyInfo(source+addrInfo.Address, cpuFlags, type);
|
||||
(*cache)[addrInfo.Address] = disassemblyInfo;
|
||||
int returnSize = 0;
|
||||
int32_t address = addrInfo.Address;
|
||||
while(address >= 0 && address < cache->size()) {
|
||||
DisassemblyInfo &disInfo = (*cache)[address];
|
||||
if(!disInfo.IsInitialized() || !disInfo.IsValid(cpuFlags)) {
|
||||
disInfo.Initialize(source+address, cpuFlags, type);
|
||||
_needDisassemble[(int)type] = true;
|
||||
disInfo = disassemblyInfo;
|
||||
}
|
||||
return disInfo.GetOpSize();
|
||||
|
||||
returnSize += disInfo.GetOpSize();
|
||||
|
||||
if(disInfo.UpdateCpuFlags(cpuFlags)) {
|
||||
address += disInfo.GetOpSize();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return returnSize;
|
||||
}
|
||||
|
||||
void Disassembler::ResetPrgCache()
|
||||
|
|
|
@ -32,6 +32,11 @@ bool DisassemblyInfo::IsInitialized()
|
|||
return _initialized;
|
||||
}
|
||||
|
||||
bool DisassemblyInfo::IsValid(uint8_t cpuFlags)
|
||||
{
|
||||
return _flags == (cpuFlags & (ProcFlags::MemoryMode8 | ProcFlags::IndexMode8));
|
||||
}
|
||||
|
||||
void DisassemblyInfo::Reset()
|
||||
{
|
||||
_initialized = false;
|
||||
|
@ -125,6 +130,32 @@ bool DisassemblyInfo::IsReturnInstruction(uint8_t opCode, CpuType type)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool DisassemblyInfo::UpdateCpuFlags(uint8_t &cpuFlags)
|
||||
{
|
||||
uint8_t opCode = GetOpCode();
|
||||
switch(_cpuType) {
|
||||
case CpuType::Cpu:
|
||||
if(opCode == 0x00 || opCode == 0x20 || opCode == 0x40 || opCode == 0x60 || opCode == 0x80 || opCode == 0x22 || opCode == 0xFC || opCode == 0x6B || opCode == 0x4C || opCode == 0x5C || opCode == 0x6C || opCode == 0x6C || opCode == 0x02) {
|
||||
//Jumps, RTI, RTS, BRK, COP, etc., stop disassembling
|
||||
return false;
|
||||
} else if(opCode == 0xC2) {
|
||||
//REP, update the flags and keep disassembling
|
||||
uint8_t flags = GetByteCode()[1];
|
||||
cpuFlags &= ~flags;
|
||||
} else if(opCode == 0xE2) {
|
||||
//SEP, update the flags and keep disassembling
|
||||
uint8_t flags = GetByteCode()[1];
|
||||
cpuFlags |= flags;
|
||||
} else if(opCode == 0x28) {
|
||||
//PLP, stop disassembling
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
case CpuType::Spc: return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t DisassemblyInfo::GetMemoryValue(uint32_t effectiveAddress, MemoryManager *memoryManager, uint8_t &valueSize)
|
||||
{
|
||||
if(_flags & ProcFlags::MemoryMode8) {
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
|
||||
void Initialize(uint8_t *opPointer, uint8_t cpuFlags, CpuType type);
|
||||
bool IsInitialized();
|
||||
bool IsValid(uint8_t cpuFlags);
|
||||
void Reset();
|
||||
|
||||
void GetDisassembly(string &out, uint32_t memoryAddr, LabelManager *labelManager);
|
||||
|
@ -42,6 +43,8 @@ public:
|
|||
static bool IsJumpToSub(uint8_t opCode, CpuType type);
|
||||
static bool IsReturnInstruction(uint8_t opCode, CpuType type);
|
||||
|
||||
bool UpdateCpuFlags(uint8_t & cpuFlags);
|
||||
|
||||
int32_t GetEffectiveAddress(Console *console, void *cpuState);
|
||||
uint16_t GetMemoryValue(uint32_t effectiveAddress, MemoryManager *memoryManager, uint8_t &valueSize);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue