foxygit / fake-08-xbox360 Log in
commit 2567a139e270a1e437425eb1cc3585619c5802eb
Author:     mrfox <jens.se@icloud.com>
AuthorDate: Wed Nov 25 16:19:01 2026 +0100
Commit:     mrfox <jens.se@icloud.com>
CommitDate: Wed Nov 25 16:19:01 2026 +0100

    xex video: load an identity LUT, try VdTurnDisplayOn

    On hardware the display LUT is all zero for a starting title, which maps
    every colour to black; the identity ramp is now loaded after the first
    flip. The test calls VdTurnDisplayOn(0) after 6 s and draws opaque pixels.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
 platform/xex/runtime/extra_imports.S |  9 +++++++++
 platform/xex/runtime/video.c         | 22 +++++++++++++++++++++
 platform/xex/runtime/xex_video.h     |  2 ++
 platform/xex/tests/video/main.cpp    | 38 +++++++++---------------------------
 4 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/platform/xex/runtime/extra_imports.S b/platform/xex/runtime/extra_imports.S
index 27d3f01..604119d 100644
--- a/platform/xex/runtime/extra_imports.S
+++ b/platform/xex/runtime/extra_imports.S
@@ -45,3 +45,12 @@ xbox360_stub VdQueryVideoMode, 0x010001ca
 	xbox360_return 0x70
 	xbox360_end VdInitializeScalerCommandBuffer, 0x010001c5
 .endif
+
+/* Display output control (xboxkrnl 0x1DE / 0x1DD); arguments unknown,
+ * called with 0. Direct3D turns the output on once a title's first frame
+ * is up. */
+xbox360_stub VdTurnDisplayOn, 0x010001de
+xbox360_stub VdTurnDisplayOff, 0x010001dd
+
+/* VdCallGraphicsNotificationRoutines(1, ...) - xboxkrnl 0x1B1 */
+xbox360_stub VdCallGraphicsNotificationRoutines, 0x010001b1
diff --git a/platform/xex/runtime/video.c b/platform/xex/runtime/video.c
index 3f68500..c6f9d35 100644
--- a/platform/xex/runtime/video.c
+++ b/platform/xex/runtime/video.c
@@ -25,6 +25,9 @@ extern ULONG VdInitializeScalerCommandBuffer(ULONG source_xy, ULONG source_wh, U
                                              ULONG horizontal_filter_type, void *horizontal_filter,
                                              ULONG unknown9, PULONG commands, ULONG command_dwords);

+extern ULONG VdTurnDisplayOn(ULONG unknown);
+extern ULONG VdCallGraphicsNotificationRoutines(ULONG unknown0, ULONG unknown1, ULONG unknown2);
+
 void (*xex_video_trace)(const char *fmt, ...);
 #define TRACE(...) do { if (xex_video_trace) xex_video_trace(__VA_ARGS__); } while (0)

@@ -533,6 +536,24 @@ 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)
+{
+    gpu_write(0x6108 / 4, 0);   /* D1GRPH_LUT_SEL: LUT A */
+    gpu_write(0x64c0 / 4, 0);   /* DC_LUTA_CONTROL */
+    gpu_write(0x6488 / 4, 0);   /* DC_LUT_RW_INDEX */
+    gpu_write(0x6484 / 4, 0);   /* DC_LUT_RW_MODE */
+    gpu_write(0x649c / 4, 7);   /* DC_LUT_WRITE_EN_MASK */
+    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");
+}
+
+uint32_t xex_video_turn_display_on(void) { return VdTurnDisplayOn(0); }
+uint32_t xex_video_call_notifications(void) { return VdCallGraphicsNotificationRoutines(1, 0, 0); }
+
 int xex_video_scaler_via_kernel = 0;

 const char *xex_video_error(void)
@@ -631,6 +652,7 @@ void xex_video_present(void)
         xex_video_dump_registers("after first flip");
         VdSetDisplayMode(0x40000000);
         TRACE("VdSetDisplayMode(0x40000000) done");
+        load_identity_gamma();
     }
 }

diff --git a/platform/xex/runtime/xex_video.h b/platform/xex/runtime/xex_video.h
index 2340138..56c0d69 100644
--- a/platform/xex/runtime/xex_video.h
+++ b/platform/xex/runtime/xex_video.h
@@ -44,6 +44,8 @@ void xex_video_dump_registers(const char *label);
 uint32_t xex_video_read_register(uint32_t offset);
 void xex_video_write_register(uint32_t offset, uint32_t value);
 void xex_video_dump_lut(void);
+uint32_t xex_video_turn_display_on(void);       /* VdTurnDisplayOn(0) */
+uint32_t xex_video_call_notifications(void);    /* VdCallGraphicsNotificationRoutines(1, 0, 0) */
 /* Nonzero: program the scaler with VdInitializeScalerCommandBuffer at init
  * (hangs on hardware so far). */
 extern int xex_video_scaler_via_kernel;
diff --git a/platform/xex/tests/video/main.cpp b/platform/xex/tests/video/main.cpp
index fe09522..66f6512 100644
--- a/platform/xex/tests/video/main.cpp
+++ b/platform/xex/tests/video/main.cpp
@@ -48,13 +48,12 @@ int main(int, char **) {
     xex_video_dump_registers("after init");
     uint64_t startTime = xex_timebase();
     int seconds = 0;
-    uint32_t alpha = 0;
     for (;;) {
         xex_pad pad;
         int connected = xex_input_get(0, &pad);
         // stop by itself after 20 s, so a black screen still tells whether the loop runs
-        if (xex_timebase() - startTime > 24 * freq) {
-            logLine("24 s elapsed, exiting");
+        if (xex_timebase() - startTime > 20 * freq) {
+            logLine("20 s elapsed, exiting");
             break;
         }
         if ((pad.buttons & XEX_PAD_BACK) && (pad.buttons & XEX_PAD_START)) break;
@@ -86,7 +85,7 @@ int main(int, char **) {
                 } else {
                     c = xex_video_rgb((uint8_t)(x + t), (uint8_t)(y + t / 2), 96);
                 }
-                f.pixels[xex_video_tiled_index(f.window_x + x, py, f.pitch)] = c | alpha;
+                f.pixels[xex_video_tiled_index(f.window_x + x, py, f.pitch)] = c | 0xff;
             }
         }
         xex_video_present();
@@ -105,32 +104,13 @@ int main(int, char **) {
             }
             // Phases to find what keeps the picture black (the display
             // registers already point at our buffer):
+            // Phases to find what keeps the picture black (display registers
+            // point at our buffer, the LUT is loaded after the first flip):
             if (seconds == 6) {
-                logLine("PHASE 2 (6 s): pixels with alpha 0xff");
-                alpha = 0xff;
-            }
-            if (seconds == 12) {
-                logLine("PHASE 3 (12 s): RGB colour matrix as libxenon");
-                static const uint32_t cm[] = {0x00db4000, 0, 0, 0x00408000, 0, 0x00db4000, 0, 0x00408000,
-                                              0, 0, 0x00db4000, 0x00408000};
-                xex_video_write_register(0x6380, 1);
-                for (int i = 0; i < 12; i++) xex_video_write_register(0x6384 + i * 4, cm[i]);
-                xex_video_write_register(0x63b4, 0);
-                xex_video_dump_registers("phase 3");
-            }
-            if (seconds == 18) {
-                logLine("PHASE 4 (18 s): LUT autofill (identity ramp) as libxenon");
-                xex_video_write_register(0x6108, 0);
-                xex_video_write_register(0x64c0, 0);
-                xex_video_write_register(0x6488, 0);
-                xex_video_write_register(0x6484, 0);
-                xex_video_write_register(0x649c, 7);
-                xex_video_write_register(0x64a0, 1);
-                uint64_t w = xex_timebase();
-                while (!(xex_video_read_register(0x64a0) & 2) && xex_timebase() - w < freq / 10) {}
-                logLine("autofill %s", (xex_video_read_register(0x64a0) & 2) ? "done" : "timed out");
-                xex_video_dump_registers("phase 4");
-                xex_video_dump_lut();
+                logLine("PHASE 2 (6 s): VdTurnDisplayOn(0)");
+                unsigned r = xex_video_turn_display_on();
+                logLine("VdTurnDisplayOn -> %08x", r);
+                xex_video_dump_registers("phase 2");
             }
             frames = 0;
             second = now;