mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-27 21:14:21 +01:00
Snes9x - Add support for mapping more than 128KByte SRAM (#975)
This commit is contained in:
parent
33d7a143cb
commit
514d6c88ff
@ -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));
|
||||||
|
@ -1947,7 +1947,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)
|
||||||
@ -1982,15 +1982,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);
|
||||||
@ -2014,7 +2016,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);
|
||||||
@ -2071,8 +2073,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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user