foxygit / fake-08-xbox360 Log in
main xbox360 commits tags

/platform/xex/README.md · 6.82 KB

raw

FAKE-08 as a native Xbox 360 XEX (no XDK)

A second Xbox 360 target next to platform/xenon (bare-metal libxenon ELF started from XeLL). This one builds a normal default.xex that runs under the dashboard and is started from Aurora/FSD like any other app, on RGH/JTAG consoles. It does not use the Microsoft XDK.

How it is built

PieceFrom
Compiler, newlib, libstdc++GCC 16 in the free60/libxenon docker image (libxenon itself is not linked)
Import thunks, title entry, kernel/XAM headersxenon-forge src/sdk (MIT/Apache-2.0), copied to sdk/
ELF -> XEXxex-link from xenon-forge, built by tools/build-xex-link.sh
C/C++ runtimeruntime/: start-up (static constructors, .eh_frame registration), newlib system calls on the kernel's Nt* API, dirent, time, heap

The code is compiled as 32-bit SysV PowerPC (-m32 -mpowerpc64), which is what titles run as (32-bit pointers in 64-bit registers). Calls into the kernel go through xenon-forge's thunks, which add the 0x50-byte home area the console ABI needs and convert 64-bit results; the title entry saves r14-r31 in full 64 bits.

Build

From the repository root:

once: build xex-link (static binary in platform/xex/tools/bin)

docker run --rm -v $PWD:/build_dir rust:latest \
/bin/sh -ex /build_dir/platform/xex/tools/build-xex-link.sh

runtime + test programs

docker run --rm -v $PWD:/build_dir -w /build_dir free60/libxenon:latest \
bash -lc 'make xex'

Output: platform/xex/build/fake08/default.xex (FAKE-08) and platform/xex/build/tests/<name>/default.xex. The ELF next to it (app.elf) has the symbols for xenon-addr2line.

The test programs also run in Xenia Canary (xenia_canary --log_file=xenia.log --log_level=4 default.xex); their DbgPrint output shows up in the log. Xenia mounts the XEX's folder read-only, so file writes only work on a console.

FAKE-08

Copy build/fake08/default.xex into a folder of its own (for example Hdd1:\Apps\FAKE-08\) and add it to Aurora. Carts are read from the first p8carts folder found: next to the XEX, then usb0:-usb2:, then the hard disk root (Hdd1:\p8carts); without one, p8carts is created next to the XEX. Settings, saves (cdata) and pico.log go to a fake08 folder next to the XEX (or hdd:\fake08, or cache: in Xenia, when that folder is read-only).

Controller
D-pad / left stickarrows
A, Y / B, XO / X (swapped with the "button layout" setting)
Startpause menu
Backcycle screen sizes
Xbox buttonGuide; Xbox Home leaves to Aurora
Back+Startquit (some dashboard plugins use it for screenshots)

Controllers 2-4 are players 2-4. Sound goes through the kernel's audio render driver at 48 kHz (front left and right).

The source is source/XexHost.cpp, the same logic as the libxenon host (platform/xenon/source/XenonHost.cpp) on this platform's runtime.

Runtime

  • Paths: game:/... (folder of the XEX), usb0:-usb2:

    (\Device\Mass0-2), hdd: (\Device\Harddisk0\Partition1, Aurora's Hdd1:). Relative paths are under game:. / and \ both work.

  • Files: open/read/write/lseek/close/stat/fstat/unlink/mkdir,

    opendir/readdir/closedir (stdio and iostreams work on top).

  • Time: gettimeofday (KeQuerySystemTime), clock()/times() (time

    base), xex_sleep_ms, usleep. The time base runs at 49.875 MHz, not the 50 MHz KeQueryPerformanceFrequency reports; xex_timebase_freq() gives the real rate.

  • Stack: 1 MB for the main thread (tools/build-xex-link.sh patches

    xex-link's 256 KB).

  • Heap: a 96 MB .bss arena (XEX_HEAP_SIZE).
  • Exit: returning from main/exit() calls XamLoaderTerminateTitle,

    which goes back to the dashboard.

  • Crashes: a CPU fault (bad pointer, illegal instruction) writes

    game:/crash.txt with the exception, the faulting address, the registers and the return addresses on the stack, then goes back to the dashboard (RtlSetVectoredExceptionHandler, as found by xsdk). Look addresses up with xenon-addr2line -f -C -e build/fake08/app.elf <address>. A stack overflow can't be reported.

  • xex_runtime.h: xex_notify() (guide notification), timing helpers.
  • Video (xex_video.h): takes the GPU engines like Direct3D, flips two

    tiled 32 bpp front buffers with VdSwap at vertical blank. On a progressive output the front buffers have the output's size (for example 1920x1080) and are shown 1:1 with the display scaler off, so the title scales sharply itself; otherwise (interlaced output, Xenia) the kernel's 640x480 surface is stretched by its scaler (xex_video_native = 0 forces that). On hardware a title's surface only shows once the display LUT is filled and the surface is committed the way XAM does it (0x2840/0x2844 + D1GRPH, then 0x60EC = 1); found by xsdk (docs/HARDWARE.md). Pixels: B << 24 | G << 16 | R << 8 | A.

  • Guide: every frame goes through VdSwap with the kernel's system

    command buffer; while XAM draws the Guide, VdSwap hands back XAM's surface, which is shown instead (scaler set for its size, the kernel's scaling back afterwards), and XAM is told the title's display size (graphics notification event 1). As found by xsdk. A title must not end by itself while the Guide shows (xex_video_guide_visible()).

  • Audio (xex_audio.h): an XAudio render driver client. The kernel

    calls back every 5.33 ms for a frame of 256 samples at 48 kHz, 6 channels of big-endian floats one after the other (xsdk's findings); the title queues frames into a 16-frame ring, and the callback plays silence when it is empty. Kernel callbacks enter through kernel_entries.S, which keeps r14-r31 whole.

  • Input (xex_input.h): XamInputGetState per port.

Tests

TestChecks
tests/hellostatic constructors, C++ exceptions, std::regex, an 896 KB deep stack (progress in game:/stack-test.txt), notifications, exit to dashboard
tests/audiolatency: a click and a white flash together every second (A: at once); up/down set the frames queued ahead (2, 4, 8, 15); logs the driver's callback rate to game:/audio-log.txt
tests/faultstores to address 0 after 2 s: the fault report must land in game:/crash.txt and the console go back to the dashboard
tests/fstime, clock(), directory listing, write/append/read/seek/stat/mkdir/remove on every device; writes game:/fs-test-report.txt
tests/videoCPU-drawn frames at 60 fps through the title's own GPU ring, controller input (d-pad moves a square, A/B/X/Y colour it); a row of 16 boxes lights up with the pressed buttons and every controller change is logged to game:/video-log.txt; exits after 60 s (not while the Guide shows) or on Back+Start; the Xbox button opens the Guide, whose Xbox Home leaves