2008-08-07 14:26:07 +02:00
|
|
|
/***************************************************************************************
|
2009-05-13 16:26:55 +02:00
|
|
|
* Genesis Plus
|
2009-06-02 20:12:31 +02:00
|
|
|
* Backup RAM support
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port)
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
|
|
|
|
|
|
|
T_SRAM sram;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* A quick guide to SRAM on the Genesis
|
|
|
|
*
|
|
|
|
* The SRAM definition is held at offset 0x1b0 of the ROM header.
|
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* 1B0h: dc.b 'RA', %1x1yz000, %00100000
|
|
|
|
* 1B4h: dc.l RAM start address
|
|
|
|
* 1B8h: dc.l RAM end address
|
2008-08-07 14:26:07 +02:00
|
|
|
* x 1 for BACKUP and 0 If not BACKUP
|
|
|
|
* yz 10 if even address only
|
|
|
|
* 11 if odd address only
|
|
|
|
* 00 if both even and odd address
|
|
|
|
*
|
|
|
|
* Assuming max. 64k SRAM / Battery RAM throughout
|
|
|
|
****************************************************************************/
|
|
|
|
void sram_init()
|
|
|
|
{
|
|
|
|
memset (&sram, 0, sizeof (T_SRAM));
|
|
|
|
memset (&sram.sram[0], 0xFF, 0x10000);
|
|
|
|
sram.crc = crc32 (0, &sram.sram[0], 0x10000);
|
|
|
|
|
2009-08-06 20:31:05 +02:00
|
|
|
if ((READ_BYTE(cart.rom,0x1b0) == 0x52) && (READ_BYTE(cart.rom,0x1b1) == 0x41))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
/* retrieve informations from headezr */
|
2008-12-11 18:38:29 +01:00
|
|
|
sram.detected = 1;
|
2009-08-06 20:31:05 +02:00
|
|
|
sram.start = READ_WORD_LONG(cart.rom, 0x1b4);
|
|
|
|
sram.end = READ_WORD_LONG(cart.rom, 0x1b8);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-12-11 18:38:29 +01:00
|
|
|
/* fixe some bad header informations */
|
|
|
|
if ((sram.start > sram.end) || ((sram.end - sram.start) >= 0x10000))
|
|
|
|
sram.end = sram.start + 0xffff;
|
|
|
|
sram.start &= 0xfffffffe;
|
2008-08-07 14:26:07 +02:00
|
|
|
sram.end |= 1;
|
2009-08-07 19:30:14 +02:00
|
|
|
sram.on = 1;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-11 18:38:29 +01:00
|
|
|
/* default SRAM region */
|
|
|
|
sram.start = 0x200000;
|
2008-08-07 14:26:07 +02:00
|
|
|
sram.end = 0x20ffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set SRAM ON by default when ROM is not mapped */
|
2009-08-07 19:30:14 +02:00
|
|
|
if (cart.romsize <= sram.start) sram.on = 1;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* Some games with bad header or specific configuration */
|
|
|
|
if (strstr(rominfo.product,"T-113016") != NULL)
|
|
|
|
{
|
2008-12-11 18:38:29 +01:00
|
|
|
/* Pugsy (try accessing unmapped area for copy protection) */
|
|
|
|
sram.on = 0;
|
2009-08-07 19:30:14 +02:00
|
|
|
}
|
|
|
|
else if (strstr(rominfo.international,"SONIC THE HEDGEHOG 2") != NULL)
|
|
|
|
{
|
|
|
|
/* Sonic the Hedgehog 2 does not use SRAM */
|
|
|
|
/* this prevents SRAM activation when using Sonic & Knuckles LOCK-ON feature */
|
|
|
|
sram.on = 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
else if ((strstr(rominfo.product,"T-26013") != NULL) && (rominfo.checksum == 0xa837))
|
|
|
|
{
|
2008-12-11 18:38:29 +01:00
|
|
|
/* Psy-O-Blade (bad header) */
|
|
|
|
sram.on = 1;
|
|
|
|
sram.start = 0x200001;
|
|
|
|
sram.end = 0x203fff;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
else if (((realchecksum == 0xaeaa) || (realchecksum == 0x8dba)) && (rominfo.checksum == 0x8104))
|
|
|
|
{
|
2008-12-11 18:38:29 +01:00
|
|
|
/* Xin Qigai Wangzi, aka Beggar Prince (no header, use uncommon area) */
|
|
|
|
sram.on = 1;
|
|
|
|
sram.start = 0x400000;
|
|
|
|
sram.end = 0x40ffff;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|