mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-27 18:52:11 -04:00
e6ce5006b4
The repository root carried seven markdown files that were not onboarding
material, plus two that had been superseded by the code they described. This
sorts them: reader-facing docs to docs/, working notes to docs/internal/, and
the two superseded ones merged into the docs that replaced them.
Moved to docs/: WIDESCREEN.md, ENHANCEMENTS.md, TCP_COMMANDS.md
Moved to docs/internal/: PRINCIPLES.md, ISSUES.md, DEBUG.md, GTE_LM_FIX.md,
and from docs/: bios-hardening.md, overlay-status.md,
overlay-plan.md, overlay-recompilation-design.md,
overlay-discovery.md, TOMBA2_EXC_CONSULT_RESPONSE.md,
CASE_A_AOT_GAP.md, audit_inventory.md
Moved to docs/internal/upstream/: UPSTREAM_2026-08-20.md
The root keeps only what belongs there: README.md, CONTRIBUTING.md, LICENSE,
CLAUDE.md, THIRD_PARTY_ATTRIBUTION.md, RELEASE_NOTES.md, the dotfiles and
psxrecomp_cli.py.
MERGES
SPLITGEN_MIGRATION.md folded into docs/BUILDING.md as "Split generated C". Its
migration instructions were stale in a way that mattered: it told every game
repo to hand-edit its CMakeLists and add a file(GLOB ...) over
<serial>_full*.c, but runtime/runtime.cmake now does that itself. GEN_FULL_GLOB
is a multi-value argument of psxrecomp_add_game_runtime(); the loop at
runtime.cmake:1985 makes each pattern absolute against CMAKE_CURRENT_SOURCE_DIR,
expands it with file(GLOB), and concatenates the hits into
GAME_GENERATED_FULL_C. So a title names the pattern and gets however many shards
a regeneration produced. The rewritten section describes that, the two-step
fallback when the globs match nothing (GEN_FULL_FALLBACK, else <serial>_full.c
derived from the dispatch marker by substituting _dispatch.c), and the one
caveat the code actually has: that file(GLOB) is plain, not CONFIGURE_DEPENDS,
so a regeneration which changes the shard COUNT needs a re-configure to be seen.
psxrecomp-toml-readme.md folded into docs/GAME_PROJECT_SETUP.md as "EXE-only
autofill (psxrecomp-toml)", placed after "Disc autofill (probe_disc.py)" and
before "Project Studio" so the two autofill paths sit together. Its documented
flags were checked against the usage text in recompiler/src/main_toml.cpp:28-42
and against the argument parser at :150-165 -- all seven options match with no
drift, so the flag list is reproduced as-is. Added a pointer that probe_disc.py
is preferable when a cue exists, since that tool does the same EXE-header work
plus disc identity and netplay gates.
FUNCTIONAL FIXES
tools/gen_tcp_commands.py wrote to REPO/"TCP_COMMANDS.md". After the move that
path does not exist, so the generator would have created a new stray root file
and --check would have failed against it forever. Retargeted to
REPO/"docs"/"TCP_COMMANDS.md", along with the seven docstring and message
strings that name the path.
Running it surfaced two further problems, both fixed here:
* The doc was genuinely stale -- pre-existing drift, not introduced by this
commit (the moved file is byte-identical to origin/master, and no
debug-server command table is touched here). Four commands registered since
the last regeneration were missing from the index -- cdrom_timing_dump,
savestate_status, ws_ui_groups, xprobe_watch -- and scanline had gained a
backend. Regenerated: 307 -> 311 commands, and the change is confined to the
AUTOGEN block (the hand-written head and tail are byte-identical to master).
tools/gen_tcp_commands.py --check now exits 0.
* DOC.write_text() has no newline argument, so Python translated every newline
to os.linesep. On Windows that rewrote all 585 lines of the file to CRLF and
turned a four-line index update into a whole-file diff -- measured: 589 CRLF
/ 0 LF after a run, against 0 CRLF / 585 LF in the repo. Now written through
an explicit newline="" handle, verified to leave the file at 0 CRLF.
runtime/include/debug_server.h:9 and runtime/src/debug_server.c:8 cited "TCP.md
and DEBUG.md". TCP.md has never existed in this repo under that name; both now
name docs/TCP_COMMANDS.md and docs/internal/DEBUG.md.
LINK AND REFERENCE FIXES
Every inbound reference to a moved file was located by grepping each basename
across the whole tracked tree, not just the markdown. Markdown hrefs in
README.md, CONTRIBUTING.md, docs/ARCHITECTURE.md, docs/COMPILING_OVERLAYS.md,
docs/AOT_OVERLAY_PLAN.md, docs/RELOCATION_MANIFEST_FORMAT.md,
docs/config_schema.md, docs/OVERLAY_XREF.md, docs/TCP_COMMANDS.md and several
docs/internal/ files now point at the new locations; where two files became
siblings under docs/internal/ the path was shortened rather than lengthened
(bios-hardening.md's reference to overlay-discovery.md, for instance).
docs/COMPILING_OVERLAYS.md's "in this folder" phrasing was wrong once two of the
three files it listed moved, so it now names internal/ explicitly.
24 source-comment mentions of ENHANCEMENTS.md sections G1.x across 19 files
(recompiler, runtime, cmake) were retargeted to docs/ENHANCEMENTS.md with the
section numbers untouched. docs/SHADOW_ENHANCEMENTS.md is a DIFFERENT file and
was deliberately excluded.
20 rationale strings citing docs/CASE_A_AOT_GAP.md across the four
recompiler/seeds/*.json files were updated. Done as a byte-level substring
replacement rather than a JSON round-trip: two of those files are stored with
CRLF endings and two with LF, and re-serializing them reformatted 5,700 lines.
The byte-level version changes exactly 20 lines and each file still parses.
References that look similar but point elsewhere were deliberately left alone,
and are worth naming so a future pass does not "fix" them:
* "recomp-template PRINCIPLES.md" / "NES recomp template PRINCIPLES.md" in
CLAUDE.md:43, docs/SHADOW_ENHANCEMENTS.md:28,
docs/internal/HLE_SCHEDULER_CARVEOUT_PLAN.md:5,
runtime/src/debug_server.c:4934 and tools/parity_diff.py:8 are a different
repository's file. Only the five that mean this repo's PRINCIPLES.md were
updated.
* Every remaining bare ISSUES.md mention is a GAME repo's tracker
(MegaManX6Recomp 2/7/8/9, TombaRecomp 6), not this repo's.
* docs/disc-speed.md:4,54,56 and docs/internal/bios-hardening.md:5 name
overlay-discovery as a BRANCH, not a file, so no path applies.
INDEXES
README.md's "New here?" table gains rows for docs/WIDESCREEN.md,
docs/ENHANCEMENTS.md and docs/TCP_COMMANDS.md. docs/internal/README.md gains
sections indexing all fourteen documents that moved in, plus an "Upstream
contributor reviews" section describing upstream/ and the new sweep file, plus a
"Removed" bullet for CYCLE_TIMING_ARCH.md (deleted in the previous commit)
pointing at FAITHFUL_TIMING_PLAN.md, CYCLE_MODEL_BEETLE.md and
PRECISE_IRQ_SLICE.md -- following the SLJIT_PERSIST_CACHE.md precedent already
in that file.
docs/ENHANCEMENTS.md:7 claimed framework bugs live in "game repos' ISSUES.md
until a framework tracker exists". A framework tracker does exist; it now says
so and names the Beads epic.
VERIFICATION
A link checker was written to scan every tracked *.md for relative links,
resolving each against the tree being scanned. Baseline at origin/master: 129
files, 137 relative links, 3 broken. After both commits: 127 files, 159 relative
links, 3 broken -- the SAME three, all pre-existing and untouched here:
docs/DATA_SHARDS.md -> INSTANT_LOADS_PARKED.md (never existed)
docs/DATA_SHARDS.md -> INSTANT_LOADS_SPIKE2.md (never existed)
docs/NETPLAY.md -> ../lib/recomp-net/README.md (inside a submodule)
Zero new broken links. The checker's own coverage was checked against a raw grep
for markdown link openers: the 3-link difference is C++ lambdas inside code
blocks, correctly not treated as links.
Also verified: py_compile over all 113 tracked tools/*.py plus psxrecomp_cli.py;
all four seed JSONs still parse; the test-registration guard still reports 123
test files all registered; recompiler/tests/test_coverage_vault.py still passes;
and no file in this commit had its line endings flipped (checked mechanically
across all 50 modified files, after two files were caught and redone).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
149 lines
6.9 KiB
C++
149 lines
6.9 KiB
C++
#include "pgxp_hook_emitter.h"
|
|
|
|
#include <fmt/format.h>
|
|
|
|
namespace PSXRecomp {
|
|
|
|
namespace {
|
|
/* Same register naming both emitters use ("cpu->gpr[n]"); kept local so this
|
|
* TU links into psxrecomp-bios without pulling the game CodeGenerator. */
|
|
inline std::string reg_name(uint32_t n) { return fmt::format("cpu->gpr[{}]", n); }
|
|
inline uint32_t get_rs(uint32_t i) { return (i >> 21) & 0x1F; }
|
|
inline uint32_t get_rt(uint32_t i) { return (i >> 16) & 0x1F; }
|
|
inline uint32_t get_rd(uint32_t i) { return (i >> 11) & 0x1F; }
|
|
inline int16_t get_imm16(uint32_t i) { return (int16_t)(i & 0xFFFF); }
|
|
}
|
|
|
|
/* PGXP dataflow-shadowing hook emission (docs/ENHANCEMENTS.md G1.10; pgxp_hooks.h).
|
|
*
|
|
* Wraps the translated statement with a PGXP_*() macro carrying the raw
|
|
* instruction word plus the operand values the runtime engine needs. Source
|
|
* operands that the statement may clobber (a load/ALU destination aliasing a
|
|
* source, a load overwriting its own base register) are captured into locals
|
|
* BEFORE the statement; everything else is read after it. In the base build
|
|
* the macros preprocess to ((void)0) and the optimizer erases the dead
|
|
* capture locals, so base objects are unchanged; only a -DPSX_PGXP=1 TU pays.
|
|
*
|
|
* Deliberately unhooked: AND/XOR/NOR/SLT-family and the exotic immediates —
|
|
* they only ever DESTROY precision, and the engine's validate-on-read drops
|
|
* their stale shadows without help. The configured widescreen special sites
|
|
* return early above translate_instruction's main dispatch and are likewise
|
|
* unhooked (they are cull compares, not vertex moves; validation covers). */
|
|
bool emission_ends_on_preprocessor_directive(const std::string& code) {
|
|
/* Scan back to the start of the final line, then find its first
|
|
* non-blank character. A directive is legal with leading whitespace, so
|
|
* " #endif" counts just as much as "#endif". */
|
|
const std::size_t nl = code.find_last_of('\n');
|
|
const std::size_t line_begin = (nl == std::string::npos) ? 0u : nl + 1u;
|
|
for (std::size_t i = line_begin; i < code.size(); ++i) {
|
|
const char c = code[i];
|
|
if (c == ' ' || c == '\t' || c == '\r') continue;
|
|
return c == '#';
|
|
}
|
|
return false; /* blank final line -- appending is already safe */
|
|
}
|
|
|
|
void append_pgxp_hooks(uint32_t instr, std::string& code) {
|
|
const uint32_t opcode = (instr >> 26) & 0x3F;
|
|
const uint32_t rs = get_rs(instr);
|
|
const uint32_t rt = get_rt(instr);
|
|
const uint32_t rd = get_rd(instr);
|
|
const int16_t offset = get_imm16(instr);
|
|
const auto addr_expr = [&]() {
|
|
return (offset == 0) ? reg_name(rs)
|
|
: fmt::format("{} + {}", reg_name(rs), offset);
|
|
};
|
|
|
|
switch (opcode) {
|
|
case 0x00: { /* SPECIAL */
|
|
const uint32_t funct = instr & 0x3F;
|
|
switch (funct) {
|
|
case 0x00: case 0x02: case 0x03: /* SLL / SRL / SRA */
|
|
if (rd == 0 || instr == 0) return; /* skip plain nop */
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgx1 = {}; {}\n PGXP_ALU(0x{:08X}u, {}, _pgx1, {}u); }}",
|
|
reg_name(rt), code, instr, reg_name(rd), (instr >> 6) & 31u);
|
|
return;
|
|
case 0x04: case 0x06: case 0x07: /* SLLV / SRLV / SRAV */
|
|
if (rd == 0) return;
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgx1 = {}; uint32_t _pgx2 = {}; {}\n "
|
|
"PGXP_ALU(0x{:08X}u, {}, _pgx1, _pgx2); }}",
|
|
reg_name(rt), reg_name(rs), code, instr, reg_name(rd));
|
|
return;
|
|
case 0x10: case 0x12: /* MFHI / MFLO */
|
|
if (rd == 0) return;
|
|
code = fmt::format("{}\n PGXP_ALU(0x{:08X}u, {}, {}, 0u);",
|
|
code, instr, reg_name(rd),
|
|
funct == 0x10 ? "cpu->hi" : "cpu->lo");
|
|
return;
|
|
case 0x11: case 0x13: /* MTHI / MTLO */
|
|
code = fmt::format("{}\n PGXP_ALU(0x{:08X}u, {}, {}, 0u);",
|
|
code, instr,
|
|
funct == 0x11 ? "cpu->hi" : "cpu->lo",
|
|
funct == 0x11 ? "cpu->hi" : "cpu->lo");
|
|
return;
|
|
case 0x18: case 0x19: case 0x1A: case 0x1B: /* MULT(U)/DIV(U) */
|
|
code = fmt::format(
|
|
"{}\n PGXP_MULDIV(0x{:08X}u, cpu->hi, cpu->lo, {}, {});",
|
|
code, instr, reg_name(rs), reg_name(rt));
|
|
return;
|
|
case 0x20: case 0x21: case 0x22: case 0x23: /* ADD(U)/SUB(U) */
|
|
case 0x25: /* OR */
|
|
if (rd == 0) return;
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgx1 = {}; uint32_t _pgx2 = {}; {}\n "
|
|
"PGXP_ALU(0x{:08X}u, {}, _pgx1, _pgx2); }}",
|
|
reg_name(rs), reg_name(rt), code, instr, reg_name(rd));
|
|
return;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
case 0x08: case 0x09: /* ADDI / ADDIU */
|
|
if (rt == 0) return;
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgx1 = {}; {}\n PGXP_ALU(0x{:08X}u, {}, _pgx1, 0x{:08X}u); }}",
|
|
reg_name(rs), code, instr, reg_name(rt),
|
|
(uint32_t)(int32_t)offset);
|
|
return;
|
|
case 0x0D: /* ORI */
|
|
if (rt == 0) return;
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgx1 = {}; {}\n PGXP_ALU(0x{:08X}u, {}, _pgx1, 0x{:04X}u); }}",
|
|
reg_name(rs), code, instr, reg_name(rt),
|
|
(uint32_t)(uint16_t)offset);
|
|
return;
|
|
case 0x0F: /* LUI */
|
|
if (rt == 0) return;
|
|
code = fmt::format("{}\n PGXP_ALU(0x{:08X}u, {}, 0u, 0u);",
|
|
code, instr, reg_name(rt));
|
|
return;
|
|
case 0x12: { /* COP2 register transfers */
|
|
const uint32_t cop_op = (instr >> 21) & 0x1F;
|
|
if ((cop_op == 0x00 && rt != 0) || cop_op == 0x04) /* MFC2 / MTC2 */
|
|
code = fmt::format("{}\n PGXP_COP2(0x{:08X}u, {}, 0u);",
|
|
code, instr, reg_name(rt));
|
|
return;
|
|
}
|
|
case 0x20: case 0x21: case 0x22: case 0x23:
|
|
case 0x24: case 0x25: case 0x26: /* loads */
|
|
if (rt == 0) return;
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgxa = {}; {}\n PGXP_LOAD(0x{:08X}u, _pgxa, {}); }}",
|
|
addr_expr(), code, instr, reg_name(rt));
|
|
return;
|
|
case 0x28: case 0x29: case 0x2A: case 0x2B:
|
|
case 0x2E: /* stores */
|
|
code = fmt::format(
|
|
"{{ uint32_t _pgxa = {}; {}\n PGXP_STORE(0x{:08X}u, _pgxa, {}); }}",
|
|
addr_expr(), code, instr, reg_name(rt));
|
|
return;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace PSXRecomp
|