Advertise Jaguar memory map for RetroAchievements support#112
Advertise Jaguar memory map for RetroAchievements support#112JoeMatt wants to merge 2 commits intolibretro:masterfrom
Conversation
Call RETRO_ENVIRONMENT_SET_MEMORY_MAPS in retro_load_game so frontends like RetroArch can resolve emulated Jaguar addresses to host buffers. This enables rcheevos to read the 2 MB main RAM at 0x000000, tagged big-endian to match Jaguar native byte order.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a libretro memory map advertisement for Atari Jaguar main RAM so frontends (e.g., RetroArch) can translate emulated addresses to host buffers for features like RetroAchievements.
Changes:
- Defines a memory descriptor for Jaguar main RAM (2 MB @ 0x000000, big-endian).
- Calls
RETRO_ENVIRONMENT_SET_MEMORY_MAPSduringretro_load_game.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| struct retro_memory_descriptor descs[1]; | ||
| struct retro_memory_map memmap; | ||
|
|
||
| memset(descs, 0, sizeof(descs)); | ||
| descs[0].flags = RETRO_MEMDESC_SYSTEM_RAM | RETRO_MEMDESC_BIGENDIAN; | ||
| descs[0].ptr = jaguarMainRAM; | ||
| descs[0].start = 0x000000; | ||
| descs[0].len = 0x200000; | ||
| descs[0].addrspace = "RAM"; | ||
|
|
||
| memmap.descriptors = descs; | ||
| memmap.num_descriptors = sizeof(descs) / sizeof(descs[0]); | ||
| environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &memmap); | ||
| } |
There was a problem hiding this comment.
The descs array (and memmap) are stack-allocated and go out of scope when retro_load_game returns, but frontends may keep and query the memory map later. This can leave the frontend with dangling pointers for memmap.descriptors, causing incorrect reads or crashes. Make the descriptors and the retro_memory_map storage persist for the lifetime of the loaded game (e.g., static/global storage, or heap-allocate and free on retro_unload_game).
There was a problem hiding this comment.
@copilot apply changes based on this feedback
| descs[0].start = 0x000000; | ||
| descs[0].len = 0x200000; |
There was a problem hiding this comment.
These are magic constants for the main RAM mapping. To reduce the chance of future mismatches, prefer using a named constant (e.g., JAGUAR_MAIN_RAM_SIZE) or sizeof (if jaguarMainRAM is a real array in this translation unit) for len.
Co-authored-by: Copilot <[email protected]>
|
duped by #117 |
Call RETRO_ENVIRONMENT_SET_MEMORY_MAPS in retro_load_game so frontends like RetroArch can resolve emulated Jaguar addresses to host buffers. This enables rcheevos to read the 2 MB main RAM at 0x000000, tagged big-endian to match Jaguar native byte order.