# HG changeset patch # User negativeExponent # Date 1586826865 25200 # Node ID 81b059e3ded67b0ecd48236bbb781330b9ed8e62 # Parent 23394a8905082280378acec142547a04cc2d5b88 Add memory hook for cheat/rumble/cheevos support diff -r 23394a890508 -r 81b059e3ded6 libblastem.c --- a/libblastem.c Mon Apr 13 18:14:22 2020 -0700 +++ b/libblastem.c Mon Apr 13 18:14:25 2020 -0700 @@ -6,6 +6,8 @@ #include "vdp.h" #include "render.h" #include "io.h" +#include "genesis.h" +#include "sms.h" static retro_environment_t retro_environment; RETRO_API void retro_set_environment(retro_environment_t re) @@ -218,6 +220,7 @@ } /* Loads a game. */ +static system_type stype; RETRO_API bool retro_load_game(const struct retro_game_info *game) { serialize_size_cache = 0; @@ -229,7 +232,8 @@ media.buffer = malloc(nearest_pow2(game->size)); memcpy(media.buffer, game->data, game->size); media.size = game->size; - current_system = alloc_config_system(detect_system_type(&media), &media, 0, 0); + stype = detect_system_type(&media); + current_system = alloc_config_system(stype, &media, 0, 0); unsigned format = RETRO_PIXEL_FORMAT_XRGB8888; retro_environment(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &format); @@ -265,11 +269,43 @@ /* Gets region of memory. */ RETRO_API void *retro_get_memory_data(unsigned id) { + if (id == RETRO_MEMORY_SYSTEM_RAM) + { + switch (stype) + { + case SYSTEM_GENESIS: + { + genesis_context *gen = (genesis_context *)current_system; + return (uint8_t *)gen->work_ram; + } + break; +#ifndef NO_Z80 + case SYSTEM_SMS: + { + sms_context *sms = (sms_context *)current_system; + return sms->ram; + } + break; +#endif + } + } return NULL; } RETRO_API size_t retro_get_memory_size(unsigned id) { + if (id == RETRO_MEMORY_SYSTEM_RAM) + { + switch (stype) + { + case SYSTEM_GENESIS: + return RAM_WORDS * sizeof(uint16_t); +#ifndef NO_Z80 + case SYSTEM_SMS: + return SMS_RAM_SIZE; +#endif + } + } return 0; }