Debugger: Fixed crash when using event viewer in PAL mode

This commit is contained in:
Sour 2019-10-08 21:04:32 -04:00
parent f2f692e984
commit 60a8abcbd5
12 changed files with 37 additions and 24 deletions

1
.github/FUNDING.yml vendored Normal file
View file

@ -0,0 +1 @@
patreon: Mesen

View file

@ -334,6 +334,7 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom)
return true; return true;
} }
MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName());
return false; return false;
} }

View file

@ -142,13 +142,13 @@ void EventManager::DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t
int iMax = drawBackground ? 3 : 1; int iMax = drawBackground ? 3 : 1;
int jMin = drawBackground ? -2 : 0; int jMin = drawBackground ? -2 : 0;
int jMax = drawBackground ? 3 : 1; int jMax = drawBackground ? 3 : 1;
uint32_t y = std::min(evt.Scanline * 2, 262 * 2); uint32_t y = std::min<uint32_t>(evt.Scanline * 2, _scanlineCount * 2);
uint32_t x = evt.Cycle * 2; uint32_t x = evt.Cycle * 2;
for(int i = iMin; i <= iMax; i++) { for(int i = iMin; i <= iMax; i++) {
for(int j = jMin; j <= jMax; j++) { for(int j = jMin; j <= jMax; j++) {
int32_t pos = (y + i) * 340 * 2 + x + j; int32_t pos = (y + i) * 340 * 2 + x + j;
if(pos < 0 || pos > 340 * 2 * 262 * 2) { if(pos < 0 || pos >= 340 * 2 * _scanlineCount * 2) {
continue; continue;
} }
buffer[pos] = color; buffer[pos] = color;
@ -156,7 +156,7 @@ void EventManager::DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t
} }
} }
void EventManager::TakeEventSnapshot(EventViewerDisplayOptions options) uint32_t EventManager::TakeEventSnapshot(EventViewerDisplayOptions options)
{ {
DebugBreakHelper breakHelper(_debugger); DebugBreakHelper breakHelper(_debugger);
auto lock = _lock.AcquireSafe(); auto lock = _lock.AcquireSafe();
@ -180,6 +180,9 @@ void EventManager::TakeEventSnapshot(EventViewerDisplayOptions options)
} }
} }
} }
_scanlineCount = _ppu->GetVblankEndScanline() + 1;
return _scanlineCount;
} }
void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions options) void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions options)
@ -187,7 +190,7 @@ void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions
auto lock = _lock.AcquireSafe(); auto lock = _lock.AcquireSafe();
_sentEvents.clear(); _sentEvents.clear();
for(int i = 0; i < 340 * 2 * 262 * 2; i++) { for(int i = 0; i < 340 * 2 * _scanlineCount * 2; i++) {
buffer[i] = 0xFF555555; buffer[i] = 0xFF555555;
} }

View file

@ -29,6 +29,7 @@ private:
bool _overscanMode = false; bool _overscanMode = false;
bool _useHighResOutput = false; bool _useHighResOutput = false;
uint32_t _scanlineCount = 262;
uint16_t *_ppuBuffer; uint16_t *_ppuBuffer;
void DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer, EventViewerDisplayOptions &options); void DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer, EventViewerDisplayOptions &options);
@ -44,7 +45,7 @@ public:
uint32_t GetEventCount(bool getPreviousFrameData); uint32_t GetEventCount(bool getPreviousFrameData);
void ClearFrameEvents(); void ClearFrameEvents();
void TakeEventSnapshot(EventViewerDisplayOptions options); uint32_t TakeEventSnapshot(EventViewerDisplayOptions options);
void GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions options); void GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions options);
DebugEventInfo GetEvent(uint16_t scanline, uint16_t cycle, EventViewerDisplayOptions &options); DebugEventInfo GetEvent(uint16_t scanline, uint16_t cycle, EventViewerDisplayOptions &options);
}; };

View file

@ -401,6 +401,10 @@ bool Ppu::ProcessEndOfScanline(uint16_t hClock)
if(_scanline == 0) { if(_scanline == 0) {
_mosaicScanlineCounter = _mosaicEnabled ? _mosaicSize + 1 : 0; _mosaicScanlineCounter = _mosaicEnabled ? _mosaicSize + 1 : 0;
if(!_skipRender) {
//If we're not skipping this frame, reset the high resolution flag
_useHighResOutput = false;
}
} }
if(_mosaicScanlineCounter) { if(_mosaicScanlineCounter) {
@ -483,10 +487,6 @@ bool Ppu::ProcessEndOfScanline(uint16_t hClock)
(_settings->GetEmulationSpeed() == 0 || _settings->GetEmulationSpeed() > 150) && (_settings->GetEmulationSpeed() == 0 || _settings->GetEmulationSpeed() > 150) &&
_frameSkipTimer.GetElapsedMS() < 10 _frameSkipTimer.GetElapsedMS() < 10
); );
if(!_skipRender) {
//If we're not skipping this frame, reset the high resolution flag
_useHighResOutput = false;
}
//Update overclock timings once per frame //Update overclock timings once per frame
UpdateNmiScanline(); UpdateNmiScanline();
@ -564,6 +564,11 @@ uint16_t Ppu::GetRealScanline()
return _scanline; return _scanline;
} }
uint16_t Ppu::GetVblankEndScanline()
{
return _vblankEndScanline;
}
uint16_t Ppu::GetLastScanline() uint16_t Ppu::GetLastScanline()
{ {
return _baseVblankEndScanline; return _baseVblankEndScanline;

View file

@ -262,6 +262,7 @@ public:
uint32_t GetFrameCount(); uint32_t GetFrameCount();
uint16_t GetRealScanline(); uint16_t GetRealScanline();
uint16_t GetVblankEndScanline();
uint16_t GetScanline(); uint16_t GetScanline();
uint16_t GetCycle(); uint16_t GetCycle();
uint16_t GetNmiScanline(); uint16_t GetNmiScanline();

View file

@ -90,7 +90,7 @@ extern "C"
DllExport uint32_t __stdcall GetDebugEventCount(bool getPreviousFrameData) { return GetDebugger()->GetEventManager()->GetEventCount(getPreviousFrameData); } DllExport uint32_t __stdcall GetDebugEventCount(bool getPreviousFrameData) { return GetDebugger()->GetEventManager()->GetEventCount(getPreviousFrameData); }
DllExport void __stdcall GetEventViewerOutput(uint32_t *buffer, EventViewerDisplayOptions options) { GetDebugger()->GetEventManager()->GetDisplayBuffer(buffer, options); } DllExport void __stdcall GetEventViewerOutput(uint32_t *buffer, EventViewerDisplayOptions options) { GetDebugger()->GetEventManager()->GetDisplayBuffer(buffer, options); }
DllExport DebugEventInfo __stdcall GetEventViewerEvent(uint16_t scanline, uint16_t cycle, EventViewerDisplayOptions options) { return GetDebugger()->GetEventManager()->GetEvent(scanline, cycle, options); } DllExport DebugEventInfo __stdcall GetEventViewerEvent(uint16_t scanline, uint16_t cycle, EventViewerDisplayOptions options) { return GetDebugger()->GetEventManager()->GetEvent(scanline, cycle, options); }
DllExport void __stdcall TakeEventSnapshot(EventViewerDisplayOptions options) { GetDebugger()->GetEventManager()->TakeEventSnapshot(options); } DllExport uint32_t __stdcall TakeEventSnapshot(EventViewerDisplayOptions options) { return GetDebugger()->GetEventManager()->TakeEventSnapshot(options); }
DllExport int32_t __stdcall LoadScript(char* name, char* content, int32_t scriptId) { return GetDebugger()->GetScriptManager()->LoadScript(name, content, scriptId); } DllExport int32_t __stdcall LoadScript(char* name, char* content, int32_t scriptId) { return GetDebugger()->GetScriptManager()->LoadScript(name, content, scriptId); }
DllExport void __stdcall RemoveScript(int32_t scriptId) { GetDebugger()->GetScriptManager()->RemoveScript(scriptId); } DllExport void __stdcall RemoveScript(int32_t scriptId) { GetDebugger()->GetScriptManager()->RemoveScript(scriptId); }

View file

@ -106,7 +106,7 @@ extern "C" {
} }
} }
DllExport void __stdcall LoadRom(char* filename, char* patchFile) { _console->LoadRom((VirtualFile)filename, patchFile ? (VirtualFile)patchFile : VirtualFile()); } DllExport bool __stdcall LoadRom(char* filename, char* patchFile) { return _console->LoadRom((VirtualFile)filename, patchFile ? (VirtualFile)patchFile : VirtualFile()); }
//DllExport void __stdcall AddKnownGameFolder(char* folder) { FolderUtilities::AddKnownGameFolder(folder); } //DllExport void __stdcall AddKnownGameFolder(char* folder) { FolderUtilities::AddKnownGameFolder(folder); }
DllExport void __stdcall GetRomInfo(InteropRomInfo &info) DllExport void __stdcall GetRomInfo(InteropRomInfo &info)

View file

@ -19,7 +19,6 @@ namespace Mesen.GUI.Debugger
public partial class ctrlEventViewerPpuView : BaseControl public partial class ctrlEventViewerPpuView : BaseControl
{ {
private int _baseWidth = 340 * 2; private int _baseWidth = 340 * 2;
private int _baseHeight = 262 * 2;
private EntityBinder _entityBinder = new EntityBinder(); private EntityBinder _entityBinder = new EntityBinder();
private Point _lastPos = new Point(-1, -1); private Point _lastPos = new Point(-1, -1);
@ -29,6 +28,7 @@ namespace Mesen.GUI.Debugger
private Bitmap _displayBitmap = null; private Bitmap _displayBitmap = null;
private byte[] _pictureData = null; private byte[] _pictureData = null;
private Font _overlayFont; private Font _overlayFont;
private UInt32 _scanlineCount = 262;
public int ImageScale { get { return picViewer.ImageScale; } set { picViewer.ImageScale = value; } } public int ImageScale { get { return picViewer.ImageScale; } set { picViewer.ImageScale = value; } }
@ -105,16 +105,16 @@ namespace Mesen.GUI.Debugger
})); }));
EventViewerDisplayOptions options = ConfigManager.Config.Debug.EventViewer.GetInteropOptions(); EventViewerDisplayOptions options = ConfigManager.Config.Debug.EventViewer.GetInteropOptions();
DebugApi.TakeEventSnapshot(options); _scanlineCount = DebugApi.TakeEventSnapshot(options);
} }
public void RefreshViewer() public void RefreshViewer()
{ {
_entityBinder.UpdateObject(); _entityBinder.UpdateObject();
EventViewerDisplayOptions options = ConfigManager.Config.Debug.EventViewer.GetInteropOptions(); EventViewerDisplayOptions options = ConfigManager.Config.Debug.EventViewer.GetInteropOptions();
_pictureData = DebugApi.GetEventViewerOutput(options); _pictureData = DebugApi.GetEventViewerOutput(_scanlineCount, options);
int picHeight = _baseHeight; int picHeight = (int)_scanlineCount*2;
if(_screenBitmap == null || _screenBitmap.Height != picHeight) { if(_screenBitmap == null || _screenBitmap.Height != picHeight) {
_screenBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb); _screenBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb);
_overlayBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb); _overlayBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb);
@ -123,7 +123,7 @@ namespace Mesen.GUI.Debugger
GCHandle handle = GCHandle.Alloc(this._pictureData, GCHandleType.Pinned); GCHandle handle = GCHandle.Alloc(this._pictureData, GCHandleType.Pinned);
try { try {
Bitmap source = new Bitmap(_baseWidth, _baseHeight, _baseWidth*4, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject()); Bitmap source = new Bitmap(_baseWidth, (int)_scanlineCount*2, _baseWidth*4, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject());
using(Graphics g = Graphics.FromImage(_screenBitmap)) { using(Graphics g = Graphics.FromImage(_screenBitmap)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
@ -164,7 +164,7 @@ namespace Mesen.GUI.Debugger
} }
} }
picViewer.ImageSize = new Size(_baseWidth, _baseHeight); picViewer.ImageSize = new Size(_baseWidth, (int)_scanlineCount*2);
picViewer.Image = _displayBitmap; picViewer.Image = _displayBitmap;
_needUpdate = false; _needUpdate = false;
} }

View file

@ -34,9 +34,10 @@ namespace Mesen.GUI.Emulation
} }
_romPath = romPath; _romPath = romPath;
EmuApi.LoadRom(romPath, patchPath); if(EmuApi.LoadRom(romPath, patchPath)) {
ConfigManager.Config.RecentFiles.AddRecentFile(romPath, patchPath); ConfigManager.Config.RecentFiles.AddRecentFile(romPath, patchPath);
StartEmulation(); StartEmulation();
}
} }
public static void LoadPatchFile(string patchFile) public static void LoadPatchFile(string patchFile)

View file

@ -108,12 +108,12 @@ namespace Mesen.GUI
} }
[DllImport(DllPath)] public static extern DebugEventInfo GetEventViewerEvent(UInt16 scanline, UInt16 cycle, EventViewerDisplayOptions options); [DllImport(DllPath)] public static extern DebugEventInfo GetEventViewerEvent(UInt16 scanline, UInt16 cycle, EventViewerDisplayOptions options);
[DllImport(DllPath)] public static extern void TakeEventSnapshot(EventViewerDisplayOptions options); [DllImport(DllPath)] public static extern UInt32 TakeEventSnapshot(EventViewerDisplayOptions options);
[DllImport(DllPath, EntryPoint = "GetEventViewerOutput")] private static extern void GetEventViewerOutputWrapper([In, Out]byte[] buffer, EventViewerDisplayOptions options); [DllImport(DllPath, EntryPoint = "GetEventViewerOutput")] private static extern void GetEventViewerOutputWrapper([In, Out]byte[] buffer, EventViewerDisplayOptions options);
public static byte[] GetEventViewerOutput(EventViewerDisplayOptions options) public static byte[] GetEventViewerOutput(UInt32 scanlineCount, EventViewerDisplayOptions options)
{ {
byte[] buffer = new byte[340*2 * 262*2 * 4]; byte[] buffer = new byte[340*2 * scanlineCount*2 * 4];
DebugApi.GetEventViewerOutputWrapper(buffer, options); DebugApi.GetEventViewerOutputWrapper(buffer, options);
return buffer; return buffer;
} }

View file

@ -46,7 +46,7 @@ namespace Mesen.GUI
[DllImport(DllPath)] public static extern void TakeScreenshot(); [DllImport(DllPath)] public static extern void TakeScreenshot();
[DllImport(DllPath)] public static extern void LoadRom( [DllImport(DllPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool LoadRom(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filepath, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string filepath,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string patchFile = "" [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]string patchFile = ""
); );