2019-02-12 22:13:09 -05:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Debugger.h"
|
|
|
|
#include "Cpu.h"
|
2019-02-13 13:32:21 -05:00
|
|
|
#include "Ppu.h"
|
2019-02-12 22:13:09 -05:00
|
|
|
#include "CpuTypes.h"
|
|
|
|
#include "DisassemblyInfo.h"
|
|
|
|
#include "TraceLogger.h"
|
|
|
|
#include "../Utilities/HexUtilities.h"
|
|
|
|
|
2019-02-13 13:32:21 -05:00
|
|
|
Debugger::Debugger(shared_ptr<Cpu> cpu, shared_ptr<Ppu> ppu, shared_ptr<MemoryManager> memoryManager)
|
2019-02-12 22:13:09 -05:00
|
|
|
{
|
|
|
|
_cpu = cpu;
|
2019-02-13 13:32:21 -05:00
|
|
|
_ppu = ppu;
|
2019-02-12 22:13:09 -05:00
|
|
|
_memoryManager = memoryManager;
|
|
|
|
_traceLogger.reset(new TraceLogger(this, memoryManager));
|
|
|
|
|
2019-02-13 23:02:43 -05:00
|
|
|
_cpuStepCount = 0;
|
2019-02-12 22:13:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Debugger::~Debugger()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::ProcessCpuRead(uint32_t addr, uint8_t value, MemoryOperationType type)
|
|
|
|
{
|
|
|
|
if(type == MemoryOperationType::ExecOpCode) {
|
|
|
|
CpuState state = _cpu->GetState();
|
|
|
|
DisassemblyInfo disassemblyInfo(state, _memoryManager.get());
|
2019-02-13 13:32:21 -05:00
|
|
|
DebugState debugState;
|
|
|
|
GetState(&debugState);
|
2019-02-13 18:44:12 -05:00
|
|
|
_traceLogger->LogEffectiveAddress(_cpu->GetLastOperand());
|
2019-02-12 22:13:09 -05:00
|
|
|
_traceLogger->Log(debugState, disassemblyInfo);
|
|
|
|
|
|
|
|
if(_cpuStepCount > 0) {
|
|
|
|
_cpuStepCount--;
|
|
|
|
while(_cpuStepCount == 0) {
|
|
|
|
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>(10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::ProcessCpuWrite(uint32_t addr, uint8_t value, MemoryOperationType type)
|
|
|
|
{
|
|
|
|
if(type == MemoryOperationType::ExecOpCode) {
|
|
|
|
//_traceLogger->Trace
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::Run()
|
|
|
|
{
|
|
|
|
_cpuStepCount = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::Step(int32_t stepCount)
|
|
|
|
{
|
|
|
|
_cpuStepCount = stepCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::IsExecutionStopped()
|
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-13 13:32:21 -05:00
|
|
|
void Debugger::GetState(DebugState *state)
|
|
|
|
{
|
|
|
|
state->Cpu = _cpu->GetState();
|
|
|
|
state->Ppu = _ppu->GetState();
|
|
|
|
}
|
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
shared_ptr<TraceLogger> Debugger::GetTraceLogger()
|
|
|
|
{
|
|
|
|
return _traceLogger;
|
|
|
|
}
|