Added callback when new module is launched

This avoids having to guess the display window title format
Also manually fixed the linting errors picked out by travis which do not
get picked up using xb format locally
This commit is contained in:
x1nixmzeng 2016-01-09 17:36:46 +00:00
parent 5fa9499a12
commit 6530b9dc49
11 changed files with 56 additions and 53 deletions

View File

@ -35,11 +35,12 @@ class EmulatorWindow {
ui::Loop* loop() const { return loop_.get(); }
ui::Window* window() const { return window_.get(); }
void UpdateTitle();
private:
explicit EmulatorWindow(Emulator* emulator);
bool Initialize();
void UpdateTitle();
void CpuTimeScalarReset();
void CpuTimeScalarSetHalf();

View File

@ -195,7 +195,8 @@ int xenia_main(const std::vector<std::wstring>& args) {
// Normalize the path and make absolute.
std::wstring abs_path = xe::to_absolute_path(path);
result = emulator->LaunchPath(abs_path);
result = emulator->LaunchPath(abs_path,
[&]() { emulator_window->UpdateTitle(); });
if (XFAILED(result)) {
XELOGE("Failed to launch target: %.8X", result);
emulator.reset();

View File

@ -465,8 +465,8 @@ bool XexModule::SetupLibraryImports(const char* name,
GuestFunction::ExternHandler handler = nullptr;
if (kernel_export) {
if (kernel_export->function_data.trampoline) {
handler = (GuestFunction::ExternHandler)kernel_export
->function_data.trampoline;
handler = (GuestFunction::ExternHandler)
kernel_export->function_data.trampoline;
} else {
handler =
(GuestFunction::ExternHandler)kernel_export->function_data.shim;

View File

@ -192,7 +192,8 @@ X_STATUS Emulator::Setup(
return result;
}
X_STATUS Emulator::LaunchPath(std::wstring path) {
X_STATUS Emulator::LaunchPath(std::wstring path,
std::function<void()> on_launch) {
// Launch based on file type.
// This is a silly guess based on file extension.
auto last_slash = path.find_last_of(xe::kPathSeparator);
@ -202,18 +203,19 @@ X_STATUS Emulator::LaunchPath(std::wstring path) {
}
if (last_dot == std::wstring::npos) {
// Likely an STFS container.
return LaunchStfsContainer(path);
return LaunchStfsContainer(path, on_launch);
} else if (path.substr(last_dot) == L".xex" ||
path.substr(last_dot) == L".elf") {
// Treat as a naked xex file.
return LaunchXexFile(path);
return LaunchXexFile(path, on_launch);
} else {
// Assume a disc image.
return LaunchDiscImage(path);
return LaunchDiscImage(path, on_launch);
}
}
X_STATUS Emulator::LaunchXexFile(std::wstring path) {
X_STATUS Emulator::LaunchXexFile(std::wstring path,
std::function<void()> on_launch) {
// We create a virtual filesystem pointing to its directory and symlink
// that to the game filesystem.
// e.g., /my/files/foo.xex will get a local fs at:
@ -245,10 +247,11 @@ X_STATUS Emulator::LaunchXexFile(std::wstring path) {
// Launch the game.
std::string fs_path = "game:\\" + xe::to_string(file_name);
return CompleteLaunch(path, fs_path);
return CompleteLaunch(path, fs_path, on_launch);
}
X_STATUS Emulator::LaunchDiscImage(std::wstring path) {
X_STATUS Emulator::LaunchDiscImage(std::wstring path,
std::function<void()> on_launch) {
auto mount_path = "\\Device\\Cdrom0";
// Register the disc image in the virtual filesystem.
@ -267,10 +270,11 @@ X_STATUS Emulator::LaunchDiscImage(std::wstring path) {
file_system_->RegisterSymbolicLink("d:", mount_path);
// Launch the game.
return CompleteLaunch(path, "game:\\default.xex");
return CompleteLaunch(path, "game:\\default.xex", on_launch);
}
X_STATUS Emulator::LaunchStfsContainer(std::wstring path) {
X_STATUS Emulator::LaunchStfsContainer(std::wstring path,
std::function<void()> on_launch) {
auto mount_path = "\\Device\\Cdrom0";
// Register the container in the virtual filesystem.
@ -289,7 +293,7 @@ X_STATUS Emulator::LaunchStfsContainer(std::wstring path) {
file_system_->RegisterSymbolicLink("d:", mount_path);
// Launch the game.
return CompleteLaunch(path, "game:\\default.xex");
return CompleteLaunch(path, "game:\\default.xex", on_launch);
}
void Emulator::Pause() {
@ -495,7 +499,8 @@ void Emulator::WaitUntilExit() {
}
X_STATUS Emulator::CompleteLaunch(const std::wstring &path,
const std::string& module_path) {
const std::string &module_path,
std::function<void()> on_launch) {
// Allow xam to request module loads.
auto xam = kernel_state()->GetKernelModule<kernel::xam::XamModule>("xam.xex");
@ -510,10 +515,6 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
}
kernel_state_->SetExecutableModule(module);
auto main_xthread = module->Launch();
if (!main_xthread) {
return X_STATUS_UNSUCCESSFUL;
}
// Try and load the resource database (xex only)
char title[9] = {0};
@ -526,15 +527,7 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
if (xdb_ptr != nullptr) {
xe::xdbf::XdbfWrapper db;
if (db.initialize(xdb_ptr, static_cast<size_t>(resource_size))) {
std::string game_title(xe::xdbf::get_title(db));
if (!game_title.empty()) {
game_title_ = xe::to_wstring(game_title);
// TODO(x1nixmzeng): Need to somehow callback to
// EmulatorWindow::UpdateTitle
display_window_->set_title(game_title_ + L" - " +
display_window_->title());
}
game_title_ = xe::to_wstring(xe::xdbf::get_title(db));
xe::xdbf::XdbfBlock icon_block = xe::xdbf::get_icon(db);
if (icon_block.buffer != nullptr) {
display_window_->SetIconFromBuffer(icon_block.buffer,
@ -544,6 +537,12 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
}
}
auto main_xthread = module->Launch();
if (!main_xthread) {
return X_STATUS_UNSUCCESSFUL;
}
on_launch();
main_thread_ = main_xthread->thread();
WaitUntilExit();

View File

@ -109,17 +109,18 @@ class Emulator {
// Launches a game from the given file path.
// This will attempt to infer the type of the given file (such as an iso, etc)
// using heuristics.
X_STATUS LaunchPath(std::wstring path);
X_STATUS LaunchPath(std::wstring path, std::function<void()> on_launch);
// Launches a game from a .xex file by mounting the containing folder as if it
// was an extracted STFS container.
X_STATUS LaunchXexFile(std::wstring path);
X_STATUS LaunchXexFile(std::wstring path, std::function<void()> on_launch);
// Launches a game from a disc image file (.iso, etc).
X_STATUS LaunchDiscImage(std::wstring path);
X_STATUS LaunchDiscImage(std::wstring path, std::function<void()> on_launch);
// Launches a game from an STFS container file.
X_STATUS LaunchStfsContainer(std::wstring path);
X_STATUS LaunchStfsContainer(std::wstring path,
std::function<void()> on_launch);
void Pause();
void Resume();
@ -135,7 +136,8 @@ class Emulator {
bool ExceptionCallback(Exception* ex);
X_STATUS CompleteLaunch(const std::wstring &path,
const std::string& module_path);
const std::string &module_path,
std::function<void()> on_launch);
std::wstring command_line_;
std::wstring game_title_;

View File

@ -105,8 +105,8 @@ uint32_t KernelModule::GetProcAddressByOrdinal(uint16_t ordinal) {
cpu::GuestFunction::ExternHandler handler = nullptr;
if (export_entry->function_data.trampoline) {
handler = (cpu::GuestFunction::ExternHandler)export_entry
->function_data.trampoline;
handler = (cpu::GuestFunction::ExternHandler)
export_entry->function_data.trampoline;
} else {
handler =
(cpu::GuestFunction::ExternHandler)export_entry->function_data.shim;