foxygit / fake-08-xbox360 Log in
commit fbfd266a3aee2d4eb02710bc286e7d8a271a9a3f
Author:     mrfox <jens.se@icloud.com>
AuthorDate: Wed Nov 25 17:00:29 2026 +0100
Commit:     mrfox <jens.se@icloud.com>
CommitDate: Wed Nov 25 17:00:29 2026 +0100

    xex video: no direct display writes without a display controller

    Xenia has no display controller (the LUT autofill never finishes) and
    shows what VdSwap names; the CPU writes to its scanout register (0x1844)
    from the XAM-style commit turned its picture white. The register path is
    now used only when the autofill finishes, as on the console.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
 platform/xex/runtime/video.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/platform/xex/runtime/video.c b/platform/xex/runtime/video.c
index 70483aa..990b163 100644
--- a/platform/xex/runtime/video.c
+++ b/platform/xex/runtime/video.c
@@ -314,6 +314,10 @@ static struct {
     int showing_system;
     unsigned system_frames;
     int guide_supported;
+    /* A display controller answers (the LUT autofill finishes): show
+     * surfaces through its registers. Xenia has none and shows what VdSwap
+     * names; writing its scanout register directly turns its picture white. */
+    int controller;
     uint32_t output_width, output_height;
 } display;

@@ -395,6 +399,7 @@ static uint32_t kernel_scaler[SCALER_REGISTERS];

 static void scaler_write(const uint32_t values[SCALER_REGISTERS])
 {
+    if (!display.controller) return;
     gpu_write(REG_SCALER_UPDATE, 0x10000);
     for (int i = 0; i < SCALER_REGISTERS; i++) gpu_write(scaler_offsets[i] / 4, values[i]);
     gpu_write(REG_SCALER_UPDATE, 0);
@@ -420,6 +425,7 @@ static void scaler_plan(uint32_t width, uint32_t height, uint32_t values[SCALER_

 static int display_apply(const display_surface *s)
 {
+    if (!display.controller) return 1;
     gpu_write(REG_SURFACE_2840, s->address);
     gpu_write(REG_PITCH_2844, s->pitch);
     gpu_write(SCANOUT_ADDRESS, s->address);
@@ -674,7 +680,7 @@ void xex_video_dump_lut(void)

 /* The kernel leaves the display LUT zeroed for a starting title (every
  * colour maps to black); load an identity ramp like libxenon does. */
-static void load_identity_gamma(void)
+static int load_identity_gamma(void)
 {
     gpu_write(0x6108 / 4, 0);   /* D1GRPH_LUT_SEL: LUT A */
     gpu_write(0x64c0 / 4, 0);   /* DC_LUTA_CONTROL */
@@ -684,7 +690,9 @@ static void load_identity_gamma(void)
     gpu_write(0x64a0 / 4, 1);   /* DC_LUT_AUTOFILL */
     uint64_t start = timebase_now();
     while (!(gpu_read(0x64a0 / 4) & 2) && timebase_now() - start < WAIT_TIMEOUT_TB) {}
-    TRACE("gamma: identity LUT %s", (gpu_read(0x64a0 / 4) & 2) ? "loaded" : "timed out");
+    int loaded = (gpu_read(0x64a0 / 4) & 2) != 0;
+    TRACE("gamma: identity LUT %s", loaded ? "loaded" : "timed out (no display controller: Xenia?)");
+    return loaded;
 }

 int xex_video_scaler_via_kernel = 0;
@@ -709,7 +717,7 @@ static void describe_display(uint32_t width, uint32_t height)
     display.output_width = mode[0];
     display.output_height = mode[1];
     /* XAM's surface is scaled by hand; xsdk only tried progressive modes */
-    display.guide_supported = mode[0] && mode[1] && !mode[2];
+    display.guide_supported = display.controller && mode[0] && mode[1] && !mode[2];
     TRACE("guide: output %ux%u interlaced %u -> %s", (unsigned)mode[0], (unsigned)mode[1], (unsigned)mode[2],
           display.guide_supported ? "supported" : "not supported");
     if (!display.guide_supported) return;
@@ -797,7 +805,7 @@ int xex_video_init(void)

     /* The display's LUT is zero while a title runs: load a ramp, then show
      * the (black) second buffer through the same path XAM uses. */
-    load_identity_gamma();
+    display.controller = load_identity_gamma();
     old_surface.address = gpu_read(SCANOUT_ADDRESS);
     old_surface.pitch = gpu_read(REG_D1GRPH_PITCH);
     old_surface.x_end = gpu_read(REG_D1GRPH_X_END);