Save state support

This commit is contained in:
Connor McLaughlin
2019-09-14 20:28:47 +10:00
parent 851ef67814
commit 2560efbebd
16 changed files with 256 additions and 56 deletions

View File

@ -1,9 +1,9 @@
#include "YBaseLib/Assert.h"
#include "YBaseLib/Log.h"
#include "YBaseLib/StringConverter.h"
#include "sdl_interface.h"
#include "pse/types.h"
#include "pse/system.h"
#include "pse/types.h"
#include "sdl_interface.h"
#include <SDL.h>
#include <cstdio>
@ -24,14 +24,6 @@ static int NoGUITest()
static int Run(int argc, char* argv[])
{
#if 0
if (argc < 2)
{
std::fprintf(stderr, "Usage: %s <path to system ini> [save state index]\n", argv[0]);
return -1;
}
#endif
// init sdl
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
@ -48,11 +40,25 @@ static int Run(int argc, char* argv[])
return -1;
}
// create system
// parameters
const char* filename = nullptr;
s32 state_index = -1;
if (argc > 2)
state_index = StringConverter::StringToInt32(argv[2]);
if (!host_interface->InitializeSystem("", state_index))
for (int i = 1; i < argc; i++)
{
#define CHECK_ARG(str) !std::strcmp(argv[i], str)
#define CHECK_ARG_PARAM(str) (!std::strcmp(argv[i], str) && ((i + 1) < argc))
if (CHECK_ARG_PARAM("-state"))
state_index = std::atoi(argv[++i]);
else
filename = argv[i];
#undef CHECK_ARG
#undef CHECK_ARG_PARAM
}
// create system
if (!host_interface->InitializeSystem(filename, state_index))
{
host_interface.reset();
SDL_Quit();
@ -83,6 +89,6 @@ int main(int argc, char* argv[])
g_pLog->SetFilterLevel(LOGLEVEL_DEBUG);
#endif
//return NoGUITest();
// return NoGUITest();
return Run(argc, argv);
}

View File

@ -148,15 +148,13 @@ std::unique_ptr<SDLInterface> SDLInterface::Create()
return intf;
}
// TinyString SDLInterface::GetSaveStateFilename(u32 index)
// {
// return TinyString::FromFormat("savestate_%u.bin", index);
// }
TinyString SDLInterface::GetSaveStateFilename(u32 index)
{
return TinyString::FromFormat("savestate_%u.bin", index);
}
bool SDLInterface::InitializeSystem(const char* filename, s32 save_state_index /* = -1 */)
{
Error error;
m_system = std::make_unique<System>(this);
if (!m_system->Initialize())
{
@ -164,21 +162,13 @@ bool SDLInterface::InitializeSystem(const char* filename, s32 save_state_index /
return false;
}
#if 0
m_system->Reset();
if (save_state_index >= 0)
{
// Load the save state.
if (!HostInterface::LoadSystemState(GetSaveStateFilename(static_cast<u32>(save_state_index)), &error))
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Loading save state failed", error.GetErrorCodeAndDescription(),
m_window);
}
LoadState(GetSaveStateFilename(static_cast<u32>(save_state_index)));
}
#endif
m_system->Reset();
//m_system->LoadEXE("tests/psxtest_cpu.psxexe");
// Resume execution.
m_running = true;
@ -458,21 +448,12 @@ void SDLInterface::RenderOSDMessages()
void SDLInterface::DoLoadState(u32 index)
{
#if 0
Error error;
if (!LoadSystemState(TinyString::FromFormat("savestate_%u.bin", index), &error))
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Loading save state failed", error.GetErrorCodeAndDescription(),
m_window);
}
#endif
LoadState(GetSaveStateFilename(index));
}
void SDLInterface::DoSaveState(u32 index)
{
#if 0
SaveSystemState(TinyString::FromFormat("savestate_%u.bin", index));
#endif
SaveState(GetSaveStateFilename(index));
}
void SDLInterface::Run()

View File

@ -19,6 +19,8 @@ public:
static std::unique_ptr<SDLInterface> Create();
static TinyString GetSaveStateFilename(u32 index);
void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height) override;
void ReportMessage(const char* message) override;
@ -61,7 +63,6 @@ private:
int m_window_width = 0;
int m_window_height = 0;
std::unique_ptr<System> m_system;
GL::Program m_display_program;
GLuint m_display_vao = 0;
GL::Texture* m_display_texture = nullptr;
@ -73,6 +74,4 @@ private:
std::deque<OSDMessage> m_osd_messages;
std::mutex m_osd_messages_lock;
bool m_running = false;
};