Support for YC phase_inc override.

This commit is contained in:
Sorgelig
2023-02-08 20:47:35 +08:00
parent 8d735d4e77
commit a91f03d56e
4 changed files with 110 additions and 3 deletions

67
cfg.cpp
View File

@@ -579,3 +579,70 @@ void cfg_print()
}
printf("--------------\n");
}
static int yc_parse_mode(char* buf, yc_mode *mode)
{
int i = 0;
while (1)
{
if (buf[i] == '=' || CHAR_IS_SPACE(buf[i]))
{
buf[i] = 0;
break;
}
else if (!buf[i]) return 0;
i++;
}
i++;
while (buf[i] == '=' || CHAR_IS_SPACE(buf[i])) i++;
ini_parser_debugf("Got yc_mode '%s' with VALUE %s", buf, buf + i);
snprintf(mode->key, sizeof(mode->key), "%s", buf);
mode->phase_inc = strtoull(buf + i, 0, 0);
if (!mode->phase_inc)
{
printf("ERROR: cannot parse YC phase_inc: '%s'\n", buf + i);
return 0;
}
return 1;
}
void yc_parse(yc_mode *yc_table, int max)
{
memset(yc_table, 0, max * sizeof(yc_mode));
static char line[INI_LINE_SIZE];
int eof;
memset(line, 0, sizeof(line));
memset(&ini_file, 0, sizeof(ini_file));
const char *corename = user_io_get_core_name(1);
int corename_len = strlen(corename);
const char *name = "yc.txt";
if (!FileOpen(&ini_file, name)) return;
ini_parser_debugf("Opened file %s with size %llu bytes.", name, ini_file.size);
ini_pt = 0;
int n = 0;
while (n < max)
{
// get line
eof = ini_getline(line);
if (!strncasecmp(line, corename, corename_len))
{
int res = yc_parse_mode(line, &yc_table[n]);
if (res) n++;
}
// if end of file, stop
if (eof) break;
}
FileClose(&ini_file);
}

8
cfg.h
View File

@@ -101,4 +101,12 @@ bool cfg_has_video_sections();
void cfg_error(const char *fmt, ...);
bool cfg_check_errors(char *msg, size_t max_len);
struct yc_mode
{
char key[64];
int64_t phase_inc;
};
void yc_parse(yc_mode *yc_table, int max);
#endif // __CFG_H__

View File

@@ -77,6 +77,8 @@ static VideoInfo current_video_info;
static int support_FHD = 0;
yc_mode yc_modes[10];
struct vrr_cap_t
{
uint8_t active;
@@ -2394,6 +2396,8 @@ void video_cfg_reset()
void video_init()
{
yc_parse(yc_modes, sizeof(yc_modes) / sizeof(yc_modes[0]));
fb_init();
hdmi_config_init();
hdmi_config_set_hdr();
@@ -2725,7 +2729,8 @@ static void set_yc_mode()
{
if (cfg.vga_mode_int >= 2)
{
int pal = (!current_video_info.vtime || (100000000 / current_video_info.vtime) < 55);
float fps = current_video_info.vtime ? (100000000.f / current_video_info.vtime) : 0.f;
int pal = fps < 55.f;
double CLK_REF = pal ? 4.43361875f : 3.579545f;
double CLK_VIDEO = current_video_info.ctime * 100.f / current_video_info.ptime;
@@ -2735,6 +2740,21 @@ static void set_yc_mode()
int COLORBURST_END = (int)(9.0f * (CLK_VIDEO / CLK_REF)) + COLORBURST_START;
int COLORBURST_RANGE = (COLORBURST_START << 10) | COLORBURST_END;
char yc_key[64];
sprintf(yc_key, "%s_%.1f%s", user_io_get_core_name(1), fps, current_video_info.interlaced ? "i" : "");
printf("Calculated YC parameters for '%s': %s PHASE_INC=%lld, COLORBURST_START=%d, COLORBURST_END=%d\n", yc_key, pal ? "PAL" : "NTSC", PHASE_INC, COLORBURST_START, COLORBURST_END);
for (uint i = 0; i < sizeof(yc_modes) / sizeof(yc_modes[0]); i++)
{
if (!strcasecmp(yc_modes[i].key, yc_key))
{
printf("Override YC PHASE_INC with value: %lld\n", yc_modes[i].phase_inc);
PHASE_INC = yc_modes[i].phase_inc;
break;
}
}
spi_uio_cmd_cont(UIO_SET_YC_PAR);
spi_w((pal ? 4 : 0) | ((cfg.vga_mode_int == 3) ? 3 : 1));
spi_w(PHASE_INC);
@@ -2743,8 +2763,6 @@ static void set_yc_mode()
spi_w(COLORBURST_RANGE);
spi_w(COLORBURST_RANGE >> 16);
DisableIO();
printf("Send YC parameters: %s PHASE_INC=%lld, COLORBURST_START=%d, COLORBURST_END=%d\n", pal ? "PAL" : "NTSC", PHASE_INC, COLORBURST_START, COLORBURST_END);
}
else
{

14
yc.txt Normal file
View File

@@ -0,0 +1,14 @@
;
; PHASE_INC override per <core_fps> mode.
; It affects only CVBS video output.
; S-Video doesn't need this file.
;
SNES_60.1=91625968981
SNES_60.0i=91625968981
SNES_50.0=114532461227
SNES_49.9i=114532461227
NEOGEO_59.2=81994830080
NEOGEO_59.6=81425421603
NEOGEO_50.1=101558653516
NEOGEO_50.4=100853152548