xenia-canary/tools/xenia-run/xenia-run.cc

117 lines
2.6 KiB
C++
Raw Normal View History

/**
******************************************************************************
* 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>
#include <gflags/gflags.h>
using namespace xe;
using namespace xe::cpu;
using namespace xe::kernel;
2013-01-13 08:34:08 +00:00
DEFINE_bool(abort_before_entry, false,
"Abort execution right before launching the module.");
class Run {
public:
Run();
~Run();
int Setup(const xechar_t* path);
int Launch();
private:
xe_pal_ref pal_;
xe_memory_ref memory_;
shared_ptr<Processor> processor_;
shared_ptr<Runtime> runtime_;
UserModule* module_;
};
Run::Run() {
}
Run::~Run() {
xe_memory_release(memory_);
xe_pal_release(pal_);
}
int Run::Setup(const xechar_t* path) {
xe_pal_options_t pal_options;
2013-01-13 08:34:08 +00:00
xe_zero_struct(&pal_options, sizeof(pal_options));
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));
memory_ = xe_memory_create(pal_, memory_options);
XEEXPECTNOTNULL(memory_);
2013-01-13 08:34:08 +00:00
processor_ = shared_ptr<Processor>(new Processor(pal_, memory_));
XEEXPECTZERO(processor_->Setup());
2013-01-13 08:34:08 +00:00
runtime_ = shared_ptr<Runtime>(new Runtime(pal_, processor_, XT("")));
2013-01-13 08:34:08 +00:00
XEEXPECTZERO(runtime_->LoadModule(path));
module_ = runtime_->GetModule(path);
2013-01-13 08:34:08 +00:00
return 0;
XECLEANUP:
return 1;
}
int Run::Launch() {
if (FLAGS_abort_before_entry) {
return 0;
}
// TODO(benvanik): wait until the module thread exits
runtime_->LaunchModule(module_);
return 0;
2013-01-13 08:34:08 +00:00
}
int xenia_run(int argc, xechar_t **argv) {
std::string usage = "usage: ";
usage += "xenia-run some.xex";
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.
do_gpu_stuff();
2013-01-13 08:34:08 +00:00
int result_code = 1;
// Grab path.
2013-01-13 08:34:08 +00:00
if (argc < 2) {
google::ShowUsageWithFlags("xenia-run");
2013-01-13 08:34:08 +00:00
return 1;
}
const xechar_t *path = argv[1];
auto_ptr<Run> run = auto_ptr<Run>(new Run());
2013-01-13 08:34:08 +00:00
result_code = run->Setup(path);
2013-01-13 08:34:08 +00:00
XEEXPECTZERO(result_code);
//xe_module_dump(run->module);
2013-01-13 08:34:08 +00:00
run->Launch();
2013-01-13 08:34:08 +00:00
result_code = 0;
2013-01-13 08:34:08 +00:00
XECLEANUP:
google::ShutDownCommandLineFlags();
2013-01-13 08:34:08 +00:00
return result_code;
}
XE_MAIN_THUNK(xenia_run);