#pragma once #include "stdafx.h" #include "CpuState.h" #include "PpuState.h" class DisassemblyInfo; class MemoryManager; class LabelManager; enum class StatusFlagFormat { Hexadecimal = 0, Text = 1, CompactText = 2 }; struct TraceLoggerOptions { bool ShowByteCode; bool ShowRegisters; bool ShowCpuCycles; bool ShowPpuCycles; bool ShowPpuScanline; bool ShowPpuFrames; bool ShowExtraInfo; bool IndentCode; bool ShowEffectiveAddresses; bool UseLabels; StatusFlagFormat StatusFormat; }; class TraceLogger { private: static TraceLogger *_instance; TraceLoggerOptions _options; string _outputFilepath; string _outputBuffer; ofstream _outputFile; bool _firstLine; shared_ptr _memoryManager; shared_ptr _labelManager; constexpr static int ExecutionLogSize = 30000; bool _logToFile; uint16_t _currentPos; State _cpuStateCache[ExecutionLogSize] = {}; PPUDebugState _ppuStateCache[ExecutionLogSize] = {}; shared_ptr _disassemblyCache[ExecutionLogSize] = {}; string _executionTrace; void GetStatusFlag(string &output, uint8_t ps); public: TraceLogger(shared_ptr memoryManager, shared_ptr labelManager); ~TraceLogger(); void Log(State &cpuState, PPUDebugState &ppuState, shared_ptr disassemblyInfo); void SetOptions(TraceLoggerOptions options); void StartLogging(string filename); void StopLogging(); void GetTraceRow(string &output, State &cpuState, PPUDebugState &ppuState, shared_ptr &disassemblyInfo, bool firstLine); const char* GetExecutionTrace(uint32_t lineCount); static void LogStatic(string log); };