libretro/snes9x — pull request #2 by Alcaro (2014-05-29 01:04:32+00:00)
Title: Create memory descriptor API

There are many ways to implement cheats in libretro.
They can be implemented by just poking RETRO_MEMORY_SYSTEM_RAM, but that would make anything libretro-based use a cheat format that's incompatible with everything else - a clearly inferior situation.
And on the other extreme, cheats can be implemented entirely in the core, as with the cheat API currently in libretro; while that gives the theoretically best results (poking RAM isn't failproof if a RAM address is written and then read in the same frame), it takes a lot more effort for each core, so it's unlikely to happen (as evidenced by the number of users of the current cheat interface). If it can't be made globally present, it's barely worth caring about.

Letting the core tell the frontend about the memory maps combines the benefits of both; it's easy for the core (this one is about 200 lines of code not counting libretro.h; exporting only WRAM can be done with only 3, though it's better to export more), while still allowing the cheats to speak the same language as both ROM hackers and other emulators.

The format is designed to be simple but powerful; a tough combination, but not impossible. Making it easy for the frontend to handle was not a priority; there are far fewer frontends than cores, so moving a task to the front means less code in total. Additionally, we can let the frontends share the cheat engine, something which is far less feasible if it's tied to a specific emulator core.

Currently only https://github.com/Alcaro/minir understands those descriptors, but the plan is to add it to RetroArch too once minir's cheat handler is finished, and then make it available to other frontends somehow.