diff --git a/Core/NsfLoader.cpp b/Core/NsfLoader.cpp index 55789efc..1a91185a 100644 --- a/Core/NsfLoader.cpp +++ b/Core/NsfLoader.cpp @@ -163,6 +163,9 @@ RomData NsfLoader::LoadRom(vector& romFile) romData.PrgRom.insert(romData.PrgRom.end(), 4096 - (romData.PrgRom.size() % 4096), 0); } + //NSF header size + romData.Info.FilePrgOffset = 0x80; + InitializeFromHeader(romData); return romData; diff --git a/Core/NsfeLoader.h b/Core/NsfeLoader.h index 04440862..f7f140c9 100644 --- a/Core/NsfeLoader.h +++ b/Core/NsfeLoader.h @@ -77,7 +77,7 @@ private: return ss.str(); } - bool ReadChunk(uint8_t* &data, uint8_t* dataEnd, RomData& romData) + bool ReadChunk(uint8_t* &data, uint8_t* dataEnd, RomData& romData, uint8_t* fileStart) { if(data + 4 > dataEnd) { return false; @@ -110,6 +110,7 @@ private: //Adjust to match NSF spec header.StartingSong++; } else if(fourCC.compare("DATA") == 0) { + romData.Info.FilePrgOffset = (int32_t)(data - fileStart); //Pad start of file to make the first block start at a multiple of 4k romData.PrgRom.insert(romData.PrgRom.end(), header.LoadAddress % 4096, 0); @@ -189,6 +190,7 @@ public: romData.Info.Format = RomFormat::Nsf; + uint8_t* fileStart = romFile.data(); uint8_t* data = romFile.data() + 4; uint8_t* endOfData = romFile.data() + romFile.size(); @@ -198,7 +200,7 @@ public: //Will be set to false when we read NEND block romData.Error = true; - while(ReadChunk(data, endOfData, romData)) { + while(ReadChunk(data, endOfData, romData, fileStart)) { //Read all chunks } diff --git a/Core/RomData.h b/Core/RomData.h index aefcba28..caa0b5c6 100644 --- a/Core/RomData.h +++ b/Core/RomData.h @@ -69,6 +69,8 @@ struct RomInfo bool IsInDatabase = false; bool IsHeaderlessRom = false; + uint32_t FilePrgOffset = 0; + uint16_t MapperID = 0; uint8_t SubMapperID = 0; diff --git a/Core/iNesLoader.cpp b/Core/iNesLoader.cpp index 52d1bf48..4a93d9a5 100644 --- a/Core/iNesLoader.cpp +++ b/Core/iNesLoader.cpp @@ -25,6 +25,9 @@ RomData iNesLoader::LoadRom(vector& romFile, NESHeader *preloadedHeader romData.Info.Format = RomFormat::iNes; + //NSF header size + romData.Info.FilePrgOffset = sizeof(NESHeader); + romData.Info.IsNes20Header = (header.GetRomHeaderVersion() == RomHeaderVersion::Nes2_0); romData.Info.MapperID = header.GetMapperID(); romData.Info.SubMapperID = header.GetSubMapper(); diff --git a/GUI.NET/Debugger/DbgImporter.cs b/GUI.NET/Debugger/DbgImporter.cs index 5b9371f4..c77586e8 100644 --- a/GUI.NET/Debugger/DbgImporter.cs +++ b/GUI.NET/Debugger/DbgImporter.cs @@ -428,11 +428,8 @@ namespace Mesen.GUI.Debugger public void Import(string path, bool silent = false) { - if(InteropEmu.IsNsf()) { - _headerSize = 0x80; - } else { - _headerSize = 0x10; - } + RomInfo romInfo = InteropEmu.GetRomInfo(); + _headerSize = (int)romInfo.FilePrgOffset; string[] fileRows = File.ReadAllLines(path); diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index b009eeb2..66f31ca6 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -1670,6 +1670,7 @@ namespace Mesen.GUI public bool IsChrRam; public UInt16 MapperId; + public UInt32 FilePrgOffset; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)] public byte[] Sha1; @@ -1692,6 +1693,7 @@ namespace Mesen.GUI public RomFormat Format; public bool IsChrRam; public UInt16 MapperId; + public UInt32 FilePrgOffset; public string Sha1; public RomInfo(InteropRomInfo romInfo) @@ -1702,6 +1704,7 @@ namespace Mesen.GUI this.Format = romInfo.Format; this.IsChrRam = romInfo.IsChrRam; this.MapperId = romInfo.MapperId; + this.FilePrgOffset = romInfo.FilePrgOffset; this.Sha1 = Encoding.UTF8.GetString(romInfo.Sha1); } diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index d947b7ad..2b15b958 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -112,6 +112,7 @@ namespace InteropEmu { RomFormat Format; bool IsChrRam; uint16_t MapperId; + uint32_t FilePrgOffset; char Sha1[40]; }; @@ -396,6 +397,7 @@ namespace InteropEmu { interopRomInfo.Format = romInfo.Format; interopRomInfo.IsChrRam = romInfo.HasChrRam; interopRomInfo.MapperId = romInfo.MapperID; + interopRomInfo.FilePrgOffset = romInfo.FilePrgOffset; if(romInfo.Hash.Sha1.size() == 40) { memcpy(interopRomInfo.Sha1, romInfo.Hash.Sha1.c_str(), 40); } @@ -410,6 +412,7 @@ namespace InteropEmu { interopRomInfo.PrgCrc32 = romData.Info.Hash.PrgCrc32; interopRomInfo.Format = RomFormat::Unknown; interopRomInfo.IsChrRam = romData.ChrRom.size() == 0; + interopRomInfo.FilePrgOffset = romData.Info.FilePrgOffset; interopRomInfo.MapperId = 0; if(romData.Info.Hash.Sha1.size() == 40) { memcpy(interopRomInfo.Sha1, romData.Info.Hash.Sha1.c_str(), 40); @@ -421,6 +424,7 @@ namespace InteropEmu { interopRomInfo.PrgCrc32 = 0; interopRomInfo.Format = RomFormat::Unknown; interopRomInfo.IsChrRam = false; + interopRomInfo.FilePrgOffset = 0; interopRomInfo.MapperId = 0; } }