diff --git a/arm9/data/config_template.ini b/arm9/data/config_template.ini index d7a03f5..7f36b3c 100644 Binary files a/arm9/data/config_template.ini and b/arm9/data/config_template.ini differ diff --git a/arm9/source/config.c b/arm9/source/config.c index d35feaa..f631330 100644 --- a/arm9/source/config.c +++ b/arm9/source/config.c @@ -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 diff --git a/arm9/source/config.h b/arm9/source/config.h index e390c37..3ac0e98 100644 --- a/arm9/source/config.h +++ b/arm9/source/config.h @@ -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, diff --git a/arm9/source/firm.c b/arm9/source/firm.c index ce4c77e..b759f9a 100755 --- a/arm9/source/firm.c +++ b/arm9/source/firm.c @@ -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; diff --git a/arm9/source/patches.c b/arm9/source/patches.c index f185bf1..80ca766 100644 --- a/arm9/source/patches.c +++ b/arm9/source/patches.c @@ -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; + } + } } \ No newline at end of file diff --git a/arm9/source/patches.h b/arm9/source/patches.h index e6f3ee8..99c1f95 100644 --- a/arm9/source/patches.h +++ b/arm9/source/patches.h @@ -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 diff --git a/k11_extension/include/config.h b/k11_extension/include/config.h index 87de174..b890fcf 100644 --- a/k11_extension/include/config.h +++ b/k11_extension/include/config.h @@ -33,6 +33,8 @@ enum singleOptions REDIRECTAPPTHREADS, PATCHVERSTRING, SHOWGBABOOT, + ENABLEDSIEXTFILTER, + ALLOWUPDOWNLEFTRIGHTDSI, PATCHUNITINFO, DISABLEARM11EXCHANDLERS, ENABLESAFEFIRMROSALINA, diff --git a/sysmodules/loader/source/patcher.h b/sysmodules/loader/source/patcher.h index 6426784..35bd17d 100644 --- a/sysmodules/loader/source/patcher.h +++ b/sysmodules/loader/source/patcher.h @@ -36,6 +36,8 @@ enum singleOptions REDIRECTAPPTHREADS, PATCHVERSTRING, SHOWGBABOOT, + ENABLEDSIEXTFILTER, + ALLOWUPDOWNLEFTRIGHTDSI, PATCHUNITINFO, DISABLEARM11EXCHANDLERS, ENABLESAFEFIRMROSALINA, diff --git a/sysmodules/pm/source/luma.h b/sysmodules/pm/source/luma.h index 68c917a..27df022 100644 --- a/sysmodules/pm/source/luma.h +++ b/sysmodules/pm/source/luma.h @@ -30,6 +30,8 @@ enum singleOptions REDIRECTAPPTHREADS, PATCHVERSTRING, SHOWGBABOOT, + ENABLEDSIEXTFILTER, + ALLOWUPDOWNLEFTRIGHTDSI, PATCHUNITINFO, DISABLEARM11EXCHANDLERS, ENABLESAFEFIRMROSALINA, diff --git a/sysmodules/rosalina/data/config_template.ini b/sysmodules/rosalina/data/config_template.ini index d7a03f5..7f36b3c 100644 Binary files a/sysmodules/rosalina/data/config_template.ini and b/sysmodules/rosalina/data/config_template.ini differ diff --git a/sysmodules/rosalina/include/luma_config.h b/sysmodules/rosalina/include/luma_config.h index b289b1b..61bbff3 100644 --- a/sysmodules/rosalina/include/luma_config.h +++ b/sysmodules/rosalina/include/luma_config.h @@ -38,6 +38,8 @@ enum singleOptions REDIRECTAPPTHREADS, PATCHVERSTRING, SHOWGBABOOT, + ENABLEDSIEXTFILTER, + ALLOWUPDOWNLEFTRIGHTDSI, PATCHUNITINFO, DISABLEARM11EXCHANDLERS, ENABLESAFEFIRMROSALINA, diff --git a/sysmodules/rosalina/source/luma_config.c b/sysmodules/rosalina/source/luma_config.c index 40364c8..ae3a8ca 100644 --- a/sysmodules/rosalina/source/luma_config.c +++ b/sysmodules/rosalina/source/luma_config.c @@ -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,