Skip to content

Commit

Permalink
rosalina: allow setting top and bot screen filters separately
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxSH committed Jan 31, 2023
1 parent 35e6c5a commit 777b43b
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 164 deletions.
Binary file modified arm9/data/config_template.ini
Binary file not shown.
86 changes: 62 additions & 24 deletions arm9/source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,33 +432,61 @@ static int configIniHandler(void* user, const char* section, const char* name, c
CHECK_PARSE_OPTION(parseDecIntOption(&opt, value, -779, 899));
cfg->ntpTzOffetMinutes = (s16)opt;
return 1;
} else if (strcmp(name, "screen_filters_cct") == 0) {
} else {
CHECK_PARSE_OPTION(-1);
}
} else if (strcmp(section, "screen_filters") == 0) {
if (strcmp(name, "screen_filters_top_cct") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecIntOption(&opt, value, 1000, 25100));
cfg->screenFiltersCct = (u32)opt;
cfg->topScreenFilter.cct = (u32)opt;
return 1;
} else if (strcmp(name, "screen_filters_gamma") == 0) {
} else if (strcmp(name, "screen_filters_top_gamma") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecFloatOption(&opt, value, 0, 1411 * FLOAT_CONV_MULT));
cfg->screenFiltersGammaEnc = opt;
cfg->topScreenFilter.gammaEnc = opt;
return 1;
} else if (strcmp(name, "screen_filters_contrast") == 0) {
} else if (strcmp(name, "screen_filters_top_contrast") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecFloatOption(&opt, value, 0, 255 * FLOAT_CONV_MULT));
cfg->screenFiltersContrastEnc = opt;
cfg->topScreenFilter.contrastEnc = opt;
return 1;
} else if (strcmp(name, "screen_filters_brightness") == 0) {
} else if (strcmp(name, "screen_filters_top_brightness") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecFloatOption(&opt, value, -1 * FLOAT_CONV_MULT, 1 * FLOAT_CONV_MULT));
cfg->screenFiltersBrightnessEnc = opt;
cfg->topScreenFilter.brightnessEnc = opt;
return 1;
} else if (strcmp(name, "screen_filters_invert") == 0) {
} else if (strcmp(name, "screen_filters_top_invert") == 0) {
bool opt;
CHECK_PARSE_OPTION(parseBoolOption(&opt, value));
cfg->screenFiltersInvert = opt;
cfg->topScreenFilter.invert = opt;
return 1;
}
else {
} else if (strcmp(name, "screen_filters_bot_cct") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecIntOption(&opt, value, 1000, 25100));
cfg->bottomScreenFilter.cct = (u32)opt;
return 1;
} else if (strcmp(name, "screen_filters_bot_gamma") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecFloatOption(&opt, value, 0, 1411 * FLOAT_CONV_MULT));
cfg->bottomScreenFilter.gammaEnc = opt;
return 1;
} else if (strcmp(name, "screen_filters_bot_contrast") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecFloatOption(&opt, value, 0, 255 * FLOAT_CONV_MULT));
cfg->bottomScreenFilter.contrastEnc = opt;
return 1;
} else if (strcmp(name, "screen_filters_bot_brightness") == 0) {
s64 opt;
CHECK_PARSE_OPTION(parseDecFloatOption(&opt, value, -1 * FLOAT_CONV_MULT, 1 * FLOAT_CONV_MULT));
cfg->bottomScreenFilter.brightnessEnc = opt;
return 1;
} else if (strcmp(name, "screen_filters_bot_invert") == 0) {
bool opt;
CHECK_PARSE_OPTION(parseBoolOption(&opt, value));
cfg->bottomScreenFilter.invert = opt;
return 1;
} else {
CHECK_PARSE_OPTION(-1);
}
} else if (strcmp(section, "autoboot") == 0) {
Expand Down Expand Up @@ -531,12 +559,19 @@ static size_t saveLumaIniConfigToStr(char *out)
static const int pinOptionToDigits[] = { 0, 4, 6, 8 };
int pinNumDigits = pinOptionToDigits[MULTICONFIG(PIN)];

char screenFiltersGammaStr[32];
char screenFiltersContrastStr[32];
char screenFiltersBrightnessStr[32];
encodedFloatToString(screenFiltersGammaStr, cfg->screenFiltersGammaEnc);
encodedFloatToString(screenFiltersContrastStr, cfg->screenFiltersContrastEnc);
encodedFloatToString(screenFiltersBrightnessStr, cfg->screenFiltersBrightnessEnc);
char topScreenFilterGammaStr[32];
char topScreenFilterContrastStr[32];
char topScreenFilterBrightnessStr[32];
encodedFloatToString(topScreenFilterGammaStr, cfg->topScreenFilter.gammaEnc);
encodedFloatToString(topScreenFilterContrastStr, cfg->topScreenFilter.contrastEnc);
encodedFloatToString(topScreenFilterBrightnessStr, cfg->topScreenFilter.brightnessEnc);

char bottomScreenFilterGammaStr[32];
char bottomScreenFilterContrastStr[32];
char bottomScreenFilterBrightnessStr[32];
encodedFloatToString(bottomScreenFilterGammaStr, cfg->bottomScreenFilter.gammaEnc);
encodedFloatToString(bottomScreenFilterContrastStr, cfg->bottomScreenFilter.contrastEnc);
encodedFloatToString(bottomScreenFilterBrightnessStr, cfg->bottomScreenFilter.brightnessEnc);

int n = sprintf(
out, (const char *)config_template_ini,
Expand All @@ -555,9 +590,11 @@ static size_t saveLumaIniConfigToStr(char *out)
cfg->hbldr3dsxTitleId, rosalinaMenuComboStr,
(int)cfg->ntpTzOffetMinutes,

(int)cfg->screenFiltersCct, screenFiltersGammaStr,
screenFiltersContrastStr, screenFiltersBrightnessStr,
(int)cfg->screenFiltersInvert,
(int)cfg->topScreenFilter.cct, (int)cfg->bottomScreenFilter.cct,
topScreenFilterGammaStr, bottomScreenFilterGammaStr,
topScreenFilterContrastStr, bottomScreenFilterContrastStr,
topScreenFilterBrightnessStr, bottomScreenFilterBrightnessStr,
(int)cfg->topScreenFilter.invert, (int)cfg->bottomScreenFilter.invert,

cfg->autobootTwlTitleId, (int)cfg->autobootCtrAppmemtype,

Expand Down Expand Up @@ -666,9 +703,10 @@ bool readConfig(void)
configData.splashDurationMsec = 3000;
configData.hbldr3dsxTitleId = HBLDR_DEFAULT_3DSX_TID;
configData.rosalinaMenuCombo = 1u << 9 | 1u << 7 | 1u << 2; // L+Start+Select
configData.screenFiltersCct = 6500; // default temp, no-op
configData.screenFiltersGammaEnc = 1 * FLOAT_CONV_MULT; // 1.0f
configData.screenFiltersContrastEnc = 1 * FLOAT_CONV_MULT; // 1.0f
configData.topScreenFilter.cct = 6500; // default temp, no-op
configData.topScreenFilter.gammaEnc = 1 * FLOAT_CONV_MULT; // 1.0f
configData.topScreenFilter.contrastEnc = 1 * FLOAT_CONV_MULT; // 1.0f
configData.bottomScreenFilter = configData.topScreenFilter;
configData.autobootTwlTitleId = AUTOBOOT_DEFAULT_TWL_TID;
ret = false;
}
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#define CONFIG_FILE "config.bin"
#define CONFIG_VERSIONMAJOR 3
#define CONFIG_VERSIONMINOR 3
#define CONFIG_VERSIONMINOR 4

#define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)
Expand Down
16 changes: 6 additions & 10 deletions arm9/source/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
s16 ntpTzOffetMinutes;
u16 screenFiltersCct;
s64 screenFiltersGammaEnc;
s64 screenFiltersContrastEnc;
s64 screenFiltersBrightnessEnc;
bool screenFiltersInvert;

ScreenFiltersCfgData topScreenFilter;
ScreenFiltersCfgData bottomScreenFilter;

u64 autobootTwlTitleId;
u8 autobootCtrAppmemtype;
} info;
Expand Down Expand Up @@ -214,11 +213,8 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
info->hbldr3dsxTitleId = configData.hbldr3dsxTitleId;
info->rosalinaMenuCombo = configData.rosalinaMenuCombo;
info->ntpTzOffetMinutes = configData.ntpTzOffetMinutes;
info->screenFiltersCct = configData.screenFiltersCct;
info->screenFiltersGammaEnc = configData.screenFiltersGammaEnc;
info->screenFiltersContrastEnc = configData.screenFiltersContrastEnc;
info->screenFiltersBrightnessEnc = configData.screenFiltersBrightnessEnc;
info->screenFiltersInvert = configData.screenFiltersInvert;
info->topScreenFilter = configData.topScreenFilter;
info->bottomScreenFilter = configData.bottomScreenFilter;
info->autobootTwlTitleId = configData.autobootTwlTitleId;
info->autobootCtrAppmemtype = configData.autobootCtrAppmemtype;
info->versionMajor = VERSION_MAJOR;
Expand Down
18 changes: 12 additions & 6 deletions arm9/source/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ typedef volatile s64 vs64;
#define ISN3DS (CFG11_SOCINFO & 2)
#define ISDEVUNIT (CFG_UNITINFO != 0)

typedef struct {
typedef struct ScreenFiltersCfgData {
u16 cct;
bool invert;
s64 gammaEnc;
s64 contrastEnc;
s64 brightnessEnc;
} ScreenFiltersCfgData;

typedef struct CfgData {
u16 formatVersionMajor, formatVersionMinor;

u32 config, multiConfig, bootConfig;
Expand All @@ -70,11 +78,9 @@ typedef struct {
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
s16 ntpTzOffetMinutes;
u16 screenFiltersCct;
s64 screenFiltersGammaEnc;
s64 screenFiltersContrastEnc;
s64 screenFiltersBrightnessEnc;
bool screenFiltersInvert;

ScreenFiltersCfgData topScreenFilter;
ScreenFiltersCfgData bottomScreenFilter;

u64 autobootTwlTitleId;
u8 autobootCtrAppmemtype;
Expand Down
17 changes: 12 additions & 5 deletions k11_extension/include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ extern void (*initFPU)(void);
extern void (*mcuReboot)(void);
extern void (*coreBarrier)(void);

typedef struct ScreenFiltersCfgData {
u16 cct;
bool invert;
s64 gammaEnc;
s64 contrastEnc;
s64 brightnessEnc;
} ScreenFiltersCfgData;

typedef struct CfwInfo
{
char magic[4];
Expand All @@ -132,11 +140,10 @@ typedef struct CfwInfo
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
s16 ntpTzOffetMinutes;
u16 screenFiltersCct;
s64 screenFiltersGammaEnc;
s64 screenFiltersContrastEnc;
s64 screenFiltersBrightnessEnc;
bool screenFiltersInvert;

ScreenFiltersCfgData topScreenFilter;
ScreenFiltersCfgData bottomScreenFilter;

u64 autobootTwlTitleId;
u8 autobootCtrAppmemtype;
} CfwInfo;
Expand Down
27 changes: 22 additions & 5 deletions k11_extension/source/svc/GetSystemInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param)
{
switch(param)
{
// Please do not use these, except 0, 1, and 0x200
// Other types may get removed or reordered without notice
case 0:
*out = SYSTEM_VERSION(cfwInfo.versionMajor, cfwInfo.versionMinor, cfwInfo.versionBuild);
break;
Expand Down Expand Up @@ -75,22 +77,37 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param)
*out = cfwInfo.rosalinaMenuCombo;
break;
case 0x102:
*out = cfwInfo.screenFiltersCct;
*out = cfwInfo.topScreenFilter.cct;
break;
case 0x103:
*out = (s64)cfwInfo.ntpTzOffetMinutes;
break;
case 0x104:
*out = cfwInfo.screenFiltersGammaEnc;
*out = cfwInfo.topScreenFilter.gammaEnc;
break;
case 0x105:
*out = cfwInfo.screenFiltersContrastEnc;
*out = cfwInfo.topScreenFilter.contrastEnc;
break;
case 0x106:
*out = cfwInfo.screenFiltersBrightnessEnc;
*out = cfwInfo.topScreenFilter.brightnessEnc;
break;
case 0x107:
*out = (s64)cfwInfo.screenFiltersInvert;
*out = (s64)cfwInfo.topScreenFilter.invert;
break;
case 0x108:
*out = cfwInfo.bottomScreenFilter.cct;
break;
case 0x109:
*out = cfwInfo.bottomScreenFilter.gammaEnc;
break;
case 0x10A:
*out = cfwInfo.bottomScreenFilter.contrastEnc;
break;
case 0x10B:
*out = cfwInfo.bottomScreenFilter.brightnessEnc;
break;
case 0x10C:
*out = (s64)cfwInfo.bottomScreenFilter.invert;
break;

case 0x200: // isRelease
Expand Down
Binary file modified sysmodules/rosalina/data/config_template.ini
Binary file not shown.
16 changes: 11 additions & 5 deletions sysmodules/rosalina/include/menus/screen_filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@

extern Menu screenFiltersMenu;

extern int screenFiltersCurrentTemperature;
extern float screenFiltersCurrentGamma;
extern float screenFiltersCurrentContrast;
extern float screenFiltersCurrentBrightness;
extern bool screenFiltersCurrentInvert;
typedef struct ScreenFilter {
u16 cct;
bool invert;
float gamma;
float contrast;
float brightness;
} ScreenFilter;

extern ScreenFilter topScreenFilter;
extern ScreenFilter bottomScreenFilter;

void ScreenFiltersMenu_RestoreSettings(void);
void ScreenFiltersMenu_LoadConfig(void);

void ScreenFiltersMenu_SetDefault(void); // 6500K (default)

Expand Down
27 changes: 1 addition & 26 deletions sysmodules/rosalina/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,32 +258,7 @@ void menuThreadMain(void)
while (!isServiceUsable("ac:u") || !isServiceUsable("hid:USER") || !isServiceUsable("gsp::Gpu"))
svcSleepThread(250 * 1000 * 1000LL);

s64 out = 0;

svcGetSystemInfo(&out, 0x10000, 0x102);
screenFiltersCurrentTemperature = (int)(u32)out;
if (screenFiltersCurrentTemperature < 1000 || screenFiltersCurrentTemperature > 25100)
screenFiltersCurrentTemperature = 6500;

svcGetSystemInfo(&out, 0x10000, 0x104);
screenFiltersCurrentGamma = (float)(out / FLOAT_CONV_MULT);
if (screenFiltersCurrentGamma < 0.0f || screenFiltersCurrentGamma > 1411.0f)
screenFiltersCurrentGamma = 1.0f;

svcGetSystemInfo(&out, 0x10000, 0x105);
screenFiltersCurrentContrast = (float)(out / FLOAT_CONV_MULT);
if (screenFiltersCurrentContrast < 0.0f || screenFiltersCurrentContrast > 255.0f)
screenFiltersCurrentContrast = 1.0f;

svcGetSystemInfo(&out, 0x10000, 0x106);
screenFiltersCurrentBrightness = (float)(out / FLOAT_CONV_MULT);
if (screenFiltersCurrentBrightness < -1.0f || screenFiltersCurrentBrightness > 1.0f)
screenFiltersCurrentBrightness = 0.0f;

svcGetSystemInfo(&out, 0x10000, 0x107);
screenFiltersCurrentInvert = (bool)out;

ScreenFiltersMenu_RestoreSettings();
ScreenFiltersMenu_LoadConfig();

hidInit(); // assume this doesn't fail
isHidInitialized = true;
Expand Down
Loading

0 comments on commit 777b43b

Please sign in to comment.