Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions UI/Debugger/ViewModels/NesHeaderEditViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ public class NesHeaderEditViewModel : DisposableViewModel
[Reactive] public string ErrorMessage { get; private set; } = "";

private RomInfo _romInfo;
private byte[] _prgRom;
private byte[] _chrRom;

public NesHeaderEditViewModel()
{
bool releaseDebugger = !DebugWindowManager.HasOpenedDebugWindows();
bool paused = EmuApi.IsPaused();
byte[] headerBytes = DebugApi.GetRomHeader();
_prgRom = DebugApi.GetMemoryState(MemoryType.NesPrgRom);
_chrRom = DebugApi.GetMemoryState(MemoryType.NesChrRom);
if(releaseDebugger) {
//GetRomHeader will initialize the debugger - stop the debugger if no other debug window is opened
DebugApi.ReleaseDebugger();
Expand Down Expand Up @@ -150,16 +154,14 @@ private string GetErrorMessage()

public async Task<bool> Save(Window wnd)
{
string? filepath = await FileDialogHelper.SaveFile(Path.GetDirectoryName(_romInfo.RomPath), Path.GetFileName(_romInfo.RomPath), wnd, FileDialogHelper.NesExt);
string? filepath = await FileDialogHelper.SaveFile(Path.GetDirectoryName(_romInfo.RomPath), _romInfo.GetRomName(), wnd, FileDialogHelper.NesExt);
if(filepath != null) {
byte[]? data = FileHelper.ReadAllBytes(_romInfo.RomPath);
if(data != null) {
byte[] header = Header.ToBytes();
for(int i = 0; i < 16; i++) {
data[i] = header[i];
}
return FileHelper.WriteAllBytes(filepath, data);
}
byte[] data = new byte[_prgRom.Length + _chrRom.Length + 16];
byte[] header = Header.ToBytes();
Array.Copy(header, data, 16);
Array.Copy(_prgRom, 0, data, 16, _prgRom.Length);
Array.Copy(_chrRom, 0, data, 16 + _prgRom.Length, _chrRom.Length);
return FileHelper.WriteAllBytes(filepath, data);
}
return false;
}
Expand Down
Loading