SNES saveram: check for existance

checks if SGB saveram exists before attempting to assign it to the buffer pointer.

Also return null if no saveram is found, which conforms to what other cores are doing and what EMUHawk expects
This commit is contained in:
alyosha-tas 2017-06-16 08:50:28 -04:00 committed by GitHub
parent 4e1decfa21
commit 5b731cf8b8
1 changed files with 6 additions and 1 deletions

View File

@ -15,11 +15,16 @@ 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)
if (buf == null && Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM)>0)
{
buf = Api.QUERY_get_memory_data(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
size = Api.QUERY_get_memory_size(LibsnesApi.SNES_MEMORY.SGB_CARTRAM);
}
if (buf==null)
{
return null;
}
var ret = new byte[size];
Marshal.Copy((IntPtr)buf, ret, 0, size);