Mercurial > repos > blastem
comparison libblastem.c @ 1924:81b059e3ded6
Add memory hook for cheat/rumble/cheevos support
author | negativeExponent <negativeExponent@users.noreply.github.com> |
---|---|
date | Mon, 13 Apr 2020 18:14:25 -0700 |
parents | 377f110e4cea |
children | 94f37e4b1469 |
comparison
equal
deleted
inserted
replaced
1923:23394a890508 | 1924:81b059e3ded6 |
---|---|
4 #include "system.h" | 4 #include "system.h" |
5 #include "util.h" | 5 #include "util.h" |
6 #include "vdp.h" | 6 #include "vdp.h" |
7 #include "render.h" | 7 #include "render.h" |
8 #include "io.h" | 8 #include "io.h" |
9 #include "genesis.h" | |
10 #include "sms.h" | |
9 | 11 |
10 static retro_environment_t retro_environment; | 12 static retro_environment_t retro_environment; |
11 RETRO_API void retro_set_environment(retro_environment_t re) | 13 RETRO_API void retro_set_environment(retro_environment_t re) |
12 { | 14 { |
13 retro_environment = re; | 15 retro_environment = re; |
216 RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code) | 218 RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code) |
217 { | 219 { |
218 } | 220 } |
219 | 221 |
220 /* Loads a game. */ | 222 /* Loads a game. */ |
223 static system_type stype; | |
221 RETRO_API bool retro_load_game(const struct retro_game_info *game) | 224 RETRO_API bool retro_load_game(const struct retro_game_info *game) |
222 { | 225 { |
223 serialize_size_cache = 0; | 226 serialize_size_cache = 0; |
224 if (game->path) { | 227 if (game->path) { |
225 media.dir = path_dirname(game->path); | 228 media.dir = path_dirname(game->path); |
227 media.extension = path_extension(game->path); | 230 media.extension = path_extension(game->path); |
228 } | 231 } |
229 media.buffer = malloc(nearest_pow2(game->size)); | 232 media.buffer = malloc(nearest_pow2(game->size)); |
230 memcpy(media.buffer, game->data, game->size); | 233 memcpy(media.buffer, game->data, game->size); |
231 media.size = game->size; | 234 media.size = game->size; |
232 current_system = alloc_config_system(detect_system_type(&media), &media, 0, 0); | 235 stype = detect_system_type(&media); |
236 current_system = alloc_config_system(stype, &media, 0, 0); | |
233 | 237 |
234 unsigned format = RETRO_PIXEL_FORMAT_XRGB8888; | 238 unsigned format = RETRO_PIXEL_FORMAT_XRGB8888; |
235 retro_environment(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &format); | 239 retro_environment(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &format); |
236 return current_system != NULL; | 240 return current_system != NULL; |
237 } | 241 } |
263 } | 267 } |
264 | 268 |
265 /* Gets region of memory. */ | 269 /* Gets region of memory. */ |
266 RETRO_API void *retro_get_memory_data(unsigned id) | 270 RETRO_API void *retro_get_memory_data(unsigned id) |
267 { | 271 { |
272 if (id == RETRO_MEMORY_SYSTEM_RAM) | |
273 { | |
274 switch (stype) | |
275 { | |
276 case SYSTEM_GENESIS: | |
277 { | |
278 genesis_context *gen = (genesis_context *)current_system; | |
279 return (uint8_t *)gen->work_ram; | |
280 } | |
281 break; | |
282 #ifndef NO_Z80 | |
283 case SYSTEM_SMS: | |
284 { | |
285 sms_context *sms = (sms_context *)current_system; | |
286 return sms->ram; | |
287 } | |
288 break; | |
289 #endif | |
290 } | |
291 } | |
268 return NULL; | 292 return NULL; |
269 } | 293 } |
270 | 294 |
271 RETRO_API size_t retro_get_memory_size(unsigned id) | 295 RETRO_API size_t retro_get_memory_size(unsigned id) |
272 { | 296 { |
297 if (id == RETRO_MEMORY_SYSTEM_RAM) | |
298 { | |
299 switch (stype) | |
300 { | |
301 case SYSTEM_GENESIS: | |
302 return RAM_WORDS * sizeof(uint16_t); | |
303 #ifndef NO_Z80 | |
304 case SYSTEM_SMS: | |
305 return SMS_RAM_SIZE; | |
306 #endif | |
307 } | |
308 } | |
273 return 0; | 309 return 0; |
274 } | 310 } |
275 | 311 |
276 //blastem render backend API implementation | 312 //blastem render backend API implementation |
277 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b) | 313 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b) |