Skip to content

Commit

Permalink
Merge pull request #19136 from hrydgard/gpi-gpo-support
Browse files Browse the repository at this point in the history
Add basic checkbox UI for GPI switches, add display of GPO LEDs
  • Loading branch information
hrydgard committed May 12, 2024
2 parents 9dc8c05 + 1dd363a commit 0f15bf4
Show file tree
Hide file tree
Showing 54 changed files with 208 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,11 @@ void CheckBox::GetContentDimensions(const UIContext &dc, float &w, float &h) con
w = bounds_.w;
}

BitCheckBox::BitCheckBox(uint32_t *bitfield, uint32_t bit, std::string_view text, std::string_view smallText, LayoutParams *layoutParams)
: CheckBox(nullptr, text, smallText, layoutParams), bitfield_(bitfield), bit_(bit) {
_dbg_assert_msg_(bit != 0, "bit is a mask, not a bit index");
}

void BitCheckBox::Toggle() {
if (bitfield_) {
*bitfield_ = *bitfield_ ^ bit_;
Expand Down
6 changes: 2 additions & 4 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,8 @@ class CollapsibleHeader : public CheckBox {

class BitCheckBox : public CheckBox {
public:
BitCheckBox(uint32_t *bitfield, uint32_t bit, std::string_view text, std::string_view smallText = "", LayoutParams *layoutParams = nullptr)
: CheckBox(nullptr, text, smallText, layoutParams), bitfield_(bitfield), bit_(bit) {
}

// bit is a bitmask (should only have a single bit set), not a bit index.
BitCheckBox(uint32_t *bitfield, uint32_t bit, std::string_view text, std::string_view smallText = "", LayoutParams *layoutParams = nullptr);
BitCheckBox(int *bitfield, int bit, std::string_view text, std::string_view smallText = "", LayoutParams *layoutParams = nullptr) : BitCheckBox((uint32_t *)bitfield, (uint32_t)bit, text, smallText, layoutParams) {}

void Toggle() override;
Expand Down
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ static const ConfigSetting generalSettings[] = {
ConfigSetting("IgnoreCompatSettings", &g_Config.sIgnoreCompatSettings, "", CfgFlag::PER_GAME | CfgFlag::REPORT),

ConfigSetting("RunBehindPauseMenu", &g_Config.bRunBehindPauseMenu, false, CfgFlag::DEFAULT),

ConfigSetting("ShowGPOLEDs", &g_Config.bShowGPOLEDs, false, CfgFlag::PER_GAME),
};

static bool DefaultSasThread() {
Expand Down
3 changes: 3 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ struct Config {
bool bRenderDuplicateFrames;
bool bRenderMultiThreading;

// HW debug
bool bShowGPOLEDs;

// Sound
bool bEnableSound;
int iAudioBackend;
Expand Down
16 changes: 10 additions & 6 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static bool kernelRunning = false;
KernelObjectPool kernelObjects;
KernelStats kernelStats;
u32 registeredExitCbId;
u32 g_GPOBits; // Really just 8 bits on the real hardware.
u32 g_GPIBits; // Really just 8 bits on the real hardware.

void __KernelInit()
{
Expand Down Expand Up @@ -161,6 +163,7 @@ void __KernelInit()
__PPGeInit();

kernelRunning = true;
g_GPOBits = 0;
INFO_LOG(SCEKERNEL, "Kernel initialized.");
}

Expand Down Expand Up @@ -355,18 +358,19 @@ int sceKernelRegisterDefaultExceptionHandler()
return 0;
}

void sceKernelSetGPO(u32 ledAddr)
void sceKernelSetGPO(u32 ledBits)
{
// Sets debug LEDs.
// Not really interesting, and a few games really spam it
// DEBUG_LOG(SCEKERNEL, "sceKernelSetGPO(%02x)", ledAddr);
// Sets debug LEDs. Some games do interesting stuff with this, like a metronome in Parappa.
// Shows up as a vertical strip of LEDs at the side of the screen, if enabled.
g_GPOBits = ledBits;
}

u32 sceKernelGetGPI()
{
// Always returns 0 on production systems.
DEBUG_LOG(SCEKERNEL, "0=sceKernelGetGPI()");
return 0;
// On developer systems, there are 8 switches that control the lower 8 bits of the return value.
DEBUG_LOG(SCEKERNEL, "%d=sceKernelGetGPI()", g_GPIBits);
return g_GPIBits;
}

// #define LOG_CACHE
Expand Down
3 changes: 3 additions & 0 deletions Core/HLE/sceKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ struct KernelStats {
extern KernelStats kernelStats;
extern u32 registeredExitCbId;

extern u32 g_GPOBits;
extern u32 g_GPIBits;

void Register_ThreadManForUser();
void Register_ThreadManForKernel();
void Register_LoadExecForUser();
Expand Down
4 changes: 2 additions & 2 deletions Tools/langtool/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "Core/System.h"
#include "Core/Reporting.h"
#include "Core/CoreParameter.h"
#include "Core/HLE/sceKernel.h" // GPI/GPO
#include "Core/MIPS/MIPSTables.h"
#include "Core/MIPS/JitCommon/JitBlockCache.h"
#include "Core/MIPS/JitCommon/JitCommon.h"
Expand Down Expand Up @@ -141,6 +142,11 @@ void DevMenuScreen::CreatePopupContents(UI::ViewGroup *parent) {

items->Add(new Choice(dev->T("Reset limited logging")))->OnClick.Handle(this, &DevMenuScreen::OnResetLimitedLogging);

items->Add(new Choice(dev->T("GPI/GPO switches/LEDs")))->OnClick.Add([=](UI::EventParams &e) {
screenManager()->push(new GPIGPOScreen(dev->T("GPI/GPO switches/LEDs")));
return UI::EVENT_DONE;
});

items->Add(new Choice(dev->T("Create frame dump")))->OnClick.Add([](UI::EventParams &e) {
GPURecord::RecordNextFrame([](const Path &dumpPath) {
NOTICE_LOG(SYSTEM, "Frame dump created at '%s'", dumpPath.c_str());
Expand Down Expand Up @@ -213,6 +219,16 @@ void DevMenuScreen::dialogFinished(const Screen *dialog, DialogResult result) {
// TriggerFinish(DR_OK);
}

void GPIGPOScreen::CreatePopupContents(UI::ViewGroup *parent) {
using namespace UI;
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
parent->Add(new CheckBox(&g_Config.bShowGPOLEDs, dev->T("Show GPO LEDs")));
for (int i = 0; i < 8; i++) {
std::string name = ApplySafeSubstitutions(dev->T("GPI switch %1"), i);
parent->Add(new BitCheckBox(&g_GPIBits, 1 << i, name));
}
}

void LogScreen::UpdateLog() {
using namespace UI;
RingbufferLogListener *ring = LogManager::GetInstance()->GetRingbufferListener();
Expand Down
9 changes: 9 additions & 0 deletions UI/DevScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ class AddressPromptScreen : public PopupScreen {
unsigned int addr_;
};

class GPIGPOScreen : public PopupScreen {
public:
GPIGPOScreen(std::string_view title) : PopupScreen(title, "OK") {}
const char *tag() const override { return "GPIGPO"; }

protected:
void CreatePopupContents(UI::ViewGroup *parent) override;
};

class JitCompareScreen : public UIDialogScreenWithBackground {
public:
void CreateViews() override;
Expand Down
22 changes: 22 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,8 @@ bool EmuScreen::hasVisibleUI() {
return true;
if (g_Config.bEnableCardboardVR || g_Config.bEnableNetworkChat)
return true;
if (g_Config.bShowGPOLEDs)
return true;
// Debug UI.
if ((DebugOverlay)g_Config.iDebugOverlay != DebugOverlay::OFF || g_Config.bShowDeveloperMenu)
return true;
Expand Down Expand Up @@ -1571,6 +1573,26 @@ void EmuScreen::renderUI() {
}
#endif

if (g_Config.bShowGPOLEDs) {
// Draw a vertical strip of LEDs at the right side of the screen.
const float ledSize = 24.0f;
const float spacing = 4.0f;
const float height = 8 * ledSize + 7 * spacing;
const float x = ctx->GetBounds().w - spacing - ledSize;
const float y = (ctx->GetBounds().h - height) * 0.5f;
ctx->FillRect(UI::Drawable(0xFF000000), Bounds(x - spacing, y - spacing, ledSize + spacing * 2, height + spacing * 2));
for (int i = 0; i < 8; i++) {
int bit = (g_GPOBits >> i) & 1;
uint32_t color = 0xFF30FF30;
if (!bit) {
color = darkenColor(darkenColor(color));
}
Bounds ledBounds(x, y + (spacing + ledSize) * i, ledSize, ledSize);
ctx->FillRect(UI::Drawable(color), ledBounds);
}
ctx->Flush();
}

if (coreState == CORE_RUNTIME_ERROR || coreState == CORE_STEPPING) {
const MIPSExceptionInfo &info = Core_GetExceptionInfo();
if (info.type != MIPSExceptionType::NONE) {
Expand Down
5 changes: 5 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,11 @@ void DeveloperToolsScreen::CreateViews() {

list->Add(new CheckBox(&g_Config.bShowOnScreenMessages, dev->T("Show on-screen messages")));

list->Add(new Choice(dev->T("GPI/GPO switches/LEDs")))->OnClick.Add([=](UI::EventParams &e) {
screenManager()->push(new GPIGPOScreen(dev->T("GPI/GPO switches/LEDs")));
return UI::EVENT_DONE;
});

#if PPSSPP_PLATFORM(ANDROID)
static const char *framerateModes[] = { "Default", "Request 60Hz", "Force 60Hz" };
PopupMultiChoice *framerateMode = list->Add(new PopupMultiChoice(&g_Config.iDisplayFramerateMode, gr->T("Framerate mode"), framerateModes, 0, ARRAY_SIZE(framerateModes), I18NCat::GRAPHICS, screenManager()));
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -341,6 +343,7 @@ Run CPU Tests = ‎شغل فحوص المعالج
Save new textures = ‎حفظ الرسم الجديد
Shader Viewer = ‎مستعرض الرسوميات
Show Developer Menu = ‎أظهر قائمة المطور
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = إظهار الرسائل على الشاشة
Stats = ‎الحالات
System Information = ‎معلومات النظام
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Run CPU tests
Save new textures = Save new textures
Shader Viewer = Shader viewer
Show Developer Menu = Show developer menu
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Stats
System Information = System information
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Run CPU tests
Save new textures = Save new textures
Shader Viewer = Shader viewer
Show Developer Menu = Покажи developer меню
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Stats
System Information = Системна информация
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/ca_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Amidar el rendiment
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Proves de CPU
Save new textures = Desa les noves textures
Shader Viewer = Visualitzador de shader
Show Developer Menu = Mostra el menú de desenvolupament
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Estadístiques
System Information = Informació del sistema
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/cz_CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Profilovač snímku
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Spustit zkoušky CPU
Save new textures = Save new textures
Shader Viewer = Prohlížeč shaderů
Show Developer Menu = Zobrazit nabídku pro vývojáře
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Statistiky
System Information = Informace o systému
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/da_DK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Kør CPU test
Save new textures = Gem nye textures
Shader Viewer = Shader viewer
Show Developer Menu = Vis udviklermenu
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Stats
System Information = System information
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/de_DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Frame Profiler
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU Treibertest
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = CPU Test starten
Save new textures = Speichere neue Texturen
Shader Viewer = Shader-Anzeige
Show Developer Menu = Zeige Entwicklermenü
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Statistiken
System Information = Systeminformationen
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/dr_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Pajalanni tes CPU
Save new textures = Save new textures
Shader Viewer = Shader viewer
Show Developer Menu = Show developer menu
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Stats
System Information = Pempakitan to sistem dipake
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ FPU = FPU
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
Frame timing = Frame timing
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = GPU driver test
GPU Profile = GPU profile
Expand All @@ -359,6 +361,7 @@ Run CPU Tests = Run CPU tests
Save new textures = Save new textures
Shader Viewer = Shader viewer
Show Developer Menu = Show developer menu
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Show on-screen messages
Stats = Stats
System Information = System information
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/es_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame Profiler = Medir rendimiento
Frame timing = Frame timing
Framedump tests = Tests de volcado de cuadros
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = Test de controlador GPU
GPU log profiler = log de perfiles GPU
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Pruebas de CPU
Save new textures = Guardar texturas nuevas
Shader Viewer = Visor de shader
Show Developer Menu = Mostrar menú de desarrollo
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Mostrar mensajes en pantalla
Stats = Estadísticas
System Information = Información del sistema
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/es_LA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Fragment = Fragment
Frame timing = Frame timing
Framedump tests = Pruebas de volcado de frames
Frame Profiler = Perfilado de frame
GPI switch %1 = GPI switch %1
GPI/GPO switches/LEDs = GPI/GPO switches/LEDs
GPU Allocator Viewer = GPU Allocator Viewer
GPU Driver Test = Probar controlador GPU
GPU log profiler = GPU log profiler
Expand All @@ -333,6 +335,7 @@ Run CPU Tests = Ejecutando pruebas de CPU
Save new textures = Guardar nuevas texturas
Shader Viewer = Visor de shader
Show Developer Menu = Mostrar menú de desarrollador
Show GPO LEDs = Show GPO LEDs
Show on-screen messages = Mostrar mensajes en pantalla
Stats = Estadísticas
System Information = Información del sistema
Expand Down

0 comments on commit 0f15bf4

Please sign in to comment.