Debugger: GB - Allow saving rom modifications as .gb or .ips files
This commit is contained in:
parent
704598212a
commit
bdecd6270b
6 changed files with 52 additions and 8 deletions
|
@ -313,6 +313,19 @@ RomInfo BaseCartridge::GetRomInfo()
|
|||
return info;
|
||||
}
|
||||
|
||||
vector<uint8_t> BaseCartridge::GetOriginalPrgRom()
|
||||
{
|
||||
RomInfo romInfo = GetRomInfo();
|
||||
shared_ptr<BaseCartridge> originalCart = BaseCartridge::CreateCartridge(_console, romInfo.RomFile, romInfo.PatchFile);
|
||||
if(originalCart->_gameboy) {
|
||||
uint8_t* orgPrgRom = originalCart->_gameboy->DebugGetMemory(SnesMemoryType::GbPrgRom);
|
||||
uint32_t orgRomSize = originalCart->_gameboy->DebugGetMemorySize(SnesMemoryType::GbPrgRom);
|
||||
return vector<uint8_t>(orgPrgRom, orgPrgRom + orgRomSize);
|
||||
} else {
|
||||
return vector<uint8_t>(originalCart->DebugGetPrgRom(), originalCart->DebugGetPrgRom() + originalCart->DebugGetPrgRomSize());
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BaseCartridge::GetCrc32()
|
||||
{
|
||||
if(_gameboy) {
|
||||
|
@ -594,6 +607,7 @@ bool BaseCartridge::LoadGameboy(VirtualFile &romFile)
|
|||
}
|
||||
|
||||
_cartInfo = { };
|
||||
_headerOffset = Gameboy::HeaderOffset;
|
||||
_coprocessorType = CoprocessorType::Gameboy;
|
||||
SetupCpuHalt();
|
||||
return true;
|
||||
|
|
|
@ -90,6 +90,7 @@ public:
|
|||
void Init(MemoryMappings &mm);
|
||||
|
||||
RomInfo GetRomInfo();
|
||||
vector<uint8_t> GetOriginalPrgRom();
|
||||
ConsoleRegion GetRegion();
|
||||
uint32_t GetCrc32();
|
||||
string GetSha1Hash();
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "AluMulDiv.h"
|
||||
#include "Assembler.h"
|
||||
#include "GbAssembler.h"
|
||||
#include "GameboyHeader.h"
|
||||
#include "../Utilities/HexUtilities.h"
|
||||
#include "../Utilities/FolderUtilities.h"
|
||||
#include "../Utilities/IpsPatcher.h"
|
||||
|
@ -621,18 +622,32 @@ void Debugger::SetBreakpoints(Breakpoint breakpoints[], uint32_t length)
|
|||
|
||||
void Debugger::SaveRomToDisk(string filename, bool saveAsIps, CdlStripOption stripOption)
|
||||
{
|
||||
RomInfo romInfo = _cart->GetRomInfo();
|
||||
vector<uint8_t> rom(_cart->DebugGetPrgRom(), _cart->DebugGetPrgRom() + _cart->DebugGetPrgRomSize());
|
||||
vector<uint8_t> output;
|
||||
RomInfo romInfo = _cart->GetRomInfo();
|
||||
Gameboy* gb = _cart->GetGameboy();
|
||||
|
||||
vector<uint8_t> rom;
|
||||
if(gb) {
|
||||
uint8_t* prgRom = gb->DebugGetMemory(SnesMemoryType::GbPrgRom);
|
||||
uint32_t prgRomSize = gb->DebugGetMemorySize(SnesMemoryType::GbPrgRom);
|
||||
rom = vector<uint8_t>(prgRom, prgRom+prgRomSize);
|
||||
} else {
|
||||
rom = vector<uint8_t>(_cart->DebugGetPrgRom(), _cart->DebugGetPrgRom() + _cart->DebugGetPrgRomSize());
|
||||
}
|
||||
|
||||
if(saveAsIps) {
|
||||
shared_ptr<BaseCartridge> originalCart = BaseCartridge::CreateCartridge(_console.get(), romInfo.RomFile, romInfo.PatchFile);
|
||||
vector<uint8_t> originalRom(originalCart->DebugGetPrgRom(), originalCart->DebugGetPrgRom() + originalCart->DebugGetPrgRomSize());
|
||||
output = IpsPatcher::CreatePatch(originalRom, rom);
|
||||
output = IpsPatcher::CreatePatch(_cart->GetOriginalPrgRom(), rom);
|
||||
} else {
|
||||
if(stripOption != CdlStripOption::StripNone) {
|
||||
GetCodeDataLogger()->StripData(rom.data(), stripOption);
|
||||
//Preserve SNES rom header regardless of CDL file contents
|
||||
memcpy(rom.data()+romInfo.HeaderOffset, &romInfo.Header, sizeof(SnesCartInformation));
|
||||
|
||||
//Preserve rom header regardless of CDL file contents
|
||||
if(gb) {
|
||||
GameboyHeader header = gb->GetHeader();
|
||||
memcpy(rom.data() + romInfo.HeaderOffset, &header, sizeof(GameboyHeader));
|
||||
} else {
|
||||
memcpy(rom.data() + romInfo.HeaderOffset, &romInfo.Header, sizeof(SnesCartInformation));
|
||||
}
|
||||
}
|
||||
output = rom;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ Gameboy* Gameboy::Create(Console* console, VirtualFile &romFile)
|
|||
romFile.ReadFile(romData);
|
||||
|
||||
GameboyHeader header;
|
||||
memcpy(&header, romData.data() + 0x134, sizeof(GameboyHeader));
|
||||
memcpy(&header, romData.data() + Gameboy::HeaderOffset, sizeof(GameboyHeader));
|
||||
|
||||
MessageManager::Log("-----------------------------");
|
||||
MessageManager::Log("File: " + romFile.GetFileName());
|
||||
|
@ -257,6 +257,13 @@ int32_t Gameboy::GetRelativeAddress(AddressInfo& absAddress)
|
|||
return -1;
|
||||
}
|
||||
|
||||
GameboyHeader Gameboy::GetHeader()
|
||||
{
|
||||
GameboyHeader header;
|
||||
memcpy(&header, _prgRom + Gameboy::HeaderOffset, sizeof(GameboyHeader));
|
||||
return header;
|
||||
}
|
||||
|
||||
bool Gameboy::IsCgb()
|
||||
{
|
||||
return _cgbMode;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "DebugTypes.h"
|
||||
#include "GameboyHeader.h"
|
||||
#include "../Utilities/ISerializable.h"
|
||||
|
||||
class Console;
|
||||
|
@ -52,6 +53,8 @@ private:
|
|||
uint32_t _bootRomSize = 0;
|
||||
|
||||
public:
|
||||
static constexpr int HeaderOffset = 0x134;
|
||||
|
||||
static Gameboy* Create(Console* console, VirtualFile& romFile);
|
||||
virtual ~Gameboy();
|
||||
|
||||
|
@ -66,6 +69,7 @@ public:
|
|||
GbPpu* GetPpu();
|
||||
GbCpu* GetCpu();
|
||||
GbState GetState();
|
||||
GameboyHeader GetHeader();
|
||||
|
||||
uint32_t DebugGetMemorySize(SnesMemoryType type);
|
||||
uint8_t* DebugGetMemory(SnesMemoryType type);
|
||||
|
|
|
@ -741,6 +741,9 @@ namespace Mesen.GUI.Debugger
|
|||
if(saveAsIps) {
|
||||
sfd.SetFilter("IPS files (*.ips)|*.ips");
|
||||
sfd.FileName = EmuApi.GetRomInfo().GetRomName() + ".ips";
|
||||
} else if(_cpuType == CpuType.Gameboy) {
|
||||
sfd.SetFilter("GB files (*.gb,*.gbc)|*.gb;*.gbc");
|
||||
sfd.FileName = EmuApi.GetRomInfo().GetRomName() + "_Modified.gb";
|
||||
} else {
|
||||
sfd.SetFilter("SFC files (*.sfc)|*.sfc");
|
||||
sfd.FileName = EmuApi.GetRomInfo().GetRomName() + "_Modified.sfc";
|
||||
|
|
Loading…
Add table
Reference in a new issue