Browse Source

Do not disable backlight on o2DS

pull/3626/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
758bcad08b
  1. 40
      Source/platform/ctr/cfgu_service.hpp
  2. 25
      Source/platform/ctr/locale.cpp
  3. 38
      Source/platform/ctr/system.cpp

40
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

25
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 "";

38
Source/platform/ctr/system.cpp

@ -1,13 +1,15 @@
#include <3ds.h>
#include <cstdlib>
#include <cstdio>
#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(); });

Loading…
Cancel
Save