Skip to content

Commit

Permalink
Add code to manage New 3DS CPU speedup
Browse files Browse the repository at this point in the history
# Conflicts:
#	libctru/include/3ds/os.h
#	libctru/include/3ds/services/ptm.h
  • Loading branch information
fincs committed Oct 11, 2015
1 parent b9e5ddb commit e12c8ff
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
6 changes: 6 additions & 0 deletions libctru/include/3ds/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ u64 osGetTime();
* @return the Wifi signal strength
*/
u8 osGetWifiStrength();

/**
* @brief Configures the New 3DS speedup.
* @param enable Specifies whether to enable or disable the speedup.
*/
void osSetSpeedupEnable(bool enable);
5 changes: 5 additions & 0 deletions libctru/include/3ds/services/ptm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
Result ptmInit();
Result ptmExit();

Result ptmSysmInit(void);
Result ptmSysmExit(void);

Result PTMU_GetShellState(Handle* servhandle, u8 *out);
Result PTMU_GetBatteryLevel(Handle* servhandle, u8 *out);
Result PTMU_GetBatteryChargeState(Handle* servhandle, u8 *out);
Result PTMU_GetPedometerState(Handle* servhandle, u8 *out);
Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps);

Result PTMSYSM_ConfigureNew3DSCPU(u8 value);
17 changes: 17 additions & 0 deletions libctru/source/os.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <3ds/types.h>
#include <3ds/os.h>
#include <3ds/svc.h>
#include <3ds/services/ptm.h>

#include <sys/time.h>
#include <reent.h>
Expand All @@ -26,6 +27,7 @@ static volatile datetime_t* __datetime0 =
static volatile datetime_t* __datetime1 =
(datetime_t*) 0x1FF81040;

__attribute__((weak)) bool __ctru_speedup = false;

//---------------------------------------------------------------------------------
u32 osConvertVirtToPhys(u32 vaddr) {
Expand Down Expand Up @@ -155,3 +157,18 @@ u8 osGetWifiStrength(void) {
//---------------------------------------------------------------------------------
return *((u8*)0x1FF81066);
}

void __ctru_speedup_config(void)
{
if (ptmSysmInit()==0)
{
PTMSYSM_ConfigureNew3DSCPU(__ctru_speedup ? 3 : 0);
ptmSysmExit();
}
}

void osSetSpeedupEnable(bool enable)
{
__ctru_speedup = enable;
__ctru_speedup_config();
}
12 changes: 7 additions & 5 deletions libctru/source/services/apt.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ __attribute__((weak)) void _aptDebug(int a, int b)
{
}

void __ctru_speedup_config(void);

static void aptAppStarted(void);

static bool aptIsReinit(void)
Expand Down Expand Up @@ -395,7 +397,7 @@ static bool __handle_incoming_parameter() {
aptSetStatus(APP_APPLETCLOSED);
return true;
case 0xB: // Just returned from menu.
if (aptStatusMutex)
if (aptGetStatus() != APP_NOTINITIALIZED)
{
GSPGPU_AcquireRight(NULL, 0x0);
GSPGPU_RestoreVramSysArea(NULL);
Expand Down Expand Up @@ -462,6 +464,8 @@ Result aptInit(void)

svcCreateEvent(&aptStatusEvent, 0);
svcCreateEvent(&aptSleepSync, 0);
svcCreateMutex(&aptStatusMutex, false);
aptStatus=0;

if(!aptIsCrippled())
{
Expand Down Expand Up @@ -626,10 +630,6 @@ void aptAppStarted()
{
u8 buf1[4], buf2[4];

svcCreateMutex(&aptStatusMutex, true);
aptStatus=0;
svcReleaseMutex(aptStatusMutex);

aptSetStatus(APP_RUNNING);

if(!aptIsCrippled())
Expand Down Expand Up @@ -669,6 +669,8 @@ void aptSetStatus(APP_STATUS status)

//if(prevstatus != APP_NOTINITIALIZED)
//{
if(status == APP_RUNNING)
__ctru_speedup_config();
if(status == APP_RUNNING || status == APP_EXITING || status == APP_APPLETSTARTED || status == APP_APPLETCLOSED)
svcSignalEvent(aptStatusEvent);
//}
Expand Down
27 changes: 25 additions & 2 deletions libctru/source/services/ptm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
#include <3ds/services/ptm.h>


static Handle ptmHandle;
static Handle ptmHandle, ptmSysmHandle;

Result ptmInit()
{
return srvGetServiceHandle(&ptmHandle, "ptm:u");
return srvGetServiceHandle(&ptmHandle, "ptm:u");
}

Result ptmExit()
{
return svcCloseHandle(ptmHandle);
}

Result ptmSysmInit(void)
{
return srvGetServiceHandle(&ptmSysmHandle, "ptm:sysm");
}

Result ptmSysmExit(void)
{
return svcCloseHandle(ptmSysmHandle);
}

Result PTMU_GetShellState(Handle* servhandle, u8 *out)
{
if(!servhandle)servhandle=&ptmHandle;
Expand Down Expand Up @@ -91,3 +101,16 @@ Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps)

return (Result)cmdbuf[1];
}

Result PTMSYSM_ConfigureNew3DSCPU(u8 value)
{
Result ret;
u32 *cmdbuf = getThreadCommandBuffer();

cmdbuf[0] = 0x08180040;
cmdbuf[1] = value;

if((ret = svcSendSyncRequest(ptmSysmHandle))!=0)return ret;

return (Result)cmdbuf[1];
}

0 comments on commit e12c8ff

Please sign in to comment.