Skip to content

Commit

Permalink
[OSD Settings] add screen aspect ratio and video mode manipulation (#…
Browse files Browse the repository at this point in the history
…1057)

* initial commit

* finish job

* Update system.c

* clang format

* Update system.c

* fix codacy issues?
  • Loading branch information
israpps authored Aug 14, 2023
1 parent ea72571 commit 9e12706
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 43 deletions.
21 changes: 11 additions & 10 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ enum CONFIG_INDEX {
#define CONFIG_ITEM_DNAS "$DNAS"
#define CONFIG_ITEM_CONFIGSOURCE "$ConfigSource"

#define CONFIG_ITEM_OSDLNG "$CustomLanguageValue"
#define CONFIG_ITEM_OSDLNG_SOURCE "$CustomLanguageSource"
#define CONFIG_ITEM_OSDLNG_ENABLE "$CustomLanguageEnable"

#define CONFIG_ITEM_OSD_SETTINGS_LANGID "$CustomLanguageValue"
#define CONFIG_ITEM_OSD_SETTINGS_SOURCE "$CustomLanguageSource"
#define CONFIG_ITEM_OSD_SETTINGS_ENABLE "$OSDSettingsEnable"
#define CONFIG_ITEM_OSD_SETTINGS_TV_ASP "$OSDAspectRatio"
#define CONFIG_ITEM_OSD_SETTINGS_VMODE "$OSDVideoMode"
// Per-Game GSM keys. -Bat-
#define CONFIG_ITEM_GSMSOURCE "$GSMSource"
#define CONFIG_ITEM_ENABLEGSM "$EnableGSM"
#define CONFIG_ITEM_GSMVMODE "$GSMVMode"
#define CONFIG_ITEM_GSMXOFFSET "$GSMXOffset"
#define CONFIG_ITEM_GSMYOFFSET "$GSMYOffset"
#define CONFIG_ITEM_GSMFIELDFIX "$GSMFIELDFix"
#define CONFIG_ITEM_GSMSOURCE "$GSMSource"
#define CONFIG_ITEM_ENABLEGSM "$EnableGSM"
#define CONFIG_ITEM_GSMVMODE "$GSMVMode"
#define CONFIG_ITEM_GSMXOFFSET "$GSMXOffset"
#define CONFIG_ITEM_GSMYOFFSET "$GSMYOffset"
#define CONFIG_ITEM_GSMFIELDFIX "$GSMFIELDFix"

// Per-Game CHEAT keys. -Bat-
#define CONFIG_ITEM_CHEATSSOURCE "$CheatsSource"
Expand Down
2 changes: 2 additions & 0 deletions include/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ enum UI_ITEMS {
OSD_LANGUAGE_SOURCE,
OSD_LANGUAGE_ENABLE,
OSD_LANGUAGE_VALUE,
OSD_TVASPECT_VALUE,
OSD_VMODE_VALUE,

#ifdef PADEMU
PADEMU_GLOBAL_BUTTON,
Expand Down
2 changes: 2 additions & 0 deletions include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ extern int gGSMSource;
extern int gPadEmuSource;

extern int gOSDLanguageValue;
extern int gOSDTVAspectRatio;
extern int gOSDVideOutput;
extern int gOSDLanguageEnable;
extern int gOSDLanguageSource;

Expand Down
14 changes: 12 additions & 2 deletions lng_tmpl/_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,21 @@ gui_strings:
- label: LANGUAGE_SIMPL_CHINESE
string: SIMPLIFIED CHINESE
- label: OSD_SETTINGS
string: OSD settings
string: OSD Settings
- label: OSD_SETTINGS_LNG
string: OSD Language
- label: HINT_OSD_SETTINGS_LNG
string: Force a custom language configuration
- label: ENABLE_LNG
string: Change language
string: Enable
- label: OSD_SETTINGS_TVASPECT
string: Screen Size
- label: FULL_SCREEN
string: Full Screen
- label: OSD_SETTINGS_VMODE
string: Video Mode
- label: SYSTEM_DEFAULT
string: System Default
- label: BGM
string: Background Music
- label: BGM_VOLUME
Expand Down
16 changes: 13 additions & 3 deletions src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ struct UIItem diaOSDConfig[] = {
{UI_LABEL, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_OSD_SETTINGS}}},
{UI_SPLITTER},

{UI_LABEL, 0, 1, 1, -1, -50, 0, {.label = {NULL, _STR_SETTINGS_SOURCE}}},
{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_SETTINGS_SOURCE}}},
{UI_SPACER},
{UI_ENUM, OSD_LANGUAGE_SOURCE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},
Expand All @@ -1043,9 +1043,19 @@ struct UIItem diaOSDConfig[] = {
{UI_BOOL, OSD_LANGUAGE_ENABLE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_OSD_SETTINGS_LNG}}},
{UI_LABEL, 0, 1, 1, -1, -41, 0, {.label = {NULL, _STR_OSD_SETTINGS_LNG}}},
{UI_SPACER},
{UI_ENUM, OSD_LANGUAGE_VALUE, 1, 1, _STR_HINT_OSD_SETTINGS_LNG, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -41, 0, {.label = {NULL, _STR_OSD_SETTINGS_TVASPECT}}},
{UI_SPACER},
{UI_ENUM, OSD_TVASPECT_VALUE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -41, 0, {.label = {NULL, _STR_OSD_SETTINGS_VMODE}}},
{UI_SPACER},
{UI_ENUM, OSD_LANGUAGE_VALUE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_ENUM, OSD_VMODE_VALUE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

// buttons
Expand Down
68 changes: 47 additions & 21 deletions src/guigame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,10 @@ void guiGameRemoveGlobalSettings(config_set_t *configGame)
configRemoveKey(configGame, CONFIG_ITEM_GSMYOFFSET);
configRemoveKey(configGame, CONFIG_ITEM_GSMFIELDFIX);
//OSD Language
configRemoveKey(configGame, CONFIG_ITEM_OSDLNG);
configRemoveKey(configGame, CONFIG_ITEM_OSDLNG_ENABLE);
configRemoveKey(configGame, CONFIG_ITEM_OSD_SETTINGS_LANGID);
configRemoveKey(configGame, CONFIG_ITEM_OSD_SETTINGS_TV_ASP);
configRemoveKey(configGame, CONFIG_ITEM_OSD_SETTINGS_VMODE);
configRemoveKey(configGame, CONFIG_ITEM_OSD_SETTINGS_ENABLE);

#ifdef PADEMU
// PADEMU
Expand Down Expand Up @@ -1146,9 +1148,11 @@ void guiGameRemoveSettings(config_set_t *configSet)
configRemoveKey(configSet, CONFIG_ITEM_CHEATMODE);

//OSD Language
configRemoveKey(configSet, CONFIG_ITEM_OSDLNG);
configRemoveKey(configSet, CONFIG_ITEM_OSDLNG_SOURCE);
configRemoveKey(configSet, CONFIG_ITEM_OSDLNG_ENABLE);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_LANGID);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_TV_ASP);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_VMODE);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_SOURCE);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_ENABLE);

#ifdef PADEMU
// PADEMU
Expand Down Expand Up @@ -1322,26 +1326,35 @@ static int guiGameOSDLanguageUpdater(int modified)
// update GUI to display per-game or global settings if changed
if (previousSource != gOSDLanguageSource && gOSDLanguageSource == SETTINGS_GLOBAL) {
config_set_t *configSet = gameMenuLoadConfig(diaOSDConfig);
configRemoveKey(configSet, CONFIG_ITEM_OSDLNG_SOURCE);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_SOURCE);
guiGameLoadOSDLanguageConfig(configSet, configGetByType(CONFIG_GAME));
} else if (previousSource != gOSDLanguageSource && gOSDLanguageSource == SETTINGS_PERGAME) {
config_set_t *configSet = gameMenuLoadConfig(diaOSDConfig);
configSetInt(configSet, CONFIG_ITEM_OSDLNG_SOURCE, gOSDLanguageSource);
configSetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_SOURCE, gOSDLanguageSource);
guiGameLoadOSDLanguageConfig(configSet, configGetByType(CONFIG_GAME));
}

diaGetInt(diaOSDConfig, OSD_LANGUAGE_ENABLE, &gOSDLanguageEnable);
diaGetInt(diaOSDConfig, OSD_LANGUAGE_VALUE, &gOSDLanguageValue);

diaGetInt(diaOSDConfig, OSD_TVASPECT_VALUE, &gOSDTVAspectRatio);
diaGetInt(diaOSDConfig, OSD_VMODE_VALUE, &gOSDVideOutput);
diaSetEnabled(diaOSDConfig, OSD_LANGUAGE_VALUE, gOSDLanguageEnable);
diaSetEnabled(diaOSDConfig, OSD_TVASPECT_VALUE, gOSDLanguageEnable);
diaSetEnabled(diaOSDConfig, OSD_VMODE_VALUE, gOSDLanguageEnable);
return 0;
}

void guiGameShowOSDLanguageConfig(int forceGlobal)
{
const char *Lngs[] = {_l(_STR_LANGUAGE_JAPANESE), _l(_STR_LANGUAGE_ENGLISH), _l(_STR_LANGUAGE_FRENCH), _l(_STR_LANGUAGE_SPANISH), _l(_STR_LANGUAGE_GERMAN), _l(_STR_LANGUAGE_ITALIAN), _l(_STR_LANGUAGE_DUTCH), _l(_STR_LANGUAGE_PORTUGUESE), NULL};
/// `_STR_SYSTEM_DEFAULT` MUST BE AT THE END OF THE LIST. ELSE, THE ENUMERATOR VALUES WILL NOT MATCH THE ONES ON OSDCONFIG. BREAKING THIS FEATURE
const char *Lngs[] = {_l(_STR_LANGUAGE_JAPANESE), _l(_STR_LANGUAGE_ENGLISH), _l(_STR_LANGUAGE_FRENCH), _l(_STR_LANGUAGE_SPANISH), _l(_STR_LANGUAGE_GERMAN), _l(_STR_LANGUAGE_ITALIAN), _l(_STR_LANGUAGE_DUTCH), _l(_STR_LANGUAGE_PORTUGUESE), _l(_STR_SYSTEM_DEFAULT), NULL};
const char *sources[] = {_l(_STR_GLOBAL_SETTINGS), _l(_STR_PERGAME_SETTINGS), NULL};
const char *TV[] = {"4:3", _l(_STR_FULL_SCREEN), "16:9", _l(_STR_SYSTEM_DEFAULT), NULL};
const char *VMOD[] = {"RGB", "Y Cb/Pb Cr/Pr", _l(_STR_SYSTEM_DEFAULT), NULL};
diaSetEnum(diaOSDConfig, OSD_LANGUAGE_VALUE, Lngs);
diaSetEnum(diaOSDConfig, OSD_LANGUAGE_SOURCE, sources);
diaSetEnum(diaOSDConfig, OSD_TVASPECT_VALUE, TV);
diaSetEnum(diaOSDConfig, OSD_VMODE_VALUE, VMOD);
forceGlobalOSDLanguage = forceGlobal;
diaSetEnabled(diaOSDConfig, OSD_LANGUAGE_SOURCE, !forceGlobalOSDLanguage);

Expand All @@ -1361,12 +1374,17 @@ void guiGameShowOSDLanguageConfig(int forceGlobal)
static int guiGameSaveOSDLanguageGameConfig(config_set_t *configSet, int result)
{
if (gOSDLanguageSource == SETTINGS_PERGAME) {
if ((result = configSetInt(configSet, CONFIG_ITEM_OSDLNG_SOURCE, gOSDLanguageSource)))
if ((result = configSetInt(configSet, CONFIG_ITEM_OSDLNG_ENABLE, gOSDLanguageEnable)))
result = configSetInt(configSet, CONFIG_ITEM_OSDLNG, gOSDLanguageValue);
if ((result = configSetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_SOURCE, gOSDLanguageSource)))
if ((result = configSetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_ENABLE, gOSDLanguageEnable))) {
configSetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_LANGID, gOSDLanguageValue);
configSetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_TV_ASP, gOSDTVAspectRatio);
result = configSetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_VMODE, gOSDVideOutput);
}
} else {
configRemoveKey(configSet, CONFIG_ITEM_OSDLNG);
configRemoveKey(configSet, CONFIG_ITEM_OSDLNG_ENABLE);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_LANGID);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_TV_ASP);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_VMODE);
configRemoveKey(configSet, CONFIG_ITEM_OSD_SETTINGS_ENABLE);
}

return result;
Expand All @@ -1375,8 +1393,10 @@ static int guiGameSaveOSDLanguageGameConfig(config_set_t *configSet, int result)
void guiGameSaveOSDLanguageGlobalConfig(config_set_t *configGame)
{
if (gOSDLanguageSource == SETTINGS_GLOBAL) {
configSetInt(configGame, CONFIG_ITEM_OSDLNG_ENABLE, gOSDLanguageEnable);
configSetInt(configGame, CONFIG_ITEM_OSDLNG, gOSDLanguageValue);
configSetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_ENABLE, gOSDLanguageEnable);
configSetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_LANGID, gOSDLanguageValue);
configSetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_TV_ASP, gOSDTVAspectRatio);
configSetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_VMODE, gOSDVideOutput);
}
}

Expand All @@ -1386,16 +1406,22 @@ static void guiGameLoadOSDLanguageConfig(config_set_t *configSet, config_set_t *
gOSDLanguageEnable = 0;
gOSDLanguageSource = 0;

configGetInt(configGame, CONFIG_ITEM_OSDLNG_ENABLE, &gOSDLanguageEnable);
configGetInt(configGame, CONFIG_ITEM_OSDLNG, &gOSDLanguageValue);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_ENABLE, &gOSDLanguageEnable);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_LANGID, &gOSDLanguageValue);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_TV_ASP, &gOSDTVAspectRatio);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_VMODE, &gOSDVideOutput);
// override global with per-game settings if available and selected.
if (!forceGlobalOSDLanguage) {
configGetInt(configSet, CONFIG_ITEM_OSDLNG_SOURCE, &gOSDLanguageSource);
configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_SOURCE, &gOSDLanguageSource);
if (gOSDLanguageSource == SETTINGS_PERGAME) {
if (!configGetInt(configSet, CONFIG_ITEM_OSDLNG_ENABLE, &gOSDLanguageEnable))
if (!configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_ENABLE, &gOSDLanguageEnable))
gOSDLanguageEnable = 0;
if (!configGetInt(configSet, CONFIG_ITEM_OSDLNG, &gOSDLanguageValue))
if (!configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_LANGID, &gOSDLanguageValue))
gOSDLanguageValue = 0;
if (!configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_TV_ASP, &gOSDTVAspectRatio))
gOSDTVAspectRatio = 0;
if (!configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_VMODE, &gOSDVideOutput))
gOSDVideOutput = 0;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ char *gHDDPrefix;
char gExportName[32];

int gOSDLanguageValue;
int gOSDTVAspectRatio;
int gOSDVideOutput;
int gOSDLanguageEnable;
int gOSDLanguageSource;

Expand Down
14 changes: 9 additions & 5 deletions src/supportbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,16 @@ int sbPrepare(base_game_info_t *game, config_set_t *configSet, int size_cdvdman,
}
#endif

if (configGetInt(configSet, CONFIG_ITEM_OSDLNG_SOURCE, &gOSDLanguageSource)) {
configGetInt(configSet, CONFIG_ITEM_OSDLNG_ENABLE, &gOSDLanguageEnable);
configGetInt(configSet, CONFIG_ITEM_OSDLNG, &gOSDLanguageValue);
if (configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_SOURCE, &gOSDLanguageSource)) {
configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_ENABLE, &gOSDLanguageEnable);
configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_LANGID, &gOSDLanguageValue);
configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_TV_ASP, &gOSDTVAspectRatio);
configGetInt(configSet, CONFIG_ITEM_OSD_SETTINGS_VMODE, &gOSDVideOutput);
} else {
configGetInt(configGame, CONFIG_ITEM_OSDLNG_ENABLE, &gOSDLanguageEnable);
configGetInt(configGame, CONFIG_ITEM_OSDLNG, &gOSDLanguageValue);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_ENABLE, &gOSDLanguageEnable);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_LANGID, &gOSDLanguageValue);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_TV_ASP, &gOSDTVAspectRatio);
configGetInt(configGame, CONFIG_ITEM_OSD_SETTINGS_VMODE, &gOSDVideOutput);
}

*patchindex = i;
Expand Down
18 changes: 16 additions & 2 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,22 @@ void sysLaunchLoaderElf(const char *filename, const char *mode_str, int size_cdv

#define CONFIGPARAMDATA " %d %d %d %d %d %d %d %d %d"
ConfigParam PARAM;
GetOsdConfigParam(&PARAM); //get system configuration
PARAM.language = (gOSDLanguageEnable) ? gOSDLanguageValue : PARAM.language; //patch what we care about
GetOsdConfigParam(&PARAM);
if (gOSDLanguageEnable) { // only patch if enabled, and only on config fields wich have not chosen "system default"
if (gOSDLanguageValue >= LANGUAGE_JAPANESE && gOSDLanguageValue <= LANGUAGE_PORTUGUESE) {
PARAM.language = gOSDLanguageValue;
LOG("System Language enforced to %d\n", gOSDLanguageValue);
}
if (gOSDTVAspectRatio >= TV_SCREEN_43 && gOSDTVAspectRatio <= TV_SCREEN_169) {
PARAM.screenType = gOSDTVAspectRatio;
LOG("System screenType enforced to %d\n", gOSDTVAspectRatio);
}
if (gOSDVideOutput == VIDEO_OUTPUT_RGB || gOSDVideOutput == VIDEO_OUTPUT_COMPONENT) {
PARAM.videoOutput = gOSDVideOutput;
LOG("System video output enforced to %d\n", gOSDVideOutput);
}
}

#define CONFIGPARAMDATA_ARGUMENT , PARAM.spdifMode, PARAM.screenType, PARAM.videoOutput, PARAM.japLanguage, PARAM.ps1drvConfig, PARAM.version, PARAM.language, PARAM.timezoneOffset, gOSDLanguageEnable

argc = 0;
Expand Down

0 comments on commit 9e12706

Please sign in to comment.