Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Debugger: GB - Properly implemented vram/oam breakpoints
Browse files Browse the repository at this point in the history
+ Fixed access counters in gameboy-only mode
  • Loading branch information
SourMesen committed Jul 3, 2020
1 parent a223021 commit d4f0b34
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Core/DebugUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -72,6 +74,7 @@ class DebugUtilities
case SnesMemoryType::SpriteRam:
case SnesMemoryType::CGRam:
case SnesMemoryType::GbVideoRam:
case SnesMemoryType::GbSpriteRam:
return true;

default:
Expand Down
12 changes: 8 additions & 4 deletions Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CpuType cpuType>
Expand Down
11 changes: 9 additions & 2 deletions Core/GbPpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
9 changes: 3 additions & 6 deletions UI/Debugger/Breakpoints/Breakpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions UI/Debugger/Breakpoints/frmBreakpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
3 changes: 2 additions & 1 deletion UI/Debugger/MemoryTools/ctrlMemoryAccessCounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
17 changes: 17 additions & 0 deletions UI/Interop/DebugApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit d4f0b34

Please sign in to comment.