From 7a7bef3d06b68083b83567a723413ded371d59be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Barroso=20Galindo?= Date: Wed, 4 Mar 2026 07:39:07 +0100 Subject: [PATCH] Add video_mode FIFO command for CRT video mode switching (#1107) * Add video_mode FIFO command for CRT video mode switching - video.cpp: Add video_mode_cmd() that parses custom modelines and applies them via video_set_mode(), with hfreq safety check blocking modes outside 15625-16500Hz to protect 15kHz CRT monitors - video.h: Declare video_mode_cmd() - input.cpp: Dispatch "video_mode" commands from MiSTer_cmd FIFO to video_mode_cmd() * Remove hfreq guard from video_mode_cmd The horizontal frequency check was limiting the command to 15kHz modes only. Removing it allows custom modelines with any frequency to be applied. Software at the other end must take care of not calling this API with unsafe frequencies. --- input.cpp | 1 + video.cpp | 17 +++++++++++++++++ video.h | 1 + 3 files changed, 19 insertions(+) diff --git a/input.cpp b/input.cpp index 95c141c..917eafb 100644 --- a/input.cpp +++ b/input.cpp @@ -5864,6 +5864,7 @@ int input_test(int getchar) cmd[len] = 0; printf("MiSTer_cmd: %s\n", cmd); if (!strncmp(cmd, "fb_cmd", 6)) video_cmd(cmd); + else if (!strncmp(cmd, "video_mode ", 11)) video_mode_cmd(cmd + 11); else if (!strncmp(cmd, "load_core ", 10)) { if(isXmlName(cmd)) xml_load(cmd + 10); diff --git a/video.cpp b/video.cpp index 777d14e..3e43d05 100644 --- a/video.cpp +++ b/video.cpp @@ -3900,6 +3900,23 @@ void video_cmd(char *cmd) } } +void video_mode_cmd(char *cmd) +{ + vmode_custom_t v = {}; + int ret = parse_custom_video_mode(cmd, &v); + if (ret != -2) + { + printf("video_mode_cmd: only custom modelines are supported, got \"%s\"\n", cmd); + return; + } + + v_def = v; + v_cur = v; + video_set_mode(&v, v.Fpix); + user_io_send_buttons(1); + printf("video_mode_cmd: applied mode \"%s\"\n", cmd); +} + static constexpr int CELL_GRAN_RND = 4; static int determine_vsync(int w, int h) diff --git a/video.h b/video.h index 6225a80..8cd39bc 100644 --- a/video.h +++ b/video.h @@ -67,6 +67,7 @@ void video_menu_bg(int n, int idle = 0); int video_bg_has_picture(); int video_chvt(int num); void video_cmd(char *cmd); +void video_mode_cmd(char *cmd); void video_core_description(char *str, size_t len); void video_scaler_description(char *str, size_t len);