SDL: Implement SDL_GetSystemRAM and SDL_GetNumLogicalCPUCores for the 3ds (#12494)

From 5d804a39d929ead6b73032d705511e6449070e62 Mon Sep 17 00:00:00 2001
From: TheMode <[EMAIL REDACTED]>
Date: Sat, 8 Mar 2025 18:51:37 +0100
Subject: [PATCH] Implement SDL_GetSystemRAM and SDL_GetNumLogicalCPUCores for
 the 3ds (#12494)

---
 src/cpuinfo/SDL_cpuinfo.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
index bf425a38c7629..81d1e914ce8cf 100644
--- a/src/cpuinfo/SDL_cpuinfo.c
+++ b/src/cpuinfo/SDL_cpuinfo.c
@@ -85,7 +85,9 @@
 #include <kernel.h>
 #include <swis.h>
 #endif
-
+#ifdef SDL_PLATFORM_3DS
+#include <3ds.h>
+#endif
 #ifdef SDL_PLATFORM_PS2
 #include <kernel.h>
 #endif
@@ -642,6 +644,15 @@ int SDL_GetNumLogicalCPUCores(void)
             GetSystemInfo(&info);
             SDL_NumLogicalCPUCores = info.dwNumberOfProcessors;
         }
+#endif
+#ifdef SDL_PLATFORM_3DS
+        if (SDL_NumLogicalCPUCores <= 0) {
+            bool isNew3DS = false;
+            APT_CheckNew3DS(&isNew3DS);
+            // 1 core is always dedicated to the OS
+            // Meaning that the New3DS has 3 available core, and the Old3DS only one.
+            SDL_NumLogicalCPUCores = isNew3DS ? 4 : 2;
+        }
 #endif
         // There has to be at least 1, right? :)
         if (SDL_NumLogicalCPUCores <= 0) {
@@ -1156,6 +1167,12 @@ int SDL_GetSystemRAM(void)
             }
         }
 #endif
+#ifdef SDL_PLATFORM_3DS
+        if (SDL_SystemRAM <= 0) {
+            // The New3DS has 255MiB, the Old3DS 127MiB
+            SDL_SystemRAM = (int)(osGetMemRegionSize(MEMREGION_ALL) / (1024 * 1024));
+        }
+#endif
 #ifdef SDL_PLATFORM_VITA
         if (SDL_SystemRAM <= 0) {
             /* Vita has 512MiB on SoC, that's split into 256MiB(+109MiB in extended memory mode) for app