From e71cdf8440d9f63b694d0f75cd8cb9b3a783ddd0 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:18:43 -0700 Subject: [PATCH] Initial SA1 IRAM exposure for RetroAchievements see https://github.com/RetroAchievements/rcheevos/pull/371 --- .../RetroAchievements.Memory.cs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Memory.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Memory.cs index a43f3c9953..cac8c6e221 100644 --- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Memory.cs +++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.Memory.cs @@ -400,11 +400,41 @@ namespace BizHawk.Client.EmuHawk break; case ConsoleID.SNES: mfs.Add(new(domains["WRAM"], 0, domains["WRAM"].Size)); - TryAddDomain("CARTRAM"); + + var snesSramAdded = 0; + const int MAX_SNES_SRAM = 0x80000; // 512KiB, the highest theoretically mappable under normal hardware (also max enforced by our cores) + void AddSnesSramDomain(string domain) + { + if (snesSramAdded == MAX_SNES_SRAM) + { + return; + } + + if (domains.Has(domain)) + { + var domainSize = domains[domain]!.Size; + if (snesSramAdded + domainSize > MAX_SNES_SRAM) + { + Console.WriteLine("SNES CartRAM domains exceed 512KiB for RetroAchievements memory mapping (this is bad!)"); + domainSize = MAX_SNES_SRAM - snesSramAdded; + } + + mfs.Add(new(domains[domain], 0, domainSize)); + snesSramAdded += (int)domainSize; + } + } + + AddSnesSramDomain("CARTRAM"); // sufami B sram - // don't think this is actually hooked up at all anyways... - TryAddDomain("CARTRAM B"); // Snes9x - TryAddDomain("SUFAMI TURBO B RAM"); // new BSNES + AddSnesSramDomain("CARTRAM B"); // Snes9x + AddSnesSramDomain("SUFAMI TURBO B RAM"); // new BSNES + + if (snesSramAdded < MAX_SNES_SRAM) + { + mfs.Add(new NullMemFunctions(MAX_SNES_SRAM - snesSramAdded)); + } + + TryAddDomain("SA1 IRAM"); break; case ConsoleID.GB: case ConsoleID.GBC: