Interface: Support loading filenames on command line
This commit is contained in:
parent
363d62e5c1
commit
3d6b8e485e
|
@ -42,14 +42,14 @@ static int Run(int argc, char* argv[])
|
|||
|
||||
// parameters
|
||||
const char* filename = nullptr;
|
||||
s32 state_index = -1;
|
||||
TinyString state_filename;
|
||||
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]);
|
||||
state_filename = SDLInterface::GetSaveStateFilename(std::strtoul(argv[++i], nullptr, 10));
|
||||
else
|
||||
filename = argv[i];
|
||||
|
||||
|
@ -58,7 +58,7 @@ static int Run(int argc, char* argv[])
|
|||
}
|
||||
|
||||
// create system
|
||||
if (!host_interface->InitializeSystem(filename, state_index))
|
||||
if (!host_interface->InitializeSystem(filename, state_filename.IsEmpty() ? nullptr : state_filename.GetCharArray()))
|
||||
{
|
||||
host_interface.reset();
|
||||
SDL_Quit();
|
||||
|
|
|
@ -153,28 +153,6 @@ TinyString SDLInterface::GetSaveStateFilename(u32 index)
|
|||
return TinyString::FromFormat("savestate_%u.bin", index);
|
||||
}
|
||||
|
||||
bool SDLInterface::InitializeSystem(const char* filename, s32 save_state_index /* = -1 */)
|
||||
{
|
||||
m_system = std::make_unique<System>(this);
|
||||
if (!m_system->Initialize())
|
||||
{
|
||||
m_system.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_system->Reset();
|
||||
|
||||
if (save_state_index >= 0)
|
||||
{
|
||||
// Load the save state.
|
||||
LoadState(GetSaveStateFilename(static_cast<u32>(save_state_index)));
|
||||
}
|
||||
|
||||
// Resume execution.
|
||||
m_running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SDLInterface::ReportMessage(const char* message)
|
||||
{
|
||||
AddOSDMessage(message, 3.0f);
|
||||
|
@ -314,6 +292,7 @@ void SDLInterface::RenderDisplay()
|
|||
glViewport(0, 0, m_window_width, m_window_height);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
m_display_program.Bind();
|
||||
m_display_texture->Bind();
|
||||
|
|
|
@ -28,8 +28,6 @@ public:
|
|||
// Adds OSD messages, duration is in seconds.
|
||||
void AddOSDMessage(const char* message, float duration = 2.0f) override;
|
||||
|
||||
bool InitializeSystem(const char* filename, s32 save_state_index /* = -1 */);
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,11 +1,46 @@
|
|||
#include "host_interface.h"
|
||||
#include "YBaseLib/ByteStream.h"
|
||||
#include "YBaseLib/Log.h"
|
||||
#include "system.h"
|
||||
Log_SetChannel(HostInterface);
|
||||
|
||||
HostInterface::HostInterface() = default;
|
||||
|
||||
HostInterface::~HostInterface() = default;
|
||||
|
||||
bool HostInterface::InitializeSystem(const char* filename, const char* save_state_filename)
|
||||
{
|
||||
m_system = std::make_unique<System>(this);
|
||||
if (!m_system->Initialize())
|
||||
{
|
||||
m_system.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_system->Reset();
|
||||
|
||||
if (filename)
|
||||
{
|
||||
const StaticString filename_str(filename);
|
||||
if (filename_str.EndsWith(".psxexe", false) || filename_str.EndsWith(".exe", false))
|
||||
{
|
||||
Log_InfoPrintf("Sideloading EXE file %s", filename);
|
||||
if (!m_system->LoadEXE(filename))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to load EXE file %s", filename);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (save_state_filename)
|
||||
LoadState(save_state_filename);
|
||||
|
||||
// Resume execution.
|
||||
m_running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HostInterface::LoadState(const char* filename)
|
||||
{
|
||||
ByteStream* stream;
|
||||
|
|
|
@ -14,6 +14,8 @@ public:
|
|||
HostInterface();
|
||||
virtual ~HostInterface();
|
||||
|
||||
bool InitializeSystem(const char* filename, const char* save_state_filename);
|
||||
|
||||
virtual void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height) = 0;
|
||||
virtual void ReportMessage(const char* message) = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue