2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-07-13 01:31:43 -06:00
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
#include "DolphinNoGUI/Platform.h"
|
|
|
|
|
2016-01-17 04:13:09 -07:00
|
|
|
#include <OptionParser.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstddef>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include <cstdio>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstring>
|
2016-09-24 13:17:34 -06:00
|
|
|
#include <signal.h>
|
2014-03-12 13:33:41 -06:00
|
|
|
#include <string>
|
2020-12-27 15:11:22 -07:00
|
|
|
#include <vector>
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
#ifndef _WIN32
|
2015-09-04 00:14:10 -06:00
|
|
|
#include <unistd.h>
|
2019-11-25 21:25:19 -07:00
|
|
|
#else
|
|
|
|
#include <Windows.h>
|
2018-10-23 23:50:54 -06:00
|
|
|
#endif
|
2009-05-15 02:55:46 -06:00
|
|
|
|
2019-11-25 21:25:19 -07:00
|
|
|
#include "Common/StringUtil.h"
|
2017-05-27 07:43:40 -06:00
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/BootManager.h"
|
|
|
|
#include "Core/Core.h"
|
2020-09-15 04:13:10 -06:00
|
|
|
#include "Core/DolphinAnalytics.h"
|
2014-08-02 00:21:03 -06:00
|
|
|
#include "Core/Host.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
|
2016-01-17 04:13:09 -07:00
|
|
|
#include "UICommon/CommandLineParse.h"
|
2018-06-08 14:56:11 -06:00
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
#include "UICommon/DiscordPresence.h"
|
|
|
|
#endif
|
2014-10-04 13:12:15 -06:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2022-03-08 14:16:54 -07:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
|
|
|
|
2016-11-19 06:03:20 -07:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
static std::unique_ptr<Platform> s_platform;
|
2016-09-24 13:17:34 -06:00
|
|
|
|
|
|
|
static void signal_handler(int)
|
|
|
|
{
|
|
|
|
const char message[] = "A signal was received. A second signal will force Dolphin to stop.\n";
|
2018-10-23 23:50:54 -06:00
|
|
|
#ifdef _WIN32
|
|
|
|
puts(message);
|
|
|
|
#else
|
2016-09-24 13:17:34 -06:00
|
|
|
if (write(STDERR_FILENO, message, sizeof(message)) < 0)
|
|
|
|
{
|
|
|
|
}
|
2018-10-23 23:50:54 -06:00
|
|
|
#endif
|
2016-10-01 13:35:29 -06:00
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
s_platform->RequestShutdown();
|
2016-09-24 13:17:34 -06:00
|
|
|
}
|
2010-05-26 15:23:44 -06:00
|
|
|
|
2020-12-27 15:11:22 -07:00
|
|
|
std::vector<std::string> Host_GetPreferredLocales()
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2011-02-08 08:36:15 -07:00
|
|
|
void Host_NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
}
|
2020-12-27 15:11:22 -07:00
|
|
|
|
2011-02-08 08:36:15 -07:00
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2008-09-07 14:26:38 -06:00
|
|
|
|
2019-03-18 10:30:33 -06:00
|
|
|
bool Host_UIBlocksControllerState()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
static Common::Event s_update_main_frame_event;
|
2018-05-28 11:03:29 -06:00
|
|
|
void Host_Message(HostMessageID id)
|
2010-03-16 07:18:52 -06:00
|
|
|
{
|
2018-05-28 11:03:29 -06:00
|
|
|
if (id == HostMessageID::WMUserStop)
|
2018-10-23 23:50:54 -06:00
|
|
|
s_platform->Stop();
|
2010-03-16 07:18:52 -06:00
|
|
|
}
|
2008-09-07 14:26:38 -06:00
|
|
|
|
2014-08-05 22:44:21 -06:00
|
|
|
void Host_UpdateTitle(const std::string& title)
|
|
|
|
{
|
2018-10-23 23:50:54 -06:00
|
|
|
s_platform->SetTitle(title);
|
2014-08-05 22:44:21 -06:00
|
|
|
}
|
2010-04-18 21:06:18 -06:00
|
|
|
|
2008-09-07 14:26:38 -06:00
|
|
|
void Host_UpdateDisasmDialog()
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2008-09-07 14:26:38 -06:00
|
|
|
}
|
|
|
|
|
2008-09-07 15:06:55 -06:00
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
2018-10-23 23:50:54 -06:00
|
|
|
s_update_main_frame_event.Set();
|
2008-09-07 15:06:55 -06:00
|
|
|
}
|
2008-09-07 14:26:38 -06:00
|
|
|
|
2011-01-25 05:52:20 -07:00
|
|
|
void Host_RequestRenderWindowSize(int width, int height)
|
|
|
|
{
|
|
|
|
}
|
2014-07-16 07:53:33 -06:00
|
|
|
|
2010-04-11 19:33:10 -06:00
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
2018-10-23 23:50:54 -06:00
|
|
|
return s_platform->IsWindowFocused();
|
2010-04-11 19:33:10 -06:00
|
|
|
}
|
2008-09-07 14:26:38 -06:00
|
|
|
|
2021-05-09 04:28:04 -06:00
|
|
|
bool Host_RendererHasFullFocus()
|
|
|
|
{
|
|
|
|
// Mouse capturing isn't implemented
|
|
|
|
return Host_RendererHasFocus();
|
|
|
|
}
|
|
|
|
|
2015-01-04 09:09:56 -07:00
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
2018-10-23 23:50:54 -06:00
|
|
|
return s_platform->IsWindowFullscreen();
|
2015-01-04 09:09:56 -07:00
|
|
|
}
|
|
|
|
|
2016-11-10 09:55:21 -07:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-13 19:31:31 -07:00
|
|
|
void Host_TitleChanged()
|
|
|
|
{
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
Discord::UpdateDiscordPresence();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-07-04 05:09:46 -06:00
|
|
|
std::unique_ptr<GBAHostInterface> Host_CreateGBAHost(std::weak_ptr<HW::GBA::Core> core)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
static std::unique_ptr<Platform> GetPlatform(const optparse::Values& options)
|
2014-08-05 22:34:31 -06:00
|
|
|
{
|
2018-10-23 23:50:54 -06:00
|
|
|
std::string platform_name = static_cast<const char*>(options.get("platform"));
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
#if HAVE_X11
|
|
|
|
if (platform_name == "x11" || platform_name.empty())
|
|
|
|
return Platform::CreateX11Platform();
|
2010-04-21 22:28:34 -06:00
|
|
|
#endif
|
2010-11-24 19:26:46 -07:00
|
|
|
|
2019-04-10 08:44:21 -06:00
|
|
|
#ifdef __linux__
|
|
|
|
if (platform_name == "fbdev" || platform_name.empty())
|
|
|
|
return Platform::CreateFBDevPlatform();
|
|
|
|
#endif
|
|
|
|
|
2019-11-25 21:25:19 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (platform_name == "win32" || platform_name.empty())
|
|
|
|
return Platform::CreateWin32Platform();
|
|
|
|
#endif
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
if (platform_name == "headless" || platform_name.empty())
|
|
|
|
return Platform::CreateHeadlessPlatform();
|
2009-01-12 13:52:45 -07:00
|
|
|
|
2014-08-05 22:34:31 -06:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-08 00:22:35 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define main app_main
|
|
|
|
#endif
|
|
|
|
|
2014-08-05 22:34:31 -06:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2016-01-17 04:13:09 -07:00
|
|
|
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::OmitGUIOptions);
|
2018-10-23 23:50:54 -06:00
|
|
|
parser->add_option("-p", "--platform")
|
|
|
|
.action("store")
|
|
|
|
.help("Window platform to use [%choices]")
|
|
|
|
.choices({
|
|
|
|
"headless"
|
2019-04-10 08:44:21 -06:00
|
|
|
#ifdef __linux__
|
|
|
|
,
|
|
|
|
"fbdev"
|
|
|
|
#endif
|
2018-10-23 23:50:54 -06:00
|
|
|
#if HAVE_X11
|
|
|
|
,
|
|
|
|
"x11"
|
2019-11-25 21:25:19 -07:00
|
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
|
|
,
|
|
|
|
"win32"
|
2018-10-23 23:50:54 -06:00
|
|
|
#endif
|
|
|
|
});
|
|
|
|
|
2016-01-17 04:13:09 -07:00
|
|
|
optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
|
|
|
|
std::vector<std::string> args = parser->args();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2020-05-06 21:10:30 -06:00
|
|
|
std::optional<std::string> save_state_path;
|
|
|
|
if (options.is_set("save_state"))
|
|
|
|
{
|
|
|
|
save_state_path = static_cast<const char*>(options.get("save_state"));
|
|
|
|
}
|
|
|
|
|
2017-10-01 16:09:07 -06:00
|
|
|
std::unique_ptr<BootParameters> boot;
|
2020-05-06 21:10:30 -06:00
|
|
|
bool game_specified = false;
|
2016-01-17 04:13:09 -07:00
|
|
|
if (options.is_set("exec"))
|
2011-01-15 03:33:07 -07:00
|
|
|
{
|
2018-11-05 11:20:45 -07:00
|
|
|
const std::list<std::string> paths_list = options.all("exec");
|
|
|
|
const std::vector<std::string> paths{std::make_move_iterator(std::begin(paths_list)),
|
|
|
|
std::make_move_iterator(std::end(paths_list))};
|
2021-11-20 11:38:09 -07:00
|
|
|
boot = BootParameters::GenerateFromFile(
|
|
|
|
paths, BootSessionData(save_state_path, DeleteSavestateAfterBoot::No));
|
2020-05-06 21:10:30 -06:00
|
|
|
game_specified = true;
|
2017-10-01 16:09:07 -06:00
|
|
|
}
|
|
|
|
else if (options.is_set("nand_title"))
|
|
|
|
{
|
|
|
|
const std::string hex_string = static_cast<const char*>(options.get("nand_title"));
|
|
|
|
if (hex_string.length() != 16)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Invalid title ID\n");
|
|
|
|
parser->print_help();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const u64 title_id = std::stoull(hex_string, nullptr, 16);
|
|
|
|
boot = std::make_unique<BootParameters>(BootParameters::NANDTitle{title_id});
|
2011-01-15 03:33:07 -07:00
|
|
|
}
|
2016-01-17 04:13:09 -07:00
|
|
|
else if (args.size())
|
2011-01-15 03:33:07 -07:00
|
|
|
{
|
2021-11-20 11:38:09 -07:00
|
|
|
boot = BootParameters::GenerateFromFile(
|
|
|
|
args.front(), BootSessionData(save_state_path, DeleteSavestateAfterBoot::No));
|
2016-01-17 04:13:09 -07:00
|
|
|
args.erase(args.begin());
|
2020-05-06 21:10:30 -06:00
|
|
|
game_specified = true;
|
2016-01-17 04:13:09 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parser->print_help();
|
|
|
|
return 0;
|
2008-09-07 15:02:57 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-28 12:36:11 -07:00
|
|
|
std::string user_directory;
|
|
|
|
if (options.is_set("user"))
|
|
|
|
user_directory = static_cast<const char*>(options.get("user"));
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
UICommon::SetUserDirectory(user_directory);
|
|
|
|
UICommon::Init();
|
2022-03-08 14:16:54 -07:00
|
|
|
GCAdapter::Init();
|
2018-10-23 23:50:54 -06:00
|
|
|
|
|
|
|
s_platform = GetPlatform(options);
|
|
|
|
if (!s_platform || !s_platform->Init())
|
2014-08-05 22:34:31 -06:00
|
|
|
{
|
2018-10-23 23:50:54 -06:00
|
|
|
fprintf(stderr, "No platform found, or failed to initialize.\n");
|
2014-08-05 22:34:31 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2020-05-06 21:10:30 -06:00
|
|
|
if (save_state_path && !game_specified)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "A save state cannot be loaded without specifying a game to launch.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-12-31 05:03:20 -07:00
|
|
|
Core::AddOnStateChangedCallback([](Core::State state) {
|
2017-09-04 11:57:42 -06:00
|
|
|
if (state == Core::State::Uninitialized)
|
2018-10-23 23:50:54 -06:00
|
|
|
s_platform->Stop();
|
2017-09-04 11:57:42 -06:00
|
|
|
});
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2019-11-25 21:25:19 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
#else
|
2016-09-24 13:17:34 -06:00
|
|
|
// Shut down cleanly on SIGINT and SIGTERM
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = signal_handler;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_RESETHAND;
|
|
|
|
sigaction(SIGINT, &sa, nullptr);
|
|
|
|
sigaction(SIGTERM, &sa, nullptr);
|
2019-11-25 21:25:19 -07:00
|
|
|
#endif
|
2016-09-24 13:17:34 -06:00
|
|
|
|
2019-06-23 11:26:07 -06:00
|
|
|
DolphinAnalytics::Instance().ReportDolphinStart("nogui");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
if (!BootManager::BootCore(std::move(boot), s_platform->GetWindowSystemInfo()))
|
2014-08-05 22:34:31 -06:00
|
|
|
{
|
2017-10-01 16:09:07 -06:00
|
|
|
fprintf(stderr, "Could not boot the specified file\n");
|
2014-08-05 22:34:31 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2018-06-08 14:56:11 -06:00
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
Discord::UpdateDiscordPresence();
|
|
|
|
#endif
|
|
|
|
|
2018-10-23 23:50:54 -06:00
|
|
|
s_platform->MainLoop();
|
2014-08-05 22:34:31 -06:00
|
|
|
Core::Stop();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-06 06:52:09 -06:00
|
|
|
Core::Shutdown();
|
2018-10-23 23:50:54 -06:00
|
|
|
s_platform.reset();
|
2014-10-04 13:12:15 -06:00
|
|
|
UICommon::Shutdown();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2011-01-15 03:33:07 -07:00
|
|
|
return 0;
|
2008-09-07 14:26:38 -06:00
|
|
|
}
|
2022-03-08 00:22:35 -07:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
int wmain(int, wchar_t*[], wchar_t*[])
|
|
|
|
{
|
|
|
|
std::vector<std::string> args = CommandLineToUtf8Argv(GetCommandLineW());
|
|
|
|
const int argc = static_cast<int>(args.size());
|
|
|
|
std::vector<char*> argv(args.size());
|
|
|
|
for (size_t i = 0; i < args.size(); ++i)
|
|
|
|
argv[i] = args[i].data();
|
|
|
|
|
|
|
|
return main(argc, argv.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef main
|
|
|
|
#endif
|