From c641e163f92b8b5b05977a94a1c7d0dae8ac1574 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 6 May 2017 16:23:26 -0500 Subject: [PATCH] SGB CDL c# side; and fix SGB loading (broken by pwrap refactors) --- .../Consoles/Nintendo/SNES/LibsnesApi.cs | 1 + .../Consoles/Nintendo/SNES/LibsnesApi_CMD.cs | 4 +- .../Nintendo/SNES/LibsnesApi_QUERY.cs | 25 +++++++-- .../SNES/LibsnesCore.ICodeDataLogger.cs | 19 ++++--- .../SNES/LibsnesCore.IMemoryDomains.cs | 52 +++++++++---------- 5 files changed, 62 insertions(+), 39 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs index 69e584ddcc..8c4d69d4bb 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs @@ -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 }; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_CMD.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_CMD.cs index 72ca65187d..076a4752c5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_CMD.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_CMD.cs @@ -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, () => { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs index a107c4e545..07a86657e3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs @@ -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); - } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs index a181ee4e10..028a91a14d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs @@ -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; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IMemoryDomains.cs index be1249d563..b03c27c1c0 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IMemoryDomains.cs @@ -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(_memoryDomains);