diff --git a/genplus-gx32/core/cart_hw/md_cart.c b/genplus-gx32/core/cart_hw/md_cart.c index 5a552f0beb..a0f0bd6d92 100644 --- a/genplus-gx32/core/cart_hw/md_cart.c +++ b/genplus-gx32/core/cart_hw/md_cart.c @@ -723,7 +723,7 @@ void md_cart_reset(int hard_reset) m68k.memory_map[i].base = cart.rom + ((i<<16) & cart.mask); } } - + /* SVP chip */ if (svp) { @@ -927,20 +927,59 @@ static void mapper_sega_w(uint32 data) */ static void mapper_ssf2_w(uint32 address, uint32 data) { - /* 8 x 512k banks */ - address = (address << 2) & 0x38; - - /* bank 0 remains unchanged */ - if (address) - { - uint32 i; - uint8 *src = cart.rom + (data << 19); + /* 8 x 512k banks */ + address = (address << 2) & 0x38; + + /* bank 0 remains unchanged */ + if (address) + { + uint32 i; + uint8 *src = cart.rom + (data << 19); + + for (i = 0; i<8; i++) + { + m68k.memory_map[address++].base = src + (i << 16); + } + } + else // emulate turning on SRAM + { + if (data & 1) + { + if (sram.on) + { + /* Backup RAM mapped to $200000-$20ffff (normally mirrored up to $3fffff but this breaks Sonic Megamix and no game need it) */ + cart.hw.bankshift = m68k.memory_map[0x20].base; + m68k.memory_map[0x20].base = sram.sram; + m68k.memory_map[0x20].read8 = sram_read_byte; + m68k.memory_map[0x20].read16 = sram_read_word; + zbank_memory_map[0x20].read = sram_read_byte; - for (i=0; i<8; i++) - { - m68k.memory_map[address++].base = src + (i<<16); - } - } + /* Backup RAM write protection */ + if (data & 2) + { + m68k.memory_map[0x20].write8 = m68k_unused_8_w; + m68k.memory_map[0x20].write16 = m68k_unused_16_w; + zbank_memory_map[0x20].write = zbank_unused_w; + } + else + { + m68k.memory_map[0x20].write8 = sram_write_byte; + m68k.memory_map[0x20].write16 = sram_write_word; + zbank_memory_map[0x20].write = sram_write_byte; + } + } + } + else + { + // automatically turn off writing to SRAM if SRAM is not visible + m68k.memory_map[0x20].write8 = m68k_unused_8_w; + m68k.memory_map[0x20].write16 = m68k_unused_16_w; + zbank_memory_map[0x20].write = zbank_unused_w; + + // put the ROM data back in the memory map + m68k.memory_map[0x20].base = cart.hw.bankshift; + } + } } /*