diff --git a/Core/Debugger/Debugger.h b/Core/Debugger/Debugger.h index e2ffbf33..bef00b58 100644 --- a/Core/Debugger/Debugger.h +++ b/Core/Debugger/Debugger.h @@ -57,7 +57,7 @@ private: EmuSettings* _settings = nullptr; - CpuInfo _debuggers[(int)DebugUtilities::GetLastCpuType() + 1] = {}; + CpuInfo _debuggers[(int)DebugUtilities::GetLastCpuType() + 1]; CpuType _mainCpuType = CpuType::Snes; unordered_set _cpuTypes; diff --git a/Core/Debugger/Disassembler.cpp b/Core/Debugger/Disassembler.cpp index 1724e4ab..f7952c34 100644 --- a/Core/Debugger/Disassembler.cpp +++ b/Core/Debugger/Disassembler.cpp @@ -134,7 +134,7 @@ vector Disassembler::Disassemble(CpuType cpuType, uint16_t ba AddressInfo addrInfo = {}; - auto pushEndBlock = [&relAddress, &prevAddrInfo, &results, &inVerifiedBlock, &inUnknownBlock, &byteCounter, showData, showUnident, bytesPerRow]() { + auto pushEndBlock = [&]() { if(inUnknownBlock || inVerifiedBlock) { int flags = LineFlags::BlockEnd; if(inVerifiedBlock) { diff --git a/Core/Debugger/DisassemblySearch.cpp b/Core/Debugger/DisassemblySearch.cpp index bc3fddd6..e6625413 100644 --- a/Core/Debugger/DisassemblySearch.cpp +++ b/Core/Debugger/DisassemblySearch.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "Debugger/Disassembler.h" #include "Debugger/DisassemblySearch.h" diff --git a/Core/Gameboy/Debugger/GbDebugger.h b/Core/Gameboy/Debugger/GbDebugger.h index b9e53e91..3e6467e4 100644 --- a/Core/Gameboy/Debugger/GbDebugger.h +++ b/Core/Gameboy/Debugger/GbDebugger.h @@ -71,7 +71,7 @@ public: void SaveRomToDisk(string filename, bool saveAsIps, CdlStripOption stripOption); - void ProcessInputOverrides(DebugControllerState inputOverrides[8]); + void ProcessInputOverrides(DebugControllerState inputOverrides[8]) override; void SetProgramCounter(uint32_t addr) override; uint32_t GetProgramCounter(bool getInstPc) override; diff --git a/Core/NES/Debugger/NesDebugger.cpp b/Core/NES/Debugger/NesDebugger.cpp index 5423fec7..44c4fd8e 100644 --- a/Core/NES/Debugger/NesDebugger.cpp +++ b/Core/NES/Debugger/NesDebugger.cpp @@ -353,7 +353,7 @@ bool NesDebugger::IsRegister(MemoryOperationInfo& op) { if(op.Address >= 0x2000 && op.Address <= 0x3FFF) { return true; - } else if(op.Address >= 0x4000 && op.Address <= 0x4015 || (op.Address == 0x4017 && op.Type == MemoryOperationType::Write)) { + } else if((op.Address >= 0x4000 && op.Address <= 0x4015) || (op.Address == 0x4017 && op.Type == MemoryOperationType::Write)) { return true; } else if(op.Address == 0x4016 || (op.Address == 0x4017 && op.Type == MemoryOperationType::Read)) { return true; diff --git a/Core/NES/Debugger/NesDebugger.h b/Core/NES/Debugger/NesDebugger.h index 4045cdc3..3dd71296 100644 --- a/Core/NES/Debugger/NesDebugger.h +++ b/Core/NES/Debugger/NesDebugger.h @@ -66,7 +66,7 @@ public: void Reset() override; - uint64_t GetCpuCycleCount(); + uint64_t GetCpuCycleCount() override; void ProcessInstruction(); void ProcessRead(uint32_t addr, uint8_t value, MemoryOperationType type); @@ -76,7 +76,7 @@ public: void ProcessPpuWrite(uint16_t addr, uint8_t value, MemoryType memoryType); void ProcessPpuCycle(); - void ProcessInputOverrides(DebugControllerState inputOverrides[8]); + void ProcessInputOverrides(DebugControllerState inputOverrides[8]) override; void Run() override; void Step(int32_t stepCount, StepType type) override; diff --git a/Core/NES/Debugger/NesEventManager.cpp b/Core/NES/Debugger/NesEventManager.cpp index 64c4ff1d..3d9878a3 100644 --- a/Core/NES/Debugger/NesEventManager.cpp +++ b/Core/NES/Debugger/NesEventManager.cpp @@ -154,7 +154,7 @@ EventViewerCategoryCfg NesEventManager::GetEventConfig(DebugEventInfo& evt) } } else if(addr >= 0x4018 && _mapper->IsWriteRegister(addr)) { return _config.MapperRegisterWrites; - } else if(addr >= 0x4000 && addr <= 0x4015 || addr == 0x4017) { + } else if((addr >= 0x4000 && addr <= 0x4015) || addr == 0x4017) { return _config.ApuRegisterWrites; } else if(addr == 0x4016) { return _config.ControlRegisterWrites; diff --git a/Core/NES/Debugger/NesEventManager.h b/Core/NES/Debugger/NesEventManager.h index 9f45939e..153a2bac 100644 --- a/Core/NES/Debugger/NesEventManager.h +++ b/Core/NES/Debugger/NesEventManager.h @@ -78,9 +78,9 @@ public: void ClearFrameEvents() override; - EventViewerCategoryCfg GetEventConfig(DebugEventInfo& evt); + EventViewerCategoryCfg GetEventConfig(DebugEventInfo& evt) override; - uint32_t TakeEventSnapshot(); + uint32_t TakeEventSnapshot() override; FrameInfo GetDisplayBufferSize() override; diff --git a/Core/PCE/Debugger/PceDebugger.h b/Core/PCE/Debugger/PceDebugger.h index d837e008..20920ae3 100644 --- a/Core/PCE/Debugger/PceDebugger.h +++ b/Core/PCE/Debugger/PceDebugger.h @@ -67,7 +67,7 @@ public: void Reset() override; - uint64_t GetCpuCycleCount(); + uint64_t GetCpuCycleCount() override; void ProcessInstruction(); void ProcessRead(uint32_t addr, uint8_t value, MemoryOperationType type); @@ -90,7 +90,7 @@ public: ITraceLogger* GetTraceLogger() override; PpuTools* GetPpuTools() override; void SaveRomToDisk(string filename, bool saveAsIps, CdlStripOption stripOption); - void ProcessInputOverrides(DebugControllerState inputOverrides[8]); + void ProcessInputOverrides(DebugControllerState inputOverrides[8]) override; CallstackManager* GetCallstackManager() override; IAssembler* GetAssembler() override; BaseEventManager* GetEventManager() override; diff --git a/Core/PCE/Debugger/PceDisUtils.cpp b/Core/PCE/Debugger/PceDisUtils.cpp index e42298b3..a72f0c32 100644 --- a/Core/PCE/Debugger/PceDisUtils.cpp +++ b/Core/PCE/Debugger/PceDisUtils.cpp @@ -84,7 +84,7 @@ void PceDisUtils::GetDisassembly(DisassemblyInfo& info, string& out, uint32_t me } }; - auto writeZeroAddr = [&str, &info, &writeLabelOrAddr, labelManager](uint8_t zero) { + auto writeZeroAddr = [&str](uint8_t zero) { str.WriteAll('$', HexUtilities::ToHex(zero)); }; diff --git a/Core/PCE/IPceMapper.h b/Core/PCE/IPceMapper.h index 469019f6..2afcdb75 100644 --- a/Core/PCE/IPceMapper.h +++ b/Core/PCE/IPceMapper.h @@ -4,6 +4,8 @@ class IPceMapper { public: + virtual ~IPceMapper() = default; + virtual uint8_t Read(uint8_t bank, uint16_t addr, uint8_t value) { return value; } virtual void Write(uint8_t bank, uint16_t addr, uint8_t value) {} }; diff --git a/Core/PCE/PceTimer.h b/Core/PCE/PceTimer.h index a6b659cf..6475bfb2 100644 --- a/Core/PCE/PceTimer.h +++ b/Core/PCE/PceTimer.h @@ -11,7 +11,6 @@ private: uint16_t _scaler = 1024 * 3; bool _enabled = false; PceMemoryManager* _memoryManager = nullptr; - uint64_t _lastClock = 0; public: PceTimer(PceMemoryManager* memoryManager); diff --git a/Core/SNES/Debugger/SnesDebugger.cpp b/Core/SNES/Debugger/SnesDebugger.cpp index 6bba39df..b9ce4a17 100644 --- a/Core/SNES/Debugger/SnesDebugger.cpp +++ b/Core/SNES/Debugger/SnesDebugger.cpp @@ -117,7 +117,7 @@ void SnesDebugger::ProcessConfigChange() _runSpc = _spcTraceLogger->IsEnabled() || _settings->CheckDebuggerFlag(DebuggerFlags::SpcDebuggerEnabled); _runCoprocessors = ( - _dspTraceLogger && _dspTraceLogger->IsEnabled() || + (_dspTraceLogger && _dspTraceLogger->IsEnabled()) || _settings->CheckDebuggerFlag(DebuggerFlags::NecDspDebuggerEnabled) || _settings->CheckDebuggerFlag(DebuggerFlags::GbDebuggerEnabled) ); diff --git a/Core/SNES/Debugger/SnesDebugger.h b/Core/SNES/Debugger/SnesDebugger.h index 31c731d8..eec28278 100644 --- a/Core/SNES/Debugger/SnesDebugger.h +++ b/Core/SNES/Debugger/SnesDebugger.h @@ -85,7 +85,7 @@ public: void ProcessConfigChange() override; - uint64_t GetCpuCycleCount(); + uint64_t GetCpuCycleCount() override; void ProcessInstruction(); void ProcessRead(uint32_t addr, uint8_t value, MemoryOperationType type); @@ -116,5 +116,5 @@ public: void GetPpuState(BaseState& state) override; void SetPpuState(BaseState& state) override; void SaveRomToDisk(string filename, bool saveAsIps, CdlStripOption stripOption); - void ProcessInputOverrides(DebugControllerState inputOverrides[8]); + void ProcessInputOverrides(DebugControllerState inputOverrides[8]) override; }; \ No newline at end of file diff --git a/Core/stdafx.h b/Core/stdafx.h index a1bf691f..f3f7af30 100644 --- a/Core/stdafx.h +++ b/Core/stdafx.h @@ -6,6 +6,9 @@ #pragma warning( disable : 4245 ) //conversion from 'x' to 'y', signed/unsigned mismatch #endif +//TODO, fix warnings and remove this +#pragma clang diagnostic ignored "-Wswitch" + #include #include #include diff --git a/InteropDLL/EmuApiWrapper.cpp b/InteropDLL/EmuApiWrapper.cpp index 6dce4afd..dc9d13b4 100644 --- a/InteropDLL/EmuApiWrapper.cpp +++ b/InteropDLL/EmuApiWrapper.cpp @@ -183,14 +183,15 @@ extern "C" { DllExport bool __stdcall IsPaused() { - //TODO sometimes crashes when called after refresh (e.g by timer, etc.) return _emu->IsPaused(); } DllExport void __stdcall Release() { - _emu->Stop(true); - _emu->Release(); + if(_emu) { + _emu->Stop(true); + _emu->Release(); + } _renderer.reset(); _soundManager.reset(); diff --git a/NewUI/Program.cs b/NewUI/Program.cs index a337fb03..83d5bf90 100644 --- a/NewUI/Program.cs +++ b/NewUI/Program.cs @@ -12,6 +12,7 @@ using System.Reflection; using System.Threading.Tasks; using System.Diagnostics; using System.Runtime.InteropServices; +using Mesen.Interop; namespace Mesen { @@ -60,6 +61,7 @@ namespace Mesen Program.CommandLineArgs = (string[])args.Clone(); bool useWgl = args.Any(arg => arg.ToLowerInvariant() == "-wgl"); BuildAvaloniaApp(useWgl).StartWithClassicDesktopLifetime(args, ShutdownMode.OnMainWindowClose); + EmuApi.Release(); } } diff --git a/NewUI/Utilities/MouseManager.cs b/NewUI/Utilities/MouseManager.cs index 18b7d0f6..16b58e25 100644 --- a/NewUI/Utilities/MouseManager.cs +++ b/NewUI/Utilities/MouseManager.cs @@ -16,7 +16,7 @@ using System.Threading.Tasks; namespace Mesen.Utilities { - public class MouseManager + public class MouseManager : IDisposable { private const int LeftMouseButtonKeyCode = 0x200; private const int RightMouseButtonKeyCode = 0x201; @@ -228,5 +228,12 @@ namespace Mesen.Utilities } } + public void Dispose() + { + if(_timer is DispatcherTimer timer) { + timer.Tick -= tmrProcessMouse; + timer.Stop(); + } + } } } diff --git a/NewUI/Windows/MainWindow.axaml.cs b/NewUI/Windows/MainWindow.axaml.cs index 9bc08590..6de6b386 100644 --- a/NewUI/Windows/MainWindow.axaml.cs +++ b/NewUI/Windows/MainWindow.axaml.cs @@ -103,7 +103,7 @@ namespace Mesen.Windows protected override void OnClosed(EventArgs e) { base.OnClosed(e); - EmuApi.Release(); + _mouseManager.Dispose(); } protected override void OnDataContextChanged(EventArgs e) diff --git a/Utilities/Audio/HermiteResampler.cpp b/Utilities/Audio/HermiteResampler.cpp index aec57f21..475ad026 100644 --- a/Utilities/Audio/HermiteResampler.cpp +++ b/Utilities/Audio/HermiteResampler.cpp @@ -77,13 +77,13 @@ uint32_t HermiteResampler::Resample(int16_t* in, uint32_t inSampleCount, int16_t _pendingSamples.clear(); if(_rateRatio == 1.0) { - uint32_t count = std::min((uint32_t)maxOutSampleCount, inSampleCount * 2); - memcpy(out, in, count * sizeof(int16_t)); - for(uint32_t i = count; count < inSampleCount * 2; i += 2) { + uint32_t count = std::min((uint32_t)maxOutSampleCount - outPos, inSampleCount * 2); + memcpy(out+outPos, in, count * sizeof(int16_t)); + for(uint32_t i = count; i < inSampleCount * 2; i += 2) { _pendingSamples.push_back(in[i]); _pendingSamples.push_back(in[i + 1]); } - return count / 2; + return (count + outPos) / 2; } for(uint32_t i = 0; i < inSampleCount * 2; i += 2) { diff --git a/Utilities/Audio/WavReader.h b/Utilities/Audio/WavReader.h index 7ec3f9a8..3ddc5564 100644 --- a/Utilities/Audio/WavReader.h +++ b/Utilities/Audio/WavReader.h @@ -5,7 +5,6 @@ class WavReader { private: - int16_t* _outputBuffer = nullptr; uint8_t* _fileData = nullptr; uint32_t _fileOffset = 0;