mirror of https://github.com/snes9xgit/snes9x.git
Add support for mapping more than 128KByte SRAM
This commit is contained in:
parent
9398d21e01
commit
e66acceeda
22
getset.h
22
getset.h
|
@ -100,7 +100,7 @@ inline uint8 S9xGetByte (uint32 Address)
|
||||||
|
|
||||||
case CMemory::MAP_HIROM_SRAM:
|
case CMemory::MAP_HIROM_SRAM:
|
||||||
case CMemory::MAP_RONLY_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;
|
addCyclesInMemoryAccess;
|
||||||
return (byte);
|
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_HIROM_SRAM:
|
||||||
case CMemory::MAP_RONLY_SRAM:
|
case CMemory::MAP_RONLY_SRAM:
|
||||||
if (Memory.SRAMMask >= MEMMAP_MASK)
|
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
|
else
|
||||||
word = (*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) |
|
word = (*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask)) |
|
||||||
(*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0xf0000) >> 3)) & Memory.SRAMMask)) << 8));
|
(*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0x1f0000) >> 3)) & Memory.SRAMMask)) << 8));
|
||||||
addCyclesInMemoryAccess_x2;
|
addCyclesInMemoryAccess_x2;
|
||||||
return (word);
|
return (word);
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ inline void S9xSetByte (uint8 Byte, uint32 Address)
|
||||||
case CMemory::MAP_HIROM_SRAM:
|
case CMemory::MAP_HIROM_SRAM:
|
||||||
if (Memory.SRAMMask)
|
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;
|
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)
|
||||||
{
|
{
|
||||||
if (Memory.SRAMMask >= MEMMAP_MASK)
|
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
|
else
|
||||||
{
|
{
|
||||||
*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3)) & Memory.SRAMMask)) = (uint8) Word;
|
*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0x1f0000) >> 3)) & Memory.SRAMMask)) = (uint8) Word;
|
||||||
*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0xf0000) >> 3)) & Memory.SRAMMask)) = Word >> 8;
|
*(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0x1f0000) >> 3)) & Memory.SRAMMask)) = Word >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPU.SRAMModified = TRUE;
|
CPU.SRAMModified = TRUE;
|
||||||
|
@ -730,7 +730,7 @@ inline void S9xSetPCBase (uint32 Address)
|
||||||
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
|
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
|
||||||
CPU.PCBase = NULL;
|
CPU.PCBase = NULL;
|
||||||
else
|
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;
|
return;
|
||||||
|
|
||||||
case CMemory::MAP_BWRAM:
|
case CMemory::MAP_BWRAM:
|
||||||
|
@ -786,7 +786,7 @@ inline uint8 * S9xGetBasePointer (uint32 Address)
|
||||||
case CMemory::MAP_HIROM_SRAM:
|
case CMemory::MAP_HIROM_SRAM:
|
||||||
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
|
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
|
||||||
return (NULL);
|
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:
|
case CMemory::MAP_BWRAM:
|
||||||
return (Memory.BWRAM - 0x6000 - (Address & 0x8000));
|
return (Memory.BWRAM - 0x6000 - (Address & 0x8000));
|
||||||
|
@ -831,7 +831,7 @@ inline uint8 * S9xGetMemPointer (uint32 Address)
|
||||||
case CMemory::MAP_HIROM_SRAM:
|
case CMemory::MAP_HIROM_SRAM:
|
||||||
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
|
if ((Memory.SRAMMask & MEMMAP_MASK) != MEMMAP_MASK)
|
||||||
return (NULL);
|
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:
|
case CMemory::MAP_BWRAM:
|
||||||
return (Memory.BWRAM - 0x6000 + (Address & 0x7fff));
|
return (Memory.BWRAM - 0x6000 + (Address & 0x7fff));
|
||||||
|
|
18
memmap.cpp
18
memmap.cpp
|
@ -1916,7 +1916,7 @@ void CMemory::ClearSRAM (bool8 onlyNonSavedSRAM)
|
||||||
if (!(Settings.SuperFX && ROMType < 0x15) && !(Settings.SA1 && ROMType == 0x34)) // can have SRAM
|
if (!(Settings.SuperFX && ROMType < 0x15) && !(Settings.SA1 && ROMType == 0x34)) // can have SRAM
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(SRAM, SNESGameFixes.SRAMInitialValue, 0x20000);
|
memset(SRAM, SNESGameFixes.SRAMInitialValue, sizeof(SRAM));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool8 CMemory::LoadSRAM (const char *filename)
|
bool8 CMemory::LoadSRAM (const char *filename)
|
||||||
|
@ -1951,15 +1951,17 @@ bool8 CMemory::LoadSRAM (const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0;
|
size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0;
|
||||||
if (size > 0x20000)
|
if (LoROM)
|
||||||
size = 0x20000;
|
size = size < 0x70000 ? size : 0x70000;
|
||||||
|
else if (HiROM)
|
||||||
|
size = size < 0x40000 ? size : 0x40000;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
file = fopen(sramName, "rb");
|
file = fopen(sramName, "rb");
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
len = fread((char *) SRAM, 1, 0x20000, file);
|
len = fread((char *) SRAM, 1, size, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if (len - size == 512)
|
if (len - size == 512)
|
||||||
memmove(SRAM, SRAM + 512, size);
|
memmove(SRAM, SRAM + 512, size);
|
||||||
|
@ -1983,7 +1985,7 @@ bool8 CMemory::LoadSRAM (const char *filename)
|
||||||
file = fopen(path, "rb");
|
file = fopen(path, "rb");
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
len = fread((char *) SRAM, 1, 0x20000, file);
|
len = fread((char *) SRAM, 1, size, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if (len - size == 512)
|
if (len - size == 512)
|
||||||
memmove(SRAM, SRAM + 512, size);
|
memmove(SRAM, SRAM + 512, size);
|
||||||
|
@ -2040,8 +2042,10 @@ bool8 CMemory::SaveSRAM (const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0;
|
size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0;
|
||||||
if (size > 0x20000)
|
if (LoROM)
|
||||||
size = 0x20000;
|
size = size < 0x70000 ? size : 0x70000;
|
||||||
|
else if (HiROM)
|
||||||
|
size = size < 0x40000 ? size : 0x40000;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1169,8 +1169,11 @@ void S9xNPSendSRAMToClient (int c)
|
||||||
uint8 sram [7];
|
uint8 sram [7];
|
||||||
int SRAMSize = Memory.SRAMSize ?
|
int SRAMSize = Memory.SRAMSize ?
|
||||||
(1 << (Memory.SRAMSize + 3)) * 128 : 0;
|
(1 << (Memory.SRAMSize + 3)) * 128 : 0;
|
||||||
if (SRAMSize > 0x10000)
|
if (Memory.LoROM)
|
||||||
SRAMSize = 0x10000;
|
SRAMSize = SRAMSize < 0x70000 ? SRAMSize : 0x70000;
|
||||||
|
else if (Memory.HiROM)
|
||||||
|
SRAMSize = SRAMSize < 0x40000 ? SRAMSize : 0x40000;
|
||||||
|
|
||||||
int len = 7 + SRAMSize;
|
int len = 7 + SRAMSize;
|
||||||
|
|
||||||
sprintf (NetPlay.ActionMsg, "SERVER: Sending S-RAM to player %d...", c + 1);
|
sprintf (NetPlay.ActionMsg, "SERVER: Sending S-RAM to player %d...", c + 1);
|
||||||
|
|
Loading…
Reference in New Issue