Skip to content

Commit

Permalink
Merge pull request #1361 from RobLoach/memory
Browse files Browse the repository at this point in the history
libretro: Update the memory data slots
  • Loading branch information
nesbox authored Feb 26, 2021
2 parents b475491 + 2a9a40d commit c6025d9
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/system/libretro/tic80_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit c6025d9

Please sign in to comment.