From 0f667a84427f1b983a79f2ebab0a5e5066910d79 Mon Sep 17 00:00:00 2001 From: misteraddons <51079966+misteraddons@users.noreply.github.com> Date: Sun, 14 Sep 2025 04:13:51 -0600 Subject: [PATCH] Video: Automatic Direct Video dv_dac.txt Parsing Fix (#1036) * Simple Auto Direct Video direct_video=2 Checks for 1024x768 HDMI resolution and sets direct_video=1 No hot plug detect No EDID parsing No device whitelist No hdmi_limited set based on EDID whitelist * Add EDID detection and set hdmi_limited for common DACs - AG6200 sets hdmi_limited=2 - CS5213 sets hdmi_limited=0 * Fix logic to pass normal EDID resolution if not 1024x768 * Update MiSTer.ini * Remove 1024x768 resolution check - Only use mfg_id from EDID to identify known compatible DACs * Add DAC id and settings to dv_dac.txt and dv_dac_user.txt - mfg_id - rgb range - hdmi_audio_96khz - composite_sync: 0, 1, or "" (default is "") - dv_dac_user.txt for HDMI video upscalers that support direct video - device commented out by default * Fix parsing of dv_dac.txt DAC model name wasn't being displayed due to empty composite_sync field --- dv_dac.txt | 8 ++++---- video.cpp | 33 ++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/dv_dac.txt b/dv_dac.txt index e54b44c..b2d8a48 100644 --- a/dv_dac.txt +++ b/dv_dac.txt @@ -16,9 +16,9 @@ # Combined as: (byte_08 << 8) | byte_09 # # Examples: -# 0x48F4,0,0,,Full-range CS5213 DAC -# 0x04EF,2,0,1,Limited-range AG6200 DAC +# 0x48F4,0,0,,CS5213 DAC +# 0x04EF,2,0,1,AG6200 DAC # Known DACs -0x48F4,0,0,,Full-range CS5213 DAC -0x04EF,2,0,,Limited-range AG6200 DAC +0x48F4,0,0,,CS5213 DAC +0x04EF,2,0,,AG6200 DAC diff --git a/video.cpp b/video.cpp index 7726d99..3531cee 100644 --- a/video.cpp +++ b/video.cpp @@ -2456,16 +2456,35 @@ static void load_dac_file(const char *filename) // Example: 0x48F4,0,0,,Full-range CS5213 DAC unsigned int mfg, limited, audio_96k = 0; char name[64] = {0}; - char csync_str[16] = {0}; int8_t csync = -1; // Default to use MiSTer.ini setting - // Parse with optional composite_sync field - int fields = sscanf(line, "%x,%u,%u,%15[^,],%63[^\n]", &mfg, &limited, &audio_96k, csync_str, name); - if (fields >= 2) { - // Parse composite sync field if present - if (fields >= 4 && strlen(csync_str) > 0) { - csync = (csync_str[0] == '1') ? 1 : 0; + // Find commas to parse fields manually (to handle empty fields) + const char *comma1 = strchr(line, ','); + if (!comma1) continue; + const char *comma2 = strchr(comma1 + 1, ','); + if (!comma2) continue; + const char *comma3 = strchr(comma2 + 1, ','); + if (!comma3) continue; + const char *comma4 = strchr(comma3 + 1, ','); + if (!comma4) continue; + + // Parse mfg_id, hdmi_limited, hdmi_audio_96k + if (sscanf(line, "%x,%u,%u", &mfg, &limited, &audio_96k) >= 2) { + // Parse composite_sync field (between comma3 and comma4) + if (comma4 - comma3 > 1) { + char csync_char = comma3[1]; + if (csync_char == '0' || csync_char == '1') { + csync = (csync_char == '1') ? 1 : 0; + } } + + // Parse name (after comma4) + strncpy(name, comma4 + 1, 63); + // Remove newline if present + char *newline = strchr(name, '\n'); + if (newline) *newline = '\0'; + char *carriage = strchr(name, '\r'); + if (carriage) *carriage = '\0'; // Check if this mfg_id already exists and update it bool found = false; for (int i = 0; i < dac_config_count; i++) {