Skip to content

Commit

Permalink
Add option to force audio routing to speakers, closes #1837
Browse files Browse the repository at this point in the history
Also refactor ini file a little bit
  • Loading branch information
TuxSH committed Feb 10, 2023
1 parent 89f77db commit ef1072f
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 32 deletions.
Binary file modified arm9/data/config_template.ini
Binary file not shown.
70 changes: 53 additions & 17 deletions arm9/source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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);
return 1;
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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -889,6 +925,7 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
{ .visible = true },
{ .visible = ISN3DS },
{ .visible = true },
{ .visible = true },
};

struct singleOption {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions arm9/source/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,6 +51,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};

enum singleOptions
Expand All @@ -62,7 +63,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,
Expand Down
2 changes: 1 addition & 1 deletion k11_extension/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};

enum singleOptions
Expand All @@ -33,7 +34,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,
Expand Down
2 changes: 1 addition & 1 deletion sysmodules/loader/source/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};

enum singleOptions
Expand All @@ -36,7 +37,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,
Expand Down
2 changes: 1 addition & 1 deletion sysmodules/pm/source/luma.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};

enum singleOptions
Expand All @@ -30,7 +31,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,
Expand Down
Binary file modified sysmodules/rosalina/data/config_template.ini
Binary file not shown.
2 changes: 1 addition & 1 deletion sysmodules/rosalina/include/luma_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
FORCEHEADPHONEOUTPUT,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,
Expand All @@ -53,6 +52,7 @@ enum multiOptions
PIN,
NEWCPU,
AUTOBOOTMODE,
FORCEAUDIOOUTPUT,
};

void LumaConfig_ConvertComboToString(char *out, u32 combo);
Expand Down
19 changes: 17 additions & 2 deletions sysmodules/rosalina/source/luma_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 19 additions & 6 deletions sysmodules/rosalina/source/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}

0 comments on commit ef1072f

Please sign in to comment.