From 1a7184dd8273c063644675a70ea37e0fe2f349e5 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Sun, 6 Oct 2024 19:52:46 -0700 Subject: [PATCH] Expand SNES memory exposure 1. Expand Cartridge RAM from 128KiB to 512KiB. This is the maximum theoretically mappable for any official ROM types, possibly used in homebrews. This limit is also what Snes9x and other emulators internally limit Cartridge RAM to (although notably, libretro Snes9x limits Cartridge RAM to 128KiB for purposes of exposing memory, leaving the rest present but unexposed. This seems to be an artifact of the old 128KiB limit older Snes9x imposed, probably a trivial fix on that side anyways). 2. Set the "native address" of Cartridge RAM to 0x1000000, outside of the native addressing space. The old value used is only necessarily valid for LoROM; HiROM and SA-1 (BW-RAM) have Cartridge RAM elsewhere, and even then, the old value would only work assuming > 128KiB of Cartridge RAM wasn't mapped. Nearly all libretro cores do not implement explicit memory maps in the first place, the only 2 which do are bsnes-mercury and Snes9x 2010, which are known to be problematic (and thus unsupported) already (probably due to this quirk with Cartridge RAM if anything). 3. Map SA-1 I-RAM after Cartridge RAM. Unlike BW-RAM, this isn't SaveRAM (and thus not exposed as such by emulators), so it's a separate memory block. It is mapped outside of the native addressing space as it's native location is typically just SNES WRAM for other cartridge types. This approach has already been implemented in BizHawk (for all Snes9x, Faust, BSNES, and BSNESv115+ cores). --- src/rcheevos/consoleinfo.c | 14 +++++++++++--- test/rcheevos/test_consoleinfo.c | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rcheevos/consoleinfo.c b/src/rcheevos/consoleinfo.c index 98b43b6d..25e1e944 100644 --- a/src/rcheevos/consoleinfo.c +++ b/src/rcheevos/consoleinfo.c @@ -868,10 +868,18 @@ static const rc_memory_regions_t rc_memory_regions_scv = { _rc_memory_regions_sc /* ===== Super Nintendo ===== */ /* https://en.wikibooks.org/wiki/Super_NES_Programming/SNES_memory_map#LoROM */ static const rc_memory_region_t _rc_memory_regions_snes[] = { - { 0x000000U, 0x01FFFFU, 0x7E0000U, RC_MEMORY_TYPE_SYSTEM_RAM, "System RAM" }, - { 0x020000U, 0x03FFFFU, 0xFE0000U, RC_MEMORY_TYPE_SAVE_RAM, "Cartridge RAM" } + { 0x000000U, 0x01FFFFU, 0x07E0000U, RC_MEMORY_TYPE_SYSTEM_RAM, "System RAM" }, + /* Cartridge RAM here could be in a variety of places in SNES memory, depending on the ROM type. + * Due to this, we place Cartridge RAM outside of the possible native addressing space. + * Note that this also covers SA-1 BW-RAM (which is exposed as RETRO_MEMORY_SAVE_RAM for libretro). + */ + { 0x020000U, 0x09FFFFU, 0x1000000U, RC_MEMORY_TYPE_SAVE_RAM, "Cartridge RAM" }, + /* I-RAM on the SA-1 is normally at 0x003000. However, this address typically just has a mirror of System RAM for other ROM types. + * To avoid conflicts, don't use 0x003000, instead map it outside of the possible native addressing space. + */ + { 0x0A0000U, 0x0A07FFU, 0x1080000U, RC_MEMORY_TYPE_SYSTEM_RAM, "I-RAM (SA-1)" } }; -static const rc_memory_regions_t rc_memory_regions_snes = { _rc_memory_regions_snes, 2 }; +static const rc_memory_regions_t rc_memory_regions_snes = { _rc_memory_regions_snes, 3 }; /* ===== Thomson TO8 ===== */ /* https://github.com/mamedev/mame/blob/master/src/mame/drivers/thomson.cpp#L1617 */ diff --git a/test/rcheevos/test_consoleinfo.c b/test/rcheevos/test_consoleinfo.c index b7670ada..41dc18f6 100644 --- a/test/rcheevos/test_consoleinfo.c +++ b/test/rcheevos/test_consoleinfo.c @@ -177,7 +177,7 @@ void test_consoleinfo(void) { TEST_PARAMS2(test_memory, RC_CONSOLE_SEGA_CD, 0x090000); TEST_PARAMS2(test_memory, RC_CONSOLE_SG1000, 0x006000); TEST_PARAMS2(test_memory, RC_CONSOLE_SUPER_CASSETTEVISION, 0x010000); - TEST_PARAMS2(test_memory, RC_CONSOLE_SUPER_NINTENDO, 0x040000); + TEST_PARAMS2(test_memory, RC_CONSOLE_SUPER_NINTENDO, 0x0A0800); TEST_PARAMS2(test_memory, RC_CONSOLE_SUPERVISION, 0x006000); TEST_PARAMS2(test_memory, RC_CONSOLE_THOMSONTO8, 0x080000); TEST_PARAMS2(test_memory, RC_CONSOLE_TI83, 0x08000);