Add support for mapping more than 128KByte SRAM

This commit is contained in:
qwertymodo 2021-08-20 15:33:23 -07:00
parent 9398d21e01
commit e66acceeda
3 changed files with 27 additions and 20 deletions

View File

@ -100,7 +100,7 @@ inline uint8 S9xGetByte (uint32 Address)
case CMemory::MAP_HIROM_SRAM:
case CMemory::MAP_RONLY_SRAM:
byte = *(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask));
byte = *(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask));
addCyclesInMemoryAccess;
return (byte);
@ -241,10 +241,10 @@ inline uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w = WRAP_NONE)
case CMemory::MAP_HIROM_SRAM:
case CMemory::MAP_RONLY_SRAM:
if (Memory.SRAMMask >= MEMMAP_MASK)
word = READ_WORD(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask));
word = READ_WORD(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask));
else
word = (*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) |
(*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0xf0000) >> 3)) & Memory.SRAMMask)) << 8));
word = (*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask)) |
(*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0x1f0000) >> 3)) & Memory.SRAMMask)) << 8));
addCyclesInMemoryAccess_x2;
return (word);
@ -368,7 +368,7 @@ inline void S9xSetByte (uint8 Byte, uint32 Address)
case CMemory::MAP_HIROM_SRAM:
if (Memory.SRAMMask)
{
*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) = Byte;
*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask)) = Byte;
CPU.SRAMModified = TRUE;
}
@ -555,11 +555,11 @@ inline void S9xSetWord (uint16 Word, uint32 Address, enum s9xwrap_t w = WRAP_NON
if (Memory.SRAMMask)
{
if (Memory.SRAMMask >= MEMMAP_MASK)
WRITE_WORD(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask), Word);
WRITE_WORD(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask), Word);
else
{
*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) = (uint8) Word;
*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0xf0000) >> 3)) & Memory.SRAMMask)) = Word >> 8;
*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask)) = (uint8) Word;
*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0x1f0000) >> 3)) & Memory.SRAMMask)) = Word >> 8;
}
CPU.SRAMModified = TRUE;
@ -730,7 +730,7 @@ inline void S9xSetPCBase (uint32 Address)
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
CPU.PCBase = NULL;
else
CPU.PCBase = Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask) - (Address & 0xffff);
CPU.PCBase = Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask) - (Address & 0xffff);
return;
case CMemory::MAP_BWRAM:
@ -786,7 +786,7 @@ inline uint8 * S9xGetBasePointer (uint32 Address)
case CMemory::MAP_HIROM_SRAM:
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
return (NULL);
return (Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask) - (Address & 0xffff));
return (Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask) - (Address & 0xffff));
case CMemory::MAP_BWRAM:
return (Memory.BWRAM - 0x6000 - (Address & 0x8000));
@ -831,7 +831,7 @@ inline uint8 * S9xGetMemPointer (uint32 Address)
case CMemory::MAP_HIROM_SRAM:
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
return (NULL);
return (Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask));
return (Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask));
case CMemory::MAP_BWRAM:
return (Memory.BWRAM - 0x6000 + (Address & 0x7fff));

View File

@ -1916,7 +1916,7 @@ void CMemory::ClearSRAM (bool8 onlyNonSavedSRAM)
if (!(Settings.SuperFX && ROMType < 0x15) && !(Settings.SA1 && ROMType == 0x34)) // can have SRAM
return;
memset(SRAM, SNESGameFixes.SRAMInitialValue, 0x20000);
memset(SRAM, SNESGameFixes.SRAMInitialValue, sizeof(SRAM));
}
bool8 CMemory::LoadSRAM (const char *filename)
@ -1951,15 +1951,17 @@ bool8 CMemory::LoadSRAM (const char *filename)
}
size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0;
if (size > 0x20000)
size = 0x20000;
if (LoROM)
size = size < 0x70000 ? size : 0x70000;
else if (HiROM)
size = size < 0x40000 ? size : 0x40000;
if (size)
{
file = fopen(sramName, "rb");
if (file)
{
len = fread((char *) SRAM, 1, 0x20000, file);
len = fread((char *) SRAM, 1, size, file);
fclose(file);
if (len - size == 512)
memmove(SRAM, SRAM + 512, size);
@ -1983,7 +1985,7 @@ bool8 CMemory::LoadSRAM (const char *filename)
file = fopen(path, "rb");
if (file)
{
len = fread((char *) SRAM, 1, 0x20000, file);
len = fread((char *) SRAM, 1, size, file);
fclose(file);
if (len - size == 512)
memmove(SRAM, SRAM + 512, size);
@ -2040,8 +2042,10 @@ bool8 CMemory::SaveSRAM (const char *filename)
}
size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0;
if (size > 0x20000)
size = 0x20000;
if (LoROM)
size = size < 0x70000 ? size : 0x70000;
else if (HiROM)
size = size < 0x40000 ? size : 0x40000;
if (size)
{

View File

@ -1169,8 +1169,11 @@ void S9xNPSendSRAMToClient (int c)
uint8 sram [7];
int SRAMSize = Memory.SRAMSize ?
(1 << (Memory.SRAMSize + 3)) * 128 : 0;
if (SRAMSize > 0x10000)
SRAMSize = 0x10000;
if (Memory.LoROM)
SRAMSize = SRAMSize < 0x70000 ? SRAMSize : 0x70000;
else if (Memory.HiROM)
SRAMSize = SRAMSize < 0x40000 ? SRAMSize : 0x40000;
int len = 7 + SRAMSize;
sprintf (NetPlay.ActionMsg, "SERVER: Sending S-RAM to player %d...", c + 1);