diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..0f77cb1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: Mesen \ No newline at end of file diff --git a/Core/Console.cpp b/Core/Console.cpp index 986daa5..3e3f4a1 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -334,6 +334,7 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom) return true; } + MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName()); return false; } diff --git a/Core/EventManager.cpp b/Core/EventManager.cpp index 544b619..84218da 100644 --- a/Core/EventManager.cpp +++ b/Core/EventManager.cpp @@ -142,13 +142,13 @@ void EventManager::DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t int iMax = drawBackground ? 3 : 1; int jMin = drawBackground ? -2 : 0; int jMax = drawBackground ? 3 : 1; - uint32_t y = std::min(evt.Scanline * 2, 262 * 2); + uint32_t y = std::min(evt.Scanline * 2, _scanlineCount * 2); uint32_t x = evt.Cycle * 2; for(int i = iMin; i <= iMax; i++) { for(int j = jMin; j <= jMax; 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; } 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); 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) @@ -187,7 +190,7 @@ void EventManager::GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions auto lock = _lock.AcquireSafe(); _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; } diff --git a/Core/EventManager.h b/Core/EventManager.h index db72f5c..7800c92 100644 --- a/Core/EventManager.h +++ b/Core/EventManager.h @@ -29,6 +29,7 @@ private: bool _overscanMode = false; bool _useHighResOutput = false; + uint32_t _scanlineCount = 262; uint16_t *_ppuBuffer; void DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer, EventViewerDisplayOptions &options); @@ -44,7 +45,7 @@ public: uint32_t GetEventCount(bool getPreviousFrameData); void ClearFrameEvents(); - void TakeEventSnapshot(EventViewerDisplayOptions options); + uint32_t TakeEventSnapshot(EventViewerDisplayOptions options); void GetDisplayBuffer(uint32_t *buffer, EventViewerDisplayOptions options); DebugEventInfo GetEvent(uint16_t scanline, uint16_t cycle, EventViewerDisplayOptions &options); }; diff --git a/Core/Ppu.cpp b/Core/Ppu.cpp index a4dd28a..5b817ba 100644 --- a/Core/Ppu.cpp +++ b/Core/Ppu.cpp @@ -401,6 +401,10 @@ bool Ppu::ProcessEndOfScanline(uint16_t hClock) if(_scanline == 0) { _mosaicScanlineCounter = _mosaicEnabled ? _mosaicSize + 1 : 0; + if(!_skipRender) { + //If we're not skipping this frame, reset the high resolution flag + _useHighResOutput = false; + } } if(_mosaicScanlineCounter) { @@ -483,10 +487,6 @@ bool Ppu::ProcessEndOfScanline(uint16_t hClock) (_settings->GetEmulationSpeed() == 0 || _settings->GetEmulationSpeed() > 150) && _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 UpdateNmiScanline(); @@ -564,6 +564,11 @@ uint16_t Ppu::GetRealScanline() return _scanline; } +uint16_t Ppu::GetVblankEndScanline() +{ + return _vblankEndScanline; +} + uint16_t Ppu::GetLastScanline() { return _baseVblankEndScanline; diff --git a/Core/Ppu.h b/Core/Ppu.h index 42a37bc..703ad73 100644 --- a/Core/Ppu.h +++ b/Core/Ppu.h @@ -262,6 +262,7 @@ public: uint32_t GetFrameCount(); uint16_t GetRealScanline(); + uint16_t GetVblankEndScanline(); uint16_t GetScanline(); uint16_t GetCycle(); uint16_t GetNmiScanline(); diff --git a/InteropDLL/DebugApiWrapper.cpp b/InteropDLL/DebugApiWrapper.cpp index 0eacced..22415f0 100644 --- a/InteropDLL/DebugApiWrapper.cpp +++ b/InteropDLL/DebugApiWrapper.cpp @@ -90,7 +90,7 @@ extern "C" 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 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 void __stdcall RemoveScript(int32_t scriptId) { GetDebugger()->GetScriptManager()->RemoveScript(scriptId); } diff --git a/InteropDLL/EmuApiWrapper.cpp b/InteropDLL/EmuApiWrapper.cpp index 2f55678..741e8fe 100644 --- a/InteropDLL/EmuApiWrapper.cpp +++ b/InteropDLL/EmuApiWrapper.cpp @@ -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 GetRomInfo(InteropRomInfo &info) diff --git a/UI/Debugger/EventViewer/ctrlEventViewerPpuView.cs b/UI/Debugger/EventViewer/ctrlEventViewerPpuView.cs index 062001b..66ee734 100644 --- a/UI/Debugger/EventViewer/ctrlEventViewerPpuView.cs +++ b/UI/Debugger/EventViewer/ctrlEventViewerPpuView.cs @@ -19,7 +19,6 @@ namespace Mesen.GUI.Debugger public partial class ctrlEventViewerPpuView : BaseControl { private int _baseWidth = 340 * 2; - private int _baseHeight = 262 * 2; private EntityBinder _entityBinder = new EntityBinder(); private Point _lastPos = new Point(-1, -1); @@ -29,6 +28,7 @@ namespace Mesen.GUI.Debugger private Bitmap _displayBitmap = null; private byte[] _pictureData = null; private Font _overlayFont; + private UInt32 _scanlineCount = 262; 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(); - DebugApi.TakeEventSnapshot(options); + _scanlineCount = DebugApi.TakeEventSnapshot(options); } public void RefreshViewer() { _entityBinder.UpdateObject(); 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) { _screenBitmap = 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); 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)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; 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; _needUpdate = false; } diff --git a/UI/Emulation/EmuRunner.cs b/UI/Emulation/EmuRunner.cs index 7e1558f..8468837 100644 --- a/UI/Emulation/EmuRunner.cs +++ b/UI/Emulation/EmuRunner.cs @@ -34,9 +34,10 @@ namespace Mesen.GUI.Emulation } _romPath = romPath; - EmuApi.LoadRom(romPath, patchPath); - ConfigManager.Config.RecentFiles.AddRecentFile(romPath, patchPath); - StartEmulation(); + if(EmuApi.LoadRom(romPath, patchPath)) { + ConfigManager.Config.RecentFiles.AddRecentFile(romPath, patchPath); + StartEmulation(); + } } public static void LoadPatchFile(string patchFile) diff --git a/UI/Interop/DebugApi.cs b/UI/Interop/DebugApi.cs index ccf860d..cbd7ae0 100644 --- a/UI/Interop/DebugApi.cs +++ b/UI/Interop/DebugApi.cs @@ -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 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); - 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); return buffer; } diff --git a/UI/Interop/EmuApi.cs b/UI/Interop/EmuApi.cs index 2a4e5be..7d40690 100644 --- a/UI/Interop/EmuApi.cs +++ b/UI/Interop/EmuApi.cs @@ -46,7 +46,7 @@ namespace Mesen.GUI [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 patchFile = "" );