2013-06-01 03:46:03 +00:00
|
|
|
#include "FrameDump.h"
|
2013-07-06 05:47:47 +00:00
|
|
|
#include "MemoryStateFile.h"
|
|
|
|
#include "RegisterStateFile.h"
|
2013-06-01 03:46:03 +00:00
|
|
|
|
2013-07-06 05:47:47 +00:00
|
|
|
#define STATE_INITIAL_GSRAM "init/gsram"
|
|
|
|
#define STATE_INITIAL_GSREGS "init/gsregs"
|
2014-11-22 01:23:49 -05:00
|
|
|
#define STATE_INITIAL_GSPRIVREGS "init/gsprivregs"
|
2013-07-06 05:47:47 +00:00
|
|
|
#define STATE_PACKET_PREFIX "packet_"
|
|
|
|
#define STATE_PACKET_METADATA_PREFIX "packetmetadata_"
|
2013-06-01 03:46:03 +00:00
|
|
|
|
2014-11-22 01:23:49 -05:00
|
|
|
#define STATE_PRIVREG_SMODE2 "SMODE2"
|
|
|
|
|
2013-06-01 03:46:03 +00:00
|
|
|
CFrameDump::CFrameDump()
|
|
|
|
{
|
|
|
|
m_initialGsRam = new uint8[CGSHandler::RAMSIZE];
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
CFrameDump::~CFrameDump()
|
|
|
|
{
|
|
|
|
delete [] m_initialGsRam;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFrameDump::Reset()
|
|
|
|
{
|
|
|
|
m_packets.clear();
|
2014-05-06 01:57:03 -04:00
|
|
|
memset(m_initialGsRam, 0, CGSHandler::RAMSIZE);
|
|
|
|
memset(&m_initialGsRegisters, 0, sizeof(m_initialGsRegisters));
|
2014-11-22 01:23:49 -05:00
|
|
|
m_initialSMODE2 = 0;
|
2013-06-01 03:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8* CFrameDump::GetInitialGsRam()
|
|
|
|
{
|
|
|
|
return m_initialGsRam;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64* CFrameDump::GetInitialGsRegisters()
|
|
|
|
{
|
|
|
|
return m_initialGsRegisters;
|
|
|
|
}
|
|
|
|
|
2014-11-22 01:23:49 -05:00
|
|
|
uint64 CFrameDump::GetInitialSMODE2() const
|
|
|
|
{
|
|
|
|
return m_initialSMODE2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFrameDump::SetInitialSMODE2(uint64 value)
|
|
|
|
{
|
|
|
|
m_initialSMODE2 = value;
|
|
|
|
}
|
|
|
|
|
2013-06-01 03:46:03 +00:00
|
|
|
const CFrameDump::PacketArray& CFrameDump::GetPackets() const
|
|
|
|
{
|
|
|
|
return m_packets;
|
|
|
|
}
|
|
|
|
|
2013-07-06 05:47:47 +00:00
|
|
|
void CFrameDump::AddPacket(const CGSHandler::RegisterWrite* registerWrites, uint32 count, const CGsPacketMetadata* metadata)
|
2013-06-01 03:46:03 +00:00
|
|
|
{
|
2013-07-06 05:47:47 +00:00
|
|
|
CGsPacket packet;
|
|
|
|
packet.writes = CGsPacket::WriteArray(registerWrites, registerWrites + count);
|
|
|
|
if(metadata)
|
|
|
|
{
|
|
|
|
packet.metadata = *metadata;
|
|
|
|
}
|
|
|
|
m_packets.push_back(packet);
|
2013-06-01 03:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CFrameDump::Read(Framework::CStream& input)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
Framework::CZipArchiveReader archive(input);
|
|
|
|
|
|
|
|
archive.BeginReadFile(STATE_INITIAL_GSRAM)->Read(m_initialGsRam, CGSHandler::RAMSIZE);
|
|
|
|
archive.BeginReadFile(STATE_INITIAL_GSREGS)->Read(m_initialGsRegisters, sizeof(uint64) * CGSHandler::REGISTER_MAX);
|
|
|
|
|
2014-11-22 01:23:49 -05:00
|
|
|
{
|
|
|
|
CRegisterStateFile registerFile(*archive.BeginReadFile(STATE_INITIAL_GSPRIVREGS));
|
|
|
|
m_initialSMODE2 = registerFile.GetRegister64(STATE_PRIVREG_SMODE2);
|
|
|
|
}
|
|
|
|
|
2013-06-01 03:46:03 +00:00
|
|
|
std::map<unsigned int, std::string> packetFiles;
|
|
|
|
for(const auto& fileHeader : archive.GetFileHeaders())
|
|
|
|
{
|
|
|
|
if(fileHeader.first.find(STATE_PACKET_PREFIX) == 0)
|
|
|
|
{
|
|
|
|
unsigned int packetIdx = 0;
|
|
|
|
sscanf(fileHeader.first.c_str(), STATE_PACKET_PREFIX "%d", &packetIdx);
|
|
|
|
packetFiles[packetIdx] = fileHeader.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(const auto& packetFilePair : packetFiles)
|
|
|
|
{
|
|
|
|
const auto& packetFile = packetFilePair.second;
|
|
|
|
const auto& packetFileHeader = archive.GetFileHeader(packetFile.c_str());
|
|
|
|
unsigned int writeCount = packetFileHeader->uncompressedSize / sizeof(CGSHandler::RegisterWrite);
|
|
|
|
assert(packetFileHeader->uncompressedSize % sizeof(CGSHandler::RegisterWrite) == 0);
|
|
|
|
|
2013-07-06 05:47:47 +00:00
|
|
|
std::string packetMetadataFile = STATE_PACKET_METADATA_PREFIX + std::to_string(packetFilePair.first);
|
2013-06-01 03:46:03 +00:00
|
|
|
|
2013-07-06 05:47:47 +00:00
|
|
|
CGsPacket packet;
|
|
|
|
packet.writes.resize(writeCount);
|
|
|
|
|
|
|
|
archive.BeginReadFile(packetFile.c_str())->Read(packet.writes.data(), packet.writes.size() * sizeof(CGSHandler::RegisterWrite));
|
|
|
|
archive.BeginReadFile(packetMetadataFile.c_str())->Read(&packet.metadata, sizeof(CGsPacketMetadata));
|
2013-06-01 03:46:03 +00:00
|
|
|
|
|
|
|
m_packets.push_back(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFrameDump::Write(Framework::CStream& output) const
|
|
|
|
{
|
|
|
|
Framework::CZipArchiveWriter archive;
|
|
|
|
|
2013-07-06 05:47:47 +00:00
|
|
|
archive.InsertFile(new CMemoryStateFile(STATE_INITIAL_GSRAM, m_initialGsRam, CGSHandler::RAMSIZE));
|
|
|
|
archive.InsertFile(new CMemoryStateFile(STATE_INITIAL_GSREGS, m_initialGsRegisters, sizeof(uint64) * CGSHandler::REGISTER_MAX));
|
|
|
|
|
2014-11-22 01:23:49 -05:00
|
|
|
{
|
|
|
|
auto privRegsStateFile = new CRegisterStateFile(STATE_INITIAL_GSPRIVREGS);
|
|
|
|
privRegsStateFile->SetRegister64(STATE_PRIVREG_SMODE2, m_initialSMODE2);
|
|
|
|
archive.InsertFile(privRegsStateFile);
|
|
|
|
}
|
|
|
|
|
2013-07-06 05:47:47 +00:00
|
|
|
unsigned int currentPacket = 0;
|
|
|
|
for(const auto& packet : m_packets)
|
|
|
|
{
|
|
|
|
std::string packetName = STATE_PACKET_PREFIX + std::to_string(currentPacket);
|
|
|
|
std::string packetMetadataName = STATE_PACKET_METADATA_PREFIX + std::to_string(currentPacket);
|
|
|
|
archive.InsertFile(new CMemoryStateFile(packetName.c_str(), packet.writes.data(), packet.writes.size() * sizeof(CGSHandler::RegisterWrite)));
|
|
|
|
archive.InsertFile(new CMemoryStateFile(packetMetadataName.c_str(), &packet.metadata, sizeof(CGsPacketMetadata)));
|
|
|
|
currentPacket++;
|
|
|
|
}
|
|
|
|
|
|
|
|
archive.Write(output);
|
2013-06-01 03:46:03 +00:00
|
|
|
}
|