diff --git a/Core/DebugUtilities.h b/Core/DebugUtilities.h index 969181bb..df38c98a 100644 --- a/Core/DebugUtilities.h +++ b/Core/DebugUtilities.h @@ -48,9 +48,11 @@ class DebugUtilities case SnesMemoryType::GbPrgRom: case SnesMemoryType::GbWorkRam: case SnesMemoryType::GbCartRam: - case SnesMemoryType::GbVideoRam: case SnesMemoryType::GbHighRam: case SnesMemoryType::GbBootRom: + case SnesMemoryType::GbVideoRam: + case SnesMemoryType::GbSpriteRam: + case SnesMemoryType::GameboyMemory: return CpuType::Gameboy; default: @@ -72,6 +74,7 @@ class DebugUtilities case SnesMemoryType::SpriteRam: case SnesMemoryType::CGRam: case SnesMemoryType::GbVideoRam: + case SnesMemoryType::GbSpriteRam: return true; default: diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index cb0b218e..a70fced6 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -197,18 +197,22 @@ void Debugger::ProcessPpuRead(uint16_t addr, uint8_t value, SnesMemoryType memor { AddressInfo addressInfo { addr, memoryType }; MemoryOperationInfo operation { addr, value, MemoryOperationType::Read }; - ProcessBreakConditions(false, _cpuDebugger->GetBreakpointManager(), operation, addressInfo); + + BreakpointManager* bpManager = DebugUtilities::ToCpuType(memoryType) == CpuType::Gameboy ? _gbDebugger->GetBreakpointManager() : _cpuDebugger->GetBreakpointManager(); + ProcessBreakConditions(false, bpManager, operation, addressInfo); - _memoryAccessCounter->ProcessMemoryRead(addressInfo, _memoryManager->GetMasterClock()); + _memoryAccessCounter->ProcessMemoryRead(addressInfo, _console->GetMasterClock()); } void Debugger::ProcessPpuWrite(uint16_t addr, uint8_t value, SnesMemoryType memoryType) { AddressInfo addressInfo { addr, memoryType }; MemoryOperationInfo operation { addr, value, MemoryOperationType::Write }; - ProcessBreakConditions(false, _cpuDebugger->GetBreakpointManager(), operation, addressInfo); + + BreakpointManager* bpManager = DebugUtilities::ToCpuType(memoryType) == CpuType::Gameboy ? _gbDebugger->GetBreakpointManager() : _cpuDebugger->GetBreakpointManager(); + ProcessBreakConditions(false, bpManager, operation, addressInfo); - _memoryAccessCounter->ProcessMemoryWrite(addressInfo, _memoryManager->GetMasterClock()); + _memoryAccessCounter->ProcessMemoryWrite(addressInfo, _console->GetMasterClock()); } template diff --git a/Core/GbPpu.cpp b/Core/GbPpu.cpp index 52a5c428..bcdb4df4 100644 --- a/Core/GbPpu.cpp +++ b/Core/GbPpu.cpp @@ -811,7 +811,9 @@ bool GbPpu::IsVramWriteAllowed() uint8_t GbPpu::ReadVram(uint16_t addr) { if(IsVramReadAllowed()) { - return _vram[(_state.CgbVramBank << 13) | (addr & 0x1FFF)]; + uint16_t vramAddr = (_state.CgbVramBank << 13) | (addr & 0x1FFF); + _console->ProcessPpuRead(vramAddr, _vram[vramAddr], SnesMemoryType::GbVideoRam); + return _vram[vramAddr]; } else { _console->BreakImmediately(BreakSource::GbInvalidVramAccess); return 0xFF; @@ -826,7 +828,9 @@ uint8_t GbPpu::PeekVram(uint16_t addr) void GbPpu::WriteVram(uint16_t addr, uint8_t value) { if(IsVramWriteAllowed()) { - _vram[(_state.CgbVramBank << 13) | (addr & 0x1FFF)] = value; + uint16_t vramAddr = (_state.CgbVramBank << 13) | (addr & 0x1FFF); + _console->ProcessPpuWrite(vramAddr, value, SnesMemoryType::GbVideoRam); + _vram[vramAddr] = value; } else { _console->BreakImmediately(BreakSource::GbInvalidVramAccess); } @@ -870,6 +874,7 @@ uint8_t GbPpu::ReadOam(uint8_t addr) { if(addr < 0xA0) { if(IsOamReadAllowed()) { + _console->ProcessPpuRead(addr, _oam[addr], SnesMemoryType::GbSpriteRam); return _oam[addr]; } else { _console->BreakImmediately(BreakSource::GbInvalidOamAccess); @@ -887,8 +892,10 @@ void GbPpu::WriteOam(uint8_t addr, uint8_t value, bool forDma) if(addr < 0xA0) { if(forDma) { _oam[addr] = value; + _console->ProcessPpuWrite(addr, value, SnesMemoryType::GbSpriteRam); } else if(IsOamWriteAllowed()) { _oam[addr] = value; + _console->ProcessPpuWrite(addr, value, SnesMemoryType::GbSpriteRam); } else { _console->BreakImmediately(BreakSource::GbInvalidOamAccess); } diff --git a/UI/Debugger/Breakpoints/Breakpoint.cs b/UI/Debugger/Breakpoints/Breakpoint.cs index 2af026d9..deac9c2a 100644 --- a/UI/Debugger/Breakpoints/Breakpoint.cs +++ b/UI/Debugger/Breakpoints/Breakpoint.cs @@ -60,12 +60,7 @@ public string GetAddressString(bool showLabel) public static bool IsTypeCpuBreakpoint(SnesMemoryType type) { - return ( - type != SnesMemoryType.Register && - type != SnesMemoryType.VideoRam && - type != SnesMemoryType.CGRam && - type != SnesMemoryType.SpriteRam - ); + return type != SnesMemoryType.Register && !type.IsPpuMemory(); } public void SetEnabled(bool enabled) @@ -136,6 +131,8 @@ public string ToReadableType() case SnesMemoryType.GbCartRam: type = "SRAM"; break; case SnesMemoryType.GbHighRam: type = "HRAM"; break; case SnesMemoryType.GbBootRom: type = "BOOT"; break; + case SnesMemoryType.GbVideoRam: type = "VRAM"; break; + case SnesMemoryType.GbSpriteRam: type = "OAM"; break; case SnesMemoryType.Register: type = "REG"; break; } diff --git a/UI/Debugger/Breakpoints/frmBreakpoint.cs b/UI/Debugger/Breakpoints/frmBreakpoint.cs index 94528d62..17587986 100644 --- a/UI/Debugger/Breakpoints/frmBreakpoint.cs +++ b/UI/Debugger/Breakpoints/frmBreakpoint.cs @@ -92,6 +92,9 @@ public frmBreakpoint(Breakpoint breakpoint) if(DebugApi.GetMemorySize(SnesMemoryType.GbBootRom) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbBootRom)); } + cboBreakpointType.Items.Add("-"); + cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbVideoRam)); + cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbSpriteRam)); } this.toolTip.SetToolTip(this.picExpressionWarning, "Condition contains invalid syntax or symbols."); diff --git a/UI/Debugger/MemoryTools/ctrlMemoryAccessCounters.cs b/UI/Debugger/MemoryTools/ctrlMemoryAccessCounters.cs index 138b156b..6a885799 100644 --- a/UI/Debugger/MemoryTools/ctrlMemoryAccessCounters.cs +++ b/UI/Debugger/MemoryTools/ctrlMemoryAccessCounters.cs @@ -49,8 +49,9 @@ public void RefreshData() DebugApi.GetMemoryAccessCounts(_memoryType, ref _newCounts); + bool isGameboyMode = EmuApi.GetRomInfo().CoprocessorType == CoprocessorType.Gameboy; DebugState state = DebugApi.GetState(); - _masterClock = state.MasterClock; + _masterClock = isGameboyMode ? state.Gameboy.MemoryManager.CycleCount : state.MasterClock; _sorting = true; Task.Run(() => { diff --git a/UI/Interop/DebugApi.cs b/UI/Interop/DebugApi.cs index e7e41334..160e8047 100644 --- a/UI/Interop/DebugApi.cs +++ b/UI/Interop/DebugApi.cs @@ -253,6 +253,8 @@ public static CpuType ToCpuType(this SnesMemoryType memType) case SnesMemoryType.GbCartRam: case SnesMemoryType.GbHighRam: case SnesMemoryType.GbBootRom: + case SnesMemoryType.GbVideoRam: + case SnesMemoryType.GbSpriteRam: case SnesMemoryType.GameboyMemory: return CpuType.Gameboy; @@ -261,6 +263,21 @@ public static CpuType ToCpuType(this SnesMemoryType memType) } } + public static bool IsPpuMemory(this SnesMemoryType memType) + { + switch(memType) { + case SnesMemoryType.VideoRam: + case SnesMemoryType.SpriteRam: + case SnesMemoryType.CGRam: + case SnesMemoryType.GbVideoRam: + case SnesMemoryType.GbSpriteRam: + return true; + + default: + return false; + } + } + public static bool IsRelativeMemory(this SnesMemoryType memType) { switch(memType) {