Skip to content

Commit

Permalink
Added ability to launch XBEs inside XISO images (redump style isos ar…
Browse files Browse the repository at this point in the history
…e also supported)
  • Loading branch information
ergo720 committed Aug 11, 2024
1 parent 1bbaf52 commit a89d755
Show file tree
Hide file tree
Showing 18 changed files with 494 additions and 156 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ set(HEADERS
"${NXBX_ROOT_DIR}/src/pe.hpp"
"${NXBX_ROOT_DIR}/src/settings.hpp"
"${NXBX_ROOT_DIR}/src/util.hpp"
"${NXBX_ROOT_DIR}/src/xbe.hpp"
"${NXBX_ROOT_DIR}/src/xiso.hpp"
"${NXBX_ROOT_DIR}/src/xpartition.hpp"
"${NXBX_ROOT_DIR}/src/hw/cmos.hpp"
"${NXBX_ROOT_DIR}/src/hw/cpu.hpp"
Expand Down Expand Up @@ -89,6 +91,8 @@ set(SOURCES
"${NXBX_ROOT_DIR}/src/main.cpp"
"${NXBX_ROOT_DIR}/src/settings.cpp"
"${NXBX_ROOT_DIR}/src/util.cpp"
"${NXBX_ROOT_DIR}/src/xbe.cpp"
"${NXBX_ROOT_DIR}/src/xiso.cpp"
"${NXBX_ROOT_DIR}/src/xpartition.cpp"
"${NXBX_ROOT_DIR}/src/hw/cmos.cpp"
"${NXBX_ROOT_DIR}/src/hw/cpu.cpp"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nxbx - XBE launcher
# Nxbx - XBE / XISO launcher

Nxbx is a software to start executing XBE (original xbox executable) programs. To do this, it uses [lib86cpu](https://github.com/ergo720/lib86cpu),
Nxbx is a software to start executing XBE (original xbox executable) programs or to launch XISO images (original xbox iso). To do this, it uses [lib86cpu](https://github.com/ergo720/lib86cpu),
a cpu emulation library, and [nboxkrnl](https://github.com/ergo720/nboxkrnl), a re-implementation of the kernel of the original xbox.\
**NOTE: It doesn't run any games right now.**\
The only supported architecture is x86-64.
Expand Down
14 changes: 7 additions & 7 deletions src/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class console {
bool init(const init_info_t &init_info)
{
if (m_is_init == false) {
if (!((init_info.m_type == console_t::xbox) ||
(init_info.m_type == console_t::chihiro) ||
(init_info.m_type == console_t::devkit))) {
logger_nxbx(error, "Attempted to create unrecognized machine of type %" PRIu32, (uint32_t)init_info.m_type);
if (!((init_info.m_console_type == console_t::xbox) ||
(init_info.m_console_type == console_t::chihiro) ||
(init_info.m_console_type == console_t::devkit))) {
logger_nxbx(error, "Attempted to create unrecognized machine of type %" PRIu32, (uint32_t)init_info.m_console_type);
return false;
}
timer::init();
if (!m_machine.init(init_info)) {
m_machine.deinit();
return false;
}
if (!io::init(init_info.m_nxbx_path, init_info.m_xbe_path, m_machine.get<cpu_t *>())) {
if (!io::init(init_info, m_machine.get<cpu_t *>())) {
m_machine.deinit();
return false;
}
m_type = init_info.m_type;
m_console_type = init_info.m_console_type;
m_is_init = true;
}
return true;
Expand All @@ -61,5 +61,5 @@ class console {

machine m_machine;
bool m_is_init;
console_t m_type;
console_t m_console_type;
};
51 changes: 16 additions & 35 deletions src/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@


bool
file_exists(std::pair<std::filesystem::path, std::string> path_to_check, std::filesystem::path &resolved_path)
file_exists(std::filesystem::path dev_path, std::string remaining_name, std::filesystem::path &resolved_path)
{
// path_to_check.first -> base device part, decided by host, path_to_check.second -> remaining variable part, decided by xbox
// dev_path -> base device part, decided by host, remaining_name -> remaining variable part, decided by xbox

try {
resolved_path = path_to_check.first / path_to_check.second;
resolved_path = dev_path / remaining_name;
bool exists = std::filesystem::exists(resolved_path);
if (!exists) {
// If it failed, the path might still exists, but the OS filesystem doesn't do case-insensitive comparisons (which the xbox always does)
// E.g.: on Linux, the ext4 filesystem might trigger this case

if (path_to_check.second.empty()) {
if (remaining_name.empty()) {
return false;
}

// This starts from the device path, and checks each file name component of the path for a case-insensitive match with a host file in the current inspected directory
size_t pos_to_check = 0, name_size = path_to_check.second.size();
size_t pos_to_check = 0, name_size = remaining_name.size();
int64_t remaining_path_size = name_size;
std::filesystem::path local_path(path_to_check.first);
std::filesystem::path local_path(dev_path);
do {
size_t pos = path_to_check.second.find_first_of('\\', pos_to_check);
size_t pos = remaining_name.find_first_of(std::filesystem::path::preferred_separator, pos_to_check);
pos = std::min(pos, name_size);
util::xbox_string_view xbox_name(util::traits_cast<util::xbox_char_traits, char, std::char_traits<char>>(std::string_view(&path_to_check.second[pos_to_check], pos - pos_to_check)));
util::xbox_string_view xbox_name(util::traits_cast<util::xbox_char_traits, char, std::char_traits<char>>(std::string_view(&remaining_name[pos_to_check], pos - pos_to_check)));
for (const auto &directory_entry : std::filesystem::directory_iterator(local_path)) {
std::string host_name(directory_entry.path().filename().string());
util::xbox_string xbox_host_name(util::traits_cast<util::xbox_char_traits, char, std::char_traits<char>>(host_name));
Expand All @@ -61,28 +61,22 @@ file_exists(std::pair<std::filesystem::path, std::string> path_to_check, std::fi
}
return true;
}
catch (const std::filesystem::filesystem_error &e) {
logger_en(info, "Failed to check existence of path %s, the error was %s", resolved_path.string().c_str(), e.what());
}
catch (const std::bad_alloc &e) {
catch (const std::exception &e) {
logger_en(info, "Failed to check existence of path %s, the error was %s", resolved_path.string().c_str(), e.what());
}

return false;
}

bool
file_exists(std::pair<std::filesystem::path, std::string> path_to_check, std::filesystem::path &resolved_path, bool *is_directory)
file_exists(std::filesystem::path dev_path, std::string remaining_name, std::filesystem::path &resolved_path, bool *is_directory)
{
if (file_exists(path_to_check, resolved_path)) {
if (file_exists(dev_path, remaining_name, resolved_path)) {
try {
*is_directory = std::filesystem::is_directory(resolved_path);
return true;
}
catch (const std::filesystem::filesystem_error &e) {
logger_en(info, "Failed to determine the file type of path %s, the error was %s", resolved_path.string().c_str(), e.what());
}
catch (const std::bad_alloc &e) {
catch (const std::exception &e) {
logger_en(info, "Failed to determine the file type of path %s, the error was %s", resolved_path.string().c_str(), e.what());
}
}
Expand All @@ -96,10 +90,7 @@ file_exists(std::filesystem::path path)
try {
return std::filesystem::exists(path);
}
catch (const std::filesystem::filesystem_error &e) {
logger_en(info, "Failed to determine the file type of path %s, the error was %s", path.string().c_str(), e.what());
}
catch (const std::bad_alloc &e) {
catch (const std::exception &e) {
logger_en(info, "Failed to determine the file type of path %s, the error was %s", path.string().c_str(), e.what());
}

Expand Down Expand Up @@ -127,10 +118,7 @@ create_directory(std::filesystem::path path)

return true;
}
catch (const std::filesystem::filesystem_error &e) {
logger_en(info, "Failed to created directory %s, the error was %s", path.string().c_str(), e.what());
}
catch (const std::bad_alloc &e) {
catch (const std::exception &e) {
logger_en(info, "Failed to created directory %s, the error was %s", path.string().c_str(), e.what());
}

Expand All @@ -153,10 +141,7 @@ create_file(std::filesystem::path path, uint64_t initial_size)
try {
std::filesystem::resize_file(path, initial_size);
}
catch (const std::filesystem::filesystem_error &e) {
logger_en(info, "Failed to set the initial file size of path %s, the error was %s", path.string().c_str(), e.what());
}
catch (const std::bad_alloc &e) {
catch (const std::exception &e) {
logger_en(info, "Failed to set the initial file size of path %s, the error was %s", path.string().c_str(), e.what());
}
}
Expand All @@ -179,11 +164,7 @@ open_file(std::filesystem::path path, std::uintmax_t *size)
try {
*size = std::filesystem::file_size(path);
}
catch (const std::filesystem::filesystem_error &e) {
*size = 0;
logger_en(info, "Failed to determine the file size of path %s, the error was %s", path.string().c_str(), e.what());
}
catch (const std::bad_alloc &e) {
catch (const std::exception &e) {
*size = 0;
logger_en(info, "Failed to determine the file size of path %s, the error was %s", path.string().c_str(), e.what());
}
Expand Down
4 changes: 2 additions & 2 deletions src/files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


bool create_directory(std::filesystem::path path);
bool file_exists(std::pair<std::filesystem::path, std::string> path_to_check, std::filesystem::path &resolved_path);
bool file_exists(std::pair<std::filesystem::path, std::string> path_to_check, std::filesystem::path &resolved_path, bool *is_directory);
bool file_exists(std::filesystem::path dev_path, std::string remaining_name, std::filesystem::path &resolved_path);
bool file_exists(std::filesystem::path dev_path, std::string remaining_name, std::filesystem::path &resolved_path, bool *is_directory);
bool file_exists(std::filesystem::path path);
std::optional<std::fstream> create_file(std::filesystem::path path);
std::optional<std::fstream> create_file(std::filesystem::path path, uint64_t initial_size);
Expand Down
2 changes: 1 addition & 1 deletion src/hw/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ cpu::reset()
bool
cpu::init(const init_info_t &init_info)
{
m_ramsize = init_info.m_type == console_t::xbox ? RAM_SIZE64 : RAM_SIZE128;
m_ramsize = init_info.m_console_type == console_t::xbox ? RAM_SIZE64 : RAM_SIZE128;

// Load the nboxkrnl exe file
std::ifstream ifs(init_info.m_kernel.c_str(), std::ios_base::in | std::ios_base::binary);
Expand Down
Loading

0 comments on commit a89d755

Please sign in to comment.