Qt: Add dump VRAM and SPU RAM actions

This commit is contained in:
Connor McLaughlin
2021-01-13 19:24:41 +10:00
parent 5746dcdbd4
commit 2b5cfb272c
9 changed files with 131 additions and 12 deletions

View File

@ -3,6 +3,7 @@
#include "common/heap_array.h"
#include "common/log.h"
#include "common/state_wrapper.h"
#include "common/string_util.h"
#include "dma.h"
#include "host_display.h"
#include "host_interface.h"
@ -1453,6 +1454,26 @@ void GPU::SetTextureWindow(u32 value)
m_draw_mode.texture_window_changed = true;
}
bool GPU::DumpVRAMToFile(const char* filename)
{
ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
const char* extension = std::strrchr(filename, '.');
if (extension && StringUtil::Strcasecmp(extension, ".png") == 0)
{
return DumpVRAMToFile(filename, VRAM_WIDTH, VRAM_HEIGHT, sizeof(u16) * VRAM_WIDTH, m_vram_ptr, true);
}
else if (extension && StringUtil::Strcasecmp(extension, ".bin") == 0)
{
return FileSystem::WriteBinaryFile(filename, m_vram_ptr, VRAM_WIDTH * VRAM_HEIGHT * sizeof(u16));
}
else
{
Log_ErrorPrintf("Unknown extension: '%s'", filename);
return false;
}
}
bool GPU::DumpVRAMToFile(const char* filename, u32 width, u32 height, u32 stride, const void* buffer, bool remove_alpha)
{
auto fp = FileSystem::OpenManagedCFile(filename, "wb");

View File

@ -160,6 +160,9 @@ public:
// Returns the video clock frequency.
TickCount GetCRTCFrequency() const;
// Dumps raw VRAM to a file.
bool DumpVRAMToFile(const char* filename);
protected:
TickCount CRTCTicksToSystemTicks(TickCount crtc_ticks, TickCount fractional_ticks) const;
TickCount SystemTicksToCRTCTicks(TickCount sysclk_ticks, TickCount* fractional_ticks) const;

View File

@ -17,6 +17,12 @@ class TimingEvent;
class SPU
{
public:
enum : u32
{
RAM_SIZE = 512 * 1024,
RAM_MASK = RAM_SIZE - 1,
};
SPU();
~SPU();
@ -47,9 +53,11 @@ public:
/// Stops dumping audio to file, if started.
bool StopDumpingAudio();
/// Access to SPU RAM.
const std::array<u8, RAM_SIZE>& GetRAM() const { return m_ram; }
std::array<u8, RAM_SIZE>& GetRAM() { return m_ram; }
private:
static constexpr u32 RAM_SIZE = 512 * 1024;
static constexpr u32 RAM_MASK = RAM_SIZE - 1;
static constexpr u32 SPU_BASE = 0x1F801C00;
static constexpr u32 NUM_VOICES = 24;
static constexpr u32 NUM_VOICE_REGISTERS = 8;

View File

@ -1635,11 +1635,30 @@ void UpdateMemoryCards()
bool DumpRAM(const char* filename)
{
auto fp = FileSystem::OpenManagedCFile(filename, "wb");
if (!fp)
if (!IsValid())
return false;
return std::fwrite(Bus::g_ram, Bus::RAM_SIZE, 1, fp.get()) == 1;
return FileSystem::WriteBinaryFile(filename, Bus::g_ram, Bus::RAM_SIZE);
}
bool DumpVRAM(const char* filename)
{
if (!IsValid())
return false;
g_gpu->RestoreGraphicsAPIState();
const bool result = g_gpu->DumpVRAMToFile(filename);
g_gpu->ResetGraphicsAPIState();
return result;
}
bool DumpSPURAM(const char* filename)
{
if (!IsValid())
return false;
return FileSystem::WriteBinaryFile(filename, g_spu.GetRAM().data(), SPU::RAM_SIZE);
}
bool HasMedia()

View File

@ -175,6 +175,12 @@ void UpdateMemoryCards();
/// Dumps RAM to a file.
bool DumpRAM(const char* filename);
/// Dumps video RAM to a file.
bool DumpVRAM(const char* filename);
/// Dumps sound RAM to a file.
bool DumpSPURAM(const char* filename);
bool HasMedia();
bool InsertMedia(const char* path);
void RemoveMedia();