2013-01-11 10:23:08 +01: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 06:31:23 +01:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
|
2013-01-13 08:25:41 +01:00
|
|
|
|
2013-01-20 10:13:59 +01:00
|
|
|
using namespace xe;
|
2013-01-13 09:34:08 +01:00
|
|
|
|
|
|
|
|
|
2013-05-30 06:45:54 +02:00
|
|
|
DEFINE_string(target, "",
|
|
|
|
|
"Specifies the target .xex or .iso to execute.");
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 05:42:24 +02:00
|
|
|
int xenia_run(int argc, xechar_t** argv) {
|
|
|
|
|
int result_code = 1;
|
2013-01-20 10:13:59 +01:00
|
|
|
|
2013-10-24 05:42:24 +02:00
|
|
|
Emulator* emulator = NULL;
|
2013-01-20 10:13:59 +01:00
|
|
|
|
2013-10-24 05:42:24 +02:00
|
|
|
// Grab path from the flag or unnamed argument.
|
|
|
|
|
if (!FLAGS_target.size() && argc < 2) {
|
|
|
|
|
google::ShowUsageWithFlags("xenia-run");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
const xechar_t* path = NULL;
|
|
|
|
|
if (FLAGS_target.size()) {
|
|
|
|
|
// Passed as a named argument.
|
|
|
|
|
// TODO(benvanik): find something better than gflags that supports unicode.
|
|
|
|
|
xechar_t buffer[XE_MAX_PATH];
|
|
|
|
|
XEIGNORE(xestrwiden(buffer, sizeof(buffer), FLAGS_target.c_str()));
|
|
|
|
|
path = buffer;
|
|
|
|
|
} else {
|
|
|
|
|
// Passed as an unnamed argument.
|
|
|
|
|
path = argv[1];
|
|
|
|
|
}
|
2013-06-01 06:22:00 +02:00
|
|
|
|
2013-10-24 05:42:24 +02:00
|
|
|
// Create platform abstraction layer.
|
2013-01-20 10:13:59 +01:00
|
|
|
xe_pal_options_t pal_options;
|
2013-01-13 09:34:08 +01:00
|
|
|
xe_zero_struct(&pal_options, sizeof(pal_options));
|
2013-03-29 13:07:32 +01:00
|
|
|
XEEXPECTZERO(xe_pal_init(pal_options));
|
2013-01-13 09:34:08 +01:00
|
|
|
|
2013-02-01 01:52:50 +01:00
|
|
|
// Normalize the path and make absolute.
|
|
|
|
|
// TODO(benvanik): move this someplace common.
|
|
|
|
|
xechar_t abs_path[XE_MAX_PATH];
|
2013-02-09 17:05:39 +01:00
|
|
|
xe_path_get_absolute(path, abs_path, XECOUNT(abs_path));
|
2013-02-01 01:52:50 +01:00
|
|
|
|
|
|
|
|
// Grab file extension.
|
|
|
|
|
const xechar_t* dot = xestrrchr(abs_path, '.');
|
|
|
|
|
if (!dot) {
|
2013-02-09 17:05:39 +01:00
|
|
|
XELOGE("Invalid input path; no extension found");
|
2013-02-01 01:52:50 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
2013-01-31 07:44:32 +01:00
|
|
|
|
2013-10-24 05:42:24 +02:00
|
|
|
// Create the emulator.
|
|
|
|
|
emulator = new Emulator(XT(""));
|
|
|
|
|
XEEXPECTNOTNULL(emulator);
|
|
|
|
|
X_STATUS result = emulator->Setup();
|
|
|
|
|
if (XFAILED(result)) {
|
|
|
|
|
XELOGE("Failed to setup emulator: %.8X", result);
|
|
|
|
|
XEFAIL();
|
2013-02-01 14:37:42 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-01 01:52:50 +01:00
|
|
|
// Launch based on file type.
|
|
|
|
|
// This is a silly guess based on file extension.
|
|
|
|
|
// NOTE: the runtime launch routine will wait until the module exits.
|
|
|
|
|
if (xestrcmp(dot, XT(".xex")) == 0) {
|
|
|
|
|
// Treat as a naked xex file.
|
2013-10-24 05:42:24 +02:00
|
|
|
result = emulator->LaunchXexFile(abs_path);
|
2013-02-01 01:52:50 +01:00
|
|
|
} else {
|
|
|
|
|
// Assume a disc image.
|
2013-10-24 05:42:24 +02:00
|
|
|
result = emulator->LaunchDiscImage(abs_path);
|
2013-01-13 09:34:08 +01:00
|
|
|
}
|
2013-10-24 05:42:24 +02:00
|
|
|
if (XFAILED(result)) {
|
|
|
|
|
XELOGE("Failed to launch target: %.8X", result);
|
|
|
|
|
XEFAIL();
|
2013-05-30 06:45:54 +02:00
|
|
|
}
|
2013-01-13 09:34:08 +01:00
|
|
|
|
2013-01-24 06:31:23 +01:00
|
|
|
result_code = 0;
|
2013-01-13 09:34:08 +01:00
|
|
|
XECLEANUP:
|
2013-10-24 05:42:24 +02:00
|
|
|
delete emulator;
|
2013-01-13 09:34:08 +01:00
|
|
|
return result_code;
|
2013-01-11 10:23:08 +01:00
|
|
|
}
|
2013-02-09 07:07:38 +01:00
|
|
|
XE_MAIN_THUNK(xenia_run, "xenia-run some.xex");
|