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>
|
|
|
|
|
2013-01-13 07:25:41 +00:00
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
using namespace xe;
|
|
|
|
using namespace xe::cpu;
|
|
|
|
using namespace xe::kernel;
|
2013-01-13 08:34:08 +00:00
|
|
|
|
|
|
|
|
2013-01-28 11:03:37 +00:00
|
|
|
DEFINE_bool(abort_before_entry, false,
|
|
|
|
"Abort execution right before launching the module.");
|
|
|
|
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
class Run {
|
|
|
|
public:
|
|
|
|
Run();
|
|
|
|
~Run();
|
|
|
|
|
2013-01-31 06:44:32 +00:00
|
|
|
int Setup();
|
|
|
|
int Launch(const xechar_t* path);
|
2013-01-20 09:13:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
xe_pal_ref pal_;
|
|
|
|
xe_memory_ref memory_;
|
|
|
|
shared_ptr<Processor> processor_;
|
|
|
|
shared_ptr<Runtime> runtime_;
|
|
|
|
};
|
|
|
|
|
|
|
|
Run::Run() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Run::~Run() {
|
|
|
|
xe_memory_release(memory_);
|
|
|
|
xe_pal_release(pal_);
|
|
|
|
}
|
|
|
|
|
2013-01-31 06:44:32 +00:00
|
|
|
int Run::Setup() {
|
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));
|
2013-01-20 09:13:59 +00:00
|
|
|
pal_ = xe_pal_create(pal_options);
|
|
|
|
XEEXPECTNOTNULL(pal_);
|
2013-01-13 08:34:08 +00:00
|
|
|
|
|
|
|
xe_memory_options_t memory_options;
|
|
|
|
xe_zero_struct(&memory_options, sizeof(memory_options));
|
2013-01-20 09:13:59 +00:00
|
|
|
memory_ = xe_memory_create(pal_, memory_options);
|
|
|
|
XEEXPECTNOTNULL(memory_);
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
processor_ = shared_ptr<Processor>(new Processor(pal_, memory_));
|
|
|
|
XEEXPECTZERO(processor_->Setup());
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
runtime_ = shared_ptr<Runtime>(new Runtime(pal_, processor_, XT("")));
|
2013-01-13 08:34:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
XECLEANUP:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-31 06:44:32 +00:00
|
|
|
int Run::Launch(const xechar_t* path) {
|
2013-01-28 11:03:37 +00:00
|
|
|
if (FLAGS_abort_before_entry) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-01 00:52:50 +00:00
|
|
|
// Normalize the path and make absolute.
|
|
|
|
// TODO(benvanik): move this someplace common.
|
|
|
|
xechar_t abs_path[XE_MAX_PATH];
|
|
|
|
#if XE_PLATFORM(WIN32)
|
|
|
|
_wfullpath(abs_path, path, XECOUNT(abs_path));
|
|
|
|
#else
|
|
|
|
realpath(path, abs_path);
|
|
|
|
#endif // WIN32
|
|
|
|
|
|
|
|
// Grab file extension.
|
|
|
|
const xechar_t* dot = xestrrchr(abs_path, '.');
|
|
|
|
if (!dot) {
|
|
|
|
XELOGE(XT("Invalid input path; no extension found"));
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-31 06:44:32 +00:00
|
|
|
|
2013-02-01 00:52:50 +00: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.
|
|
|
|
return runtime_->LaunchXexFile(abs_path);
|
|
|
|
} else {
|
|
|
|
// Assume a disc image.
|
|
|
|
return runtime_->LaunchDiscImage(abs_path);
|
|
|
|
}
|
2013-01-13 08:34:08 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 07:25:41 +00:00
|
|
|
int xenia_run(int argc, xechar_t **argv) {
|
2013-01-24 05:31:23 +00:00
|
|
|
std::string usage = "usage: ";
|
2013-01-30 09:35:08 +00:00
|
|
|
usage += "xenia-run some.xex";
|
2013-01-24 05:31:23 +00:00
|
|
|
google::SetUsageMessage(usage);
|
|
|
|
google::SetVersionString("1.0");
|
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2013-01-13 08:34:08 +00:00
|
|
|
// Dummy call to keep the GPU code linking in to ensure it's working.
|
2013-01-13 07:25:41 +00:00
|
|
|
do_gpu_stuff();
|
2013-01-13 08:34:08 +00:00
|
|
|
|
|
|
|
int result_code = 1;
|
|
|
|
|
2013-01-24 05:31:23 +00:00
|
|
|
// Grab path.
|
2013-01-13 08:34:08 +00:00
|
|
|
if (argc < 2) {
|
2013-01-30 09:35:08 +00:00
|
|
|
google::ShowUsageWithFlags("xenia-run");
|
2013-01-13 08:34:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const xechar_t *path = argv[1];
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
auto_ptr<Run> run = auto_ptr<Run>(new Run());
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2013-01-31 06:44:32 +00:00
|
|
|
result_code = run->Setup();
|
2013-01-13 08:34:08 +00:00
|
|
|
XEEXPECTZERO(result_code);
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
//xe_module_dump(run->module);
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2013-01-31 06:44:32 +00:00
|
|
|
run->Launch(path);
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2013-01-24 05:31:23 +00:00
|
|
|
result_code = 0;
|
2013-01-13 08:34:08 +00:00
|
|
|
XECLEANUP:
|
2013-01-24 05:31:23 +00:00
|
|
|
|
|
|
|
google::ShutDownCommandLineFlags();
|
2013-01-13 08:34:08 +00:00
|
|
|
return result_code;
|
2013-01-11 09:23:08 +00:00
|
|
|
}
|
2013-01-13 07:25:41 +00:00
|
|
|
XE_MAIN_THUNK(xenia_run);
|