Add code to manage New 3DS CPU speedup

This commit is contained in:
fincs 2015-10-11 23:44:10 +02:00
parent 3cb20a965b
commit 942ec4af9b
5 changed files with 67 additions and 7 deletions

View File

@ -83,3 +83,9 @@ u64 osGetTime(void);
* These values correspond with the number of wifi bars displayed by Home Menu.
*/
u8 osGetWifiStrength(void);
/**
* @brief Configures the New 3DS speedup.
* @param enable Specifies whether to enable or disable the speedup.
*/
void osSetSpeedupEnable(bool enable);

View File

@ -10,6 +10,12 @@ Result ptmInit(void);
/// Exits PTM.
Result ptmExit(void);
/// Initializes ptm:sysm.
Result ptmSysmInit(void);
/// Exits ptm:sysm.
Result ptmSysmExit(void);
/**
* @brief Gets the system's current shell state.
* @param servhandle Optional pointer to the handle to use.
@ -44,3 +50,9 @@ Result PTMU_GetPedometerState(Handle* servhandle, u8 *out);
* @param steps Pointer to write the total step count to.
*/
Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps);
/**
* @brief Configures the New 3DS' CPU clock speed and L2 cache.
* @param value Bit0: enable higher clock, Bit1: enable L2 cache.
*/
Result PTMSYSM_ConfigureNew3DSCPU(u8 value);

View File

@ -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>
@ -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) {
@ -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();
}

View File

@ -63,6 +63,8 @@ __attribute__((weak)) void _aptDebug(int a, int b)
{
}
void __ctru_speedup_config(void);
static void aptAppStarted(void);
static bool aptIsReinit(void)
@ -396,7 +398,7 @@ static bool __handle_incoming_parameter(void) {
aptSetStatus(APP_APPLETCLOSED);
return true;
case 0xB: // Just returned from menu.
if (aptStatusMutex)
if (aptGetStatus() != APP_NOTINITIALIZED)
{
GSPGPU_AcquireRight(0x0);
GSPGPU_RestoreVramSysArea();
@ -463,6 +465,8 @@ Result aptInit(void)
svcCreateEvent(&aptStatusEvent, 0);
svcCreateEvent(&aptSleepSync, 0);
svcCreateMutex(&aptStatusMutex, false);
aptStatus=0;
if(!aptIsCrippled())
{
@ -627,10 +631,6 @@ void aptAppStarted(void)
{
u8 buf1[4], buf2[4];
svcCreateMutex(&aptStatusMutex, true);
aptStatus=0;
svcReleaseMutex(aptStatusMutex);
aptSetStatus(APP_RUNNING);
if(!aptIsCrippled())
@ -670,6 +670,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);
//}

View File

@ -6,7 +6,7 @@
#include <3ds/ipc.h>
static Handle ptmHandle;
static Handle ptmHandle, ptmSysmHandle;
Result ptmInit(void)
{
@ -18,6 +18,16 @@ Result ptmExit(void)
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;
@ -92,3 +102,16 @@ Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps)
return (Result)cmdbuf[1];
}
Result PTMSYSM_ConfigureNew3DSCPU(u8 value)
{
Result ret;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x818,1,0); // 0x08180040
cmdbuf[1] = value;
if((ret = svcSendSyncRequest(ptmSysmHandle))!=0)return ret;
return (Result)cmdbuf[1];
}