Add enable_dsi_external_filter and allow_updown_leftright_dsi

This commit is contained in:
TuxSH 2023-07-17 01:11:43 +02:00
parent cf3cf12414
commit 41edcde5c0
12 changed files with 73 additions and 11 deletions

Binary file not shown.

View File

@ -64,6 +64,8 @@ static const char *singleOptionIniNamesBoot[] = {
"app_syscore_threads_on_core_2",
"show_system_settings_string",
"show_gba_boot_screen",
"enable_dsi_external_filter",
"allow_updown_leftright_dsi",
};
static const char *singleOptionIniNamesMisc[] = {
@ -649,6 +651,7 @@ static size_t saveLumaIniConfigToStr(char *out)
(int)CONFIG(AUTOBOOTEMU), (int)CONFIG(LOADEXTFIRMSANDMODULES),
(int)CONFIG(PATCHGAMES), (int)CONFIG(REDIRECTAPPTHREADS),
(int)CONFIG(PATCHVERSTRING), (int)CONFIG(SHOWGBABOOT),
(int)CONFIG(ENABLEDSIEXTFILTER), (int)CONFIG(ALLOWUPDOWNLEFTRIGHTDSI),
1 + (int)MULTICONFIG(DEFAULTEMU), 4 - (int)MULTICONFIG(BRIGHTNESS),
splashPosStr, (unsigned int)cfg->splashDurationMsec,
@ -828,6 +831,8 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
"( ) Redirect app. syscore threads to core2",
"( ) Show NAND or user string in System Settings",
"( ) Show GBA boot screen in patched AGB_FIRM",
"( ) Enable custom upscaling filters for DSi",
"( ) Allow Left+Right / Up+Down combos for DSi",
};
static const char *optionsDescription[] = { "Select the default EmuNAND.\n\n"
@ -912,6 +917,18 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
"Enable showing the GBA boot screen\n"
"when booting GBA games.",
"Enable replacing the default upscaling\n"
"filter used for DS(i) software by the\n"
"contents of:\n\n"
"/luma/twl_upscaling_filter.bin\n\n"
"Refer to the wiki for further details.",
"Allow Left+Right and Up+Down button\n"
"combos (using DPAD and CPAD\n"
"simultaneously) in DS(i) software.\n\n"
"Commercial software filter these\n"
"combos on their own too, though.",
};
FirmwareSource nandType = FIRMWARE_SYSNAND;
@ -949,6 +966,8 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
{ .visible = ISN3DS },
{ .visible = true },
{ .visible = true },
{ .visible = true },
{ .visible = true },
};
//Calculate the amount of the various kinds of options and pre-select the first single one

View File

@ -36,7 +36,7 @@
#define CONFIG_FILE "config.ini"
#define CONFIG_VERSIONMAJOR 3
#define CONFIG_VERSIONMINOR 9
#define CONFIG_VERSIONMINOR 10
#define BOOTCFG_NAND BOOTCONFIG(0, 1)
#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3)
@ -62,6 +62,8 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
ENABLEDSIEXTFILTER,
ALLOWUPDOWNLEFTRIGHTDSI,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -483,11 +483,7 @@ static void mergeSection0(FirmwareType firmType, u32 firmVersion, bool loadFromS
CopyKipResult copyRes = copyKip(dst, moduleList[i].src, maxModuleSize, isStockTwlBg);
if (isStockTwlBg)
{
u32 patchRes = patchTwlBg(copyRes.codeDstAddr, copyRes.codeSize);
if (patchRes > 0)
error("Failed to apply %d TwlBg patch(es)", patchRes);
}
patchTwlBg(copyRes.codeDstAddr, copyRes.codeSize);
dst += copyRes.cxiSize;
maxModuleSize -= copyRes.cxiSize;

View File

@ -767,9 +767,45 @@ u32 patchAgbBootSplash(u8 *pos, u32 size)
return 0;
}
u32 patchTwlBg(u8 *pos, u32 size)
void patchTwlBg(u8 *pos, u32 size)
{
(void)pos;
(void)size;
return 0;
// You can use the following Python code to convert something like below
// into twl_upscaling_filter.bin:
// import struct; open("twl_upscaling_filter.bin", "wb+").write(struct.pack("<30H", [array contents]))
static const u16 nintendoFilterTwl[] = {
0x0000, 0x004E, 0x011D, 0x01E3, 0x01C1,
0x0000, 0xFCA5, 0xF8D0, 0xF69D, 0xF873,
0x0000, 0x0D47, 0x1E35, 0x2F08, 0x3B6F,
0x4000, 0x3B6F, 0x2F08, 0x1E35, 0x0D47,
0x0000, 0xF873, 0xF69D, 0xF8D0, 0xFCA5,
0x0000, 0x01C1, 0x01E3, 0x011D, 0x004E,
};
// "error" func doesn't seem to work here
if (CONFIG(ENABLEDSIEXTFILTER))
{
u16 filter[5*6] = { 0 };
u32 rd = fileRead(filter, "twl_upscaling_filter.bin", sizeof(filter));
if (rd == sizeof(filter))
{
// else error("Failed to apply enable_dsi_external_filter:\n\ntwl_upscaling_filter.bin is missing or invalid.");
u8 *off = memsearch(pos, nintendoFilterTwl, size, sizeof(nintendoFilterTwl));
if (off != NULL)
memcpy(off, filter, sizeof(filter));
// else error("Failed to apply enable_dsi_external_filter.");
}
}
if (CONFIG(ALLOWUPDOWNLEFTRIGHTDSI))
{
u16 *off2;
for (off2 = (u16 *)pos; (u8 *)off2 < pos + size && (off2[0] != 0x2040 || off2[1] != 0x4020); off2++);
if ((u8 *)off2 < pos + size)
{
// else error("Failed to apply allow_updown_leftright_dsi.");
for (u32 i = 0; i < 8; i++)
off2[i] = 0x46C0;
}
}
}

View File

@ -66,4 +66,4 @@ u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion);
u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size);
u32 patchTwlShaHashChecks(u8 *pos, u32 size);
u32 patchAgbBootSplash(u8 *pos, u32 size);
u32 patchTwlBg(u8 *pos, u32 size);
void patchTwlBg(u8 *pos, u32 size); // silently fails

View File

@ -33,6 +33,8 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
ENABLEDSIEXTFILTER,
ALLOWUPDOWNLEFTRIGHTDSI,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -36,6 +36,8 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
ENABLEDSIEXTFILTER,
ALLOWUPDOWNLEFTRIGHTDSI,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -30,6 +30,8 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
ENABLEDSIEXTFILTER,
ALLOWUPDOWNLEFTRIGHTDSI,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -38,6 +38,8 @@ enum singleOptions
REDIRECTAPPTHREADS,
PATCHVERSTRING,
SHOWGBABOOT,
ENABLEDSIEXTFILTER,
ALLOWUPDOWNLEFTRIGHTDSI,
PATCHUNITINFO,
DISABLEARM11EXCHANDLERS,
ENABLESAFEFIRMROSALINA,

View File

@ -168,6 +168,7 @@ static size_t LumaConfig_SaveLumaIniConfigToStr(char *out, const CfgData *cfg)
(int)CONFIG(AUTOBOOTEMU), (int)CONFIG(LOADEXTFIRMSANDMODULES),
(int)CONFIG(PATCHGAMES), (int)CONFIG(REDIRECTAPPTHREADS),
(int)CONFIG(PATCHVERSTRING), (int)CONFIG(SHOWGBABOOT),
(int)CONFIG(ENABLEDSIEXTFILTER), (int)CONFIG(ALLOWUPDOWNLEFTRIGHTDSI),
1 + (int)MULTICONFIG(DEFAULTEMU), 4 - (int)MULTICONFIG(BRIGHTNESS),
splashPosStr, (unsigned int)cfg->splashDurationMsec,