SGB CDL c# side; and fix SGB loading (broken by pwrap refactors)

This commit is contained in:
zeromus 2017-05-06 16:23:26 -05:00
parent 64e71415a3
commit c641e163f9
5 changed files with 62 additions and 39 deletions

View File

@ -104,6 +104,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public enum eCDLog_AddrType
{
CARTROM, CARTRAM, WRAM, APURAM,
SGB_CARTROM, SGB_CARTRAM, SGB_WRAM, SGB_HRAM,
NUM
};

View File

@ -61,7 +61,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public bool CMD_load_cartridge_super_game_boy(string rom_xml, byte[] rom_data, uint rom_size, byte[] dmg_data)
{
SetAscii(0, rom_xml, () =>
SetAscii(0, rom_xml ?? "", () =>
SetBytes(1, rom_data, () =>
SetBytes(2, dmg_data, () =>
{
@ -75,7 +75,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public bool CMD_load_cartridge_normal(byte[] rom_xml, byte[] rom_data)
{
//why don't we need this for the other loads? I dont know, our XML handling is really confusing
string xml = rom_xml == null ? null : System.Text.Encoding.ASCII.GetString(rom_xml);
SetAscii(0, xml ?? "", () =>
SetBytes(1, rom_data, () =>
{

View File

@ -130,7 +130,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public void QUERY_set_cdl(ICodeDataLog cdl)
{
for (int i = 0; i < 4; i++)
for (int i = 0; i < 8; i++)
{
comm->cdl_ptr[i] = 0;
comm->cdl_size[i] = 0;
@ -149,12 +149,29 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
comm->cdl_ptr[2] = cdl.GetPin("WRAM").ToInt64();
comm->cdl_size[2] = cdl["WRAM"].Length;
comm->cdl_ptr[2] = cdl.GetPin("APURAM").ToInt64();
comm->cdl_size[2] = cdl["APURAM"].Length;
comm->cdl_ptr[3] = cdl.GetPin("APURAM").ToInt64();
comm->cdl_size[3] = cdl["APURAM"].Length;
if (cdl.Has("SGB_CARTROM"))
{
comm->cdl_ptr[4] = cdl.GetPin("SGB_CARTROM").ToInt64();
comm->cdl_size[4] = cdl["SGB_CARTROM"].Length;
if (cdl.Has("SGB_CARTRAM"))
{
comm->cdl_ptr[5] = cdl.GetPin("SGB_CARTRAM").ToInt64();
comm->cdl_size[5] = cdl["SGB_CARTRAM"].Length;
}
comm->cdl_ptr[6] = cdl.GetPin("SGB_WRAM").ToInt64();
comm->cdl_size[6] = cdl["SGB_WRAM"].Length;
comm->cdl_ptr[7] = cdl.GetPin("SGB_HRAM").ToInt64();
comm->cdl_size[7] = cdl["SGB_HRAM"].Length;
}
}
Message(eMessage.eMessage_QUERY_set_cdl);
}
}

View File

@ -18,15 +18,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public void NewCDL(ICodeDataLog cdl)
{
cdl["CARTROM"] = new byte[_memoryDomains["CARTROM"].Size];
if (_memoryDomains.Has("CARTRAM"))
{
cdl["CARTRAM"] = new byte[_memoryDomains["CARTRAM"].Size];
}
cdl["WRAM"] = new byte[_memoryDomains["WRAM"].Size];
cdl["APURAM"] = new byte[_memoryDomains["APURAM"].Size];
if (_memoryDomains.Has("CARTRAM"))
cdl["CARTRAM"] = new byte[_memoryDomains["CARTRAM"].Size];
if (IsSGB)
{
cdl["SGB_CARTROM"] = new byte[_memoryDomains["SGB CARTROM"].Size];
cdl["SGB_HRAM"] = new byte[_memoryDomains["SGB HRAM"].Size];
cdl["SGB_WRAM"] = new byte[_memoryDomains["SGB WRAM"].Size];
if (_memoryDomains.Has("SGB_CARTRAM"))
cdl["SGB_CARTRAM"] = new byte[_memoryDomains["SGB CARTRAM"].Size];
}
cdl.SubType = "SNES";
cdl.SubVer = 0;
}

View File

@ -34,13 +34,36 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private void SetupMemoryDomains(byte[] romData, byte[] sgbRomData)
{
// lets just do this entirely differently for SGB
MakeMemoryDomain("WRAM", LibsnesApi.SNES_MEMORY.WRAM, MemoryDomain.Endian.Little);
MakeMemoryDomain("CARTROM", LibsnesApi.SNES_MEMORY.CARTRIDGE_ROM, MemoryDomain.Endian.Little, byteSize: 2); //there are signs this doesnt work on SGB?
MakeMemoryDomain("CARTRAM", LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("VRAM", LibsnesApi.SNES_MEMORY.VRAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("OAM", LibsnesApi.SNES_MEMORY.OAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("CGRAM", LibsnesApi.SNES_MEMORY.CGRAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("APURAM", LibsnesApi.SNES_MEMORY.APURAM, MemoryDomain.Endian.Little, byteSize: 2);
if (!DeterministicEmulation)
{
_memoryDomainList.Add(new MemoryDomainDelegate(
"System Bus",
0x1000000,
MemoryDomain.Endian.Little,
addr => Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr),
(addr, val) => Api.QUERY_poke(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr, val), wordSize: 2));
}
else
{
// limited function bus
MakeFakeBus();
}
if (IsSGB)
{
// NOTE: CGB has 32K of wram, and DMG has 8KB of wram. Not sure how to control this right now.. bsnes might not have any ready way of doign that? I couldnt spot it.
// You wouldnt expect a DMG game to access excess wram, but what if it tried to? maybe an oversight in bsnes?
MakeMemoryDomain("SGB WRAM", LibsnesApi.SNES_MEMORY.SGB_WRAM, MemoryDomain.Endian.Little);
//uhhh why can't this be done with MakeMemoryDomain? improve that.
var romDomain = new MemoryDomainByteArray("SGB CARTROM", MemoryDomain.Endian.Little, romData, true, 1);
_memoryDomainList.Add(romDomain);
@ -50,36 +73,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
MakeMemoryDomain("SGB CARTRAM", LibsnesApi.SNES_MEMORY.SGB_CARTRAM, MemoryDomain.Endian.Little);
MakeMemoryDomain("WRAM", LibsnesApi.SNES_MEMORY.WRAM, MemoryDomain.Endian.Little);
var sgbromDomain = new MemoryDomainByteArray("SGB.SFC ROM", MemoryDomain.Endian.Little, sgbRomData, true, 1);
_memoryDomainList.Add(sgbromDomain);
}
else
{
MakeMemoryDomain("WRAM", LibsnesApi.SNES_MEMORY.WRAM, MemoryDomain.Endian.Little);
MakeMemoryDomain("CARTROM", LibsnesApi.SNES_MEMORY.CARTRIDGE_ROM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("CARTRAM", LibsnesApi.SNES_MEMORY.CARTRIDGE_RAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("VRAM", LibsnesApi.SNES_MEMORY.VRAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("OAM", LibsnesApi.SNES_MEMORY.OAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("CGRAM", LibsnesApi.SNES_MEMORY.CGRAM, MemoryDomain.Endian.Little, byteSize: 2);
MakeMemoryDomain("APURAM", LibsnesApi.SNES_MEMORY.APURAM, MemoryDomain.Endian.Little, byteSize: 2);
if (!DeterministicEmulation)
{
_memoryDomainList.Add(new MemoryDomainDelegate(
"System Bus",
0x1000000,
MemoryDomain.Endian.Little,
addr => Api.QUERY_peek(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr),
(addr, val) => Api.QUERY_poke(LibsnesApi.SNES_MEMORY.SYSBUS, (uint)addr, val), wordSize: 2));
}
else
{
// limited function bus
MakeFakeBus();
}
}
_memoryDomains = new MemoryDomainList(_memoryDomainList);
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains);