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. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xenia/xenia.h>
|
|
|
|
|
2013-01-24 05:31:23 +00:00
|
|
|
#include <gflags/gflags.h>
|
2014-08-16 23:34:04 +00:00
|
|
|
#include <poly/main.h>
|
2013-01-13 07:25:41 +00:00
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
using namespace xe;
|
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-08-16 23:34:04 +00:00
|
|
|
int xenia_run(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");
|
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
// Grab path from the flag or unnamed argument.
|
2014-08-16 23:34:04 +00:00
|
|
|
if (!FLAGS_target.size() && args.size() < 2) {
|
2013-10-24 03:42:24 +00:00
|
|
|
google::ShowUsageWithFlags("xenia-run");
|
2014-01-17 06:16:06 +00:00
|
|
|
XEFATAL("Pass a file to launch.");
|
2013-10-24 03:42:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-08-16 23:34:04 +00:00
|
|
|
std::wstring path;
|
2013-10-24 03:42:24 +00:00
|
|
|
if (FLAGS_target.size()) {
|
|
|
|
// Passed as a named argument.
|
|
|
|
// TODO(benvanik): find something better than gflags that supports unicode.
|
2014-08-16 23:34:04 +00:00
|
|
|
path = poly::to_wstring(FLAGS_target);
|
2013-10-24 03:42:24 +00:00
|
|
|
} else {
|
|
|
|
// Passed as an unnamed argument.
|
2014-08-16 23:34:04 +00:00
|
|
|
path = args[1];
|
2013-10-24 03:42:24 +00:00
|
|
|
}
|
2014-08-16 23:34:04 +00:00
|
|
|
// Normalize the path and make absolute.
|
|
|
|
std::wstring abs_path = poly::to_absolute_path(path);
|
2013-06-01 04:22:00 +00:00
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
// Create platform abstraction layer.
|
2013-01-20 09:13:59 +00:00
|
|
|
xe_pal_options_t pal_options;
|
2013-01-13 08:34:08 +00:00
|
|
|
xe_zero_struct(&pal_options, sizeof(pal_options));
|
2014-08-17 00:58:33 +00:00
|
|
|
if (xe_pal_init(pal_options)) {
|
|
|
|
XELOGE("Failed to initialize PAL");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
// Create the emulator.
|
2014-08-17 00:58:33 +00:00
|
|
|
auto emulator = std::make_unique<Emulator>(L"");
|
2013-10-24 03:42:24 +00:00
|
|
|
X_STATUS result = emulator->Setup();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-01 00:52:50 +00:00
|
|
|
// Launch based on file type.
|
|
|
|
// This is a silly guess based on file extension.
|
2014-08-15 17:19:59 +00:00
|
|
|
auto file_system_type = emulator->file_system()->InferType(abs_path);
|
|
|
|
switch (file_system_type) {
|
|
|
|
case kernel::fs::FileSystemType::STFS_TITLE:
|
|
|
|
result = emulator->LaunchSTFSTitle(abs_path);
|
|
|
|
break;
|
|
|
|
case kernel::fs::FileSystemType::XEX_FILE:
|
|
|
|
result = emulator->LaunchXexFile(abs_path);
|
|
|
|
break;
|
|
|
|
case kernel::fs::FileSystemType::DISC_IMAGE:
|
|
|
|
result = emulator->LaunchDiscImage(abs_path);
|
|
|
|
break;
|
2013-01-13 08:34:08 +00:00
|
|
|
}
|
2013-10-24 03:42:24 +00:00
|
|
|
if (XFAILED(result)) {
|
|
|
|
XELOGE("Failed to launch target: %.8X", result);
|
2014-08-17 00:58:33 +00:00
|
|
|
return 1;
|
2013-05-30 04:45:54 +00:00
|
|
|
}
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2014-08-17 00:58:33 +00:00
|
|
|
emulator.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
|
|
|
|
|
|
|
DEFINE_ENTRY_POINT(L"xenia-run", L"xenia-run some.xex", xenia_run);
|