Duckstation/src/duckstation/main.cpp

108 lines
2.6 KiB
C++
Raw Normal View History

2019-09-09 07:01:26 +00:00
#include "YBaseLib/Assert.h"
#include "YBaseLib/Log.h"
#include "YBaseLib/StringConverter.h"
2019-10-04 03:54:09 +00:00
#include "core/system.h"
2019-09-14 10:28:47 +00:00
#include "sdl_interface.h"
2019-09-09 07:01:26 +00:00
#include <SDL.h>
#include <cstdio>
2019-09-12 14:18:13 +00:00
#if 0
2019-09-09 07:01:26 +00:00
static int NoGUITest()
{
std::unique_ptr<System> system = std::make_unique<System>();
if (!system->Initialize())
return -1;
system->Reset();
while (true)
system->RunFrame();
return 0;
}
2019-09-12 14:18:13 +00:00
#endif
2019-09-09 07:01:26 +00:00
static int Run(int argc, char* argv[])
{
// init sdl
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
Panic("SDL initialization failed");
return -1;
}
// create display and host interface
std::unique_ptr<SDLInterface> host_interface = SDLInterface::Create();
if (!host_interface)
{
Panic("Failed to create host interface");
SDL_Quit();
return -1;
}
2019-09-14 10:28:47 +00:00
// parameters
const char* filename = nullptr;
2019-09-22 15:28:00 +00:00
const char* exp1_filename = nullptr;
TinyString state_filename;
2019-09-14 10:28:47 +00:00
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_filename = SDLInterface::GetSaveStateFilename(std::strtoul(argv[++i], nullptr, 10));
2019-09-22 15:28:00 +00:00
else if (CHECK_ARG_PARAM("-exp1"))
exp1_filename = argv[++i];
2019-09-14 10:28:47 +00:00
else
filename = argv[i];
#undef CHECK_ARG
#undef CHECK_ARG_PARAM
}
// create system
if (!host_interface->InitializeSystem(filename, exp1_filename))
2019-09-09 07:01:26 +00:00
{
host_interface.reset();
SDL_Quit();
return -1;
}
host_interface->ConnectDevices();
if (!state_filename.IsEmpty())
host_interface->LoadState(state_filename);
2019-09-09 07:01:26 +00:00
// run
host_interface->Run();
// done
host_interface.reset();
SDL_Quit();
return 0;
}
// SDL requires the entry point declared without c++ decoration
#undef main
int main(int argc, char* argv[])
{
// set log flags
#ifdef Y_BUILD_CONFIG_RELEASE
const LOGLEVEL level = LOGLEVEL_INFO;
// const LOGLEVEL level = LOGLEVEL_DEV;
// const LOGLEVEL level = LOGLEVEL_PROFILE;
// g_pLog->SetConsoleOutputParams(true, nullptr, level);
g_pLog->SetConsoleOutputParams(true, "Pad SPU", level);
g_pLog->SetFilterLevel(level);
2019-09-09 07:01:26 +00:00
#else
// g_pLog->SetConsoleOutputParams(true, nullptr, LOGLEVEL_DEBUG);
// g_pLog->SetConsoleOutputParams(true, "GPU GPU_HW_OpenGL SPU Pad DigitalController", LOGLEVEL_DEBUG);
g_pLog->SetConsoleOutputParams(true, "GPU GPU_HW_OpenGL SPU Pad DigitalController InterruptController", LOGLEVEL_DEBUG);
2019-09-09 07:01:26 +00:00
// g_pLog->SetFilterLevel(LOGLEVEL_TRACE);
g_pLog->SetFilterLevel(LOGLEVEL_DEBUG);
// g_pLog->SetFilterLevel(LOGLEVEL_DEV);
2019-09-09 07:01:26 +00:00
#endif
2019-09-14 10:28:47 +00:00
// return NoGUITest();
2019-09-12 14:18:13 +00:00
return Run(argc, argv);
2019-09-09 07:01:26 +00:00
}