From 758bcad08b071c4b4b9ca0e21e6315130fe1b00d Mon Sep 17 00:00:00 2001 From: staphen Date: Thu, 11 Nov 2021 17:24:22 -0500 Subject: [PATCH] Do not disable backlight on o2DS --- Source/platform/ctr/cfgu_service.hpp | 40 ++++++++++++++++++++++++++++ Source/platform/ctr/locale.cpp | 25 ++++------------- Source/platform/ctr/system.cpp | 38 ++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 Source/platform/ctr/cfgu_service.hpp diff --git a/Source/platform/ctr/cfgu_service.hpp b/Source/platform/ctr/cfgu_service.hpp new file mode 100644 index 000000000..46418f902 --- /dev/null +++ b/Source/platform/ctr/cfgu_service.hpp @@ -0,0 +1,40 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include <3ds/result.h> +#include <3ds/services/cfgu.h> + +#ifdef __cplusplus +} +#endif + +namespace devilution { +namespace n3ds { + +class CFGUService { +public: + CFGUService() + { + Result res = cfguInit(); + isInitialized = R_SUCCEEDED(res); + } + + ~CFGUService() + { + cfguExit(); + } + + bool IsInitialized() + { + return isInitialized; + } + +private: + bool isInitialized; +}; + +} // namespace n3ds +} // namespace devilution diff --git a/Source/platform/ctr/locale.cpp b/Source/platform/ctr/locale.cpp index 303e9c5e9..965fa1093 100644 --- a/Source/platform/ctr/locale.cpp +++ b/Source/platform/ctr/locale.cpp @@ -1,34 +1,19 @@ -#include "platform/ctr/locale.hpp" - #include <3ds.h> +#include "platform/ctr/cfgu_service.hpp" +#include "platform/ctr/locale.hpp" + namespace devilution { namespace n3ds { -namespace { - -class CFGUService { -public: - CFGUService() - { - cfguInit(); - } - - ~CFGUService() - { - cfguExit(); - } -}; - -} // namespace - std::string GetLocale() { CFGUService cfguService; + if (!cfguService.IsInitialized()) + return ""; u8 language; Result res = CFGU_GetSystemLanguage(&language); - if (!R_SUCCEEDED(res)) return ""; diff --git a/Source/platform/ctr/system.cpp b/Source/platform/ctr/system.cpp index c3b14b818..4b6b9486e 100644 --- a/Source/platform/ctr/system.cpp +++ b/Source/platform/ctr/system.cpp @@ -1,13 +1,15 @@ +#include <3ds.h> #include #include -#include <3ds.h> -#include "platform/ctr/system.h" + +#include "platform/ctr/cfgu_service.hpp" #include "platform/ctr/random.hpp" #include "platform/ctr/sockets.hpp" +#include "platform/ctr/system.h" using namespace devilution; -bool isN3DS; +bool shouldDisableBacklight; aptHookCookie cookie; @@ -35,6 +37,8 @@ void aptHookFunc(APT_HookType hookType, void *param) void ctr_lcd_backlight_on() { + if (!shouldDisableBacklight) + return; gspLcdInit(); GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTTOM); gspLcdExit(); @@ -42,6 +46,8 @@ void ctr_lcd_backlight_on() void ctr_lcd_backlight_off() { + if (!shouldDisableBacklight) + return; gspLcdInit(); GSPLCD_PowerOffBacklight(GSPLCD_SCREEN_BOTTOM); gspLcdExit(); @@ -63,6 +69,27 @@ bool ctr_check_dsp() return true; } +bool ctr_is_n3ds() +{ + bool isN3DS; + Result res = APT_CheckNew3DS(&isN3DS); + return R_SUCCEEDED(res) && isN3DS; +} + +bool ctr_should_disable_backlight() +{ + n3ds::CFGUService cfguService; + if (!cfguService.IsInitialized()) + return false; + + u8 model; + Result res = CFGU_GetSystemModel(&model); + if (!R_SUCCEEDED(res)) + return false; + + return model != CFG_MODEL_2DS; +} + void ctr_sys_init() { if (ctr_check_dsp() == false) @@ -70,10 +97,11 @@ void ctr_sys_init() aptHook(&cookie, aptHookFunc, NULL); - APT_CheckNew3DS(&isN3DS); - if (isN3DS) + if (ctr_is_n3ds()) osSetSpeedupEnable(true); + shouldDisableBacklight = ctr_should_disable_backlight(); + ctr_lcd_backlight_off(); atexit([]() { ctr_lcd_backlight_on(); });