natt forgot to ever hook up SGB saveram, so I took care of it

This commit is contained in:
zeromus 2016-11-11 19:25:38 -06:00
parent 5a48f952f4
commit f11ae17cfb
2 changed files with 13 additions and 2 deletions

View File

@ -57,6 +57,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public byte* QUERY_get_memory_data(SNES_MEMORY id)
{
string name = QUERY_MemoryNameForId(id);
if (!SharedMemoryBlocks.ContainsKey(name)) return null;
var smb = SharedMemoryBlocks[name];
return (byte*)smb.Ptr;
}

View File

@ -788,7 +788,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
get
{
return api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM) != 0;
return api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM) != 0 || api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM) != 0;
}
}
@ -796,6 +796,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
byte* buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
var size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
if (buf == null)
{
buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
}
var ret = new byte[size];
Marshal.Copy((IntPtr)buf, ret, 0, size);
return ret;
@ -811,10 +816,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public void StoreSaveRam(byte[] data)
{
byte* buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
var size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
if (buf == null)
{
buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
}
if (size == 0) return;
if (size != data.Length) throw new InvalidOperationException("Somehow, we got a mismatch between saveram size and what bsnes says the saveram size is");
byte* buf = api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM);
Marshal.Copy(data, 0, (IntPtr)buf, size);
}