Commit Graph

613 Commits

Author SHA1 Message Date
sp00nz bf0d02df56 USB pad: queue live presses that arrive together instead of firing them at once
A title that polls its pad a few times a second -- Burnout 3 under the
software rasteriser -- read "down" and "a" in the same report, which
landed it in the wrong menu. Lines read together now fire one after
another with a 200 ms release between them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 14:57:08 -07:00
sp00nz 68b3db9012 USB pad: RECOMP_PAD_LIVE, button presses appended while the title runs
A fixed timeline cannot navigate a menu on a rasterised run: how long a
screen takes to appear depends on how much the software rasteriser has
to draw, so the same script lands its presses on different screens from
one run to the next. Burnout 3's title screen arrived at 37 s in one run
and past 44 s in the next, and the START meant for it went nowhere.

RECOMP_PAD_LIVE=<file> polls the file every 50 ms and presses each new
line -- <button>[+<button>...][:<hold ms>] -- the moment it is read.
With RECOMP_FB_DUMP that closes the loop: look at the frame, append a
press, look again. Finished steps are compacted away, so a long session
does not run out of slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:57:24 -07:00
sp00nz 967f379c2c USB pad: RECOMP_PAD_SCRIPT, a timed button script for headless bring-up
RECOMP_PAD_PRESS pulses one digital mask forever. That gets a title past
a "press Start" screen and no further: menus want A, which is an analog
button on the Xbox pad, and they want presses in order.

RECOMP_PAD_SCRIPT takes a timeline, <ms>:<button>[+<button>...][:<hold>],
comma separated or from a file with @path. Times count from the first
report the title asks for, so from enumeration rather than process
start. Digital buttons (up down left right start back lthumb rthumb) set
report byte 2; a b x y black white lt rt report fully pressed. Every
step prints as it fires, so the run log records what was pressed when.

Holds default to 150 ms, but a title rendered through the software
rasteriser polls input a few times a second, and a short press lands
between polls: Burnout 3 ignored 150 ms presses there and took 1200 ms
ones. Opt-in, like RECOMP_PAD_PRESS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:51:37 -07:00
sp00nz 423263b6fc Never hand out physical page 0 from MmAllocateContiguousMemory
The XDK's USB stack assumes the kernel keeps physical page 0 for it.
XPP carves its host controller structures from a private 0xFE0-byte
arena ending at 0x80001000 without any allocation call (sub_00365454
in Burnout 3). The contiguous bump allocator started at 0x80000000, so
the title's first MmAllocateContiguousMemory -- XAPI's launch data
page -- got the same page, and whichever wrote last won.

Timing decided which. With kernel logging slowing the title down, the
pad enumerated; without it the hub DPC reached the root port reset
with a device whose parent pointer had been overwritten and either
stopped there or faulted in sub_003675E0 walking it.

The allocator now starts one page in. Three fast Burnout 3 runs out of
three enumerate the pad (port reset, SET_CONFIGURATION, XID descriptor)
with no fault; before, none did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:29:51 -07:00
sp00nz bd87c4f48f OHCI: resolve the physical addresses a driver hands the controller
A host controller is a bus master, so HcHCCA, HcControlHeadED, the ED
and TD links and the buffer pointers are all physical. On hardware
physical P and the contiguous window's 0x80000000 + P are the same
bytes; here the window is separate storage. A driver that builds its
descriptors in MmAllocateContiguousMemory and converts them with
MmGetPhysicalAddress -- the documented way -- therefore handed the
walker addresses that named nothing it wrote.

Burnout 3's XPP does exactly that: descriptors at 0x825B50C0 written to
HcControlHeadED as 0x025B50C0. Every ED read back as zeroes, the
controller saw an empty list, and enumeration waited forever. (DDS9's
driver writes window addresses directly, which guest_ok already took.)

bus_resolve() maps an address below the contiguous allocator's
high-water mark into the window, as dma_resolve() does for pushbuffer
surface offsets, except inside the loaded image: drivers also point
transfers at their own statics (Burnout 3's first GET_DESCRIPTOR reads
into 0x0041A904), and a real kernel never hands out contiguous memory
that overlaps the image.

With it Burnout 3 enumerates the pad end to end: GET_DESCRIPTOR,
SET_ADDRESS, GET_DESCRIPTOR(config), SET_CONFIGURATION, the XID
descriptor, then input reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:27:40 -07:00
sp00nz 57a7ffdc3c Acknowledge the DSP doorbell whatever the APU front end is doing
RECOMP_APU_DSP_ACK stands in for the GP DSP clearing DirectSound's
command word. It ran from mcpx_apu_dsp_frame, i.e. only inside se_frame,
which the frame thread skips while FECTL is trapped or halted. On
hardware the GP runs regardless of the front end's method mode.

DirectSound posts a command only after the previous one is cleared, so
once the gate closed it waited forever. Burnout 3 hit it with the
pushbuffer executor on: acked at init, then stuck in sub_002F805E
polling the same doorbell before posting command 2.

The poll now runs every frame-thread iteration, ahead of the gate. Only
titles that set RECOMP_APU_DSP_ACK are affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 04:59:10 -07:00
sp00nz 21d9ce75b8 Lift switch tables whose displacement is not slot 0
MSVC's CRT memcpy/memmove dispatch unaligned lead and trail bytes as

    and  eax, 3              ; 1..3 on this path, never 0
    jmp  [eax*4 + LeadUpVec - 4]

    sub  ecx, 4              ; -4..-1 when fewer than 4 dwords remain
    jmp  [ecx*4 + TrailUpVec + 16]

Reading forward from the displacement finds the jmp's own bytes in the
first form and the code after the table in the second, so both were
lifted as unresolvable indirect tail jumps. At runtime the target is
not a function, the ICALL is skipped, and memcpy returns without
copying whenever the destination is unaligned.

The emitted switch compares the loaded value against its arms instead
of indexing, so only the set of arms matters. When slot 0 is not an arm,
the lifter now also tries the slots after it and the slots below it,
and CFG recovery's census tries skipping slot 0. A census entry stays
authoritative: the lifter never rediscovers arms recovery rejected.

Surfaced in Burnout 3: its memcpy's jump-table arms were reached as
indirect targets, and feeding them back as seeds split memcpy and sent
XAPI down its dashboard-update path. Any title linking the MSVC CRT
has these two jumps (Half-Life 2 still carries one such ITAIL).

tools/recomp/test_switch_table_offset_index.py covers both forms; it
fails without the change. pytest tools/: 562 -> 564 passed, 17 skipped
before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 04:11:43 -07:00
sp00nz bdfd497785 Leave the APU's GP/EP DSP memory untrapped under RECOMP_AC97_READY
RECOMP_AC97_READY made the whole 512 KB APU aperture PAGE_NOACCESS so
register accesses reach the APU model. Only the first 0x30000 of that
is registers and the VP. 0x30000-0x7FFFF is the GP and EP DSPs' own
X/Y/P memory, which is plain RAM on hardware and which the model does
not implement at all: mcpx_apu_dispatch_mmio drops writes there and
mcpx_apu_mmio_read returns 0.

So trapping it bought nothing and cost a fault on any access the MMIO
decoder cannot emulate. Burnout 3's DirectSound bulk-copies DSP memory
with rep movsd, which the lifter lowers to a host memcpy; that faulted
at guest 0xFE830B78 inside the CRT with no way to resume, right after
the DSP doorbell ack let DirectSoundCreate proceed.

Trap the register and VP range only. GP/EP now keep what the title
writes, which is closer to hardware than the old read-as-zero. Only
titles that set RECOMP_AC97_READY see a difference.

Surfaced bringing Burnout 3 up on the toolkit runtime: with this, its
RenderWare audio device creates and the boot continues past engine
start instead of faulting on the NULL device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 03:50:12 -07:00
sp00nz 9547d39179 Stop leaking the RAM mirror span reservation on Windows
xbox_MemoryLayoutInit reserves base + 28 mirrors as one range and then
releases the head slice with VirtualFree(base, size, MEM_RELEASE). Win32
cannot release part of a reservation: MEM_RELEASE with a nonzero size is
ERROR_INVALID_PARAMETER. Both frees fail, the base view never maps at the
span, and the whole span stays reserved for the life of the process.

At the default 64 MB map that is 1.8 GB, which the OS places at
0x80000000 -- the host range the contiguous window needs. The window
then fails with error 487 and the first read of the kernel page inside
it faults in xbox_MemoryLayoutInit. Half-Life 2 never saw it because its
768 MB map pushes the span above 4 GB.

Surfaced bringing Burnout 3 (64 MB map) up on the toolkit runtime. Any
title that keeps the default map size hits it.

The span path only works on POSIX, where the shim's VirtualFree unmaps a
sub-range, so it is now compiled there only. Windows falls straight to
the fixed-base loop it was already using after the span failed. Doing
the span on Windows needs placeholder reservations (VirtualAlloc2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 03:05:10 -07:00
Ned Heller ea60cfa485 Ask contributors where their code comes from (#132)
xboxrecomp is MIT, and a fix ported from a GPL project relicenses it by
accident -- very hard to untangle once it has shipped. Say so up front,
and ask for provenance in the PR.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 02:46:05 -07:00
sp00nz 8013525629 Release v0.12.0 -- "Never Taken"
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.12.0
2026-09-27 01:03:48 -07:00
sp00nz ddeb2ad2cc Fixups: #122's fused jcc reads the normalised form too; frndint test finds clang; apu_mmio_hook includes stdlib.h
The fused test+jcc emitted its inline condition from the raw test while
the snapshot beside it was now cmp X,0, so every fused test/jcc tested
X & 0 -- 11 conformance vector mismatches. Build the condition from the
same normalised form.

getenv without <stdlib.h> is implicit int on MSVC, which truncates the
pointer on x64 (C4013). #128 carries the same fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 01:01:04 -07:00
sp00nz 1eed5857fa Fixups for the v0.12.0 merge batch
- #89: guest-buffer floor was g_fs_base, which is per-thread; a worker
  thread's TIB sits high, so its reads into the image were refused
- #92: watch_is_code used one title's section end; use g_xbox_code_lo/hi
- #100: a negative --force-return value emitted 0x-1U
- #106: Alt+F4 stopped closing the window; pass sys keys through
- #116: an iret anywhere aborted the whole build; a linear sweep reads
  one out of data in Wreckless. It lifts as a RECOMP_UNIMPL marker now
- #122: the fused test+jcc path snapshotted test X,X but recorded
  cmp X,0, so a later jl compared X with itself; regression test added
- #125: __builtin_return_address does not exist in MSVC
- #96: holdoff comment still said 20 ms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 00:55:21 -07:00
sp00nz f1acab4a2b Merge branch 'pr/131' into work/v0.12.0
# Conflicts:
#	tools/recomp/translator.py
2026-09-27 00:47:35 -07:00
sp00nz 98d96e930b Merge branch 'pr/130' into work/v0.12.0
# Conflicts:
#	tools/recomp/translator.py
2026-09-27 00:47:18 -07:00
sp00nz c8940c5f70 Merge branch 'pr/129' into work/v0.12.0 2026-09-27 00:46:54 -07:00
sp00nz 2e2ca6037c Merge branch 'pr/126' into work/v0.12.0 2026-09-27 00:46:47 -07:00
sp00nz 4ba70f4977 Merge branch 'pr/125' into work/v0.12.0 2026-09-27 00:46:46 -07:00
sp00nz 9b73b60d34 Merge branch 'pr/124' into work/v0.12.0 2026-09-27 00:46:46 -07:00
sp00nz b53d9b799c Merge branch 'pr/123' into work/v0.12.0 2026-09-27 00:46:46 -07:00
sp00nz 0f65529fee Merge branch 'pr/122' into work/v0.12.0 2026-09-27 00:46:45 -07:00
sp00nz c7a4d598c0 Merge branch 'pr/121' into work/v0.12.0 2026-09-27 00:46:45 -07:00
sp00nz e2ff585806 Merge branch 'pr/120' into work/v0.12.0 2026-09-27 00:46:45 -07:00
sp00nz 14efad0c0a Merge branch 'pr/119' into work/v0.12.0 2026-09-27 00:46:44 -07:00
sp00nz 6014502e3d Merge branch 'pr/118' into work/v0.12.0 2026-09-27 00:46:36 -07:00
sp00nz 124719206e Merge branch 'pr/117' into work/v0.12.0 2026-09-27 00:46:36 -07:00
sp00nz 60c5ae018c Merge branch 'pr/116' into work/v0.12.0
# Conflicts:
#	tools/recomp/__main__.py
#	tools/recomp/translator.py
2026-09-27 00:46:36 -07:00
sp00nz d70307f574 Merge branch 'pr/110' into work/v0.12.0 2026-09-27 00:46:14 -07:00
sp00nz bdb0f6cb4f Merge branch 'pr/109' into work/v0.12.0 2026-09-27 00:46:14 -07:00
sp00nz 734037fa91 Merge branch 'pr/108' into work/v0.12.0 2026-09-27 00:46:13 -07:00
sp00nz 3676c0f690 Merge branch 'pr/107' into work/v0.12.0
# Conflicts:
#	src/usb/ohci.c
2026-09-27 00:46:13 -07:00
sp00nz 3e57a05f55 Merge branch 'pr/106' into work/v0.12.0
# Conflicts:
#	src/usb/usb_gamepad.c
#	src/video/fb_present.c
2026-09-27 00:45:51 -07:00
sp00nz e38d968d1b Merge branch 'pr/105' into work/v0.12.0 2026-09-27 00:45:36 -07:00
sp00nz bdbfecdc32 Merge branch 'pr/104' into work/v0.12.0 2026-09-27 00:45:36 -07:00
sp00nz d1babc9d90 Merge branch 'pr/103' into work/v0.12.0 2026-09-27 00:45:36 -07:00
sp00nz 698eb90e60 Merge branch 'pr/102' into work/v0.12.0 2026-09-27 00:45:35 -07:00
sp00nz c895d58b63 Merge branch 'pr/101' into work/v0.12.0 2026-09-27 00:45:35 -07:00
sp00nz a04f6cec26 Merge branch 'pr/100' into work/v0.12.0 2026-09-27 00:45:35 -07:00
sp00nz 45fdb257a5 Merge branch 'pr/99' into work/v0.12.0 2026-09-27 00:45:35 -07:00
sp00nz c3be79eec4 Merge branch 'pr/98' into work/v0.12.0 2026-09-27 00:45:34 -07:00
sp00nz 9b97c7f7a8 Merge branch 'pr/97' into work/v0.12.0 2026-09-27 00:45:34 -07:00
sp00nz 592d06cd00 Merge branch 'pr/96' into work/v0.12.0
# Conflicts:
#	src/usb/ohci.c
2026-09-27 00:45:34 -07:00
sp00nz 1c8dc8a22b Merge branch 'pr/95' into work/v0.12.0 2026-09-27 00:44:40 -07:00
sp00nz 133ab0f98c Merge branch 'pr/94' into work/v0.12.0 2026-09-27 00:44:39 -07:00
sp00nz 6ba07a1655 Merge branch 'pr/93' into work/v0.12.0 2026-09-27 00:44:39 -07:00
sp00nz 958d046993 Merge branch 'pr/92' into work/v0.12.0 2026-09-27 00:44:38 -07:00
sp00nz c7a744edb8 Merge branch 'pr/91' into work/v0.12.0 2026-09-27 00:44:38 -07:00
sp00nz e05190f6c7 Merge branch 'pr/90' into work/v0.12.0 2026-09-27 00:44:37 -07:00
NoRain211 f6adf8661a fix(recomp): register a switch arm only when it can run alone
A recovered arm was accepted once any instruction terminated it. An arm
could still run off its range, call a missing or empty body, or read flags
the dispatcher set, which a new C entry starts cleared. Each of those
misbehaves silently. Check every path, call and branch, and the flags read
on entry; otherwise leave the arm unresolved so dispatch stops loudly.
2026-09-26 16:09:24 -07:00
NoRain211 2a2a1444c9 fix(recomp): give switch arms outside their function an entry
A function list can cut one function at its own switch, so some arms land
past the dispatching entry's end. The lifter then emits the indexed jump as
an indirect tail call and the runtime dispatches the selected arm by
address. An arm at a function start resolves; any other arm has no
generated body, and the runtime stops on an unresolved address.

After CFG ownership settles, recover each such arm's reachable code, up to
its table, as a function of its own. A table is read only up to the next
indexed jump's table, so arms of an adjacent switch are not picked up. An
arm that branches to code with no generated body is left unresolved: that
branch would become a call to an empty stub, and a loud unresolved dispatch
is better than a silently skipped arm. Existing bodies are unchanged.

In Dead or Alive Xtreme Beach Volleyball, leaving the View Collection
screen reached 0xDE030, the shared exit of a split 4-way switch.
2026-09-26 16:02:26 -07:00