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"
|
2015-05-02 10:42:51 +00:00
|
|
|
#include "xenia/base/logging.h"
|
|
|
|
#include "xenia/base/main.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-05-02 08:25:59 +00:00
|
|
|
#include "xenia/profiling.h"
|
2015-06-27 03:27:36 +00:00
|
|
|
#include "xenia/ui/file_picker.h"
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2014-08-16 23:34:04 +00:00
|
|
|
DEFINE_string(target, "", "Specifies the target .xex or .iso to execute.");
|
2013-01-13 08:34:08 +00:00
|
|
|
|
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-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.
|
|
|
|
X_STATUS result = emulator->Setup(emulator_window->window());
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (emulator->debugger()) {
|
|
|
|
emulator->debugger()->set_debug_listener_request_handler([&](
|
|
|
|
xe::debug::Debugger* debugger) {
|
|
|
|
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->debugger()->set_debug_listener(nullptr);
|
|
|
|
emulator_window->loop()->Post([&]() { debug_window.reset(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return debug_window.get();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// If no path passed, ask the user.
|
|
|
|
if (path.empty()) {
|
2015-07-13 05:03:47 +00:00
|
|
|
auto file_picker = xe::ui::FilePicker::Create();
|
|
|
|
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
|
|
|
|
file_picker->set_type(ui::FilePicker::Type::kFile);
|
|
|
|
file_picker->set_multi_selection(false);
|
|
|
|
file_picker->set_title(L"Select Content Package");
|
|
|
|
file_picker->set_extensions({
|
2015-06-27 03:27:36 +00:00
|
|
|
{L"Supported Files", L"*.iso;*.xex;*.xcp;*.*"},
|
|
|
|
{L"Disc Image (*.iso)", L"*.iso"},
|
|
|
|
{L"Xbox Executable (*.xex)", L"*.xex"},
|
|
|
|
//{ L"Content Package (*.xcp)", L"*.xcp" },
|
|
|
|
{L"All Files (*.*)", L"*.*"},
|
|
|
|
});
|
2015-07-13 05:03:47 +00:00
|
|
|
if (file_picker->Show(emulator->display_window()->native_handle())) {
|
|
|
|
auto selected_files = file_picker->selected_files();
|
2015-06-27 03:27:36 +00:00
|
|
|
if (!selected_files.empty()) {
|
|
|
|
path = selected_files[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-12-21 06:17:57 +00:00
|
|
|
|
2015-06-27 23:27:24 +00:00
|
|
|
result = emulator->LaunchPath(abs_path);
|
2014-12-21 06:17:57 +00:00
|
|
|
if (XFAILED(result)) {
|
|
|
|
XELOGE("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;
|
|
|
|
}
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2015-02-20 15:47:06 +00:00
|
|
|
// Wait until we are exited.
|
2015-07-01 15:02:22 +00:00
|
|
|
emulator->display_window()->loop()->AwaitQuit();
|
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
|
|
|
emulator_window.reset();
|
|
|
|
|
2014-05-28 05:54:40 +00:00
|
|
|
Profiler::Dump();
|
|
|
|
Profiler::Shutdown();
|
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);
|