From 4c4d3c75d6c9fb88aedb41201140d7b7883a7675 Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 3 Jul 2020 14:06:02 -0400 Subject: [PATCH] Debugger: GB - Fixed crash when debugger accessed APU registers while running --- Core/DebugUtilities.h | 3 +++ Core/GbApu.cpp | 9 +++++++++ Core/GbApu.h | 3 +++ Core/GbMemoryManager.cpp | 2 ++ 4 files changed, 17 insertions(+) diff --git a/Core/DebugUtilities.h b/Core/DebugUtilities.h index df38c98..0220e71 100644 --- a/Core/DebugUtilities.h +++ b/Core/DebugUtilities.h @@ -90,6 +90,9 @@ public: case SnesMemoryType::GbBootRom: case SnesMemoryType::SaveRam: //Include save ram here to avoid uninit memory read warnings on save ram return true; + + default: + return false; } } diff --git a/Core/GbApu.cpp b/Core/GbApu.cpp index 9a56eaa..3a77a76 100644 --- a/Core/GbApu.cpp +++ b/Core/GbApu.cpp @@ -161,10 +161,19 @@ void GbApu::ClockFrameSequencer() _state.FrameSequenceStep = (_state.FrameSequenceStep + 1) & 0x07; } +uint8_t GbApu::Peek(uint16_t addr) +{ + return InternalRead(addr); +} + uint8_t GbApu::Read(uint16_t addr) { Run(); + return InternalRead(addr); +} +uint8_t GbApu::InternalRead(uint16_t addr) +{ switch(addr) { case 0xFF10: case 0xFF11: case 0xFF12: case 0xFF13: case 0xFF14: return _square1->Read(addr - 0xFF10); diff --git a/Core/GbApu.h b/Core/GbApu.h index 073a663..ca13e6f 100644 --- a/Core/GbApu.h +++ b/Core/GbApu.h @@ -40,6 +40,8 @@ private: GbApuState _state = {}; + uint8_t InternalRead(uint16_t addr); + public: GbApu(); virtual ~GbApu(); @@ -54,6 +56,7 @@ public: void ClockFrameSequencer(); + uint8_t Peek(uint16_t addr); uint8_t Read(uint16_t addr); void Write(uint16_t addr, uint8_t value); diff --git a/Core/GbMemoryManager.cpp b/Core/GbMemoryManager.cpp index 550d281..d1a1003 100644 --- a/Core/GbMemoryManager.cpp +++ b/Core/GbMemoryManager.cpp @@ -231,6 +231,8 @@ uint8_t GbMemoryManager::PeekRegister(uint16_t addr) return _ppu->PeekOam((uint8_t)addr); } else if(addr >= 0x8000 && addr <= 0x9FFF) { return _ppu->PeekVram(addr); + } else if(addr >= 0xFF10 && addr <= 0xFF3F) { + return _apu->Peek(addr); } else { return ReadRegister(addr); }