From 11d35160ff695b5b4395aecd2e0c4fbf8d76dc0e Mon Sep 17 00:00:00 2001 From: Sorgelig Date: Mon, 12 Feb 2024 00:07:14 +0800 Subject: [PATCH] INI: add DEBUG option to disable logging to console. --- MiSTer.ini | 1 + cfg.cpp | 10 ++++++++++ cfg.h | 1 + 3 files changed, 12 insertions(+) diff --git a/MiSTer.ini b/MiSTer.ini index 77dd641..74e5f8d 100644 --- a/MiSTer.ini +++ b/MiSTer.ini @@ -1,4 +1,5 @@ [MiSTer] +;debug=0 ; set to 0 to disable debugging messages. Default is 1. key_menu_as_rgui=0 ; set to 1 to make the MENU key map to RGUI in Minimig (e.g. for Right Amiga) forced_scandoubler=0 ; set to 1 to run scandoubler on VGA output always (depends on core). ;ypbpr=0 ; set to 1 for YPbPr on VGA output. (obsolete. see vga_mode) diff --git a/cfg.cpp b/cfg.cpp index beb64f2..333b20e 100644 --- a/cfg.cpp +++ b/cfg.cpp @@ -16,6 +16,8 @@ #include "support/arcade/mra_loader.h" cfg_t cfg; +static FILE *orig_stdout = NULL; +static FILE *dev_null = NULL; typedef enum { @@ -127,6 +129,7 @@ static const ini_var_t ini_vars[] = { "CONTROLLER_UNIQUE_MAPPING", (void *)(cfg.controller_unique_mapping), UINT32ARR, 0, 0xFFFFFFFF }, { "OSD_LOCK", (void*)(&(cfg.osd_lock)), STRING, 0, sizeof(cfg.osd_lock) - 1 }, { "OSD_LOCK_TIME", (void*)(&(cfg.osd_lock_time)), UINT16, 0, 60 }, + { "DEBUG", (void *)(&(cfg.debug)), UINT8, 0, 1 }, }; static const int nvars = (int)(sizeof(ini_vars) / sizeof(ini_var_t)); @@ -390,6 +393,10 @@ static void ini_parse_var(char* buf) default: ini_parse_numeric(var, &buf[i], var->var); + if (!strcasecmp(var->name, "DEBUG")) + { + stdout = cfg.debug ? orig_stdout : dev_null; + } break; } } @@ -401,6 +408,9 @@ static void ini_parse(int alt, const char *vmode) int section = 0; int eof; + if (!orig_stdout) orig_stdout = stdout; + if(!dev_null) dev_null = fopen("/dev/null", "w"); + 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)); diff --git a/cfg.h b/cfg.h index e5a5b0a..b7b9656 100644 --- a/cfg.h +++ b/cfg.h @@ -97,6 +97,7 @@ typedef struct { uint32_t controller_unique_mapping[256]; char osd_lock[25]; uint16_t osd_lock_time; + char debug; } cfg_t; extern cfg_t cfg;