Skip to content

Commit

Permalink
Override configuration based on video mode (#567)
Browse files Browse the repository at this point in the history
* Override configuration based on video mode

Configuration options can now be overridden based on the core's video
mode.

The config parser now supports sections with names in the format
"video=WIDTHxHEIGHT[@VREFRESH]".  When a core changes video mode, MiSTer
reloads the config file and checks for a section matching the new mode.
If one is found, the options in the section override options in the
MiSTer/core sections.

MiSTer will look for a section matching the width, height, and vertical
refresh rate first.  If none is found, it will fall back to a section
matching the width and height but not specifying a refresh rate.  If
there is still no match, no overrides will be used.

Also, VREFRESH must match exactly the output from video_info or the
logs.  To match 720x400 31.48KHz 70.1Hz, the section title would need to
be [video=720x400@70.1].

* Move video section variables out of cfg_t
  • Loading branch information
tsowell committed Mar 17, 2022
1 parent 062891c commit f5fd16c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
11 changes: 11 additions & 0 deletions MiSTer.ini
Expand Up @@ -195,3 +195,14 @@ bt_reset_before_pair=0
; This option cannot be used when defmra in CONFSTR is used (i.e. if arcade rbf is loaded directly not through MRA).
; This option is ignored for Menu core.
;waitmount=/media/usb0

; Overrides for video mode
; When the core's video mode matches the parameters in the section header, any options in the section override options from MiSTer and core sections.
; Refresh rate in header is optional and, if present, must match exactly the output from video_info or the logs. For example, if it says "60.0Hz", the header needs to be "@60.0" to match.
; When the core changes video mode, MiSTer will first look for a matching WIDTHxHEIGHT@VREFRESH section.
; If no match is found, it will fall back to a matching WIDTHxHEIGHT section with no refresh rate.
; If there is still no match, MiSTer/core options will be used without overrides.
; [video=640x400]
; ...
; [video=640x400@70.1]
; ...
44 changes: 38 additions & 6 deletions cfg.cpp
Expand Up @@ -11,6 +11,7 @@
#include "debug.h"
#include "file_io.h"
#include "user_io.h"
#include "video.h"

cfg_t cfg;

Expand Down Expand Up @@ -121,6 +122,9 @@ static const int nvars = (int)(sizeof(ini_vars) / sizeof(ini_var_t));

fileTYPE ini_file;

static bool has_video_sections = false;
static bool using_video_section = false;

int ini_pt = 0;
static char ini_getch()
{
Expand Down Expand Up @@ -148,7 +152,7 @@ static int ini_getline(char* line)
return c == 0;
}

static int ini_get_section(char* buf)
static int ini_get_section(char* buf, const char *vmode)
{
int i = 0;
int incl = (buf[0] == INCL_SECTION);
Expand All @@ -161,6 +165,7 @@ static int ini_get_section(char* buf)
else buf++;

int wc_pos = -1;
int eq_pos = -1;

// get section stop marker
while (buf[i])
Expand All @@ -172,6 +177,7 @@ static int ini_get_section(char* buf)
}

if (buf[i] == '*') wc_pos = i;
if (buf[i] == '=') eq_pos = i;

i++;
if (i >= INI_LINE_SIZE) return 0;
Expand All @@ -192,6 +198,20 @@ static int ini_get_section(char* buf)
}
return 1;
}
else if ((eq_pos >= 0) && !strncasecmp(buf, "video", eq_pos))
{
has_video_sections = true;
if(!strcasecmp(&buf[eq_pos+1], vmode))
{
using_video_section = true;
ini_parser_debugf("Got SECTION '%s'", buf);
return 1;
}
else
{
return 0;
}
}

return 0;
}
Expand Down Expand Up @@ -279,13 +299,13 @@ static void ini_parse_var(char* buf)
}
}

static void ini_parse(int alt)
static void ini_parse(int alt, const char *vmode)
{
static char line[INI_LINE_SIZE];
int section = 0;
int eof;

ini_parser_debugf("Start INI parser for core \"%s\"(%s).", user_io_get_core_name(0), user_io_get_core_name(1));
ini_parser_debugf("Start INI parser for core \"%s\"(%s), video mode \"%s\".", user_io_get_core_name(0), user_io_get_core_name(1), vmode);

memset(line, 0, sizeof(line));
memset(&ini_file, 0, sizeof(ini_file));
Expand All @@ -307,11 +327,11 @@ static void ini_parse(int alt)
if (line[0] == INI_SECTION_START)
{
// if first char in line is INI_SECTION_START, get section
section = ini_get_section(line);
section = ini_get_section(line, vmode);
}
else if (line[0] == INCL_SECTION && !section)
{
section = ini_get_section(line);
section = ini_get_section(line, vmode);
}
else if(section)
{
Expand Down Expand Up @@ -351,5 +371,17 @@ void cfg_parse()
cfg.browse_expand = 1;
cfg.logo = 1;
cfg.rumble = 1;
ini_parse(altcfg());
has_video_sections = false;
using_video_section = false;
ini_parse(altcfg(), video_get_core_mode_name(1));
if (has_video_sections && !using_video_section)
{
// second pass to look for section without vrefresh
ini_parse(altcfg(), video_get_core_mode_name(0));
}
}

bool cfg_has_video_sections()
{
return has_video_sections;
}
1 change: 1 addition & 0 deletions cfg.h
Expand Up @@ -77,5 +77,6 @@ extern cfg_t cfg;
//// functions ////
void cfg_parse();
const char* cfg_get_name(uint8_t alt);
bool cfg_has_video_sections();

#endif // __CFG_H__
30 changes: 28 additions & 2 deletions video.cpp
Expand Up @@ -1145,6 +1145,25 @@ void video_scaler_description(char *str, size_t len)
video_scaler_description(&current_video_info, &v_cur, str, len);
}

char* video_get_core_mode_name(int with_vrefresh)
{
static char tmp[256] = {};

if (with_vrefresh)
{
float vrate = 100000000;
if (current_video_info.vtime) vrate /= current_video_info.vtime; else vrate = 0;

snprintf(tmp, sizeof(tmp), "%dx%d@%.1f", current_video_info.width, current_video_info.height, vrate);
}
else
{
snprintf(tmp, sizeof(tmp), "%dx%d", current_video_info.width, current_video_info.height);
}

return tmp;
}

static void show_video_info(const VideoInfo *vi, const vmode_custom_t *vm)
{
float vrate = 100000000;
Expand Down Expand Up @@ -1230,10 +1249,17 @@ void video_mode_adjust()

if (vid_changed || force)
{
current_video_info = video_info;

if (cfg_has_video_sections())
{
cfg_parse();
video_mode_load();
user_io_send_buttons(1);
}

show_video_info(&video_info, &v_cur);
video_scaling_adjust(&video_info);

current_video_info = video_info;
}
force = false;

Expand Down
1 change: 1 addition & 0 deletions video.h
Expand Up @@ -49,6 +49,7 @@ void video_cmd(char *cmd);
bool video_is_rotated();
void video_core_description(char *str, size_t len);
void video_scaler_description(char *str, size_t len);
char* video_get_core_mode_name(int with_vrefresh = 1);


#endif // VIDEO_H

0 comments on commit f5fd16c

Please sign in to comment.