Skip to content

Commit

Permalink
Add CPU clock speed #5 for CEX & DEX only
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRouletteBoi committed Apr 16, 2022
1 parent fb547d6 commit 6046206
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
54 changes: 41 additions & 13 deletions src/Core/Menu/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ Overlay::Overlay()
{
sys_ppu_thread_create(&UpdateInfoThreadId, UpdateInfoThread, 0, 0xB01, 512, SYS_PPU_THREAD_CREATE_JOINABLE, "Overlay::UpdateInfoThread()");

// TODO(Roulette) search in lv1 "be.0.ref_clk" for CPU clock speed

if (IsConsoleDex() && GetFirmwareVersion() == 4.84f)
if (IsConsoleCex() && GetFirmwareVersion() == 4.88f)
{
// rsx_dev_clock_1 + 0x1C
m_GpuClockSpeedOffsetInLv1 = 0x53E42C;
m_GpuClockSpeedOffsetInLv1 = 0x5383EC;

// rsx_dev_clock_5 + 0x1C
m_GpuGddr3RamClocSpeedkOffsetInLv1 = 0x53E46C;
m_GpuGddr3RamClockSpeedOffsetInLv1 = 0x53842C;

m_CpuClockSpeedOffsetInLv1 = 0x32AC;
}
else if (IsConsoleCex() && GetFirmwareVersion() == 4.88f)
else if (IsConsoleDex() && GetFirmwareVersion() == 4.84f)
{
// rsx_dev_clock_1 + 0x1C
m_GpuClockSpeedOffsetInLv1 = 0x5383EC;
m_GpuClockSpeedOffsetInLv1 = 0x53E42C;

// rsx_dev_clock_5 + 0x1C
m_GpuGddr3RamClocSpeedkOffsetInLv1 = 0x53842C;
m_GpuGddr3RamClockSpeedOffsetInLv1 = 0x53E46C;

m_CpuClockSpeedOffsetInLv1 = 0x32AC;
}
}

Expand Down Expand Up @@ -75,7 +77,7 @@ void Overlay::DrawOverlay()

if (showCpuGpuClock && m_GpuClock != 0)
{
vsh::swprintf(buffer, 50, L"CPU Clock: %d MHz / GPU Clock: %d MHz\n", m_CpuClock, m_GpuClock);
vsh::swprintf(buffer, 50, L"CPU Clock: %1.1f GHz / GPU Clock: %d MHz\n", m_CpuClock / 1000.0f, m_GpuClock);
overlayText += buffer;
}

Expand Down Expand Up @@ -178,7 +180,20 @@ uint32_t Overlay::GetGpuClockSpeed()
if (IsConsoleHen())
return 0;

uint64_t frequency = PeekLv1(m_GpuClockSpeedOffsetInLv1);
volatile uint64_t frequency = PeekLv1(m_GpuClockSpeedOffsetInLv1);

if (frequency == 0xFFFFFFFF80010003) // if cfw syscalls are disabled
return 0;

return (static_cast<uint32_t>(frequency >> 32) / 0xF4240) & 0x1FFF;
}

uint32_t Overlay::GetGpuGddr3RamClockSpeed()
{
if (IsConsoleHen())
return 0;

volatile uint64_t frequency = PeekLv1(m_GpuGddr3RamClockSpeedOffsetInLv1);

if (frequency == 0xFFFFFFFF80010003) // if cfw syscalls are disabled
return 0;
Expand All @@ -193,8 +208,21 @@ uint32_t Overlay::GetGpuClockSpeed()
if ((v4 - 100) <= 7 && v11 > 0x31F)
v11 = v10 >> 19;
uint32_t gpuClock2 = v11 & 0x1FFF;
return gpuClock2;*/
uint32_t gddr3RamClock = v11 & 0x1FFF;
return gddr3RamClock;*/
}

uint32_t Overlay::GetCpuClockSpeed()
{
if (IsConsoleHen())
return 0;

uint64_t frequency = PeekLv1(m_CpuClockSpeedOffsetInLv1);

if (frequency == 0xFFFFFFFF80010003) // if cfw syscalls are disabled
return 0;

return ((static_cast<uint32_t>(frequency >> 32) / 0xF4240) & 0x1FFF) * 8;
}

void Overlay::Lv2LabelUpdate()
Expand Down Expand Up @@ -294,7 +322,7 @@ void Overlay::UpdateInfoThread(uint64_t arg)

g_Overlay.WaitAndQueueTextInLV2();

g_Overlay.m_CpuClock = 0;
g_Overlay.m_CpuClock = g_Overlay.GetCpuClockSpeed();
g_Overlay.m_GpuClock = g_Overlay.GetGpuClockSpeed();
}

Expand Down
11 changes: 6 additions & 5 deletions src/Core/Menu/Overlay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Overlay
void CalculateFps();
void GetGameName(char outTitleId[16], char outTitleName[64]);
uint32_t GetGpuClockSpeed();
uint32_t GetGpuGddr3RamClockSpeed();
uint32_t GetCpuClockSpeed();
static void UpdateInfoThread(uint64_t arg);

public:
Expand All @@ -58,12 +60,11 @@ class Overlay
bool showFirmware = true;
bool showAppName = true;

int32_t m_CpuClock{};
int32_t m_GpuClock{};
uint32_t m_CpuClock{};
uint32_t m_GpuClock{};
uint64_t m_GpuClockSpeedOffsetInLv1{};
uint64_t m_GpuGddr3RamClocSpeedkOffsetInLv1{};
uint64_t m_CpuNvcClockSpeedOffsetInLv1{};
uint64_t m_CpuDisplayClockSpeedOffsetInLv1{};
uint64_t m_GpuGddr3RamClockSpeedOffsetInLv1{};
uint64_t m_CpuClockSpeedOffsetInLv1{};

private:
vsh::vec2 m_Position{};
Expand Down

0 comments on commit 6046206

Please sign in to comment.