xemu keeps a stream voice whose next segment list is empty on that list
for good, repeating its done notification every frame, and replays a
finished list the title has not refilled yet. DirectSound (XDK 5849)
refills the list that just finished and expects the voice to go on
through an empty one: starved for a moment, it puts the next packet in
the other list. Under xemu's rule that packet waited behind the empty
list, played after later segments or again, and DirectSound's lists stayed
out of step with the voice for the rest of the stream.
Burnout 3's attract-mode trailer starves its stream voice in about half
of all runs (the next movie packet comes late once), and from then on
dropped 15-40 ms at every packet to the end of the movie. With the switch
the voice misses a few frames once and carries on: four trailer runs,
two with a starved moment, one 5 ms dip each.
Opt-in, as one title shows it so far. tests/apu_vp covers both rules;
with the switch's code taken out, the four checks of the new rule fail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The frame thread paced per 256-sample EP period: the eight 32-sample
frames ran back to back and the thread slept out the rest, where the
hardware runs one every 0.67 ms. A title that stops a voice and spins until
the voice walk retires it (DirectSound's StopEx, then GetStatus) waited for
the next bunch, up to 7 ms each; Burnout 3's crash mode stops ~900 sounds
in 5 minutes.
DMFBMX2/xboxrecomp#21 spread the frames over the period. Here that alone
changes nothing: the device queue sits at its low mark, where pace_step
allows a 42 ms render-ahead, so the frames still bunch. Instead each frame
is due an eighth of a span after the last, and the queue, read where a
period starts, sets the span: 3/4 of a period at or below low, 9/8 above
mid-band, at once below half of low, none at high. The stall fallback is
shared with pace_step (pace_watch_stall). =0 keeps period pacing.
Tests (apu_monitor): next-frame wait 6.0 -> 1.0 ms max with a smooth and a
512-sample-buffer device, queue in band, no underruns, rate kept; a 1 s
device stall drops periods and recovers. Burnout 3 headless race: stops
over 1 ms 46 -> 33, mean 3.2 -> 1.2 ms, max 6.5 -> 1.7 ms; no dropouts in
the race or in four intro-trailer recordings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the NTSC 4:3 480i/60 default while allowing titles to see independent widescreen and progressive-scan EEPROM capabilities. Cover both single queries and XC_MAX_OS copies with synthetic combinations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
heap_alloc_locked handed a freed block out whole to the next request,
however small. Kung Fu Chaos frees its 6.8 MB streaming buffers when a
load is backed out of with B; the next small requests each took one whole
(15 MB of slack in the [HEAP] exhausted report), the reload's 6.8 MB
malloc returned 0, and the next match crashed on the empty resource.
A block with at least 64 KB to spare is now split (heap_carve_block,
factored out of heap_carve_free; it clears `named` like the rest) and the
rest stays free. Small slack keeps the old behaviour. RECOMP_HEAP_SPLIT=0:
off.
tests/memory_regressions: the default and contig-avoid-image modes now
expect the split (a 16-byte request takes 16 bytes of a freed 2 MB); a new
heap-split-off mode keeps the whole-block check under RECOMP_HEAP_SPLIT=0.
All six modes pass; with RECOMP_HEAP_SPLIT=0 forced, the default mode
fails both split checks.
Tested on Kung Fu Chaos (apexJCL fork, same allocator): 3 of 3 unattended
cancel-and-reenter runs without a crash, the large block reused at the
same address.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RECOMP_WAIT_LOG (#247), RECOMP_TEX_BILINEAR/ANISO (#253),
RECOMP_STRIP_ALT_WINDING (#249), RECOMP_PB_CONST_FAST (#273),
RECOMP_CS_MODE=guest (#260); RECOMP_RASTER_THREADS on POSIX (#242),
RECOMP_VBLANK=0 is off (#263), RECOMP_FULLSCREEN in SDL (#282).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CPU rasteriser takes the nearest texel whatever SET_TEXTURE_FILTER
asked for, so a floor or wall seen at a slant aliases and shimmers.
RECOMP_TEX_BILINEAR=1 blends the four nearest texels of every textured
pixel. RECOMP_TEX_ANISO=8 or 16 takes up to that many bilinear taps along
the longer of the pixel's two texel gradients and implies bilinear; any
other value leaves it off. Both are off by default and read once per
process, so with neither set every title draws exactly as before.
All three sampling paths take them:
- raster_triangle (pixel-position batches): the gradients are constant over
a triangle, so the footprint is worked out once per triangle.
- the perspective path without combiners (xf_rows): the gradient is the
coordinate one pixel right and one pixel down minus the coordinate here,
so it stays perspective-correct. XfTri gains dl[3][2], the barycentric
step per pixel, to evaluate them.
- the register-combiner stages (rc_texel, rc_stage_fetch): the same
neighbour coordinates. rc_texel's existing tent blend moves into rc_tent
so the title's own tent request and the aniso taps share it.
No mip levels: a minified texture is averaged along its stretched axis
only. GPU back ends have their own filtering and are not affected.
Test: tests/nv2a_tex_filter, one process per mode (nearest, bilinear,
aniso8, aniso16) on each of the three paths, 12 CTest cases. A two-texel
ramp checks the blend; a stripe texture of three texels to a pixel checks
that anisotropic taps average where nearest and bilinear alias.
Verified: all 12 pass on Windows (MSVC, VS 18) and Linux x86-64 (gcc 15);
nv2a_raster_batch, nv2a_ffp_backend, nv2a_combiner and nv2a_vsh pass. Built
against the unchanged nv2a_pb_exec.c, the three nearest cases pass and the
nine filtered ones fail. Each path was also broken in turn to confirm that
exactly its cases fail. The default-mode output of the test is
byte-identical before and after on all three paths.
Blast radius: nv2a_pb_exec.c only. With both switches unset the nearest
texel path is unchanged; the added work is a read of two cached ints per
texel (rc_texel), per xf_rows call and per triangle, and six multiplies per
triangle for XfTri.dl. Measured on a synthetic 64x64 textured-quad loop,
that was +2.5% on the pixel-position path, +2.3% on the perspective path
and within noise on the combiner path. With a switch set, 8 and 16 taps
cost several times the nearest path.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
docs/INDEX.md stays the one index. Every page gets one navigation line under
its title that points back to it, and runtime/ gets a reference page for the
environment variables.
docs/runtime/environment-variables.md lists every RECOMP_* switch the runtime
and tools read: its default, its effect and the source file that reads it,
grouped as bring-up, kernel, pushbuffer executor, video, audio and input.
Fifty-one of them were not in the docs at all. docs/INDEX.md links it from
"Start Here".
No page is renamed, moved or rewritten, and no other index is added.
Checked: every RECOMP_* name read by getenv, env_on, apu_env_on, env_int or
xa2_env_int in src/, tools/, templates/ and include/ is on the page, and
every name on the page is in the source. All relative links in docs/ resolve
(0 broken, as at v0.16.0). The 34 existing pages change by insertion only:
68 lines added, none removed. docs/INDEX.md gains one line.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Debug aid, off by default. With RECOMP_WAIT_LOG=1 each
NtWaitForSingleObject, NtWaitForSingleObjectEx and KeWaitForSingleObject
that timed out or lasted at least 500 ms writes one [WAIT] line to stderr:
thread, handle, timeout, result, time waited. It shows which handle a
stalled thread keeps waiting on. Waits behave as before in every case.
Test: tests/kernel_wait_log redirects stderr to a file and makes the three
waits time out on an unsignalled event, then does a signalled wait. Run
with the variable set it expects exactly three [WAIT] lines (one per
function, each with the 20 ms timeout and the timeout result) and none for
the signalled wait; run with it unset it expects none.
Verified: both runs pass on Windows (MSVC) and Linux x86-64 (gcc). With
kernel_sync.c at v0.16.0 the "set" run fails and the "unset" run passes.
Blast radius: kernel_sync.c only. Unset, the switch adds no output and no
behaviour change; the only other difference is three standard includes. Not
covered: the multi-object waits.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The executor expands a triangle strip as (i, i+1, i+2) for every i, so
every odd triangle winds the opposite way to its neighbour. A strip on
hardware keeps one winding by taking the first two vertices of each odd
triangle swapped. A back end that culls from the render state's cull
registers, or lights two-sided from the winding, therefore drops or
back-lights every second triangle of every strip.
Opt-in, off by default: with RECOMP_STRIP_ALT_WINDING unset the strip order
is unchanged and no title's output moves. Both strip expansions read it
(the transform path and the screen-space indexed path).
Test: tests/nv2a_ffp_backend draws a four-vertex strip and checks the
second triangle's vertex order, run once without the switch (1 2 3) and
once with it (2 1 3). With the switch forced off in the source the second
run fails; with it working both pass.
Verified: nv2a_ffp_backend (2 tests), nv2a_pb_walk, nv2a_raster_batch,
nv2a_vsh and nv2a_combiner pass on Windows (MSVC);
nv2a_ffp_backend passes on Linux x86-64 (gcc).
Blast radius: the strip cases of the two expansion switches in
nv2a_pb_exec.c, behind the switch.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
POP32 assigned dst before adding 4 to sp, so a lifted `pop esp` left esp
at the popped value + 4. The SDM has POP ESP load esp with the value read
from the old top of stack. Spartan: Total Warrior's round-to-int helper
(push esp; push eax; fld; frndint; fistp [esp]; pop eax; pop esp)
returned with esp off by 4, which put a garbage edi into a heap free.
POP32 now reads into a temporary, bumps sp, then writes dst; every other
destination behaves as before, and -O3 code is the same size.
Tests: the new ctest tests/stack_ops runs the lifter's emitted stack
statements (push/pop esp, the round-to-int idiom, an ordinary pop,
push/pop [esp+4], leave, pushad/popad) over a fake guest stack; the old
macro fails its three pop-esp checks. docs/pipeline/04-lifting.md and
docs/technical/register-model.md show the new macro.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stub in recomp_stubs_unresolved.c stands in for code no pass found, so
reaching one skips that code and the failure shows up elsewhere: a stall,
a wrong value, a crash far downstream. Nothing said a stub had run.
The stub file now defines RECOMP_STUB_HIT(va), and each stub calls it
before it pops. With RECOMP_STUB_LOG set to anything but "0", the first hit
of each stub prints its address, the return address on the guest stack
(the caller's caller for a tail jump) and esp to stderr. Unset, nothing is
printed; the cost is one cached getenv and one static per stub.
Tests: test_stub_log.py (the stub calls the macro and still pops its
bytes; a compiled stub file logs one line on two hits with
RECOMP_STUB_LOG=1, and none when unset or "0"). Documented in
docs/pipeline/06-debugging.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts kept both sides: #193's s_irq_line reset next to the diagnostics
reset, #190's watchdog missing-file counts before the WAV close; kernel_hal.c
keeps the merged #194's field-pin comment.
The RECOMP_AUDIO_HOST starvation check raised its reference
(deficit_max) on every small rise of the deficit, so a loss that arrived
in pieces below the jitter threshold was absorbed and never reported:
twenty 5 ms gaps reported nothing while one 100 ms gap reported 96 ms.
The reference now moves to the deficit only when a loss is reported, and
a loss counts only once the device has run dry (the backend's underrun
count rose): without a dry spell a rising deficit is the device's clock
(SDL's dummy driver runs about 3% slow) and the reference follows it as
before. After a dry spell it creeps at most 200 ppm, so real device
drift is not added to a pending loss; the 250 ms settle window after
each baseline covers backend staging at start. On a clock further off
than 200 ppm (the dummy driver) each dry spell can over-report by about
a buffer, and a single loss under one buffer is absorbed; real devices
sit well inside. The queue is read before the submit, as it was: both
backends count an underrun only when a poll sees the queue empty, and a
dry spell that starts mid-period gets no other poll. The frame-thread
idle rebase keeps drain and shutdown out of the count. A unit test
covers one large gap against many small ones of the same total, spaced
100 ms and 1 s apart, +-150 ppm drift over 600 s, a 3% fast or slow
clock that never runs dry, and a drain. apu_monitor runs with the three
switches =1, unset and =0, and each ctest says which to expect, so
reading =0 as on fails the off run.
The submission WAV records what the APU handed the backend, not what the
device played. The once-a-second line now reports wav/played sample
counts, starved_ms plus pending_ms (time the device inserted silence) and
refused submits; a refused buffer is in the WAV but never played, so
wav= counts every period handed over and refused= the ones dropped.
RECOMP_APU_TRACE, RECOMP_APU_RING and RECOMP_AUDIO_HOST were presence
switches, so =0 turned them on. They now parse as the other switches
(empty or 0 is off). Diagnostic state (host accounting, IRQ stats, voice
trace, ring captures and dump files) is reset on init and released in
finalize so a reinit starts clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title that streams music decodes it on the CPU into a looping PCM
voice and writes ahead of the play cursor. When the writer falls behind,
the VP plays the previous lap again: no digital zero, nothing a check on
the mix or the WAV dump can flag, only a stutter to the ear. A race
between the decoder thread and the APU looks exactly like this.
With RECOMP_APU_RING set, each looping PCM buffer of 2 KB or more is
split into 1 KB blocks and the fetched samples are hashed per block.
A buffer becomes a ring once some block plays differently on two laps
(a looped effect never does and is never judged). In a ring, a
non-silent block that plays exactly as it did one lap before is logged
as [APU-RING] stale (first 200), and once a VP second each ring reports
its stale count and the writer's lead over the cursor.
Unset, the check returns on a cached flag before touching anything.
tests/apu_monitor gains a ring case: a writer that keeps two blocks
ahead for six laps logs no stale block; once it stops, at least a lap
of blocks is stale. The plain run checks the monitor stays silent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two questions come up on every audio report, and neither could be
answered from a log. Did the device run dry, or did the APU produce the
fault? And which voice is it, reading what?
RECOMP_AUDIO_HOST (or RECOMP_APU_TRACE) sets the device's consumed
samples (new xa2_samples_played: SamplesPlayed on XAudio2, queued minus
still queued on SDL2) against the wall clock at each submit. A deficit
that grows by more than a device buffer is a starve, logged with its
sample index into the RECOMP_AUDIO_WAV dump, so the two line up. It also
times front-end trap spells, which produce no frames.
Under RECOMP_APU_TRACE:
- [APU-VSTAT], once a second per voice: format, source address and how
mcpx_apu_phys resolved it (mcpx_apu_phys_class, also on the doorbell
line), envelope, volumes, RMS and zero-crossing rate. Noise read from
the wrong place shows itself by its zero-crossing rate.
- [APU] voice N pos=CBO/EBO every 60 frames: the clock a title that
syncs to audio follows.
- [APU-IRQ] every 5 s: traps, VP frames, trapped frames, underruns.
Counted outside the interrupt delivery path, which is left as is.
RECOMP_APU_SOLO=<voice> mixes one voice; RECOMP_APU_VOICE_DUMP writes
one voice's (or every voice's) fetched samples to raw files.
All are plain getenv, read once and off when unset. tests/apu_monitor
gains a voice-trace case, run with the trace on (two lines, advancing)
and off (none). docs/pipeline/06-debugging.md lists the variables.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POSIX hosts had neither: fb_present.c is Win32 GDI with POSIX stubs, and
the xa2_* audio backend was stubbed inactive. A macOS or Linux build ran
with no picture and no sound.
fb_present_sdl.c is the framebuffer window for POSIX, opt-in with the same
RECOMP_FB_WINDOW switch. AppKit only runs on the main thread, so the shape
is inverted: a title hands its boot sequence to xbox_HostWindowMain(),
which keeps the window and the one SDL event loop on the main thread and
runs the guest on a pthread (at least the main stack; same QoS on macOS).
The flip copies the finished surface into one of three slots and publishes
it under a short mutex, so the executor never waits for the window. Same
640x480 surface convention and title bar as the GDI window. Without the
switch, headless, or with no display, the guest runs on the calling thread
as before. While the main thread pumps events, xinput_device.c only reads
the controllers.
apu_sdl2.c implements the xa2_* contract over SDL_QueueAudio, with the
XAudio2 backend's buffer size and depth (1024 x 3, a period refused while
the queue is full; SDL's queue does not count the buffer the device is
playing, so it is refused at two). RECOMP_HEADLESS=1 takes SDL's dummy driver unless
SDL_AUDIODRIVER is set.
SDL's SIGINT/SIGTERM handlers only post an SDL_QUIT that nothing reads
without a window, so every SDL entry point keeps the default handlers.
docs/runtime/README.md shows the POSIX main() a title needs: a
SIGSEGV/SIGBUS handler that calls xbox_PosixMmioFault, and the boot
sequence handed to xbox_HostWindowMain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #162 (round 2):
- The walk stops at PUT inside a method's parameters and finishes the
same method when PUT moves, as the DMA engine does. It no longer runs
on through stale ring contents, and it no longer reads the leftover
parameters as headers (D3D streams large inline arrays across kicks).
A CALL inside a CALL stops the walk instead of overwriting the return
address.
- fetch_attr checks every vertex read against guest memory, so a garbage
32-bit index drops the batch instead of reading past guest RAM. Surface
writes are refused outside guest memory and on the thread stacks, as
they already were on the image.
- 2x2 anti-aliasing: the framebuffer window takes every other row
(xbox_FramebufferWindowSetAA), and the screen-space fallback scales its
vertices like the clip rect.
- s_xf and s_bverts are allocated on first use (about 13 MB).
- Tests: PUT inside a method, nested CALL and self-jump in nv2a_pb_walk;
a garbage index, lighting below the clamp with an attenuated local
light, and the 0x0310 latch in nv2a_ffp_backend.
- Docs: the back-end advice is marked as coming from a back end not in
this tree.
The Burnout 3 run: with RECOMP_PB_EXEC=1 the DMA walk froze it at the
Crash Nav menu and in the garage, where v0.13.0 runs. A freeze report put
the main thread in KeWaitForSingleObject under D3D's fence wait: told
exactly how far the GPU has got, D3D patches a software method into the
pushbuffer and sleeps on the event the GPU's interrupt for it would set,
and this runtime does not deliver that interrupt. The walk commit alone
reproduces it. So the walk is now opt-in, RECOMP_PB_WALK=dma, and the
default is the segment scan v0.13.0 used, with 0x0310 unmodelled as
before. In the default mode Burnout 3 runs Crash Nav and loads the car,
with no faults. Under the walk, a project that mirrors its fence
(xbox_Nv2aMirrorFence) gets a 0x0310 latch whose fence bits match the
mirrored word.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pushbuffer-executor.md covers what sits around the v0.13.0 rasteriser: the
DMA-engine walk, answering the title while it runs, fixed-function transform
and lighting, anti-aliased surfaces, index width and the back-end interface.
d3d8ltcg-device-context.md gains the semaphore hand-off for a title whose fence
wait is replaced while the executor runs, and the PGRAPH 0x400B10 wait.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Folded into the existing guides:
- 02-disassembly: four ways the detector misses or merges functions,
each with the check for it
- 04-lifting: negative-index jump tables, privileged registers
- 05-runtime: thread-local registers in recomp_manual.c, replace vs
wrap, RECOMP_ABI_CHECK needing both halves
- 06-debugging: what the ABI checker always reports, guest registers
in cdb
- kernel-replacement: pseudo-handles, the 487 the CRT heap waits for,
a 64-bit call counter
- GETTING_STARTED: /m under Git Bash
New: docs/INDEX.md, every document in one place and again by symptom,
linked from the README. CONTRIBUTORS gains an entry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`--split` is functions per file, and the files are whole programs rewritten
as C. At 1000 functions a chunk reaches a quarter of a gigabyte, and GCC's
memory use follows it: a 257 MB translation unit **OOM-killed a 15 GB
machine twice**, each time after half an hour of build. The same generation
at `--split 250` tops out near 100 MB and compiles without trouble --
21400 functions either way, same totals, same output.
The trap is that the recommended value works until it doesn't. An older,
less complete lifter emitted less code per function, and the same title's
largest chunk was 206 MB, which fits. Fixing the lifter grew it by a
quarter and pushed it over -- so following the documentation exactly
produced a build that could not be completed, on a machine that had built
the same game the week before.
Also worth saying out loud, because it cost time twice: the failure does
not look like a failure. The compiler is killed by the kernel, `make`
reports a signal rather than an error, and re-running resumes and dies on
the same file. Nothing in the output points at memory.
Docs only, plus the two command lines that recommend the value.
tools/fusion/coverage_oracle.py has sat in the tree unrunnable. It grades our
function-boundary detection against Microsoft's PrecompiledSymbolTable, and
its second argument is our detection for the *donor* title -- which means you
need that title's original Xbox default.xbe to run the pipeline over. The XBE
is not in the recompiled DLL. It is inside the BC package's SVOD container,
which everyone had assumed was sealed. It is not: it is a plain XDVDFS
filesystem with SHA-1 hash blocks interleaved at a fixed stride, and the
stride is self-proving because the hashes check.
tools/fusion/svod.py reads it -- ls, extract, verify -- in the shape of
module.py. Verified by extracting default.xbe from all four shipped BC titles
and comparing sha1 against independent extractions: byte-identical on all
four (Fuzion 2,834,432 / Crimson 3,219,456 / Blinx 44,728,320 / Conker
7,774,208 bytes).
Two things in the format bite, and both are why this is more than forty lines
of seek arithmetic.
The sector base is per title. Filesystem sectors are sectors of the original
disc; the SVOD stream is a slice of it. For Fuzion and Crimson that slice is
the whole game partition and the base is the XDVDFS constant 32. For Blinx it
is 880,036 and for Conker 956,202, and assuming 32 there does not fail -- it
reads the wrong data, quietly. So derive_base() solves for it and proves the
answer: the root table must parse, it must name default.xbe, and that entry
must resolve to XBEH under the same base. Parsing alone is not enough, which
Conker demonstrates: its directory tables are packed into consecutive sectors
and bases 956,201 through 956,207 all parse into plausible entry lists.
The other is that a bad extraction still looks right. A flat contiguous copy
of the Data files -- hash blocks and all -- parses as a valid XBE and reports
the correct title, build date, base address, section names and even the
correct XDK library version, because that all lives in the first 0x1000 bytes
and the first data block is genuine. Three extractions passed a header-only
check during this work and were wrong. xbe_gate() carries the tells that do
fire: the 0x8000xxxx kernel-thunk run must be at the VA the header declares,
and the TLS zero-fill must be a few bytes rather than the ~1.9 billion a
displaced read produces.
Limits, honestly:
- The tests are arithmetic, the directory parser against a handcrafted table,
and base derivation against a synthetic image with Conker-shaped decoys.
None of them touch a package, because the repository ships none and should
not. The four sha1 comparisons are recorded in the doc; CI cannot re-run
them.
- The PIRS header at +0x379 carries a data-block offset that gets within two
sectors of the base on all four titles, but the two-sector gap on the two
enhanced-GDF-layout titles is unexplained and four samples is not a rule.
It is used as a search hint that shortens the candidate list, never as an
answer -- the gate still has to pass.
- Read-only. The hash blocks are used as a witness that the stride is right,
not validated as a tree, so this will not tell you a package is damaged.
- Measured on the four shipped BC packages only. Other SVOD content may lay
out differently; verify first, and svod.py verify is that command.
docs/technical/svod-extraction.md is a new file rather than a section in
ms-fusion-corpus.md: the corpus doc is about what the recompiler does versus
what a game is, and a container format with a per-title table and a
validation gate is a different subject. Linked from there and from the README.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X8ULfUvyuk8K69chXaNFM9
A recompiled function named `isnan` did not build. The C99 <math.h>
classification names are function-like *macros*, so the name does not
collide, it expands: `void isnan(void);` becomes
`void (fpclassify(void) == FP_NAN);` and the compiler reports a bad
parameter declarator inside corecrt_math.h, naming neither the guest
function nor the clash. Reported by @jv36 from a FIFA Street 2 port.
Fixed at `_func_ident`, which is the last guard before a func_db name
becomes a C token and the only one every name source passes through.
merge_names.py filtered a similar set earlier but sees the Ghidra path
alone, and its list was the *stronger* of the two -- so the IDA path added
in c17bf42, and any hand-written symbols file, walked straight past names
merge_names would have caught. `_func_ident` now carries C99 <math.h> and
<stdlib.h> in full; merge_names gets the classification macros too.
tests/recomp/test_reserved_idents.py compiles every reserved name against
the headers a generated TU actually includes, with a negative control that
feeds the same harness the unmangled name and requires it to fail -- all
twelve sharp cases do.
Docs, from the same conversation:
- docs/GETTING_STARTED.md omitted `tools.abi_analysis` entirely, and it is
the guide people are pointed to. It is not optional: without
abi_functions.json, recomp warns once and falls back to cdecl / 0 params
/ int_or_void for every function in the game. Added as Step 4.5, ahead of
the optional Ghidra step, which becomes 4.6.
- That guide also said 'Windows 11' as a hard requirement while the README
documents Linux and macOS, which is why someone went looking for a Linux
build they could not find. Replaced with a platform matrix that says what
actually differs: the pipeline runs anywhere, the D3D11 backend is six
files against one for OpenGL.
- `py -3` is the Windows Python Launcher and every command uses it. Noted
the python3/python spellings in both guides.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
GHIDRA_HOME defaulted to /c/tools/ghidra/ghidra_12.0.3_PUBLIC, which dates the
script the first time anyone updates -- and someone had, by ten revisions.
GHIDRA_ROOT now names the directory holding the installs and the runner takes
the newest ghidra_*_PUBLIC under it, accepting GHIDRA_ROOT itself being an
install for anyone who keeps it unversioned. GHIDRA_HOME still names one
exactly. A missing install now says so instead of failing later on a path that
is not there.
Both READMEs also claimed no XBE loader exists. One does --
XboxDev/ghidra-xbe -- and it works on current Ghidra despite warning about a
version mismatch. The flattening path still does not need it, and the reason is
worth stating: it is version-proof and puts every address where functions.json
expects it, which is what makes merging the names back work at all.
Reported by @DarthSidious666 (#26), including the version-mismatch detail.
Co-authored-by: DarthSidious666 <57962477+DarthSidious666@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BuW5WGcXFFrLAYEfvCNGs1
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
Asked for by someone using the recomp as a function splitter for a decomp,
which the toolkit was already most of the way to without saying so anywhere.
The analysis half -- boundaries, call graph, calling conventions, frame shapes,
recovered names -- is the same whether you go on to recompile or not, and
tools/recomp was simply the only consumer of it.
Each function gets a file: a header with its address range, size, section,
detection method and confidence, its signature from tools.abi_analysis, and its
callers; then the body, with branch targets inside the function labelled and
callees named.
The bytes are `db` and the disassembly is a comment beside them, which is the
opposite of what an N64 decomp does and deliberately so. MIPS round-trips
through an assembler because the encoding is fixed-width and unambiguous. x86
does not -- `mov eax, ecx` has two encodings, immediates have short forms, and
which one MSVC picked cannot be recovered from the mnemonic. Reassembling a
listing gives code that runs identically and does not match, and matching is
the only oracle a decomp has. Emitting the original bytes as data makes the
file byte-exact by construction and still leaves the disassembly to read.
Verified rather than asserted, and the verification found two real bugs:
- reconstructing bytes from the instruction stream produced files longer than
the function, because a decoded instruction can start inside a function and
run past its end wherever data was decoded as code. 102 of 2,254 functions,
silently. Bytes now come from the image and coverage is exact by
construction.
- filling only the trailing gap left three functions short, because MSVC
parks switch tables in the middle of a function body and the disassembler
correctly marks those as data. memcpy has two. Gaps are filled wherever
they occur and come out as labelled data runs in place.
Xbox Dashboard .text: 2,254 of 2,254 functions byte-identical to the shipped
binary.
docs/DECOMP.md is the guide, separate from GETTING_STARTED because it is a
different job with a different endpoint -- and it is honest about what is not
solved: no object-file grouping, code only, inferred boundaries that are wrong
in data-heavy regions, and byte-identical is not build-identical.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013pS5pcx2cx9JXyKurjok17
Asked for by someone using the recomp as a function splitter for a decomp,
which the toolkit was already most of the way to without saying so anywhere.
The analysis half -- boundaries, call graph, calling conventions, frame shapes,
recovered names -- is the same whether you go on to recompile or not, and
tools/recomp was simply the only consumer of it.
Each function gets a file: a header with its address range, size, section,
detection method and confidence, its signature from tools.abi_analysis, and its
callers; then the body, with branch targets inside the function labelled and
callees named.
The bytes are `db` and the disassembly is a comment beside them, which is the
opposite of what an N64 decomp does and deliberately so. MIPS round-trips
through an assembler because the encoding is fixed-width and unambiguous. x86
does not -- `mov eax, ecx` has two encodings, immediates have short forms, and
which one MSVC picked cannot be recovered from the mnemonic. Reassembling a
listing gives code that runs identically and does not match, and matching is
the only oracle a decomp has. Emitting the original bytes as data makes the
file byte-exact by construction and still leaves the disassembly to read.
Verified rather than asserted, and the verification found two real bugs:
- reconstructing bytes from the instruction stream produced files longer than
the function, because a decoded instruction can start inside a function and
run past its end wherever data was decoded as code. 102 of 2,254 functions,
silently. Bytes now come from the image and coverage is exact by
construction.
- filling only the trailing gap left three functions short, because MSVC
parks switch tables in the middle of a function body and the disassembler
correctly marks those as data. memcpy has two. Gaps are filled wherever
they occur and come out as labelled data runs in place.
Xbox Dashboard .text: 2,254 of 2,254 functions byte-identical to the shipped
binary.
docs/DECOMP.md is the guide, separate from GETTING_STARTED because it is a
different job with a different endpoint -- and it is honest about what is not
solved: no object-file grouping, code only, inferred boundaries that are wrong
in data-heavy regions, and byte-identical is not build-identical.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013pS5pcx2cx9JXyKurjok17
All three from people following the instructions and reporting where they
stopped.
recomp_types.h is now written into --gen-dir by tools.recomp. It lived only in
templates/runtime/, so a project copied from the template hit
`error C1083: Cannot open include file: 'recomp_types.h'` at build time and had
to find it by hand. It is the runtime's register model rather than anything a
project writes, and recomp_funcs.h includes it -- a quoted include searches the
including file's own directory first, so emitting it beside the generated code
is all it takes. An existing copy is never overwritten, so a project that has
edited it keeps its edits; delete it to get the current one back.
The disassembler now names the file it wants when the analysis JSON is missing.
It said only "run the XBE parser first", leaving both the filename and its
location to guess, and someone did: `--json JSON`, then `--analysis-json JSON`
to get past the same error one step later. It now prints the exact path and the
exact command that writes it, and says that the name is what auto-detection
keys on.
The README's own quick start was the wrong instructions. Step 3 ran
tools.xbe_parser with no --json, so step 4 could not find the analysis it
needs -- and the README is what people follow, since it is the front page. It
now passes --json with the name the next step looks for, notes what --text-only
excludes, and points at GETTING_STARTED as the version that explains why.
Also: the Ghidra naming pipeline was fully built and documented in
tools/ghidra_naming/README.md and mentioned in neither guide, so "any way to
port over Ghidra labels easily?" had no findable answer. GETTING_STARTED now
has it as step 4.5, before recompiling, because the recompiler emits whatever
name is on the functions.json entry -- run it after and the names reach the
generated C, the crash traces and the ABI reports.
And the CUSTOMIZE note on RECOMP_ICALL_IS_CODE is gone. It told readers to edit
the VA range for their title; the range has come from g_xbox_code_lo/hi since
the hardcoded 0x00400000 cutoff was removed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013pS5pcx2cx9JXyKurjok17
All three from people following the instructions and reporting where they
stopped.
recomp_types.h is now written into --gen-dir by tools.recomp. It lived only in
templates/runtime/, so a project copied from the template hit
`error C1083: Cannot open include file: 'recomp_types.h'` at build time and had
to find it by hand. It is the runtime's register model rather than anything a
project writes, and recomp_funcs.h includes it -- a quoted include searches the
including file's own directory first, so emitting it beside the generated code
is all it takes. An existing copy is never overwritten, so a project that has
edited it keeps its edits; delete it to get the current one back.
The disassembler now names the file it wants when the analysis JSON is missing.
It said only "run the XBE parser first", leaving both the filename and its
location to guess, and someone did: `--json JSON`, then `--analysis-json JSON`
to get past the same error one step later. It now prints the exact path and the
exact command that writes it, and says that the name is what auto-detection
keys on.
The README's own quick start was the wrong instructions. Step 3 ran
tools.xbe_parser with no --json, so step 4 could not find the analysis it
needs -- and the README is what people follow, since it is the front page. It
now passes --json with the name the next step looks for, notes what --text-only
excludes, and points at GETTING_STARTED as the version that explains why.
Also: the Ghidra naming pipeline was fully built and documented in
tools/ghidra_naming/README.md and mentioned in neither guide, so "any way to
port over Ghidra labels easily?" had no findable answer. GETTING_STARTED now
has it as step 4.5, before recompiling, because the recompiler emits whatever
name is on the functions.json entry -- run it after and the names reach the
generated C, the crash traces and the ABI reports.
And the CUSTOMIZE note on RECOMP_ICALL_IS_CODE is gone. It told readers to edit
the VA range for their title; the range has come from g_xbox_code_lo/hi since
the hardcoded 0x00400000 cutoff was removed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013pS5pcx2cx9JXyKurjok17
Every documented command ran inside the toolkit clone, whose CMakeLists has
no main() and never will -- so following the README to the end produced six
static libraries and no executable. templates/new-game/, which is the thing
that actually builds the exe, was named once in CONTRIBUTING.md and nowhere a
new user would look.
Both entry points now say so plainly and point at the template: README's
build section and Quick Start, and GETTING_STARTED steps 0, 5, 6 and 7. The
recomp step gains --gen-dir, since the default lands the generated code in
src/game/recomp/gen/ inside the toolkit, where no target compiles it -- the
same symptom by another route.
Step 6 previously told you to hand-write a CMakeLists.txt and a main.c whose
boot sequence no longer matches the runtime (recomp_lookup(entry) rather than
xbe_entry_point(), no dispatch init). It now customizes the template instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01617t3vMzAvehCXuyridpT1
Every documented command ran inside the toolkit clone, whose CMakeLists has
no main() and never will -- so following the README to the end produced six
static libraries and no executable. templates/new-game/, which is the thing
that actually builds the exe, was named once in CONTRIBUTING.md and nowhere a
new user would look.
Both entry points now say so plainly and point at the template: README's
build section and Quick Start, and GETTING_STARTED steps 0, 5, 6 and 7. The
recomp step gains --gen-dir, since the default lands the generated code in
src/game/recomp/gen/ inside the toolkit, where no target compiles it -- the
same symptom by another route.
Step 6 previously told you to hand-write a CMakeLists.txt and a main.c whose
boot sequence no longer matches the runtime (recomp_lookup(entry) rather than
xbe_entry_point(), no dispatch init). It now customizes the template instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01617t3vMzAvehCXuyridpT1