commit 3606fd586d4b1b06312778c6a8e1890da1cb670a
Author: mrfox <jens.se@icloud.com>
AuthorDate: Wed Nov 25 16:07:54 2026 +0100
Commit: mrfox <jens.se@icloud.com>
CommitDate: Wed Nov 25 16:07:54 2026 +0100
xex video: dump display registers, VdSetDisplayMode after first flip
VdInitializeScalerCommandBuffer hangs on hardware with the arguments used,
so the kernel scaler setup is now opt-in (xex_video_scaler_via_kernel).
The video test logs the display controller registers before/after init,
after the first flip and while running.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
platform/xex/runtime/video.c | 49 ++++++++++++++++++++++++++++++++++++++-
platform/xex/runtime/xex_video.h | 6 +++++
platform/xex/tests/video/main.cpp | 3 +++
3 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/platform/xex/runtime/video.c b/platform/xex/runtime/video.c
index 30af81e..414ed3c 100644
--- a/platform/xex/runtime/video.c
+++ b/platform/xex/runtime/video.c
@@ -10,6 +10,7 @@
*/
#include <stdint.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <xbox360/xboxkrnl.h>
@@ -301,6 +302,7 @@ static struct {
uint32_t pending_identifier;
uint32_t pending_address;
const char *error;
+ int presented;
} display;
/* fetch.rs: texture fetch constant of a tiled 8:8:8:8 front buffer */
@@ -477,6 +479,41 @@ static void setup_scaler(uint32_t surface_w, uint32_t surface_h)
ring_kick(&display.ring);
}
+/* Display controller registers (byte offsets as in libxenon's xenos.c). */
+static const struct { uint16_t offset; const char *name; } display_registers[] = {
+ {0x6000, "CRTC_H_TOTAL"}, {0x6020, "CRTC_V_TOTAL"}, {0x6028, "CRTC_6028"},
+ {0x6080, "CRTC_CONTROL"}, {0x6084, "CRTC_BLANK"}, {0x609c, "CRTC_STATUS"},
+ {0x6100, "GRPH_ENABLE"}, {0x6104, "GRPH_CONTROL"}, {0x6110, "GRPH_SURFACE"},
+ {0x6120, "GRPH_PITCH"}, {0x6124, "GRPH_OFS_X"}, {0x6128, "GRPH_OFS_Y"},
+ {0x612c, "GRPH_X_START"}, {0x6130, "GRPH_Y_START"}, {0x6134, "GRPH_X_END"},
+ {0x6138, "GRPH_Y_END"}, {0x6144, "GRPH_UPDATE"}, {0x6148, "GRPH_FLIP"},
+ {0x6520, "MODE_6520"}, {0x6524, "MODE_6524"}, {0x6528, "MODE_DATA_FMT"},
+ {0x652c, "DESKTOP_H"}, {0x6548, "MODE_6548"}, {0x6550, "MODE_6550"},
+ {0x6580, "VIEWPORT_START"}, {0x6584, "VIEWPORT_SIZE"}, {0x6590, "SCL_ENABLE"},
+ {0x6594, "SCL_TAP"}, {0x65a0, "SCL_65a0"}, {0x65b0, "SCL_65b0"}, {0x65b4, "SCL_65b4"},
+ {0x65b8, "SCL_65b8"}, {0x65c0, "SCL_65c0"}, {0x65c4, "SCL_65c4"}, {0x65c8, "SCL_65c8"},
+ {0x65cc, "SCL_UPDATE"}, {0x65d0, "SCL_65d0"}, {0x65dc, "SCL_65dc"}, {0x65e8, "SCL_65e8"},
+ {0x2840, "DETILE_BASE"}, {0x2844, "DETILE_PITCH"}, {0x2848, "DETILE_2848"},
+ {0x7900, "OUT_7900"}, {0x7938, "OUT_7938"}, {0x793c, "OUT_793c"},
+};
+
+void xex_video_dump_registers(const char *label)
+{
+ char line[200];
+ int n = 0;
+ TRACE("registers (%s):", label);
+ for (unsigned i = 0; i < sizeof(display_registers) / sizeof(display_registers[0]); i++) {
+ n += snprintf(line + n, sizeof(line) - n, " %s=%08x", display_registers[i].name,
+ (unsigned)gpu_read(display_registers[i].offset / 4));
+ if (n > 120 || i + 1 == sizeof(display_registers) / sizeof(display_registers[0])) {
+ TRACE(" %s", line);
+ n = 0;
+ }
+ }
+}
+
+int xex_video_scaler_via_kernel = 0;
+
const char *xex_video_error(void)
{
return display.error ? display.error : "";
@@ -538,7 +575,10 @@ int xex_video_init(void)
display.back = 0;
display.pending = 0;
retrain_edram(1);
- setup_scaler(sw, sh);
+ /* VdInitializeScalerCommandBuffer hangs on hardware with these
+ * arguments, so it is off unless a test turns it on. */
+ if (xex_video_scaler_via_kernel) setup_scaler(sw, sh);
+ display.presented = 0;
atexit(xex_video_shutdown);
return 0;
}
@@ -564,6 +604,13 @@ void xex_video_present(void)
front_buffer *fb = &display.buffers[display.back];
submit_flip(fb->memory.physical, fb->fetch_constant);
display.back ^= 1;
+ if (display.presented++ == 0) {
+ /* Direct3D sets the display mode once its first frame is queued
+ * (0x40000000: the bit it always sets, RGB, 8:8:8:8). */
+ xex_video_dump_registers("after first flip");
+ VdSetDisplayMode(0x40000000);
+ TRACE("VdSetDisplayMode(0x40000000) done");
+ }
}
void xex_video_shutdown(void)
diff --git a/platform/xex/runtime/xex_video.h b/platform/xex/runtime/xex_video.h
index 2cfff09..1616594 100644
--- a/platform/xex/runtime/xex_video.h
+++ b/platform/xex/runtime/xex_video.h
@@ -38,6 +38,12 @@ void xex_video_present(void);
/* Optional trace of initialization and flips (diagnostics). */
extern void (*xex_video_trace)(const char *fmt, ...);
+/* Diagnostics: traces the display controller registers. */
+void xex_video_dump_registers(const char *label);
+/* Nonzero: program the scaler with VdInitializeScalerCommandBuffer at init
+ * (hangs on hardware so far). */
+extern int xex_video_scaler_via_kernel;
+
/* Gives the GPU back to the system (also done at exit). */
void xex_video_shutdown(void);
diff --git a/platform/xex/tests/video/main.cpp b/platform/xex/tests/video/main.cpp
index 9f316bd..3f7a060 100644
--- a/platform/xex/tests/video/main.cpp
+++ b/platform/xex/tests/video/main.cpp
@@ -29,6 +29,7 @@ int main(int, char **) {
remove("game:/video-log.txt");
logLine("start");
xex_video_trace = logLine;
+ xex_video_dump_registers("before init");
if (xex_video_init() != 0) {
logLine("init failed: %s", xex_video_error());
xex_notify("video init failed");
@@ -44,6 +45,7 @@ int main(int, char **) {
unsigned t = 0;
logLine("init ok");
+ xex_video_dump_registers("after init");
uint64_t startTime = xex_timebase();
int seconds = 0;
for (;;) {
@@ -96,6 +98,7 @@ int main(int, char **) {
logLine("second %d: %d fps, %dx%d window at %d,%d, pad %s buttons %04x",
++seconds, fps, f.window_width, f.window_height, f.window_x, f.window_y,
connected == 0 ? "ok" : "none", pad.buttons);
+ if (seconds == 2 || seconds == 10) xex_video_dump_registers("running");
frames = 0;
second = now;
}