mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2025-01-14 12:19:06 +01:00
[Core/MD] fixed regression with games using SRAM bank-switching (introduced in
r792)
This commit is contained in:
parent
75ac3317ed
commit
091a0615f5
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX)
|
* Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX)
|
||||||
*
|
*
|
||||||
* Most cartridge protections were initially documented by Haze
|
* Many cartridge protections were initially documented by Haze
|
||||||
* (http://haze.mameworld.info/)
|
* (http://haze.mameworld.info/)
|
||||||
*
|
*
|
||||||
* Realtec mapper was documented by TascoDeluxe
|
* Realtec mapper was documented by TascoDeluxe
|
||||||
@ -42,6 +42,7 @@
|
|||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
|
|
||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
|
#include "eeprom_i2c.h"
|
||||||
#include "eeprom_spi.h"
|
#include "eeprom_spi.h"
|
||||||
#include "gamepad.h"
|
#include "gamepad.h"
|
||||||
|
|
||||||
@ -356,7 +357,25 @@ void md_cart_init(void)
|
|||||||
BACKUP MEMORY
|
BACKUP MEMORY
|
||||||
***********************************************/
|
***********************************************/
|
||||||
sram_init();
|
sram_init();
|
||||||
|
eeprom_i2c_init();
|
||||||
|
|
||||||
|
/* external SRAM */
|
||||||
|
if (sram.on && !sram.custom)
|
||||||
|
{
|
||||||
|
/* disabled on startup if ROM is mapped in same area */
|
||||||
|
if (cart.romsize <= sram.start)
|
||||||
|
{
|
||||||
|
/* initialize m68k bus handlers */
|
||||||
|
m68k.memory_map[sram.start >> 16].base = sram.sram;
|
||||||
|
m68k.memory_map[sram.start >> 16].read8 = sram_read_byte;
|
||||||
|
m68k.memory_map[sram.start >> 16].read16 = sram_read_word;
|
||||||
|
m68k.memory_map[sram.start >> 16].write8 = sram_write_byte;
|
||||||
|
m68k.memory_map[sram.start >> 16].write16 = sram_write_word;
|
||||||
|
zbank_memory_map[sram.start >> 16].read = sram_read_byte;
|
||||||
|
zbank_memory_map[sram.start >> 16].write = sram_write_byte;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**********************************************
|
/**********************************************
|
||||||
SVP CHIP
|
SVP CHIP
|
||||||
***********************************************/
|
***********************************************/
|
||||||
@ -492,7 +511,7 @@ void md_cart_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************
|
/**********************************************
|
||||||
Cartridge Extra Hardware
|
CARTRIDGE EXTRA HARDWARE
|
||||||
***********************************************/
|
***********************************************/
|
||||||
memset(&cart.hw, 0, sizeof(cart.hw));
|
memset(&cart.hw, 0, sizeof(cart.hw));
|
||||||
|
|
||||||
@ -607,7 +626,7 @@ void md_cart_init(void)
|
|||||||
m68k.memory_map[i].base = cart.rom + ((i & 0x03) << 16);
|
m68k.memory_map[i].base = cart.rom + ((i & 0x03) << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 32K SRAM is initially disabled at $200000-$2FFFFF */
|
/* 32K static RAM is mapped to $200000-$2FFFFF (disabled on startup) */
|
||||||
for (i=0x20; i<0x30; i++)
|
for (i=0x20; i<0x30; i++)
|
||||||
{
|
{
|
||||||
m68k.memory_map[i].base = sram.sram;
|
m68k.memory_map[i].base = sram.sram;
|
||||||
@ -789,10 +808,28 @@ int md_cart_context_load(uint8 *state)
|
|||||||
if (offset == 0xff)
|
if (offset == 0xff)
|
||||||
{
|
{
|
||||||
/* SRAM */
|
/* SRAM */
|
||||||
m68k.memory_map[i].base = sram.sram;
|
m68k.memory_map[i].base = sram.sram;
|
||||||
|
m68k.memory_map[i].read8 = sram_read_byte;
|
||||||
|
m68k.memory_map[i].read16 = sram_read_word;
|
||||||
|
m68k.memory_map[i].write8 = sram_write_byte;
|
||||||
|
m68k.memory_map[i].write16 = sram_write_word;
|
||||||
|
zbank_memory_map[i].read = sram_read_byte;
|
||||||
|
zbank_memory_map[i].write = sram_write_byte;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* check if SRAM was mapped there before loading state */
|
||||||
|
if (m68k.memory_map[i].base == sram.sram)
|
||||||
|
{
|
||||||
|
m68k.memory_map[i].read8 = NULL;
|
||||||
|
m68k.memory_map[i].read16 = NULL;
|
||||||
|
m68k.memory_map[i].write8 = m68k_unused_8_w;
|
||||||
|
m68k.memory_map[i].write16 = m68k_unused_16_w;
|
||||||
|
zbank_memory_map[i].read = NULL;
|
||||||
|
zbank_memory_map[i].write = zbank_unused_w;
|
||||||
|
}
|
||||||
|
|
||||||
/* ROM */
|
/* ROM */
|
||||||
m68k.memory_map[i].base = cart.rom + (offset << 16);
|
m68k.memory_map[i].base = cart.rom + (offset << 16);
|
||||||
}
|
}
|
||||||
@ -829,9 +866,9 @@ static void mapper_sega_w(uint32 data)
|
|||||||
{
|
{
|
||||||
/* Backup RAM mapped to $200000-$20ffff (normally mirrored up to $3fffff but this breaks Sonic Megamix and no game need it) */
|
/* Backup RAM mapped to $200000-$20ffff (normally mirrored up to $3fffff but this breaks Sonic Megamix and no game need it) */
|
||||||
m68k.memory_map[0x20].base = sram.sram;
|
m68k.memory_map[0x20].base = sram.sram;
|
||||||
m68k.memory_map[0x20].write8 = NULL;
|
m68k.memory_map[0x20].read8 = sram_read_byte;
|
||||||
m68k.memory_map[0x20].write16 = NULL;
|
m68k.memory_map[0x20].read16 = sram_read_word;
|
||||||
zbank_memory_map[0x20].write = NULL;
|
zbank_memory_map[0x20].read = sram_read_byte;
|
||||||
|
|
||||||
/* Backup RAM write protection */
|
/* Backup RAM write protection */
|
||||||
if (data & 2)
|
if (data & 2)
|
||||||
@ -840,6 +877,12 @@ static void mapper_sega_w(uint32 data)
|
|||||||
m68k.memory_map[0x20].write16 = m68k_unused_16_w;
|
m68k.memory_map[0x20].write16 = m68k_unused_16_w;
|
||||||
zbank_memory_map[0x20].write = zbank_unused_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* S&K lock-on chip */
|
/* S&K lock-on chip */
|
||||||
@ -857,10 +900,13 @@ static void mapper_sega_w(uint32 data)
|
|||||||
/* cartridge ROM mapped to $200000-$3fffff */
|
/* cartridge ROM mapped to $200000-$3fffff */
|
||||||
for (i=0x20; i<0x40; i++)
|
for (i=0x20; i<0x40; i++)
|
||||||
{
|
{
|
||||||
m68k.memory_map[i].base = cart.rom + ((i<<16) & cart.mask);
|
m68k.memory_map[i].base = cart.rom + ((i<<16) & cart.mask);
|
||||||
m68k.memory_map[i].write8 = m68k_unused_8_w;
|
m68k.memory_map[i].read8 = NULL;
|
||||||
m68k.memory_map[i].write16 = m68k_unused_16_w;
|
m68k.memory_map[i].read16 = NULL;
|
||||||
zbank_memory_map[i].write = zbank_unused_w;
|
zbank_memory_map[i].read = NULL;
|
||||||
|
m68k.memory_map[i].write8 = m68k_unused_8_w;
|
||||||
|
m68k.memory_map[i].write16 = m68k_unused_16_w;
|
||||||
|
zbank_memory_map[i].write = zbank_unused_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -907,10 +953,10 @@ static void mapper_sf001_w(uint32 address, uint32 data)
|
|||||||
m68k.memory_map[i].base = cart.rom + (i << 16);
|
m68k.memory_map[i].base = cart.rom + (i << 16);
|
||||||
m68k.memory_map[i].read8 = m68k_read_bus_8;
|
m68k.memory_map[i].read8 = m68k_read_bus_8;
|
||||||
m68k.memory_map[i].read16 = m68k_read_bus_16;
|
m68k.memory_map[i].read16 = m68k_read_bus_16;
|
||||||
m68k.memory_map[i].write8 = m68k_unused_8_w;
|
m68k.memory_map[i].write8 = (i > 0x00) ? m68k_unused_8_w : mapper_sf001_w;
|
||||||
m68k.memory_map[i].write16 = m68k_unused_16_w;
|
m68k.memory_map[i].write16 = (i > 0x00) ? m68k_unused_16_w : mapper_sf001_w;
|
||||||
zbank_memory_map[i].read = zbank_unused_r;
|
zbank_memory_map[i].read = zbank_unused_r;
|
||||||
zbank_memory_map[i].write = m68k_unused_8_w;
|
zbank_memory_map[i].write = (i > 0x00) ? m68k_unused_8_w : mapper_sf001_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,12 +985,12 @@ static void mapper_sf001_w(uint32 address, uint32 data)
|
|||||||
while (i<0x40)
|
while (i<0x40)
|
||||||
{
|
{
|
||||||
m68k.memory_map[i].base = sram.sram;
|
m68k.memory_map[i].base = sram.sram;
|
||||||
m68k.memory_map[i].read8 = NULL;
|
m68k.memory_map[i].read8 = sram_read_byte;
|
||||||
m68k.memory_map[i].read16 = NULL;
|
m68k.memory_map[i].read16 = sram_read_word;
|
||||||
m68k.memory_map[i].write8 = NULL;
|
m68k.memory_map[i].write8 = sram_write_byte;
|
||||||
m68k.memory_map[i].write16 = NULL;
|
m68k.memory_map[i].write16 = sram_write_word;
|
||||||
zbank_memory_map[i].read = NULL;
|
zbank_memory_map[i].read = sram_read_byte;
|
||||||
zbank_memory_map[i].write = NULL;
|
zbank_memory_map[i].write = sram_write_byte;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -956,10 +1002,10 @@ static void mapper_sf001_w(uint32 address, uint32 data)
|
|||||||
m68k.memory_map[i].base = cart.rom + (i << 16);
|
m68k.memory_map[i].base = cart.rom + (i << 16);
|
||||||
m68k.memory_map[i].read8 = NULL;
|
m68k.memory_map[i].read8 = NULL;
|
||||||
m68k.memory_map[i].read16 = NULL;
|
m68k.memory_map[i].read16 = NULL;
|
||||||
m68k.memory_map[i].write8 = m68k_unused_8_w;
|
m68k.memory_map[i].write8 = (i > 0x00) ? m68k_unused_8_w : mapper_sf001_w;
|
||||||
m68k.memory_map[i].write16 = m68k_unused_16_w;
|
m68k.memory_map[i].write16 = (i > 0x00) ? m68k_unused_16_w : mapper_sf001_w;
|
||||||
zbank_memory_map[i].read = NULL;
|
zbank_memory_map[i].read = NULL;
|
||||||
zbank_memory_map[i].write = m68k_unused_8_w;
|
zbank_memory_map[i].write = (i > 0x00) ? m68k_unused_8_w : mapper_sf001_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1023,12 +1069,12 @@ static void mapper_sf004_w(uint32 address, uint32 data)
|
|||||||
/* 32KB static RAM mirrored into $200000-$2FFFFF (odd bytes only) */
|
/* 32KB static RAM mirrored into $200000-$2FFFFF (odd bytes only) */
|
||||||
for (i=0x20; i<0x30; i++)
|
for (i=0x20; i<0x30; i++)
|
||||||
{
|
{
|
||||||
m68k.memory_map[i].read8 = NULL;
|
m68k.memory_map[i].read8 = sram_read_byte;
|
||||||
m68k.memory_map[i].read16 = NULL;
|
m68k.memory_map[i].read16 = sram_read_word;
|
||||||
m68k.memory_map[i].write8 = NULL;
|
m68k.memory_map[i].write8 = sram_write_byte;
|
||||||
m68k.memory_map[i].write16 = NULL;
|
m68k.memory_map[i].write16 = sram_write_word;
|
||||||
zbank_memory_map[i].read = NULL;
|
zbank_memory_map[i].read = sram_read_byte;
|
||||||
zbank_memory_map[i].write = NULL;
|
zbank_memory_map[i].write = sram_write_byte;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -37,15 +37,9 @@
|
|||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
|
|
||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
#include "eeprom_i2c.h"
|
|
||||||
|
|
||||||
T_SRAM sram;
|
T_SRAM sram;
|
||||||
|
|
||||||
static unsigned int sram_read_byte(unsigned int address);
|
|
||||||
static unsigned int sram_read_word(unsigned int address);
|
|
||||||
static void sram_write_byte(unsigned int address, unsigned int data);
|
|
||||||
static void sram_write_word(unsigned int address, unsigned int data);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* A quick guide to external RAM on the Genesis
|
* A quick guide to external RAM on the Genesis
|
||||||
*
|
*
|
||||||
@ -194,44 +188,25 @@ void sram_init()
|
|||||||
sram.on = 1;
|
sram.on = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* autodetect games with serial EEPROM */
|
|
||||||
eeprom_i2c_init();
|
|
||||||
|
|
||||||
/* initialize m68k bus handlers (if not already done) */
|
|
||||||
if (sram.on && !sram.custom)
|
|
||||||
{
|
|
||||||
/* disabled on startup if ROM is mapped in same area */
|
|
||||||
if (cart.romsize <= sram.start)
|
|
||||||
{
|
|
||||||
m68k.memory_map[sram.start >> 16].base = sram.sram;
|
|
||||||
m68k.memory_map[sram.start >> 16].read8 = sram_read_byte;
|
|
||||||
m68k.memory_map[sram.start >> 16].read16 = sram_read_word;
|
|
||||||
m68k.memory_map[sram.start >> 16].write8 = sram_write_byte;
|
|
||||||
m68k.memory_map[sram.start >> 16].write16 = sram_write_word;
|
|
||||||
zbank_memory_map[sram.start >> 16].read = sram_read_byte;
|
|
||||||
zbank_memory_map[sram.start >> 16].write = sram_write_byte;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int sram_read_byte(unsigned int address)
|
unsigned int sram_read_byte(unsigned int address)
|
||||||
{
|
{
|
||||||
return sram.sram[address & 0xffff];
|
return sram.sram[address & 0xffff];
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int sram_read_word(unsigned int address)
|
unsigned int sram_read_word(unsigned int address)
|
||||||
{
|
{
|
||||||
address &= 0xfffe;
|
address &= 0xfffe;
|
||||||
return (sram.sram[address + 1] | (sram.sram[address] << 8));
|
return (sram.sram[address + 1] | (sram.sram[address] << 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sram_write_byte(unsigned int address, unsigned int data)
|
void sram_write_byte(unsigned int address, unsigned int data)
|
||||||
{
|
{
|
||||||
sram.sram[address & 0xffff] = data;
|
sram.sram[address & 0xffff] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sram_write_word(unsigned int address, unsigned int data)
|
void sram_write_word(unsigned int address, unsigned int data)
|
||||||
{
|
{
|
||||||
address &= 0xfffe;
|
address &= 0xfffe;
|
||||||
sram.sram[address] = data >> 8;
|
sram.sram[address] = data >> 8;
|
||||||
|
@ -52,6 +52,10 @@ typedef struct
|
|||||||
|
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
extern void sram_init();
|
extern void sram_init();
|
||||||
|
extern unsigned int sram_read_byte(unsigned int address);
|
||||||
|
extern unsigned int sram_read_word(unsigned int address);
|
||||||
|
extern void sram_write_byte(unsigned int address, unsigned int data);
|
||||||
|
extern void sram_write_word(unsigned int address, unsigned int data);
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
extern T_SRAM sram;
|
extern T_SRAM sram;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user