Trace Logger: Made output match Nintendulator's output closely to make comparisons easier
This commit is contained in:
parent
2b6d625969
commit
4eb5b11607
4 changed files with 40 additions and 10 deletions
|
@ -98,6 +98,8 @@ void CPU::Exec()
|
|||
|
||||
void CPU::IncCycleCount()
|
||||
{
|
||||
_cycleCount++;
|
||||
|
||||
_memoryManager->ProcessCpuClock();
|
||||
|
||||
if(_dmcDmaRunning) {
|
||||
|
@ -122,8 +124,6 @@ void CPU::IncCycleCount()
|
|||
_prevRunIrq = _runIrq;
|
||||
_runIrq = _state.NMIFlag || (_state.IRQFlag > 0 && !CheckFlag(PSFlags::Interrupt));
|
||||
}
|
||||
|
||||
_cycleCount++;
|
||||
}
|
||||
|
||||
void CPU::RunDMATransfer(uint8_t* spriteRAM, uint8_t offsetValue)
|
||||
|
|
|
@ -62,7 +62,7 @@ void DisassemblyInfo::Initialize(uint32_t memoryAddr)
|
|||
break;
|
||||
|
||||
case AddrMode::Imm:
|
||||
output << " #" << nextByte.str();
|
||||
output << " #$" << nextByte.str();
|
||||
break;
|
||||
|
||||
case AddrMode::Ind:
|
||||
|
|
|
@ -9,6 +9,7 @@ TraceLogger::TraceLogger(string outputFilepath, TraceLoggerOptions options)
|
|||
{
|
||||
_outputFile.open(outputFilepath, ios::out | ios::binary);
|
||||
_options = options;
|
||||
_firstLine = true;
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
|
@ -26,7 +27,7 @@ TraceLogger::~TraceLogger()
|
|||
void TraceLogger::LogStatic(string log)
|
||||
{
|
||||
if(_instance) {
|
||||
_instance->_outputFile << "--- " << log << " --- Cycle: " << std::to_string(CPU::GetCycleCount()) << std::endl;
|
||||
_instance->_outputFile << " - [" << log << " - Cycle: " << std::to_string(CPU::GetCycleCount()) << "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,12 +37,40 @@ void TraceLogger::Log(DebugState &state, shared_ptr<DisassemblyInfo> disassembly
|
|||
PPUDebugState &ppuState = state.PPU;
|
||||
|
||||
string disassembly = disassemblyInfo->ToString(cpuState.DebugPC);
|
||||
while(disassembly.size() < 30) {
|
||||
disassembly += " ";
|
||||
auto separatorPosition = disassembly.begin() + disassembly.find_first_of(':', 0);
|
||||
string byteCode(disassembly.begin(), separatorPosition);
|
||||
byteCode.erase(std::remove(byteCode.begin(), byteCode.end(), '$'), byteCode.end());
|
||||
string assemblyCode(separatorPosition + 1, disassembly.end());
|
||||
|
||||
//Roughly adjust PPU cycle & scanline to take into account the PPU already ran 3 cycles by the time we get here
|
||||
short ppuCycle = (short)ppuState.Cycle - 3;
|
||||
short scanline = (short)ppuState.Scanline;
|
||||
if(ppuCycle < 0) {
|
||||
ppuCycle = 341 + ppuCycle;
|
||||
scanline--;
|
||||
if(scanline < -1) {
|
||||
scanline = EmulationSettings::GetNesModel() == NesModel::NTSC ? 260 : 310;
|
||||
}
|
||||
}
|
||||
|
||||
_outputFile << std::uppercase << std::hex << (short)cpuState.DebugPC << ": " << disassembly << " "
|
||||
<< "A:" << (short)cpuState.A << " X:" << (short)cpuState.X << " Y:" << (short)cpuState.Y << " P:" << (short)cpuState.PS << " SP:" << (short)cpuState.SP
|
||||
<< std::dec
|
||||
<< " CYC:" << (short)ppuState.Cycle << " SL:" << (short)ppuState.Scanline << " CPU Cycle:" << cpuState.CycleCount << std::endl;
|
||||
if(!_firstLine) {
|
||||
_outputFile << std::endl;
|
||||
}
|
||||
|
||||
_outputFile << std::uppercase << std::hex
|
||||
<< std::setfill('0') << std::setw(4) << (short)cpuState.DebugPC << " "
|
||||
<< std::setfill(' ') << std::setw(10) << std::left << byteCode
|
||||
<< std::setfill(' ') << std::setw(32) << std::left << assemblyCode
|
||||
<< std::setfill('0')
|
||||
<< "A:" << std::setw(2) << (short)cpuState.A
|
||||
<< " X:" << std::setw(2) << (short)cpuState.X
|
||||
<< " Y:" << std::setw(2) << (short)cpuState.Y
|
||||
<< " P:" << std::setw(2) << (short)cpuState.PS
|
||||
<< " SP:" << std::setw(2) << (short)cpuState.SP
|
||||
<< std::dec << std::setfill(' ') << std::right
|
||||
<< " CYC:" << std::setw(3) << ppuCycle << std::left
|
||||
<< " SL:" << std::setw(3) << scanline
|
||||
<< " CPU Cycle:" << cpuState.CycleCount;
|
||||
|
||||
_firstLine = false;
|
||||
}
|
|
@ -16,6 +16,7 @@ private:
|
|||
TraceLoggerOptions _options;
|
||||
string _outputFilepath;
|
||||
ofstream _outputFile;
|
||||
bool _firstLine;
|
||||
|
||||
public:
|
||||
TraceLogger(string outputFilepath, TraceLoggerOptions options);
|
||||
|
|
Loading…
Add table
Reference in a new issue