2016-11-19 04:50:05 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2018-01-01 05:31:16 +00:00
|
|
|
#include <unordered_map>
|
2016-12-09 05:02:56 +00:00
|
|
|
#include "DebuggerTypes.h"
|
2016-11-19 04:50:05 +00:00
|
|
|
|
|
|
|
class PPU;
|
|
|
|
class MemoryManager;
|
|
|
|
class BaseMapper;
|
|
|
|
class CodeDataLogger;
|
2017-02-27 01:47:39 +00:00
|
|
|
class Debugger;
|
2017-03-11 20:01:33 +00:00
|
|
|
class Disassembler;
|
2016-11-19 04:50:05 +00:00
|
|
|
|
2018-01-01 05:31:16 +00:00
|
|
|
struct TileKey
|
|
|
|
{
|
|
|
|
uint8_t TileData[16];
|
|
|
|
uint32_t TileIndex;
|
|
|
|
bool IsChrRamTile = false;
|
|
|
|
|
|
|
|
TileKey GetKey(bool defaultKey)
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetHashCode() const
|
|
|
|
{
|
|
|
|
if(IsChrRamTile) {
|
|
|
|
return CalculateHash(TileData, 16);
|
|
|
|
} else {
|
|
|
|
uint64_t key = TileIndex;
|
|
|
|
return CalculateHash((uint8_t*)&key, sizeof(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t operator() (const TileKey &tile) const
|
|
|
|
{
|
|
|
|
return tile.GetHashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const TileKey &other) const
|
|
|
|
{
|
|
|
|
if(IsChrRamTile) {
|
|
|
|
return memcmp((uint8_t*)&TileData, (uint8_t*)&other.TileData, 16) == 0;
|
|
|
|
} else {
|
|
|
|
return TileIndex == other.TileIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CalculateHash(const uint8_t* key, size_t len) const
|
|
|
|
{
|
|
|
|
uint32_t result = 0;
|
|
|
|
for(size_t i = 0; i < len; i += 4) {
|
2018-06-20 00:43:16 +00:00
|
|
|
uint32_t chunk;
|
|
|
|
memcpy(&chunk, key, sizeof(uint32_t));
|
|
|
|
|
|
|
|
result += chunk;
|
2018-01-01 05:31:16 +00:00
|
|
|
result = (result << 2) | (result >> 30);
|
|
|
|
key += 4;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <> struct hash<TileKey>
|
|
|
|
{
|
|
|
|
size_t operator()(const TileKey& x) const
|
|
|
|
{
|
|
|
|
return x.GetHashCode();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-19 04:50:05 +00:00
|
|
|
class MemoryDumper
|
|
|
|
{
|
|
|
|
private:
|
2017-02-27 01:47:39 +00:00
|
|
|
Debugger* _debugger;
|
2016-11-19 04:50:05 +00:00
|
|
|
shared_ptr<PPU> _ppu;
|
|
|
|
shared_ptr<MemoryManager> _memoryManager;
|
|
|
|
shared_ptr<BaseMapper> _mapper;
|
|
|
|
shared_ptr<CodeDataLogger> _codeDataLogger;
|
2017-03-11 20:01:33 +00:00
|
|
|
shared_ptr<Disassembler> _disassembler;
|
2016-11-19 04:50:05 +00:00
|
|
|
|
2018-02-24 19:23:54 +00:00
|
|
|
std::deque<vector<uint8_t>> _undoHistory;
|
|
|
|
|
2018-01-01 05:31:16 +00:00
|
|
|
std::unordered_map<TileKey, uint32_t> _paletteByTile;
|
|
|
|
|
2018-02-24 19:23:54 +00:00
|
|
|
void AddUndoHistory(vector<uint8_t>& originalRomData);
|
|
|
|
|
2016-11-19 04:50:05 +00:00
|
|
|
public:
|
2017-03-11 20:01:33 +00:00
|
|
|
MemoryDumper(shared_ptr<PPU> ppu, shared_ptr<MemoryManager> memoryManager, shared_ptr<BaseMapper> mapper, shared_ptr<CodeDataLogger> codeDataLogger, Debugger *debugger, shared_ptr<Disassembler> disassembler);
|
2016-11-19 04:50:05 +00:00
|
|
|
|
2018-01-01 05:31:16 +00:00
|
|
|
void GatherChrPaletteInfo();
|
|
|
|
|
2018-02-24 19:23:54 +00:00
|
|
|
bool HasUndoHistory();
|
|
|
|
void PerformUndo();
|
|
|
|
|
2017-05-03 01:23:28 +00:00
|
|
|
uint32_t GetMemorySize(DebugMemoryType type);
|
2016-11-19 04:50:05 +00:00
|
|
|
uint32_t GetMemoryState(DebugMemoryType type, uint8_t *buffer);
|
2018-02-21 03:21:51 +00:00
|
|
|
void GetNametable(int nametableIndex, bool useGrayscalePalette, uint32_t* frameBuffer, uint8_t* tileData, uint8_t* paletteData);
|
2018-01-01 05:31:16 +00:00
|
|
|
void GetChrBank(int bankIndex, uint32_t* frameBuffer, uint8_t palette, bool largeSprites, CdlHighlightType highlightType, uint32_t* paletteBuffer);
|
2016-11-19 04:50:05 +00:00
|
|
|
void GetSprites(uint32_t* frameBuffer);
|
|
|
|
void GetPalette(uint32_t* frameBuffer);
|
|
|
|
|
2017-08-30 22:31:27 +00:00
|
|
|
uint8_t GetMemoryValue(DebugMemoryType memoryType, uint32_t address, bool disableSideEffects = true);
|
|
|
|
uint16_t GetMemoryValueWord(DebugMemoryType memoryType, uint32_t address, bool disableSideEffects = true);
|
|
|
|
void SetMemoryValue(DebugMemoryType memoryType, uint32_t address, uint8_t value, bool preventRebuildCache = false, bool disableSideEffects = true);
|
|
|
|
void SetMemoryValueWord(DebugMemoryType memoryType, uint32_t address, uint16_t value, bool preventRebuildCache = false, bool disableSideEffects = true);
|
2017-03-11 20:01:33 +00:00
|
|
|
void SetMemoryValues(DebugMemoryType memoryType, uint32_t address, uint8_t* data, int32_t length);
|
2016-11-19 04:50:05 +00:00
|
|
|
void SetMemoryState(DebugMemoryType type, uint8_t *buffer);
|
|
|
|
};
|