Debugger: Fixed DBG import for NSFe files

This commit is contained in:
Sour 2018-08-20 20:12:34 -04:00
parent 4bbef43e99
commit 8c07d430c5
7 changed files with 21 additions and 7 deletions

View file

@ -163,6 +163,9 @@ RomData NsfLoader::LoadRom(vector<uint8_t>& romFile)
romData.PrgRom.insert(romData.PrgRom.end(), 4096 - (romData.PrgRom.size() % 4096), 0);
}
//NSF header size
romData.Info.FilePrgOffset = 0x80;
InitializeFromHeader(romData);
return romData;

View file

@ -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
}

View file

@ -69,6 +69,8 @@ struct RomInfo
bool IsInDatabase = false;
bool IsHeaderlessRom = false;
uint32_t FilePrgOffset = 0;
uint16_t MapperID = 0;
uint8_t SubMapperID = 0;

View file

@ -25,6 +25,9 @@ RomData iNesLoader::LoadRom(vector<uint8_t>& 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();

View file

@ -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);

View file

@ -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);
}

View file

@ -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;
}
}