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>
Runtime Implementation Guide
The recompiled C code needs a host environment to run. This directory documents the four major runtime subsystems you need to build for each game.
The Four Pillars
1. Memory Layout (xbox_memory.c)
Reproduce the Xbox's 64 MB address space at the correct virtual addresses. This is the most critical piece — get it wrong and nothing else works.
See: ../technical/memory-layout.md
Template: ../../templates/runtime/xbox_memory.h
2. Kernel Shim (xbox_kernel.c)
Replace the 147 Xbox kernel imports with Win32 equivalents. Most can be stubbed (return STATUS_SUCCESS). The critical ones are memory allocation and file I/O.
See: ../technical/kernel-replacement.md
Template: ../../templates/runtime/kernel_stubs.h
3. Graphics Translation (d3d8_to_d3d11.c)
The Xbox uses a modified Direct3D 8. You need a translation layer to D3D11 (or D3D12, Vulkan, etc.). This is the largest runtime component.
See: ../technical/d3d-translation.md
4. Input System (xbox_input.c)
Map Xbox controller input to Windows XInput. This is usually the simplest piece — Xbox controllers on Windows are nearly 1:1.
Build System
We recommend CMake with MSVC. Structure your project as static libraries:
src/
├── kernel/ → xbox_kernel.lib
├── d3d/ → d3d_translation.lib
├── audio/ → audio_stubs.lib
├── input/ → input_layer.lib
└── game/ → your_game.exe (links all the above + recompiled code)
Game-Specific Components
Beyond the four pillars, each game needs:
- Manual function overrides — hand-written replacements for functions that don't work when mechanically translated (physics, rendering orchestrators, hardware-specific code)
- Asset loaders — each game/engine has its own file formats for textures, models, levels, audio, etc.
- Game-specific workarounds — vtable guards for corrupted pointers, state machine patches, etc.
These go in the game-specific repo, not in the generic xboxrecomp toolkit.
POSIX hosts (macOS, Linux)
The template's main.c is Win32: a vectored handler that calls
xbox_VehMmioFault and a WinMain. A POSIX build needs the same two pieces
in its own main():
#include <signal.h>
#include <ucontext.h>
#include "kernel/xbox_memory_layout.h" /* xbox_PosixMmioFault */
#include "video/video_player.h" /* xbox_HostWindowMain */
/* Trapped hardware registers (APU, AC'97, USB OHCI) fault here. Return when
* the access was serviced: the program counter has been advanced past it. */
static void on_fault(int sig, siginfo_t *si, void *uc)
{
if (xbox_PosixMmioFault(uc, (uintptr_t)si->si_addr))
return;
signal(sig, SIG_DFL); /* a real crash: report and die */
}
static int boot_and_run(void)
{
/* xbox_MemoryLayoutInit, kernel init, the guest entry point, ...,
* as in the template's WinMain. */
return 0;
}
int main(void)
{
struct sigaction sa = { 0 };
sa.sa_sigaction = on_fault;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL); /* macOS reports a protected page so */
/* With RECOMP_FB_WINDOW set this opens the framebuffer window on the
* main thread (where macOS requires it) and runs boot_and_run on a second
* one; otherwise it just calls boot_and_run. */
return xbox_HostWindowMain(boot_and_run);
}
xbox_PosixMmioFault decodes the faulting instruction on arm64 hosts only;
on x86-64 POSIX it always returns 0, and the traps are not armed there.