2013-01-11 09:23:08 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
2019-10-19 15:10:19 +00:00
|
|
|
* Copyright 2020 Ben Vanik. All rights reserved. *
|
2013-01-11 09:23:08 +00:00
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
#include "xenia/app/discord/discord_presence.h"
|
2015-07-17 08:15:12 +00:00
|
|
|
#include "xenia/app/emulator_window.h"
|
2019-04-17 19:49:29 +00:00
|
|
|
#include "xenia/base/cvar.h"
|
2016-06-19 01:42:28 +00:00
|
|
|
#include "xenia/base/debugging.h"
|
2015-05-02 10:42:51 +00:00
|
|
|
#include "xenia/base/logging.h"
|
|
|
|
#include "xenia/base/main.h"
|
2015-11-07 19:25:53 +00:00
|
|
|
#include "xenia/base/profiling.h"
|
2016-06-19 01:42:28 +00:00
|
|
|
#include "xenia/base/threading.h"
|
2019-04-17 19:49:47 +00:00
|
|
|
#include "xenia/config.h"
|
2015-09-21 04:31:05 +00:00
|
|
|
#include "xenia/debug/ui/debug_window.h"
|
2015-02-01 06:49:47 +00:00
|
|
|
#include "xenia/emulator.h"
|
2015-06-27 03:27:36 +00:00
|
|
|
#include "xenia/ui/file_picker.h"
|
2018-05-23 09:33:39 +00:00
|
|
|
#include "xenia/vfs/devices/host_path_device.h"
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2015-11-08 23:02:24 +00:00
|
|
|
// Available audio systems:
|
|
|
|
#include "xenia/apu/nop/nop_audio_system.h"
|
2019-10-27 23:18:43 +00:00
|
|
|
#include "xenia/apu/sdl/sdl_audio_system.h"
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/apu/xaudio2/xaudio2_audio_system.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
|
|
|
|
// Available graphics systems:
|
2016-08-04 14:50:13 +00:00
|
|
|
#include "xenia/gpu/null/null_graphics_system.h"
|
2016-02-21 03:02:28 +00:00
|
|
|
#include "xenia/gpu/vulkan/vulkan_graphics_system.h"
|
2018-07-18 09:02:00 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/gpu/d3d12/d3d12_graphics_system.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
2015-11-08 23:02:24 +00:00
|
|
|
|
|
|
|
// Available input drivers:
|
|
|
|
#include "xenia/hid/nop/nop_hid.h"
|
2019-10-19 15:10:19 +00:00
|
|
|
#include "xenia/hid/sdl/sdl_hid.h"
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/hid/winkey/winkey_hid.h"
|
|
|
|
#include "xenia/hid/xinput/xinput_hid.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
#include "third_party/fmt/include/fmt/format.h"
|
2019-04-17 19:49:29 +00:00
|
|
|
#include "third_party/xbyak/xbyak/xbyak_util.h"
|
|
|
|
|
2019-10-27 23:18:43 +00:00
|
|
|
DEFINE_string(apu, "any", "Audio system. Use: [any, nop, sdl, xaudio2]", "APU");
|
2020-08-22 20:31:52 +00:00
|
|
|
DEFINE_string(gpu, "any", "Graphics system. Use: [any, d3d12, vulkan, null]",
|
|
|
|
"GPU");
|
2019-10-19 15:10:19 +00:00
|
|
|
DEFINE_string(hid, "any", "Input system. Use: [any, nop, sdl, winkey, xinput]",
|
2019-08-04 03:53:58 +00:00
|
|
|
"HID");
|
2015-11-08 23:02:24 +00:00
|
|
|
|
2019-08-04 03:53:58 +00:00
|
|
|
DEFINE_bool(fullscreen, false, "Toggles fullscreen", "GPU");
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_path(
|
2020-03-13 06:42:29 +00:00
|
|
|
storage_root, "",
|
|
|
|
"Root path for persistent internal data storage (config, etc.), or empty "
|
|
|
|
"to use the path preferred for the OS, such as the documents folder, or "
|
|
|
|
"the emulator executable directory if portable.txt is present in it.",
|
|
|
|
"Storage");
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_path(
|
2020-03-13 06:42:29 +00:00
|
|
|
content_root, "",
|
|
|
|
"Root path for guest content storage (saves, etc.), or empty to use the "
|
|
|
|
"content folder under the storage root.",
|
|
|
|
"Storage");
|
2020-12-07 19:23:54 +00:00
|
|
|
DEFINE_path(
|
|
|
|
cache_root, "",
|
|
|
|
"Root path for files used to speed up certain parts of the emulator or the "
|
|
|
|
"game. These files may be persistent, but they can be deleted without "
|
|
|
|
"major side effects such as progress loss. If empty, the cache folder "
|
|
|
|
"under the storage root, or, if available, the cache directory preferred "
|
|
|
|
"for the OS, will be used.",
|
|
|
|
"Storage");
|
2018-11-22 00:04:43 +00:00
|
|
|
|
2019-08-04 03:53:58 +00:00
|
|
|
DEFINE_bool(mount_scratch, false, "Enable scratch mount", "Storage");
|
|
|
|
DEFINE_bool(mount_cache, false, "Enable cache mount", "Storage");
|
2019-04-17 19:49:29 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_transient_path(target, "",
|
|
|
|
"Specifies the target .xex or .iso to execute.",
|
|
|
|
"General");
|
2020-08-07 21:04:53 +00:00
|
|
|
DEFINE_transient_bool(portable, false,
|
|
|
|
"Specifies if Xenia should run in portable mode.",
|
|
|
|
"General");
|
|
|
|
|
2019-04-17 19:49:29 +00:00
|
|
|
DECLARE_bool(debug);
|
2018-05-23 09:33:39 +00:00
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
DEFINE_bool(discord, true, "Enable Discord rich presence", "General");
|
|
|
|
|
2014-12-21 06:17:57 +00:00
|
|
|
namespace xe {
|
2015-07-17 08:15:12 +00:00
|
|
|
namespace app {
|
2014-12-21 06:17:57 +00:00
|
|
|
|
2019-08-03 22:01:34 +00:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
class Factory {
|
|
|
|
private:
|
|
|
|
struct Creator {
|
|
|
|
std::string name;
|
|
|
|
std::function<bool()> is_available;
|
|
|
|
std::function<std::unique_ptr<T>(Args...)> instantiate;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Creator> creators_;
|
|
|
|
|
|
|
|
public:
|
2020-03-02 15:37:11 +00:00
|
|
|
void Add(const std::string_view name, std::function<bool()> is_available,
|
2019-08-03 22:01:34 +00:00
|
|
|
std::function<std::unique_ptr<T>(Args...)> instantiate) {
|
2020-03-02 15:37:11 +00:00
|
|
|
creators_.push_back({std::string(name), is_available, instantiate});
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
void Add(const std::string_view name,
|
2019-08-03 22:01:34 +00:00
|
|
|
std::function<std::unique_ptr<T>(Args...)> instantiate) {
|
2020-02-22 19:50:17 +00:00
|
|
|
auto always_available = []() { return true; };
|
2020-02-22 19:23:03 +00:00
|
|
|
Add(name, always_available, instantiate);
|
2019-08-03 21:42:38 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 22:01:34 +00:00
|
|
|
template <typename DT>
|
2020-03-02 15:37:11 +00:00
|
|
|
void Add(const std::string_view name) {
|
2019-08-03 22:01:34 +00:00
|
|
|
Add(name, DT::IsAvailable, [](Args... args) {
|
2019-08-04 01:46:03 +00:00
|
|
|
return std::make_unique<DT>(std::forward<Args>(args)...);
|
2019-08-03 22:01:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
std::unique_ptr<T> Create(const std::string_view name, Args... args) {
|
2019-08-03 21:42:38 +00:00
|
|
|
if (!name.empty() && name != "any") {
|
|
|
|
auto it = std::find_if(
|
2019-08-03 22:01:34 +00:00
|
|
|
creators_.cbegin(), creators_.cend(),
|
2019-08-03 21:42:38 +00:00
|
|
|
[&name](const auto& f) { return name.compare(f.name) == 0; });
|
2019-08-03 22:01:34 +00:00
|
|
|
if (it != creators_.cend() && (*it).is_available()) {
|
|
|
|
return (*it).instantiate(std::forward<Args>(args)...);
|
2019-08-03 21:42:38 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
} else {
|
2019-08-03 22:01:34 +00:00
|
|
|
for (const auto& creator : creators_) {
|
|
|
|
if (!creator.is_available()) continue;
|
|
|
|
auto instance = creator.instantiate(std::forward<Args>(args)...);
|
|
|
|
if (!instance) continue;
|
|
|
|
return instance;
|
2019-08-03 21:42:38 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 22:01:34 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
std::vector<std::unique_ptr<T>> CreateAll(const std::string_view name,
|
2019-08-03 22:01:34 +00:00
|
|
|
Args... args) {
|
|
|
|
std::vector<std::unique_ptr<T>> instances;
|
|
|
|
if (!name.empty() && name != "any") {
|
|
|
|
auto it = std::find_if(
|
|
|
|
creators_.cbegin(), creators_.cend(),
|
|
|
|
[&name](const auto& f) { return name.compare(f.name) == 0; });
|
|
|
|
if (it != creators_.cend() && (*it).is_available()) {
|
|
|
|
auto instance = (*it).instantiate(std::forward<Args>(args)...);
|
|
|
|
if (instance) {
|
2019-08-04 01:07:19 +00:00
|
|
|
instances.emplace_back(std::move(instance));
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const auto& creator : creators_) {
|
|
|
|
if (!creator.is_available()) continue;
|
|
|
|
auto instance = creator.instantiate(std::forward<Args>(args)...);
|
|
|
|
if (instance) {
|
2019-08-04 01:07:19 +00:00
|
|
|
instances.emplace_back(std::move(instance));
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return instances;
|
|
|
|
}
|
2019-08-03 21:42:38 +00:00
|
|
|
};
|
|
|
|
|
2015-11-08 23:02:24 +00:00
|
|
|
std::unique_ptr<apu::AudioSystem> CreateAudioSystem(cpu::Processor* processor) {
|
2019-08-03 23:10:49 +00:00
|
|
|
Factory<apu::AudioSystem, cpu::Processor*> factory;
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<apu::xaudio2::XAudio2AudioSystem>("xaudio2");
|
2015-11-08 23:02:24 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
2019-10-27 23:18:43 +00:00
|
|
|
factory.Add<apu::sdl::SDLAudioSystem>("sdl");
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<apu::nop::NopAudioSystem>("nop");
|
2019-08-03 22:01:34 +00:00
|
|
|
return factory.Create(cvars::apu, processor);
|
2015-11-08 23:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<gpu::GraphicsSystem> CreateGraphicsSystem() {
|
2019-08-03 23:10:49 +00:00
|
|
|
Factory<gpu::GraphicsSystem> factory;
|
2018-07-18 09:02:00 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<gpu::d3d12::D3D12GraphicsSystem>("d3d12");
|
2018-07-18 09:02:00 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<gpu::vulkan::VulkanGraphicsSystem>("vulkan");
|
|
|
|
factory.Add<gpu::null::NullGraphicsSystem>("null");
|
2019-08-03 22:01:34 +00:00
|
|
|
return factory.Create(cvars::gpu);
|
2015-11-08 23:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<hid::InputDriver>> CreateInputDrivers(
|
|
|
|
ui::Window* window) {
|
2019-08-04 01:07:19 +00:00
|
|
|
std::vector<std::unique_ptr<hid::InputDriver>> drivers;
|
|
|
|
if (cvars::hid.compare("nop") == 0) {
|
|
|
|
drivers.emplace_back(xe::hid::nop::Create(window));
|
|
|
|
} else {
|
|
|
|
Factory<hid::InputDriver, ui::Window*> factory;
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-04 01:07:19 +00:00
|
|
|
factory.Add("xinput", xe::hid::xinput::Create);
|
2020-11-28 16:01:26 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
factory.Add("sdl", xe::hid::sdl::Create);
|
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-04 01:47:39 +00:00
|
|
|
// WinKey input driver should always be the last input driver added!
|
|
|
|
factory.Add("winkey", xe::hid::winkey::Create);
|
2015-11-08 23:02:24 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
2019-08-04 01:07:19 +00:00
|
|
|
for (auto& driver : factory.CreateAll(cvars::hid, window)) {
|
|
|
|
if (XSUCCEEDED(driver->Setup())) {
|
|
|
|
drivers.emplace_back(std::move(driver));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (drivers.empty()) {
|
|
|
|
// Fallback to nop if none created.
|
|
|
|
drivers.emplace_back(xe::hid::nop::Create(window));
|
2015-11-08 23:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return drivers;
|
|
|
|
}
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
int xenia_main(const std::vector<std::string>& args) {
|
2014-05-28 20:59:43 +00:00
|
|
|
Profiler::Initialize();
|
2014-05-28 05:54:40 +00:00
|
|
|
Profiler::ThreadEnter("main");
|
|
|
|
|
2020-03-13 06:42:29 +00:00
|
|
|
// Figure out where internal files and content should go.
|
2020-03-02 15:37:11 +00:00
|
|
|
std::filesystem::path storage_root = cvars::storage_root;
|
2020-03-13 06:42:29 +00:00
|
|
|
if (storage_root.empty()) {
|
|
|
|
storage_root = xe::filesystem::GetExecutableFolder();
|
2020-08-07 21:04:53 +00:00
|
|
|
if (!cvars::portable &&
|
|
|
|
!std::filesystem::exists(storage_root / "portable.txt")) {
|
2020-03-13 06:42:29 +00:00
|
|
|
storage_root = xe::filesystem::GetUserFolder();
|
2020-11-21 13:26:26 +00:00
|
|
|
#if defined(XE_PLATFORM_WIN32) || defined(XE_PLATFORM_GNU_LINUX)
|
2020-03-02 15:37:11 +00:00
|
|
|
storage_root = storage_root / "Xenia";
|
2018-11-22 00:04:43 +00:00
|
|
|
#else
|
2020-12-07 19:23:54 +00:00
|
|
|
// TODO(Triang3l): Point to the app's external storage "files" directory
|
|
|
|
// on Android.
|
2020-03-13 06:42:29 +00:00
|
|
|
#warning Unhandled platform for the data root.
|
2020-03-02 15:37:11 +00:00
|
|
|
storage_root = storage_root / "Xenia";
|
2018-11-22 00:04:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 15:37:11 +00:00
|
|
|
storage_root = std::filesystem::absolute(storage_root);
|
2020-02-28 20:30:48 +00:00
|
|
|
XELOGI("Storage root: {}", xe::path_to_utf8(storage_root));
|
2019-04-17 19:49:47 +00:00
|
|
|
|
2020-03-13 06:42:29 +00:00
|
|
|
config::SetupConfig(storage_root);
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
std::filesystem::path content_root = cvars::content_root;
|
2020-03-13 06:42:29 +00:00
|
|
|
if (content_root.empty()) {
|
2020-03-02 15:37:11 +00:00
|
|
|
content_root = storage_root / "content";
|
2020-04-12 21:06:17 +00:00
|
|
|
} else {
|
|
|
|
// If content root isn't an absolute path, then it should be relative to the
|
|
|
|
// storage root.
|
|
|
|
if (!content_root.is_absolute()) {
|
|
|
|
content_root = storage_root / content_root;
|
|
|
|
}
|
2020-03-13 06:42:29 +00:00
|
|
|
}
|
2020-03-02 15:37:11 +00:00
|
|
|
content_root = std::filesystem::absolute(content_root);
|
2020-02-28 20:30:48 +00:00
|
|
|
XELOGI("Content root: {}", xe::path_to_utf8(content_root));
|
2018-11-22 00:04:43 +00:00
|
|
|
|
2020-12-07 19:23:54 +00:00
|
|
|
std::filesystem::path cache_root = cvars::cache_root;
|
|
|
|
if (cache_root.empty()) {
|
|
|
|
cache_root = storage_root / "cache";
|
|
|
|
// TODO(Triang3l): Point to the app's external storage "cache" directory on
|
|
|
|
// Android.
|
|
|
|
} else {
|
|
|
|
// If content root isn't an absolute path, then it should be relative to the
|
|
|
|
// storage root.
|
|
|
|
if (!cache_root.is_absolute()) {
|
|
|
|
cache_root = storage_root / cache_root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache_root = std::filesystem::absolute(cache_root);
|
|
|
|
XELOGI("Cache root: {}", xe::path_to_utf8(cache_root));
|
|
|
|
|
2019-09-08 21:02:04 +00:00
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::Initialize();
|
|
|
|
discord::DiscordPresence::NotPlaying();
|
|
|
|
}
|
|
|
|
|
2015-07-13 05:03:47 +00:00
|
|
|
// Create the emulator but don't initialize so we can setup the window.
|
2020-12-07 19:23:54 +00:00
|
|
|
auto emulator =
|
|
|
|
std::make_unique<Emulator>("", storage_root, content_root, cache_root);
|
2015-07-13 05:03:47 +00:00
|
|
|
|
|
|
|
// Main emulator display window.
|
|
|
|
auto emulator_window = EmulatorWindow::Create(emulator.get());
|
|
|
|
|
|
|
|
// Setup and initialize all subsystems. If we can't do something
|
|
|
|
// (unsupported system, memory issues, etc) this will fail early.
|
2015-11-08 23:02:24 +00:00
|
|
|
X_STATUS result =
|
|
|
|
emulator->Setup(emulator_window->window(), CreateAudioSystem,
|
|
|
|
CreateGraphicsSystem, CreateInputDrivers);
|
2013-10-24 03:42:24 +00:00
|
|
|
if (XFAILED(result)) {
|
2020-02-28 20:30:48 +00:00
|
|
|
XELOGE("Failed to setup emulator: {:08X}", result);
|
2014-08-17 00:58:33 +00:00
|
|
|
return 1;
|
2013-02-01 13:37:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::mount_scratch) {
|
2018-05-23 09:33:39 +00:00
|
|
|
auto scratch_device = std::make_unique<xe::vfs::HostPathDevice>(
|
2020-03-02 15:37:11 +00:00
|
|
|
"\\SCRATCH", "scratch", false);
|
2018-05-23 09:33:39 +00:00
|
|
|
if (!scratch_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan scratch path");
|
|
|
|
} else {
|
|
|
|
if (!emulator->file_system()->RegisterDevice(std::move(scratch_device))) {
|
|
|
|
XELOGE("Unable to register scratch path");
|
|
|
|
} else {
|
|
|
|
emulator->file_system()->RegisterSymbolicLink("scratch:", "\\SCRATCH");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::mount_cache) {
|
2018-05-23 09:33:39 +00:00
|
|
|
auto cache0_device =
|
2020-03-02 15:37:11 +00:00
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE0", "cache0", false);
|
2018-05-23 09:33:39 +00:00
|
|
|
if (!cache0_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan cache0 path");
|
|
|
|
} else {
|
|
|
|
if (!emulator->file_system()->RegisterDevice(std::move(cache0_device))) {
|
|
|
|
XELOGE("Unable to register cache0 path");
|
|
|
|
} else {
|
|
|
|
emulator->file_system()->RegisterSymbolicLink("cache0:", "\\CACHE0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cache1_device =
|
2020-03-02 15:37:11 +00:00
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE1", "cache1", false);
|
2018-05-23 09:33:39 +00:00
|
|
|
if (!cache1_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan cache1 path");
|
|
|
|
} else {
|
|
|
|
if (!emulator->file_system()->RegisterDevice(std::move(cache1_device))) {
|
|
|
|
XELOGE("Unable to register cache1 path");
|
|
|
|
} else {
|
|
|
|
emulator->file_system()->RegisterSymbolicLink("cache1:", "\\CACHE1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 04:31:05 +00:00
|
|
|
// Set a debug handler.
|
|
|
|
// This will respond to debugging requests so we can open the debug UI.
|
|
|
|
std::unique_ptr<xe::debug::ui::DebugWindow> debug_window;
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::debug) {
|
2017-12-15 02:35:44 +00:00
|
|
|
emulator->processor()->set_debug_listener_request_handler(
|
|
|
|
[&](xe::cpu::Processor* processor) {
|
|
|
|
if (debug_window) {
|
|
|
|
return debug_window.get();
|
|
|
|
}
|
|
|
|
emulator_window->loop()->PostSynchronous([&]() {
|
|
|
|
debug_window = xe::debug::ui::DebugWindow::Create(
|
|
|
|
emulator.get(), emulator_window->loop());
|
|
|
|
debug_window->window()->on_closed.AddListener(
|
|
|
|
[&](xe::ui::UIEvent* e) {
|
|
|
|
emulator->processor()->set_debug_listener(nullptr);
|
|
|
|
emulator_window->loop()->Post(
|
|
|
|
[&]() { debug_window.reset(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return debug_window.get();
|
2015-09-21 04:31:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-19 01:42:28 +00:00
|
|
|
auto evt = xe::threading::Event::CreateAutoResetEvent(false);
|
2019-08-03 13:12:37 +00:00
|
|
|
emulator->on_launch.AddListener([&](auto title_id, const auto& game_title) {
|
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::PlayingTitle(
|
2020-03-02 15:37:11 +00:00
|
|
|
game_title.empty() ? "Unknown Title" : std::string(game_title));
|
2019-08-03 13:12:37 +00:00
|
|
|
}
|
2016-06-19 01:42:28 +00:00
|
|
|
emulator_window->UpdateTitle();
|
|
|
|
evt->Set();
|
|
|
|
});
|
|
|
|
|
2020-03-21 16:21:00 +00:00
|
|
|
emulator->on_shader_storage_initialization.AddListener(
|
|
|
|
[&](bool initializing) {
|
|
|
|
emulator_window->SetInitializingShaderStorage(initializing);
|
|
|
|
});
|
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
emulator->on_terminate.AddListener([&]() {
|
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::NotPlaying();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-28 21:05:10 +00:00
|
|
|
emulator_window->window()->on_closing.AddListener([&](ui::UIEvent* e) {
|
|
|
|
// This needs to shut down before the graphics context.
|
|
|
|
Profiler::Shutdown();
|
|
|
|
});
|
|
|
|
|
2016-06-19 01:42:28 +00:00
|
|
|
bool exiting = false;
|
|
|
|
emulator_window->loop()->on_quit.AddListener([&](ui::UIEvent* e) {
|
|
|
|
exiting = true;
|
|
|
|
evt->Set();
|
2017-12-17 18:37:58 +00:00
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::Shutdown();
|
|
|
|
}
|
|
|
|
|
2017-12-19 00:15:19 +00:00
|
|
|
// TODO(DrChat): Remove this code and do a proper exit.
|
2017-12-17 18:37:58 +00:00
|
|
|
XELOGI("Cheap-skate exit!");
|
|
|
|
exit(0);
|
2016-06-19 01:42:28 +00:00
|
|
|
});
|
|
|
|
|
2017-07-01 19:36:16 +00:00
|
|
|
// Enable the main menu now that the emulator is properly loaded
|
|
|
|
emulator_window->window()->EnableMainMenu();
|
|
|
|
|
2014-12-21 06:17:57 +00:00
|
|
|
// Grab path from the flag or unnamed argument.
|
2020-03-02 15:37:11 +00:00
|
|
|
std::filesystem::path path;
|
2019-04-17 19:49:29 +00:00
|
|
|
if (!cvars::target.empty()) {
|
2020-03-02 15:37:11 +00:00
|
|
|
path = cvars::target;
|
2015-06-27 03:27:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 19:35:49 +00:00
|
|
|
// Toggles fullscreen
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::fullscreen) emulator_window->ToggleFullscreen();
|
2016-12-06 19:35:49 +00:00
|
|
|
|
2015-06-27 03:27:36 +00:00
|
|
|
if (!path.empty()) {
|
2014-12-21 06:17:57 +00:00
|
|
|
// Normalize the path and make absolute.
|
2020-03-02 15:37:11 +00:00
|
|
|
auto abs_path = std::filesystem::absolute(path);
|
2016-06-19 01:42:28 +00:00
|
|
|
result = emulator->LaunchPath(abs_path);
|
2014-12-21 06:17:57 +00:00
|
|
|
if (XFAILED(result)) {
|
2020-03-02 15:37:11 +00:00
|
|
|
xe::FatalError(fmt::format("Failed to launch target: {:08X}", result));
|
2015-07-25 19:56:37 +00:00
|
|
|
emulator.reset();
|
|
|
|
emulator_window.reset();
|
2014-12-21 06:17:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-06-19 01:42:28 +00:00
|
|
|
}
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2016-06-19 01:42:28 +00:00
|
|
|
// Now, we're going to use the main thread to drive events related to
|
|
|
|
// emulation.
|
|
|
|
while (!exiting) {
|
|
|
|
xe::threading::Wait(evt.get(), false);
|
2016-06-19 02:00:01 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
emulator->WaitUntilExit();
|
|
|
|
if (emulator->TitleRequested()) {
|
|
|
|
emulator->LaunchNextTitle();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-20 15:47:06 +00:00
|
|
|
}
|
2014-12-21 06:17:57 +00:00
|
|
|
|
2015-09-21 04:31:05 +00:00
|
|
|
debug_window.reset();
|
2014-08-17 00:58:33 +00:00
|
|
|
emulator.reset();
|
2015-07-13 05:03:47 +00:00
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::Shutdown();
|
|
|
|
}
|
|
|
|
|
2014-05-28 05:54:40 +00:00
|
|
|
Profiler::Dump();
|
|
|
|
Profiler::Shutdown();
|
2017-12-17 20:43:52 +00:00
|
|
|
emulator_window.reset();
|
2014-08-17 00:58:33 +00:00
|
|
|
return 0;
|
2013-01-11 09:23:08 +00:00
|
|
|
}
|
2014-08-16 23:34:04 +00:00
|
|
|
|
2015-07-17 08:15:12 +00:00
|
|
|
} // namespace app
|
2014-12-21 06:17:57 +00:00
|
|
|
} // namespace xe
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_ENTRY_POINT("xenia", xe::app::xenia_main, "[Path to .iso/.xex]",
|
2019-08-24 11:23:25 +00:00
|
|
|
"target");
|