2019-02-12 22:13:09 -05:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "CpuTypes.h"
|
2019-02-13 13:32:21 -05:00
|
|
|
#include "PpuTypes.h"
|
2019-04-06 17:38:14 -04:00
|
|
|
#include "SpcTypes.h"
|
|
|
|
#include "DebugTypes.h"
|
2019-02-12 22:13:09 -05:00
|
|
|
#include "DisassemblyInfo.h"
|
|
|
|
#include "../Utilities/SimpleLock.h"
|
|
|
|
|
2019-03-07 20:12:32 -05:00
|
|
|
class Console;
|
2019-02-12 22:13:09 -05:00
|
|
|
class Debugger;
|
2019-04-28 22:19:52 -04:00
|
|
|
class LabelManager;
|
2019-02-12 22:13:09 -05:00
|
|
|
struct DebugState;
|
|
|
|
|
|
|
|
struct TraceLoggerOptions
|
|
|
|
{
|
2019-04-07 16:10:23 -04:00
|
|
|
bool LogCpu;
|
|
|
|
bool LogSpc;
|
2019-07-14 21:45:12 -04:00
|
|
|
bool LogNecDsp;
|
2019-04-07 16:10:23 -04:00
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
bool ShowExtraInfo;
|
|
|
|
bool IndentCode;
|
|
|
|
bool UseLabels;
|
|
|
|
bool UseWindowsEol;
|
|
|
|
bool ExtendZeroPage;
|
|
|
|
|
|
|
|
char Condition[1000];
|
|
|
|
char Format[1000];
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class RowDataType
|
|
|
|
{
|
|
|
|
Text = 0,
|
|
|
|
ByteCode,
|
|
|
|
Disassembly,
|
|
|
|
EffectiveAddress,
|
|
|
|
MemoryValue,
|
|
|
|
Align,
|
|
|
|
PC,
|
|
|
|
A,
|
|
|
|
X,
|
|
|
|
Y,
|
2019-02-13 13:32:21 -05:00
|
|
|
D,
|
|
|
|
DB,
|
2019-02-12 22:13:09 -05:00
|
|
|
SP,
|
|
|
|
PS,
|
|
|
|
Cycle,
|
|
|
|
Scanline,
|
2019-06-29 11:34:24 -04:00
|
|
|
HClock,
|
2019-02-12 22:13:09 -05:00
|
|
|
FrameCount,
|
|
|
|
CycleCount
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RowPart
|
|
|
|
{
|
|
|
|
RowDataType DataType;
|
|
|
|
string Text;
|
|
|
|
bool DisplayInHex;
|
|
|
|
int MinWidth;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TraceLogger
|
|
|
|
{
|
|
|
|
private:
|
2019-04-07 16:10:23 -04:00
|
|
|
static constexpr int ExecutionLogSize = 60000;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
|
|
//Must be static to be thread-safe when switching game
|
|
|
|
static string _executionTrace;
|
|
|
|
|
|
|
|
TraceLoggerOptions _options;
|
|
|
|
string _outputFilepath;
|
|
|
|
string _outputBuffer;
|
|
|
|
ofstream _outputFile;
|
2019-03-07 20:12:32 -05:00
|
|
|
shared_ptr<Console> _console;
|
2019-04-28 22:19:52 -04:00
|
|
|
shared_ptr<LabelManager> _labelManager;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
|
|
vector<RowPart> _rowParts;
|
2019-04-06 17:38:14 -04:00
|
|
|
vector<RowPart> _spcRowParts;
|
2019-07-14 21:45:12 -04:00
|
|
|
vector<RowPart> _dspRowParts;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-07-18 16:54:24 -04:00
|
|
|
bool _logCpu[(int)CpuType::NecDsp + 1] = {};
|
2019-04-07 16:10:23 -04:00
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
bool _pendingLog;
|
|
|
|
//CpuState _lastState;
|
|
|
|
//DisassemblyInfo _lastDisassemblyInfo;
|
|
|
|
|
|
|
|
bool _logToFile;
|
2019-04-07 16:10:23 -04:00
|
|
|
uint32_t _currentPos;
|
2019-02-12 22:13:09 -05:00
|
|
|
uint32_t _logCount;
|
2019-04-06 17:38:14 -04:00
|
|
|
DebugState _stateCache[ExecutionLogSize] = {};
|
2019-02-12 22:13:09 -05:00
|
|
|
DisassemblyInfo _disassemblyCache[ExecutionLogSize];
|
|
|
|
|
2019-04-06 17:38:14 -04:00
|
|
|
DebugState _stateCacheCopy[ExecutionLogSize] = {};
|
2019-02-12 22:13:09 -05:00
|
|
|
DisassemblyInfo _disassemblyCacheCopy[ExecutionLogSize];
|
|
|
|
|
|
|
|
SimpleLock _lock;
|
|
|
|
|
2019-04-07 16:10:23 -04:00
|
|
|
template<CpuType cpuType> void GetStatusFlag(string &output, uint8_t ps, RowPart& part);
|
|
|
|
|
2019-04-06 17:38:14 -04:00
|
|
|
void WriteByteCode(DisassemblyInfo &info, RowPart &rowPart, string &output);
|
|
|
|
void WriteDisassembly(DisassemblyInfo &info, RowPart &rowPart, uint8_t sp, uint32_t pc, string &output);
|
2019-04-28 22:19:52 -04:00
|
|
|
void WriteEffectiveAddress(DisassemblyInfo &info, RowPart &rowPart, void *cpuState, string &output, SnesMemoryType cpuMemoryType);
|
2019-04-06 17:38:14 -04:00
|
|
|
void WriteMemoryValue(DisassemblyInfo &info, RowPart &rowPart, void *cpuState, string &output);
|
|
|
|
void WriteAlign(int originalSize, RowPart &rowPart, string &output);
|
2019-02-12 22:13:09 -05:00
|
|
|
void AddRow(DisassemblyInfo &disassemblyInfo, DebugState &state);
|
|
|
|
//bool ConditionMatches(DebugState &state, DisassemblyInfo &disassemblyInfo, OperationInfo &operationInfo);
|
2019-04-06 17:38:14 -04:00
|
|
|
|
|
|
|
void ParseFormatString(vector<RowPart> &rowParts, string format);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-04-06 17:38:14 -04:00
|
|
|
void GetTraceRow(string &output, DisassemblyInfo &disassemblyInfo, DebugState &state);
|
2019-02-13 13:32:21 -05:00
|
|
|
void GetTraceRow(string &output, CpuState &cpuState, PpuState &ppuState, DisassemblyInfo &disassemblyInfo);
|
2019-04-06 17:38:14 -04:00
|
|
|
void GetTraceRow(string &output, SpcState &cpuState, PpuState &ppuState, DisassemblyInfo &disassemblyInfo);
|
2019-07-14 21:45:12 -04:00
|
|
|
void GetTraceRow(string &output, NecDspState &cpuState, PpuState &ppuState, DisassemblyInfo &disassemblyInfo);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
|
|
template<typename T> void WriteValue(string &output, T value, RowPart& rowPart);
|
|
|
|
|
|
|
|
public:
|
2019-03-07 20:12:32 -05:00
|
|
|
TraceLogger(Debugger* debugger, shared_ptr<Console> console);
|
2019-02-12 22:13:09 -05:00
|
|
|
~TraceLogger();
|
|
|
|
|
2019-07-14 21:45:12 -04:00
|
|
|
__forceinline bool IsCpuLogged(CpuType type) { return _logCpu[(int)type]; }
|
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
void Log(DebugState &state, DisassemblyInfo &disassemblyInfo);
|
2019-05-20 17:14:50 -04:00
|
|
|
void Clear();
|
2019-02-12 22:13:09 -05:00
|
|
|
//void LogNonExec(OperationInfo& operationInfo);
|
|
|
|
void SetOptions(TraceLoggerOptions options);
|
|
|
|
void StartLogging(string filename);
|
|
|
|
void StopLogging();
|
|
|
|
|
|
|
|
void LogExtraInfo(const char *log, uint32_t cycleCount);
|
|
|
|
|
|
|
|
const char* GetExecutionTrace(uint32_t lineCount);
|
|
|
|
};
|