mirror of
https://github.com/sp00nznet/xboxrecomp.git
synced 2026-12-06 18:39:43 +00:00
5133ba00dc
main had been sitting on v0.6.0 plus a handful of cherry-picks while the 0.7 work accumulated on a branch, so users were still getting the old direction flag, the old cmp carry flag, the old kernel memory model and the old disasm recovery. This merges the 50 commits and releases the result together with the two contributed PRs. Contributed, and credited in CONTRIBUTORS.md: #18, dplewis -- ReleaseMutex returned TRUE unconditionally on POSIX, so a thread releasing a mutex it did not own got success and NtReleaseMutant told the guest a still-held mutex was free. #17, DarthSidious666 -- D3D8 texture translation, 4,096 lines: all 66 Xbox formats mapped to DXGI, cube and volume textures, software channel conversion, and tests/d3d8_smoke to make it checkable without a D3D11 device. Also took hardcoded Burnout 3 strings out of the tools and the Linux paths. Five conflicts, all where #17's de-hardcoding met the same problem the 0.7 branch had solved differently. #17 added --game-name and a config constant; the branch read the title out of the XBE header. Both are worth keeping, so config.banner_name() prefers an explicit --game-name, falls back to the header title, and only then to the default -- the header is right without anyone remembering a flag, and the override is there for anyone who asks by name. Verified on the merged tree rather than assumed: 175 Python tests pass, the toolkit builds clean, #17's own d3d8_smoke passes, and a project copied from templates/new-game runs the documented pipeline start to finish and links -- which is the path that was broken in three separate places at the start of the week. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013pS5pcx2cx9JXyKurjok17
114 lines
3.6 KiB
Python
114 lines
3.6 KiB
Python
"""
|
|
Output formatting and statistics for the recompiler.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
|
|
from . import config
|
|
|
|
|
|
def write_summary(stats, output_dir):
|
|
"""Write a JSON summary of translation results."""
|
|
# The split/gen paths never create this directory, so a run that writes its
|
|
# generated C elsewhere would do all the work and then die at the last step.
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
summary_path = os.path.join(output_dir, "summary.json")
|
|
with open(summary_path, "w", encoding="utf-8") as f:
|
|
json.dump(stats, f, indent=2)
|
|
return summary_path
|
|
|
|
|
|
def print_stats(stats):
|
|
"""Print translation statistics to stderr."""
|
|
if isinstance(stats, dict) and "total" in stats:
|
|
# Single batch stats
|
|
_print_batch_stats(stats)
|
|
else:
|
|
# Per-category stats
|
|
total_translated = 0
|
|
total_failed = 0
|
|
total_funcs = 0
|
|
total_lines = 0
|
|
|
|
for cat, cat_stats in sorted(stats.items()):
|
|
_print_batch_stats(cat_stats, prefix=f" {cat}: ")
|
|
total_translated += cat_stats.get("translated", 0)
|
|
total_failed += cat_stats.get("failed", 0)
|
|
total_funcs += cat_stats.get("total", 0)
|
|
total_lines += cat_stats.get("total_lines", 0)
|
|
|
|
print(f"\n Total: {total_translated}/{total_funcs} translated, "
|
|
f"{total_failed} failed, {total_lines} lines of C")
|
|
|
|
|
|
def _print_batch_stats(stats, prefix=""):
|
|
"""Print stats for a single batch."""
|
|
total = stats.get("total", 0)
|
|
translated = stats.get("translated", 0)
|
|
failed = stats.get("failed", 0)
|
|
lines = stats.get("total_lines", 0)
|
|
out_file = stats.get("output_file", "")
|
|
out_size = stats.get("output_size", 0)
|
|
|
|
pct = (translated / total * 100) if total > 0 else 0
|
|
size_kb = out_size / 1024
|
|
|
|
print(f"{prefix}{translated}/{total} functions ({pct:.1f}%), "
|
|
f"{failed} failed, {lines} lines, {size_kb:.1f} KB -> {out_file}")
|
|
|
|
|
|
def generate_header(func_list, output_path, abi_db=None,
|
|
title="Xbox title"):
|
|
"""
|
|
Generate a C header with forward declarations for all translated functions.
|
|
Uses ABI data for proper signatures when available.
|
|
"""
|
|
abi_db = abi_db or {}
|
|
|
|
lines = [
|
|
"/**",
|
|
f" * {config.banner_name(title)} - Recompiled Function Declarations",
|
|
" * Auto-generated by tools/recomp",
|
|
" */",
|
|
"",
|
|
"#ifndef RECOMP_FUNCTIONS_H",
|
|
"#define RECOMP_FUNCTIONS_H",
|
|
"",
|
|
'#include "recomp_types.h"',
|
|
"",
|
|
]
|
|
|
|
for addr, func_info in sorted(func_list):
|
|
name = func_info.get("name", f"sub_{addr:08X}")
|
|
abi_info = abi_db.get(addr, {})
|
|
cc = abi_info.get("calling_convention", "cdecl")
|
|
num_params = abi_info.get("estimated_params", 0)
|
|
return_hint = abi_info.get("return_hint", "int_or_void")
|
|
|
|
if return_hint in ("float_sse", "float"):
|
|
ret_type = "float"
|
|
elif return_hint == "int_zero":
|
|
ret_type = "int"
|
|
elif num_params == 0 and return_hint == "int_or_void":
|
|
ret_type = "void"
|
|
else:
|
|
ret_type = "uint32_t"
|
|
|
|
is_thiscall = cc in ("thiscall", "thiscall_cdecl")
|
|
params = []
|
|
if is_thiscall:
|
|
params.append("void *this_ptr")
|
|
for i in range(num_params):
|
|
params.append(f"uint32_t a{i+1}")
|
|
param_str = ", ".join(params) if params else "void"
|
|
|
|
lines.append(f"{ret_type} {name}({param_str});")
|
|
|
|
lines.extend(["", "#endif /* RECOMP_FUNCTIONS_H */", ""])
|
|
|
|
with open(output_path, "w", encoding="utf-8") as f:
|
|
f.write("\n".join(lines))
|
|
|
|
return output_path
|