Add option to force audio routing to speakers, closes #1837

Also refactor ini file a little bit
This commit is contained in:
TuxSH 2023-02-10 01:02:01 +00:00
parent 89f77db986
commit ef1072f996
10 changed files with 96 additions and 32 deletions

Binary file not shown.

View File

@ -65,7 +65,6 @@ static const char *singleOptionIniNamesBoot[] = {
"app_syscore_threads_on_core_2",
"show_system_settings_string",
"show_gba_boot_screen",
"force_headphone_output",
};
static const char *singleOptionIniNamesMisc[] = {
@ -409,10 +408,31 @@ static int configIniHandler(void* user, const char* section, const char* name, c
CHECK_PARSE_OPTION(-1);
}
} else if (strcmp(name, "autoboot_mode") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecIntOption(&opt, value, 0, 2));
cfg->multiConfig |= (u32)opt << (2 * (u32)AUTOBOOTMODE);
if (strcasecmp(value, "off") == 0) {
cfg->multiConfig |= 0 << (2 * (u32)AUTOBOOTMODE);
return 1;
} else if (strcasecmp(value, "3ds") == 0) {
cfg->multiConfig |= 1 << (2 * (u32)AUTOBOOTMODE);
return 1;
} else if (strcasecmp(value, "dsi") == 0) {
cfg->multiConfig |= 2 << (2 * (u32)AUTOBOOTMODE);
return 1;
} else {
CHECK_PARSE_OPTION(-1);
}
} else if (strcmp(name, "force_audio_output") == 0) {
if (strcasecmp(value, "off") == 0) {
cfg->multiConfig |= 0 << (2 * (u32)FORCEAUDIOOUTPUT);
return 1;
} else if (strcasecmp(value, "headphones") == 0) {
cfg->multiConfig |= 1 << (2 * (u32)FORCEAUDIOOUTPUT);
return 1;
} else if (strcasecmp(value, "speakers") == 0) {
cfg->multiConfig |= 2 << (2 * (u32)FORCEAUDIOOUTPUT);
return 1;
} else {
CHECK_PARSE_OPTION(-1);
}
} else {
CHECK_PARSE_OPTION(-1);
}
@ -529,6 +549,8 @@ static size_t saveLumaIniConfigToStr(char *out)
const char *splashPosStr;
const char *n3dsCpuStr;
const char *autobootModeStr;
const char *forceAudioOutputStr;
switch (MULTICONFIG(SPLASH)) {
default: case 0: splashPosStr = "off"; break;
@ -543,6 +565,18 @@ static size_t saveLumaIniConfigToStr(char *out)
case 3: n3dsCpuStr = "clock+l2"; break;
}
switch (MULTICONFIG(AUTOBOOTMODE)) {
default: case 0: autobootModeStr = "off"; break;
case 1: autobootModeStr = "3ds"; break;
case 2: autobootModeStr = "dsi"; break;
}
switch (MULTICONFIG(FORCEAUDIOOUTPUT)) {
default: case 0: forceAudioOutputStr = "off"; break;
case 1: forceAudioOutputStr = "headphones"; break;
case 2: forceAudioOutputStr = "speakers"; break;
}
if (VERSION_BUILD != 0) {
sprintf(lumaVerStr, "Luma3DS v%d.%d.%d", (int)VERSION_MAJOR, (int)VERSION_MINOR, (int)VERSION_BUILD);
} else {
@ -582,11 +616,12 @@ static size_t saveLumaIniConfigToStr(char *out)
(int)CONFIG(AUTOBOOTEMU), (int)CONFIG(USEEMUFIRM),
(int)CONFIG(LOADEXTFIRMSANDMODULES), (int)CONFIG(PATCHGAMES),
(int)CONFIG(REDIRECTAPPTHREADS), (int)CONFIG(PATCHVERSTRING),
(int)CONFIG(SHOWGBABOOT), (int)CONFIG(FORCEHEADPHONEOUTPUT),
(int)CONFIG(SHOWGBABOOT),
1 + (int)MULTICONFIG(DEFAULTEMU), 4 - (int)MULTICONFIG(BRIGHTNESS),
splashPosStr, (unsigned int)cfg->splashDurationMsec,
pinNumDigits, n3dsCpuStr, (int)MULTICONFIG(AUTOBOOTMODE),
pinNumDigits, n3dsCpuStr,
autobootModeStr, forceAudioOutputStr,
cfg->hbldr3dsxTitleId, rosalinaMenuComboStr,
(int)cfg->ntpTzOffetMinutes,
@ -751,6 +786,7 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
"PIN lock: Off( ) 4( ) 6( ) 8( ) digits",
"New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )",
"Homebrew autoboot: Off( ) 3DS( ) DSi( )",
"Force audio: Off( ) Headphones( ) Speakers( )"
};
static const char *singleOptionsText[] = { "( ) Autoboot EmuNAND",
@ -802,6 +838,15 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
"configuration file to configure\n"
"this feature.",
"Force audio output to HPs or speakers.\n\n"
"Currently only for NATIVE_FIRM.\n\n"
"Due to software limitations, this gets\n"
"undone if you actually insert then\n"
"remove HPs (just enter then exit sleep\n"
"mode if this happens).\n\n"
"Also gets bypassed for camera shutter\n"
"sound.",
"If enabled, an EmuNAND\n"
"will be launched on boot.\n\n"
"Otherwise, SysNAND will.\n\n"
@ -859,15 +904,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
"Enable showing the GBA boot screen\n"
"when booting GBA games.",
"Force audio output to headphones.\n\n"
"Currently only for NATIVE_FIRM.\n\n"
"Due to software limitations, this gets\n"
"undone if you actually insert then\n"
"remove HPs (just enter then exit sleep\n"
"mode if this happens).\n\n"
"Also gets bypassed for camera shutter\n"
"sound.",
};
FirmwareSource nandType = FIRMWARE_SYSNAND;
@ -889,6 +925,7 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
{ .visible = true },
{ .visible = ISN3DS },
{ .visible = true },
{ .visible = true },
};
struct singleOption {
@ -903,7 +940,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
{ .visible = ISN3DS },
{ .visible = true },
{ .visible = true },
{ .visible = true },
};
//Calculate the amount of the various kinds of options and pre-select the first single one

View File

@ -34,9 +34,9 @@
#define MULTICONFIG(a) ((configData.multiConfig >> (2 * (a))) & 3)
#define BOOTCONFIG(a, b) ((configData.bootConfig >> (a)) & (b))
#define CONFIG_FILE "config.bin"
#define CONFIG_FILE "config.ini"
#define CONFIG_VERSIONMAJOR 3
#define CONFIG_VERSIONMINOR 5
#define CONFIG_VERSIONMINOR 6
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)
@ -51,6 +51,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};
enum singleOptions
@ -62,7 +63,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -22,6 +22,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};
enum singleOptions
@ -33,7 +34,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -25,6 +25,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};
enum singleOptions
@ -36,7 +37,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -19,6 +19,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};
enum singleOptions
@ -30,7 +31,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -39,7 +39,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,
@ -53,6 +52,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};
void LumaConfig_ConvertComboToString(char *out, u32 combo);

View File

@ -87,6 +87,8 @@ static size_t LumaConfig_SaveLumaIniConfigToStr(char *out, const CfgData *cfg)
const char *splashPosStr;
const char *n3dsCpuStr;
const char *autobootModeStr;
const char *forceAudioOutputStr;
s64 outInfo;
svcGetSystemInfo(&outInfo, 0x10000, 0);
@ -111,6 +113,18 @@ static size_t LumaConfig_SaveLumaIniConfigToStr(char *out, const CfgData *cfg)
case 3: n3dsCpuStr = "clock+l2"; break;
}
switch (MULTICONFIG(AUTOBOOTMODE)) {
default: case 0: autobootModeStr = "off"; break;
case 1: autobootModeStr = "3ds"; break;
case 2: autobootModeStr = "dsi"; break;
}
switch (MULTICONFIG(FORCEAUDIOOUTPUT)) {
default: case 0: forceAudioOutputStr = "off"; break;
case 1: forceAudioOutputStr = "headphones"; break;
case 2: forceAudioOutputStr = "speakers"; break;
}
if (GET_VERSION_REVISION(version) != 0) {
sprintf(lumaVerStr, "Luma3DS v%d.%d.%d", (int)GET_VERSION_MAJOR(version), (int)GET_VERSION_MINOR(version), (int)GET_VERSION_REVISION(version));
} else {
@ -150,11 +164,12 @@ static size_t LumaConfig_SaveLumaIniConfigToStr(char *out, const CfgData *cfg)
(int)CONFIG(AUTOBOOTEMU), (int)CONFIG(USEEMUFIRM),
(int)CONFIG(LOADEXTFIRMSANDMODULES), (int)CONFIG(PATCHGAMES),
(int)CONFIG(REDIRECTAPPTHREADS), (int)CONFIG(PATCHVERSTRING),
(int)CONFIG(SHOWGBABOOT), (int)CONFIG(FORCEHEADPHONEOUTPUT),
(int)CONFIG(SHOWGBABOOT),
1 + (int)MULTICONFIG(DEFAULTEMU), 4 - (int)MULTICONFIG(BRIGHTNESS),
splashPosStr, (unsigned int)cfg->splashDurationMsec,
pinNumDigits, n3dsCpuStr, (int)MULTICONFIG(AUTOBOOTMODE),
pinNumDigits, n3dsCpuStr,
autobootModeStr, forceAudioOutputStr,
cfg->hbldr3dsxTitleId, rosalinaMenuComboStr,
(int)cfg->ntpTzOffetMinutes,

View File

@ -30,7 +30,7 @@
#include "screen_filters.h"
#include "luma_config.h"
static void forceHeadphoneOutput(void)
static void forceAudioOutput(u32 forceOp)
{
// DSP/Codec sysmodule already have a way to force headphone output,
// but it's only for when the shell is closed (applied on shell close,
@ -58,7 +58,19 @@ static void forceHeadphoneOutput(void)
if (R_FAILED(res))
return;
u8 reg = 0x30; // Enable override selection (always set), then select HP.
u8 reg;
switch (forceOp) {
case 0:
default:
__builtin_trap();
break;
case 1:
reg = 0x30;
break;
case 2:
reg = 0x20;
break;
}
res = CDCCHK_WriteRegisters2(100, 69, &reg, 1);
svcCloseHandle(*cdcChkHandlePtr);
@ -67,8 +79,9 @@ static void forceHeadphoneOutput(void)
void handleShellOpened(void)
{
s64 out = 0;
svcGetSystemInfo(&out, 0x10000, 3);
u32 config = (u32)out;
svcGetSystemInfo(&out, 0x10000, 4);
u32 multiConfig = (u32)out;
u32 forceOp = (multiConfig >> (2 * (u32)FORCEAUDIOOUTPUT)) & 3;
// We need to check here if GSP has done its init stuff, in particular
// clock and reset, otherwise we'll cause core1 to be in a waitstate
@ -77,6 +90,6 @@ void handleShellOpened(void)
if (isServiceUsable("gsp::Gpu"))
ScreenFiltersMenu_RestoreSettings();
if ((config & BIT(FORCEHEADPHONEOUTPUT)) != 0 && isServiceUsable("cdc:CHK"))
forceHeadphoneOutput();
if (forceOp != 0 && isServiceUsable("cdc:CHK"))
forceAudioOutput(forceOp);
}