Debugger: Improved bound checking for memory read/writes

This commit is contained in:
Souryo 2017-11-11 13:24:48 -05:00
parent efc934ee8e
commit 66197f2c09
3 changed files with 39 additions and 22 deletions

View File

@ -916,25 +916,38 @@ uint32_t BaseMapper::GetMemorySize(DebugMemoryType type)
uint8_t BaseMapper::GetMemoryValue(DebugMemoryType memoryType, uint32_t address)
{
switch(memoryType) {
case DebugMemoryType::ChrRom: return _onlyChrRam ? _chrRam[address] : _chrRom[address];
case DebugMemoryType::ChrRam: return _chrRam[address];
case DebugMemoryType::SaveRam: return _saveRam[address];
case DebugMemoryType::PrgRom: return _prgRom[address];
case DebugMemoryType::WorkRam: return _workRam[address];
}
uint32_t memorySize = GetMemorySize(memoryType);
if(memorySize > 0) {
if(address > memorySize) {
address %= memorySize;
}
switch(memoryType) {
case DebugMemoryType::ChrRom: return _chrRom[address];
case DebugMemoryType::ChrRam: return _chrRam[address];
case DebugMemoryType::SaveRam: return _saveRam[address];
case DebugMemoryType::PrgRom: return _prgRom[address];
case DebugMemoryType::WorkRam: return _workRam[address];
}
}
return 0;
}
void BaseMapper::SetMemoryValue(DebugMemoryType memoryType, uint32_t address, uint8_t value)
{
switch(memoryType) {
case DebugMemoryType::ChrRom: _chrRom[address] = value; break;
case DebugMemoryType::ChrRam: _chrRam[address] = value; break;
case DebugMemoryType::SaveRam: _saveRam[address] = value; break;
case DebugMemoryType::PrgRom: _prgRom[address] = value; break;
case DebugMemoryType::WorkRam: _workRam[address] = value; break;
uint32_t memorySize = GetMemorySize(memoryType);
if(memorySize > 0) {
if(address > memorySize) {
address %= memorySize;
}
switch(memoryType) {
case DebugMemoryType::ChrRom: _chrRom[address] = value; break;
case DebugMemoryType::ChrRam: _chrRam[address] = value; break;
case DebugMemoryType::SaveRam: _saveRam[address] = value; break;
case DebugMemoryType::PrgRom: _prgRom[address] = value; break;
case DebugMemoryType::WorkRam: _workRam[address] = value; break;
}
}
}

View File

@ -148,8 +148,8 @@ void MemoryDumper::SetMemoryValue(DebugMemoryType memoryType, uint32_t address,
case DebugMemoryType::PpuMemory: _mapper->DebugWriteVRAM(address, value, disableSideEffects); break;
case DebugMemoryType::PaletteMemory: _ppu->WritePaletteRAM(address, value); break;
case DebugMemoryType::SpriteMemory: _ppu->GetSpriteRam()[address] = value; break;
case DebugMemoryType::SecondarySpriteMemory: _ppu->GetSecondarySpriteRam()[address] = value; break;
case DebugMemoryType::SpriteMemory: _ppu->GetSpriteRam()[address % 0x100] = value; break;
case DebugMemoryType::SecondarySpriteMemory: _ppu->GetSecondarySpriteRam()[address % 0x20] = value; break;
case DebugMemoryType::PrgRom:
_mapper->SetMemoryValue(memoryType, address, value);
@ -202,8 +202,8 @@ uint8_t MemoryDumper::GetMemoryValue(DebugMemoryType memoryType, uint32_t addres
case DebugMemoryType::PpuMemory: return _mapper->DebugReadVRAM(address, disableSideEffects);
case DebugMemoryType::PaletteMemory: return _ppu->ReadPaletteRAM(address);
case DebugMemoryType::SpriteMemory: return _ppu->GetSpriteRam()[address];
case DebugMemoryType::SecondarySpriteMemory: return _ppu->GetSecondarySpriteRam()[address];
case DebugMemoryType::SpriteMemory: return _ppu->GetSpriteRam()[address % 0x100];
case DebugMemoryType::SecondarySpriteMemory: return _ppu->GetSecondarySpriteRam()[address % 0x20];
case DebugMemoryType::PrgRom:
case DebugMemoryType::ChrRom:

View File

@ -331,8 +331,11 @@ namespace Mesen.GUI.Debugger.Controls
int tileIndex = GetLargeSpriteIndex(_tileIndex);
byte orgByte1 = InteropEmu.DebugGetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + y));
byte orgByte2 = InteropEmu.DebugGetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + y + 8));
bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
DebugMemoryType memType = ppuMemory? DebugMemoryType.PpuMemory : (isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom);
byte orgByte1 = InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y));
byte orgByte2 = InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y + 8));
byte byte1 = (byte)(orgByte1 & ~(0x80 >> x));
byte byte2 = (byte)(orgByte2 & ~(0x80 >> x));
@ -345,8 +348,8 @@ namespace Mesen.GUI.Debugger.Controls
}
if(byte1 != orgByte1 || byte2 != orgByte2) {
InteropEmu.DebugSetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + y), byte1);
InteropEmu.DebugSetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + y + 8), byte2);
InteropEmu.DebugSetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y), byte1);
InteropEmu.DebugSetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y + 8), byte2);
GetData();
RefreshViewer();
@ -395,10 +398,11 @@ namespace Mesen.GUI.Debugger.Controls
int tileIndex = GetLargeSpriteIndex(_tileIndex);
bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0;
DebugMemoryType memType = ppuMemory ? DebugMemoryType.PpuMemory : (isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom);
StringBuilder sb = new StringBuilder();
if(isChrRam) {
for(int i = 0; i < 16; i++) {
sb.Append(InteropEmu.DebugGetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + i)).ToString("X2"));
sb.Append(InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + i)).ToString("X2"));
}
} else {
int absoluteTileIndex = ppuMemory ? InteropEmu.DebugGetAbsoluteChrAddress((uint)(baseAddress+tileIndex*16))/16 : (baseAddress / 16 + tileIndex);