2013-01-11 09:23:08 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2013-01-24 05:31:23 +00:00
|
|
|
#include <gflags/gflags.h>
|
2015-05-02 10:42:51 +00:00
|
|
|
|
2015-07-17 08:15:12 +00:00
|
|
|
#include "xenia/app/emulator_window.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"
|
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"
|
|
|
|
#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"
|
2015-11-08 23:02:24 +00:00
|
|
|
|
|
|
|
// Available input drivers:
|
|
|
|
#include "xenia/hid/nop/nop_hid.h"
|
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/hid/winkey/winkey_hid.h"
|
|
|
|
#include "xenia/hid/xinput/xinput_hid.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
|
|
|
|
DEFINE_string(apu, "any", "Audio system. Use: [any, nop, xaudio2]");
|
2018-05-04 16:54:33 +00:00
|
|
|
DEFINE_string(gpu, "any", "Graphics system. Use: [any, vulkan, null]");
|
2015-11-08 23:02:24 +00:00
|
|
|
DEFINE_string(hid, "any", "Input system. Use: [any, nop, winkey, xinput]");
|
|
|
|
|
2014-08-16 23:34:04 +00:00
|
|
|
DEFINE_string(target, "", "Specifies the target .xex or .iso to execute.");
|
2016-12-06 19:35:49 +00:00
|
|
|
DEFINE_bool(fullscreen, false, "Toggles fullscreen");
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2018-05-23 09:33:39 +00:00
|
|
|
DEFINE_bool(mount_scratch, false, "Enable scratch mount");
|
|
|
|
DEFINE_bool(mount_cache, false, "Enable cache mount");
|
|
|
|
|
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
|
|
|
|
2015-11-08 23:02:24 +00:00
|
|
|
std::unique_ptr<apu::AudioSystem> CreateAudioSystem(cpu::Processor* processor) {
|
|
|
|
if (FLAGS_apu.compare("nop") == 0) {
|
|
|
|
return apu::nop::NopAudioSystem::Create(processor);
|
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
} else if (FLAGS_apu.compare("xaudio2") == 0) {
|
|
|
|
return apu::xaudio2::XAudio2AudioSystem::Create(processor);
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
} else {
|
|
|
|
// Create best available.
|
|
|
|
std::unique_ptr<apu::AudioSystem> best;
|
|
|
|
|
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
best = apu::xaudio2::XAudio2AudioSystem::Create(processor);
|
|
|
|
if (best) {
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
|
|
|
|
// Fallback to nop.
|
|
|
|
return apu::nop::NopAudioSystem::Create(processor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<gpu::GraphicsSystem> CreateGraphicsSystem() {
|
2018-05-04 16:54:33 +00:00
|
|
|
if (FLAGS_gpu.compare("vulkan") == 0) {
|
2016-02-21 03:02:28 +00:00
|
|
|
return std::unique_ptr<gpu::GraphicsSystem>(
|
|
|
|
new xe::gpu::vulkan::VulkanGraphicsSystem());
|
2016-08-04 14:50:13 +00:00
|
|
|
} else if (FLAGS_gpu.compare("null") == 0) {
|
|
|
|
return std::unique_ptr<gpu::GraphicsSystem>(
|
|
|
|
new xe::gpu::null::NullGraphicsSystem());
|
2015-11-08 23:02:24 +00:00
|
|
|
} else {
|
|
|
|
// Create best available.
|
|
|
|
std::unique_ptr<gpu::GraphicsSystem> best;
|
|
|
|
|
|
|
|
best = std::unique_ptr<gpu::GraphicsSystem>(
|
2016-07-29 00:33:05 +00:00
|
|
|
new xe::gpu::vulkan::VulkanGraphicsSystem());
|
2015-11-08 23:02:24 +00:00
|
|
|
if (best) {
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing!
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<hid::InputDriver>> CreateInputDrivers(
|
|
|
|
ui::Window* window) {
|
|
|
|
std::vector<std::unique_ptr<hid::InputDriver>> drivers;
|
|
|
|
if (FLAGS_hid.compare("nop") == 0) {
|
|
|
|
drivers.emplace_back(xe::hid::nop::Create(window));
|
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
} else if (FLAGS_hid.compare("winkey") == 0) {
|
|
|
|
drivers.emplace_back(xe::hid::winkey::Create(window));
|
|
|
|
} else if (FLAGS_hid.compare("xinput") == 0) {
|
|
|
|
drivers.emplace_back(xe::hid::xinput::Create(window));
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
} else {
|
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
auto xinput_driver = xe::hid::xinput::Create(window);
|
|
|
|
if (xinput_driver) {
|
|
|
|
drivers.emplace_back(std::move(xinput_driver));
|
|
|
|
}
|
|
|
|
auto winkey_driver = xe::hid::winkey::Create(window);
|
|
|
|
if (winkey_driver) {
|
|
|
|
drivers.emplace_back(std::move(winkey_driver));
|
|
|
|
}
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
if (drivers.empty()) {
|
|
|
|
// Fallback to nop if none created.
|
|
|
|
drivers.emplace_back(xe::hid::nop::Create(window));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return drivers;
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:17:01 +00:00
|
|
|
int xenia_main(const std::vector<std::wstring>& args) {
|
2014-05-28 20:59:43 +00:00
|
|
|
Profiler::Initialize();
|
2014-05-28 05:54:40 +00:00
|
|
|
Profiler::ThreadEnter("main");
|
|
|
|
|
2015-07-13 05:03:47 +00:00
|
|
|
// Create the emulator but don't initialize so we can setup the window.
|
2014-08-17 00:58:33 +00:00
|
|
|
auto emulator = std::make_unique<Emulator>(L"");
|
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)) {
|
|
|
|
XELOGE("Failed to setup emulator: %.8X", result);
|
2014-08-17 00:58:33 +00:00
|
|
|
return 1;
|
2013-02-01 13:37:42 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 09:33:39 +00:00
|
|
|
if (FLAGS_mount_scratch) {
|
|
|
|
auto scratch_device = std::make_unique<xe::vfs::HostPathDevice>(
|
|
|
|
"\\SCRATCH", L"scratch", false);
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_mount_cache) {
|
|
|
|
auto cache0_device =
|
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE0", L"cache0", false);
|
|
|
|
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 =
|
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE1", L"cache1", false);
|
|
|
|
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;
|
2016-01-18 19:48:21 +00:00
|
|
|
if (FLAGS_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);
|
|
|
|
emulator->on_launch.AddListener([&]() {
|
|
|
|
emulator_window->UpdateTitle();
|
|
|
|
evt->Set();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
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.
|
2015-06-27 03:27:36 +00:00
|
|
|
std::wstring path;
|
2015-02-20 15:47:06 +00:00
|
|
|
if (!FLAGS_target.empty() || args.size() >= 2) {
|
|
|
|
if (!FLAGS_target.empty()) {
|
2014-12-21 06:17:57 +00:00
|
|
|
// Passed as a named argument.
|
|
|
|
// TODO(benvanik): find something better than gflags that supports
|
|
|
|
// unicode.
|
2015-05-02 10:42:51 +00:00
|
|
|
path = xe::to_wstring(FLAGS_target);
|
2014-12-21 06:17:57 +00:00
|
|
|
} else {
|
|
|
|
// Passed as an unnamed argument.
|
|
|
|
path = args[1];
|
|
|
|
}
|
2015-06-27 03:27:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 19:35:49 +00:00
|
|
|
// Toggles fullscreen
|
|
|
|
if (FLAGS_fullscreen) emulator_window->ToggleFullscreen();
|
|
|
|
|
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.
|
2015-05-02 10:42:51 +00:00
|
|
|
std::wstring abs_path = xe::to_absolute_path(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)) {
|
2017-12-28 22:19:32 +00:00
|
|
|
xe::FatalError("Failed to launch target: %.8X", 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
|
|
|
|
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
|
|
|
|
|
2015-07-17 08:15:12 +00:00
|
|
|
DEFINE_ENTRY_POINT(L"xenia", L"xenia some.xex", xe::app::xenia_main);
|