From f5807733420155f4acefc7889b6174168c1f5876 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 5 Dec 2020 21:56:11 -0500 Subject: [PATCH] add CARTROM-DB and CARTROM-D blocks to libsnes CDL --- .../Consoles/Nintendo/SNES/LibsnesApi.cs | 16 +++--- .../Nintendo/SNES/LibsnesApi_QUERY.cs | 54 +++++++++++++------ .../SNES/LibsnesCore.ICodeDataLogger.cs | 2 + waterbox/libsnes/bsnes/base/base.cpp | 9 ++++ waterbox/libsnes/bsnes/base/base.hpp | 11 ++-- .../bsnes/target-libsnes/libsnes_pwrap.cpp | 23 ++++---- 6 files changed, 75 insertions(+), 40 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs index dcae243be6..c350dcfc43 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi.cs @@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES { static LibsnesApi() { - if (sizeof(CommStruct) != 280) + if (sizeof(CommStruct) != 376) { throw new InvalidOperationException("sizeof(comm)"); } @@ -340,19 +340,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES [FieldOffset(128)] //bleck. this is a long so that it can be a 32/64bit pointer - public fixed long cdl_ptr[8]; - [FieldOffset(192)] - public fixed int cdl_size[8]; + public fixed long cdl_ptr[16]; + [FieldOffset(256)] + public fixed int cdl_size[16]; - [FieldOffset(224)] + [FieldOffset(320)] public CPURegs cpuregs; - [FieldOffset(260)] + [FieldOffset(356)] public LayerEnables layerEnables; - [FieldOffset(272)] + [FieldOffset(368)] //static configuration-type information which can be grabbed off the core at any time without even needing a QUERY command public SNES_REGION region; - [FieldOffset(276)] + [FieldOffset(372)] public SNES_MAPPER mapper; //utilities diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs index 81b39a5b1a..2a27eeabfe 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesApi_QUERY.cs @@ -158,7 +158,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES using (_exe.EnterExit()) { - for (int i = 0; i < 8; i++) + for (int i = 0; i < 16; i++) { _comm->cdl_ptr[i] = 0; _comm->cdl_size[i] = 0; @@ -166,37 +166,57 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES if (cdl != null) { - _comm->cdl_ptr[0] = cdl.GetPin("CARTROM").ToInt64(); - _comm->cdl_size[0] = cdl["CARTROM"].Length; + int zz = 0; + + _comm->cdl_ptr[zz] = cdl.GetPin("CARTROM").ToInt64(); + _comm->cdl_size[zz] = cdl["CARTROM"].Length; + zz++; + + _comm->cdl_ptr[zz] = cdl.GetPin("CARTROM-DB").ToInt64(); + _comm->cdl_size[zz] = cdl["CARTROM"].Length; + zz++; + + _comm->cdl_ptr[zz] = cdl.GetPin("CARTROM-D").ToInt64(); + _comm->cdl_size[zz] = cdl["CARTROM"].Length; + zz++; + if (cdl.Has("CARTRAM")) { - _comm->cdl_ptr[1] = cdl.GetPin("CARTRAM").ToInt64(); - _comm->cdl_size[1] = cdl["CARTRAM"].Length; + _comm->cdl_ptr[zz] = cdl.GetPin("CARTRAM").ToInt64(); + _comm->cdl_size[zz] = cdl["CARTRAM"].Length; } + zz++; - _comm->cdl_ptr[2] = cdl.GetPin("WRAM").ToInt64(); - _comm->cdl_size[2] = cdl["WRAM"].Length; + _comm->cdl_ptr[zz] = cdl.GetPin("WRAM").ToInt64(); + _comm->cdl_size[zz] = cdl["WRAM"].Length; + zz++; - _comm->cdl_ptr[3] = cdl.GetPin("APURAM").ToInt64(); - _comm->cdl_size[3] = cdl["APURAM"].Length; + _comm->cdl_ptr[zz] = cdl.GetPin("APURAM").ToInt64(); + _comm->cdl_size[zz] = cdl["APURAM"].Length; + zz++; if (cdl.Has("SGB_CARTROM")) { - _comm->cdl_ptr[4] = cdl.GetPin("SGB_CARTROM").ToInt64(); - _comm->cdl_size[4] = cdl["SGB_CARTROM"].Length; + _comm->cdl_ptr[zz] = cdl.GetPin("SGB_CARTROM").ToInt64(); + _comm->cdl_size[zz] = cdl["SGB_CARTROM"].Length; + zz++; 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[zz] = cdl.GetPin("SGB_CARTRAM").ToInt64(); + _comm->cdl_size[zz] = cdl["SGB_CARTRAM"].Length; } + zz++; - _comm->cdl_ptr[6] = cdl.GetPin("SGB_WRAM").ToInt64(); - _comm->cdl_size[6] = cdl["SGB_WRAM"].Length; + _comm->cdl_ptr[zz] = cdl.GetPin("SGB_WRAM").ToInt64(); + _comm->cdl_size[zz] = cdl["SGB_WRAM"].Length; + zz++; - _comm->cdl_ptr[7] = cdl.GetPin("SGB_HRAM").ToInt64(); - _comm->cdl_size[7] = cdl["SGB_HRAM"].Length; + _comm->cdl_ptr[zz] = cdl.GetPin("SGB_HRAM").ToInt64(); + _comm->cdl_size[zz] = cdl["SGB_HRAM"].Length; + zz++; } + else zz += 4; } _core.Message(eMessage.eMessage_QUERY_set_cdl); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs index e1cbb1d5ed..11a6b0cf08 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ICodeDataLogger.cs @@ -18,6 +18,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public void NewCDL(ICodeDataLog cdl) { cdl["CARTROM"] = new byte[_memoryDomains["CARTROM"].Size]; + cdl["CARTROM-DB"] = new byte[_memoryDomains["CARTROM"].Size]; + cdl["CARTROM-D"] = new byte[_memoryDomains["CARTROM"].Size*2]; cdl["WRAM"] = new byte[_memoryDomains["WRAM"].Size]; cdl["APURAM"] = new byte[_memoryDomains["APURAM"].Size]; diff --git a/waterbox/libsnes/bsnes/base/base.cpp b/waterbox/libsnes/bsnes/base/base.cpp index f2ff271d74..ccb246012c 100644 --- a/waterbox/libsnes/bsnes/base/base.cpp +++ b/waterbox/libsnes/bsnes/base/base.cpp @@ -1,3 +1,12 @@ #include "base.hpp" +#include "snes/snes.hpp" + CDLInfo cdlInfo; + +void CDLInfo::dorom(uint32_t addr) +{ + blocks[eCDLog_AddrType_CARTROM_DB][addr] = SNES::cpu.regs.db; + blocks[eCDLog_AddrType_CARTROM_D][addr*2+0] = SNES::cpu.regs.d; + blocks[eCDLog_AddrType_CARTROM_D][addr*2+1] = SNES::cpu.regs.d>>8; +} diff --git a/waterbox/libsnes/bsnes/base/base.hpp b/waterbox/libsnes/bsnes/base/base.hpp index 6f836a015a..b02db8abef 100644 --- a/waterbox/libsnes/bsnes/base/base.hpp +++ b/waterbox/libsnes/bsnes/base/base.hpp @@ -56,7 +56,7 @@ template struct hook { enum eCDLog_AddrType { - eCDLog_AddrType_CARTROM, eCDLog_AddrType_CARTRAM, eCDLog_AddrType_WRAM, eCDLog_AddrType_APURAM, + eCDLog_AddrType_CARTROM, eCDLog_AddrType_CARTROM_DB, eCDLog_AddrType_CARTROM_D, eCDLog_AddrType_CARTRAM, eCDLog_AddrType_WRAM, eCDLog_AddrType_APURAM, eCDLog_AddrType_SGB_CARTROM, eCDLog_AddrType_SGB_CARTRAM, eCDLog_AddrType_SGB_WRAM, eCDLog_AddrType_SGB_HRAM, eCDLog_AddrType_NUM }; @@ -76,15 +76,20 @@ enum eCDLog_Flags struct CDLInfo { eCDLog_Flags currFlags; - uint8_t* blocks[eCDLog_AddrType_NUM]; //[0]==nullptr -> disabled - uint32_t blockSizes[eCDLog_AddrType_NUM]; + uint8_t* blocks[16]; //[0]==nullptr -> disabled + uint32_t blockSizes[16]; void set(eCDLog_AddrType addrType, uint32_t addr) { if(!blocks[0]) return; if(addr >= blockSizes[addrType]) return; blocks[addrType][addr] |= currFlags; + if(addrType == eCDLog_AddrType_CARTROM) + { + dorom(addr); + } } + void dorom(uint32_t addr); }; extern CDLInfo cdlInfo; diff --git a/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp b/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp index 500abfc2c5..320bc959cc 100644 --- a/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp +++ b/waterbox/libsnes/bsnes/target-libsnes/libsnes_pwrap.cpp @@ -109,7 +109,7 @@ enum eStatus : int32 #endif struct CPURegsComm { u32 pc; - u16 a, x, y, z, s, d, vector; //7x + u16 a, x, y, s, d, vector; //7x u8 p, nothing; u32 aa, rd; u8 sp, dp, db, mdr; @@ -165,8 +165,8 @@ struct CommStruct int32 padding3; - int64 cdl_ptr[8]; - int32 cdl_size[8]; + int64 cdl_ptr[16]; + int32 cdl_size[16]; CPURegsComm cpuregs; LayerEnablesComm layerEnables; @@ -525,10 +525,9 @@ void QUERY_peek_cpu_regs() { comm.cpuregs.a = SNES::cpu.regs.a; comm.cpuregs.x = SNES::cpu.regs.x; comm.cpuregs.y = SNES::cpu.regs.y; - comm.cpuregs.z = SNES::cpu.regs.z; comm.cpuregs.s = SNES::cpu.regs.s; comm.cpuregs.d = SNES::cpu.regs.d; - comm.cpuregs.aa = (u32)SNES::cpu.aa; + //comm.cpuregs.aa = (u32)SNES::cpu.aa; comm.cpuregs.rd = (u32)SNES::cpu.rd; comm.cpuregs.sp = SNES::cpu.sp; comm.cpuregs.dp = SNES::cpu.dp; @@ -541,7 +540,7 @@ void QUERY_peek_cpu_regs() { comm.cpuregs.h = SNES::cpu.hdot(); } void QUERY_peek_set_cdl() { - for (int i = 0; i