Create CORE_CTL_RETRO_GET_MEMORY

This commit is contained in:
twinaphex 2016-01-27 09:29:18 +01:00
parent e516a64a0c
commit ae2cf510cd
3 changed files with 27 additions and 5 deletions

View File

@ -351,13 +351,16 @@ static bool load_ram_file(ram_type_t *ram)
*/
static bool save_ram_file(ram_type_t *ram)
{
size_t size = core.retro_get_memory_size(ram->type);
void *data = core.retro_get_memory_data(ram->type);
retro_ctx_memory_info_t mem_info;
if (!data || size == 0)
mem_info.ram = ram;
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
if (!mem_info.data || mem_info.size == 0)
return false;
if (!retro_write_file(ram->path, data, size))
if (!retro_write_file(ram->path, mem_info.data, mem_info.size))
{
RARCH_ERR("%s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
@ -366,7 +369,7 @@ static bool save_ram_file(ram_type_t *ram)
/* In case the file could not be written to,
* the fallback function 'dump_to_file_desperate'
* will be called. */
if (!dump_to_file_desperate(data, size, ram->type))
if (!dump_to_file_desperate(mem_info.data, mem_info.size, ram->type))
{
RARCH_WARN("Failed ... Cannot recover save file.\n");
}

View File

@ -174,6 +174,15 @@ bool core_ctl(enum core_ctl_state state, void *data)
switch (state)
{
case CORE_CTL_RETRO_GET_MEMORY:
{
retro_ctx_memory_info_t *info = (retro_ctx_memory_info_t*)data;
if (!info || !info->ram)
return false;
info->size = core.retro_get_memory_size(info->ram->type);
info->data = core.retro_get_memory_data(info->ram->type);
}
break;
case CORE_CTL_RETRO_LOAD_GAME:
{
retro_ctx_load_content_info_t *load_info =

View File

@ -24,6 +24,7 @@ extern "C" {
#include <boolean.h>
#include "content.h"
#include "libretro.h"
enum
@ -82,6 +83,8 @@ enum core_ctl_state
*/
CORE_CTL_VERIFY_API_VERSION,
CORE_CTL_RETRO_GET_MEMORY,
/**
* Initialize system A/V information.
**/
@ -92,6 +95,13 @@ enum core_ctl_state
CORE_CTL_RETRO_LOAD_GAME
};
typedef struct retro_ctx_memory_info
{
void *data;
size_t size;
ram_type_t *ram;
} retro_ctx_memory_info_t;
typedef struct retro_ctx_load_content_info
{
struct retro_game_info *info;