From 8ad096f5309ac7c3876b22b6d048f229cdf5677d Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 14 May 2019 23:20:35 -0700 Subject: Differentiate between the full Sega mapper and the SRAM only one. Fixes crash on save state load for Phantasy Star IV and other games that use the same mapper --- romdb.c | 8 +++++--- romdb.h | 1 + sega_mapper.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/romdb.c b/romdb.c index 9df72ee..331573e 100644 --- a/romdb.c +++ b/romdb.c @@ -77,6 +77,7 @@ void cart_serialize(system_header *sys, serialize_buffer *buf) switch(gen->mapper_type) { case MAPPER_SEGA: + case MAPPER_SEGA_SRAM: sega_mapper_serialize(gen, buf); break; case MAPPER_REALTEC: @@ -96,13 +97,14 @@ void cart_deserialize(deserialize_buffer *buf, void *vcontext) { genesis_context *gen = vcontext; uint8_t mapper_type = load_int8(buf); - if (mapper_type != gen->mapper_type) { - warning("Mapper type mismatch, skipping load of mapper state"); + if (mapper_type != gen->mapper_type && (mapper_type != MAPPER_SEGA || gen->mapper_type != MAPPER_SEGA_SRAM)) { + warning("Mapper type mismatch, skipping load of mapper state\n"); return; } switch(gen->mapper_type) { case MAPPER_SEGA: + case MAPPER_SEGA_SRAM: sega_mapper_deserialize(buf, gen); break; case MAPPER_REALTEC: @@ -365,7 +367,7 @@ void add_memmap_header(rom_info *info, uint8_t *rom, uint32_t size, memmap_chunk info->map[1].buffer = info->save_buffer; } else { //Assume the standard Sega mapper - info->mapper_type = MAPPER_SEGA; + info->mapper_type = MAPPER_SEGA_SRAM; info->map[0].end = 0x200000; info->map[0].mask = 0xFFFFFF; info->map[0].flags = MMAP_READ; diff --git a/romdb.h b/romdb.h index 67b3828..00524db 100644 --- a/romdb.h +++ b/romdb.h @@ -43,6 +43,7 @@ typedef struct { enum { MAPPER_NONE, MAPPER_SEGA, + MAPPER_SEGA_SRAM, MAPPER_REALTEC, MAPPER_XBAND, MAPPER_MULTI_GAME, diff --git a/sega_mapper.c b/sega_mapper.c index 1410f0c..a217b8a 100644 --- a/sega_mapper.c +++ b/sega_mapper.c @@ -116,7 +116,7 @@ m68k_context * write_bank_reg_w(uint32_t address, m68k_context * context, uint16 context->mem_pointers[gen->mapper_start_index + i] = gen->cart + 0x40000*gen->bank_regs[i]; } } - } else { + } else if (gen->mapper_type == MAPPER_SEGA) { void *new_ptr = gen->cart + 0x40000*value; if (context->mem_pointers[gen->mapper_start_index + address] != new_ptr) { m68k_invalidate_code_range(gen->m68k, address * 0x80000, (address + 1) * 0x80000); -- cgit v1.2.3