diff --git a/src/system/libretro/tic80_libretro.c b/src/system/libretro/tic80_libretro.c index 07d9096c8..27f40fa3f 100644 --- a/src/system/libretro/tic80_libretro.c +++ b/src/system/libretro/tic80_libretro.c @@ -844,26 +844,44 @@ RETRO_API bool retro_unserialize(const void *data, size_t size) } /** - * libretro callback; Gets region of memory. Used for achievement tracking. + * libretro callback; Gets region of memory. + * + * https://github.com/nesbox/TIC-80/wiki/ram */ RETRO_API void *retro_get_memory_data(unsigned id) { - if (state == NULL || state->tic == NULL || id >= TIC_PERSISTENT_SIZE) { + if (state == NULL || state->tic == NULL) { return NULL; } - // TODO: Have the memory data refer to the RAM rather than persistent data. - // https://github.com/nesbox/TIC-80/wiki/RAM tic80_local* tic80 = (tic80_local*)state->tic; - return &(tic80->memory->ram.persistent.data[id]); + switch (id) { + case RETRO_MEMORY_SAVE_RAM: + return tic80->memory->ram.persistent.data; + case RETRO_MEMORY_SYSTEM_RAM: + return tic80->memory->ram.data; + case RETRO_MEMORY_VIDEO_RAM: + return tic80->memory->ram.vram.data; + default: + return NULL; + } } /** - * libretro callback; Gets the size of memory. Used for achievement tracking. + * libretro callback; Gets the size of the given memory slot. */ RETRO_API size_t retro_get_memory_size(unsigned id) { - return sizeof(u32); + switch (id) { + case RETRO_MEMORY_SAVE_RAM: + return TIC_PERSISTENT_SIZE; + case RETRO_MEMORY_SYSTEM_RAM: + return TIC_RAM_SIZE; + case RETRO_MEMORY_VIDEO_RAM: + return TIC_VRAM_SIZE; + default: + return 0; + } } /**